+/*** Authentication Selection Page ***/
+
+AuthenticationSelectionPage::AuthenticationSelectionPage(const QHash<QString, QVariant> &backends, QWidget *parent)
+ : QWizardPage(parent),
+ _connectionBox(0),
+ _backends(backends)
+{
+ ui.setupUi(this);
+
+ setTitle(tr("Select Authentication Backend"));
+ setSubTitle(tr("Please select a backend for Quassel Core to use for authenticating users."));
+ setCommitPage(true);
+
+ registerField("authentication.backend", ui.backendList);
+
+ foreach(QString key, _backends.keys()) {
+ ui.backendList->addItem(_backends[key].toMap()["DisplayName"].toString(), key);
+ }
+
+ on_backendList_currentIndexChanged();
+}
+
+
+int AuthenticationSelectionPage::nextId() const
+{
+ return CoreConfigWizard::StorageSelectionPage;
+}
+
+
+QString AuthenticationSelectionPage::selectedBackend() const
+{
+ return ui.backendList->currentText();
+}
+
+
+QVariantMap AuthenticationSelectionPage::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;
+ }
+ }
+ return properties;
+}
+
+
+void AuthenticationSelectionPage::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);
+ }
+ propertyBox->setLayout(formlayout);
+ static_cast<QVBoxLayout *>(layout())->insertWidget(layout()->indexOf(ui.descriptionBox) + 1, propertyBox);
+ _connectionBox = propertyBox;
+ }
+}