-StorageSelectionPage::StorageSelectionPage(const QHash<QString, QVariant> &backends, QWidget *parent)
- : QWizardPage(parent),
- _connectionBox(0),
- _backends(backends)
-{
- ui.setupUi(this);
-
- 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;
- QStringList setupKeys = _backends[backend].toMap()["SetupKeys"].toStringList();
- if(!setupKeys.isEmpty()) {
- QVariantMap defaults = _backends[backend].toMap()["SetupDefaults"].toMap();
- foreach(QString key, setupKeys) {
- QWidget *widget = _connectionBox->findChild<QWidget *>(key);
- QVariant def;
- if(defaults.contains(key)) {
- def = defaults[key];
- }
- switch(def.type()) {
- case QVariant::Int:
- {
- QSpinBox *spinbox = qobject_cast<QSpinBox *>(widget);
- Q_ASSERT(spinbox);
- def = QVariant(spinbox->value());
- }
- break;
- default:
- {
- QLineEdit *lineEdit = qobject_cast<QLineEdit *>(widget);
- Q_ASSERT(lineEdit);
- def = QVariant(lineEdit->text());
- }
- }
- properties[key] = def;
- }
- }
- qDebug() << properties;
-
-
-// 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;
- }
-
- QStringList setupKeys = _backends[backend].toMap()["SetupKeys"].toStringList();
- if(!setupKeys.isEmpty()) {
- QVariantMap defaults = _backends[backend].toMap()["SetupDefaults"].toMap();
- QGroupBox *propertyBox = new QGroupBox(this);
- propertyBox->setTitle(tr("Connection Properties"));
- QFormLayout *formlayout = new QFormLayout;
-
- foreach(QString key, setupKeys) {
- QWidget *widget = 0;
- QVariant def;
- if(defaults.contains(key)) {
- def = defaults[key];
- }
- switch(def.type()) {
- case QVariant::Int:
- {
- QSpinBox *spinbox = new QSpinBox(propertyBox);
- spinbox->setMaximum(64000);
- spinbox->setValue(def.toInt());
- widget = spinbox;
- }
- break;
- default:
- {
- QLineEdit *lineEdit = new QLineEdit(def.toString(), propertyBox);
- if(key.toLower().contains("password")) {
- lineEdit->setEchoMode(QLineEdit::Password);
- }
- widget = lineEdit;
- }
- }
- widget->setObjectName(key);
- formlayout->addRow(key + ":", widget);
+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()));