ldap: Some cleanups for GH-170
[quassel.git] / src / qtui / coreconfigwizard.cpp
index d2ce4b8..a4cfe16 100644 (file)
@@ -27,6 +27,8 @@
 #include "coreconfigwizard.h"
 #include "coreconnection.h"
 
+#include "client.h"
+
 CoreConfigWizard::CoreConfigWizard(CoreConnection *connection, const QList<QVariant> &backends, const QList<QVariant> &authenticators, QWidget *parent)
     : QWizard(parent),
     _connection(connection)
@@ -35,18 +37,18 @@ CoreConfigWizard::CoreConfigWizard(CoreConnection *connection, const QList<QVari
     setAttribute(Qt::WA_DeleteOnClose);
 
     foreach(const QVariant &v, backends)
-    _backends[v.toMap()["DisplayName"].toString()] = v;
-    
+        _backends[v.toMap()["DisplayName"].toString()] = v;
+
     foreach(const QVariant &v, authenticators)
-    _authenticators[v.toMap()["DisplayName"].toString()] = v;
+        _authenticators[v.toMap()["DisplayName"].toString()] = v;
 
     setPage(IntroPage, new CoreConfigWizardPages::IntroPage(this));
     setPage(AdminUserPage, new CoreConfigWizardPages::AdminUserPage(this));
     setPage(AuthenticationSelectionPage, new CoreConfigWizardPages::AuthenticationSelectionPage(_authenticators, this));
     setPage(StorageSelectionPage, new CoreConfigWizardPages::StorageSelectionPage(_backends, this));
     syncPage = new CoreConfigWizardPages::SyncPage(this);
-    connect(syncPage, SIGNAL(setupCore(const QString &, const QVariantMap &, const QString &, const QVariantMap &)), 
-                       SLOT(prepareCoreSetup(const QString &, const QVariantMap &, const QString &, const QVariantMap &)));
+    connect(syncPage, SIGNAL(setupCore(const QString &, const QVariantMap &, const QString &, const QVariantMap &)),
+            SLOT(prepareCoreSetup(const QString &, const QVariantMap &, const QString &, const QVariantMap &)));
     setPage(SyncPage, syncPage);
     syncRelayPage = new CoreConfigWizardPages::SyncRelayPage(this);
     connect(syncRelayPage, SIGNAL(startOver()), this, SLOT(startOver()));
@@ -87,18 +89,27 @@ QHash<QString, QVariant> CoreConfigWizard::backends() const
     return _backends;
 }
 
+
 QHash<QString, QVariant> CoreConfigWizard::authenticators() const
 {
-       return _authenticators;
+    return _authenticators;
 }
 
-void CoreConfigWizard::prepareCoreSetup(const QString &backend, const QVariantMap &properties, const QString &authBackend, const QVariantMap &authProperties)
+
+void CoreConfigWizard::prepareCoreSetup(const QString &backend, const QVariantMap &properties, const QString &authenticator, const QVariantMap &authProperties)
 {
     // Prevent the user from changing any settings he already specified...
     foreach(int idx, visitedPages())
     page(idx)->setEnabled(false);
 
-    coreConnection()->setupCore(Protocol::SetupData(field("adminUser.user").toString(), field("adminUser.password").toString(), backend, authBackend, properties, authProperties));
+    // FIXME? We need to be able to set up older cores that don't have auth backend support.
+    // So if the core doesn't support that feature, don't pass those parameters.
+    if (!(Client::coreFeatures() & Quassel::Authenticators)) {
+        coreConnection()->setupCore(Protocol::SetupData(field("adminUser.user").toString(), field("adminUser.password").toString(), backend, properties));
+    }
+    else {
+        coreConnection()->setupCore(Protocol::SetupData(field("adminUser.user").toString(), field("adminUser.password").toString(), backend, properties, authenticator, authProperties));
+    }
 }
 
 
@@ -184,7 +195,13 @@ AdminUserPage::AdminUserPage(QWidget *parent) : QWizardPage(parent)
 
 int AdminUserPage::nextId() const
 {
-    return CoreConfigWizard::AuthenticationSelectionPage;
+    // If the core doesn't support auth backends, skip that page!
+    if (!(Client::coreFeatures() & Quassel::Authenticators)) {
+        return CoreConfigWizard::StorageSelectionPage;
+    }
+    else {
+        return CoreConfigWizard::AuthenticationSelectionPage;
+    }
 }
 
 
@@ -261,31 +278,6 @@ QVariantMap AuthenticationSelectionPage::connectionProperties() const
             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;
 }
 
@@ -510,23 +502,23 @@ void SyncPage::initializePage()
     complete = false;
     hasError = false;
 
-       // Fill in sync info about the storage layer. 
+    // Fill in sync info about the storage layer.
     StorageSelectionPage *storagePage = qobject_cast<StorageSelectionPage *>(wizard()->page(CoreConfigWizard::StorageSelectionPage));
     QString backend = storagePage->selectedBackend();
     QVariantMap properties = storagePage->connectionProperties();
-       Q_ASSERT(!backend.isEmpty());
+    Q_ASSERT(!backend.isEmpty());
     ui.backend->setText(backend);
-    
-       // Fill in synci nfo about the authentication layer.
-       AuthenticationSelectionPage *authPage = qobject_cast<AuthenticationSelectionPage *>(wizard()->page(CoreConfigWizard::AuthenticationSelectionPage));
-       QString authBackend = authPage->selectedBackend();
+
+    // Fill in sync info about the authentication layer.
+    AuthenticationSelectionPage *authPage = qobject_cast<AuthenticationSelectionPage *>(wizard()->page(CoreConfigWizard::AuthenticationSelectionPage));
+    QString authenticator = authPage->selectedBackend();
     QVariantMap authProperties = authPage->connectionProperties();
-       Q_ASSERT(!authBackend.isEmpty());
-    ui.authBackend->setText(authBackend);
+    Q_ASSERT(!authenticator.isEmpty());
+    ui.authenticator->setText(authenticator);
 
     ui.user->setText(wizard()->field("adminUser.user").toString());
 
-       emit setupCore(backend, properties, authBackend, authProperties);
+    emit setupCore(backend, properties, authenticator, authProperties);
 }