-StorageSelectionPage::StorageSelectionPage(const QHash<QString, QVariant> &backends, QWidget *parent) : QWizardPage(parent) {
- ui.setupUi(this);
- _backends = backends;
-
- setTitle(tr("Select Storage Backend"));
- setSubTitle(tr("Please select a database backend for the Quassel Core storage to store the backlog and other data in."));
- setCommitPage(true);
-
- registerField("storage.backend", ui.backendList);
-
- foreach(QString key, _backends.keys()) {
- ui.backendList->addItem(_backends[key].toMap()["DisplayName"].toString(), key);
- }
-
- on_backendList_currentIndexChanged();
-}
-
-int StorageSelectionPage::nextId() const {
- return CoreConfigWizard::SyncPage;
-}
-
-QString StorageSelectionPage::selectedBackend() const {
- return ui.backendList->currentText();
-}
-
-QVariantMap StorageSelectionPage::connectionProperties() const {
- QString backend = ui.backendList->itemData(ui.backendList->currentIndex()).toString();
- QVariantMap properties = _backends[backend].toMap()["ConnectionProperties"].toMap();
- if(!properties.isEmpty() && _connectionBox) {
- QVariantMap::iterator propertyIter = properties.begin();
- while(propertyIter != properties.constEnd()) {
- QWidget *widget = _connectionBox->findChild<QWidget *>(propertyIter.key());
- switch(propertyIter.value().type()) {
- case QVariant::Int:
- {
- QSpinBox *spinbox = qobject_cast<QSpinBox *>(widget);
- Q_ASSERT(spinbox);
- propertyIter.value() = QVariant(spinbox->value());
- }
- break;
- default:
- {
- QLineEdit *lineEdit = qobject_cast<QLineEdit *>(widget);
- Q_ASSERT(lineEdit);
- propertyIter.value() = QVariant(lineEdit->text());
- }
- }
- propertyIter++;
- }
- }
- return properties;
-}
-
-void StorageSelectionPage::on_backendList_currentIndexChanged() {
- QString backend = ui.backendList->itemData(ui.backendList->currentIndex()).toString();
- ui.description->setText(_backends[backend].toMap()["Description"].toString());
-
- if(_connectionBox) {
- layout()->removeWidget(_connectionBox);
- _connectionBox->deleteLater();
- _connectionBox = 0;
- }
-
- QVariantMap properties = _backends[backend].toMap()["ConnectionProperties"].toMap();
- if(!properties.isEmpty()) {
- QGroupBox *propertyBox = new QGroupBox(this);
- propertyBox->setTitle(tr("Connection Properties"));
- QFormLayout *formlayout = new QFormLayout;
-
- QVariantMap::const_iterator propertyIter = properties.constBegin();
- while(propertyIter != properties.constEnd()) {
- QWidget *widget = 0;
- switch(propertyIter.value().type()) {
- case QVariant::Int:
- {
- QSpinBox *spinbox = new QSpinBox(propertyBox);
- spinbox->setMaximum(64000);
- spinbox->setValue(propertyIter.value().toInt());
- widget = spinbox;
- }
- break;
- default:
- widget = new QLineEdit(propertyIter.value().toString(), propertyBox);
- }
- widget->setObjectName(propertyIter.key());
- formlayout->addRow(propertyIter.key() + ":", widget);
- propertyIter++;
+StorageSelectionPage::StorageSelectionPage(const QVariantList& backendInfos, QWidget* parent)
+ : QWizardPage(parent)
+{
+ ui.setupUi(this);
+
+ setTitle(tr("Select Storage Backend"));
+ setSubTitle(tr("Please select a storage backend for Quassel Core."));
+ setCommitPage(true);
+
+ registerField("storage.backend", ui.backendList);
+
+ int defaultIndex{0}; // Legacy cores send backend infos in arbitrary order
+
+ for (auto&& backendInfo : backendInfos) {
+ auto props = backendInfo.toMap();
+ // Extract field infos to avoid having to reparse the list
+ std::vector<FieldInfo> fields;
+
+ // Legacy cores (prior to 0.13) didn't send SetupData for storage backends; deal with this
+ if (!props.contains("SetupData")) {
+ const auto& defaultValues = props["SetupDefaults"].toMap();
+ for (auto&& key : props["SetupKeys"].toStringList()) {
+ fields.emplace_back(std::make_tuple(key, key, defaultValues.value(key, QString{})));
+ }
+ if (props.value("IsDefault", false).toBool()) {
+ defaultIndex = ui.backendList->count();
+ }
+ }
+ else {
+ const auto& list = props["SetupData"].toList();
+ for (int i = 0; i + 2 < list.size(); i += 3) {
+ fields.emplace_back(std::make_tuple(list[i].toString(), list[i + 1].toString(), list[i + 2]));
+ }
+ props.remove("SetupData");
+ }
+ props.remove("SetupKeys");
+ props.remove("SetupDefaults");
+ // Legacy cores (prior to 0.13) don't send the BackendId property
+ if (!props.contains("BackendId"))
+ props["BackendId"] = props["DisplayName"];
+ _backendProperties.emplace_back(std::move(props));
+ _backendFields.emplace_back(std::move(fields));
+
+ // Create widgets
+ ui.backendList->addItem(_backendProperties.back()["DisplayName"].toString(), _backendProperties.back()["BackendId"].toString());
+ ui.descriptionStack->addWidget(createDescriptionBox(_backendProperties.back()["Description"].toString()));
+ ui.storageSettingsStack->addWidget(createFieldBox(tr("Storage Settings"), _backendFields.back()));