X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fcoreconfigwizard.cpp;h=72a16bb9494e9e0f4f06a2f495c37ffb160e9215;hp=8225fe47f36e29910f98515ed86dd57a6316f102;hb=HEAD;hpb=b40672ab5c48b577b31371c159e60d330fdd7ce5 diff --git a/src/qtui/coreconfigwizard.cpp b/src/qtui/coreconfigwizard.cpp index 8225fe47..72a16bb9 100644 --- a/src/qtui/coreconfigwizard.cpp +++ b/src/qtui/coreconfigwizard.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2018 by the Quassel Project * + * Copyright (C) 2005-2022 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -20,19 +20,20 @@ #include "coreconfigwizard.h" -#include #include #include +#include #include #include #include "client.h" #include "coreconnection.h" #include "icon.h" +#include "util.h" namespace { -QGroupBox *createDescriptionBox(const QString &description) +QGroupBox* createDescriptionBox(const QString& description) { auto box = new QGroupBox; auto layout = new QVBoxLayout(box); @@ -44,9 +45,8 @@ QGroupBox *createDescriptionBox(const QString &description) return box; } - template -QGroupBox *createFieldBox(const QString &title, const std::vector &fieldInfos) +QGroupBox* createFieldBox(const QString& title, const std::vector& fieldInfos) { // Create a config UI based on the field types sent from the backend // We make some assumptions here (like integer range and password field names) that may not @@ -54,29 +54,29 @@ QGroupBox *createFieldBox(const QString &title, const std::vector &fi // provide specialized config widgets for those (which may be a good idea anyway, e.g. if we // think about client-side translations...) - auto *fieldBox = new QGroupBox; + auto* fieldBox = new QGroupBox; fieldBox->setTitle(title); - auto *formLayout = new QFormLayout; + auto* formLayout = new QFormLayout; fieldBox->setLayout(formLayout); - for (auto &&fieldInfo : fieldInfos) { - QWidget *widget {nullptr}; + for (auto&& fieldInfo : fieldInfos) { + QWidget* widget{nullptr}; switch (std::get<2>(fieldInfo).type()) { - case QVariant::Int: - widget = new QSpinBox(fieldBox); - // Here we assume that int fields are always in 16 bit range, like ports - static_cast(widget)->setMinimum(0); - static_cast(widget)->setMaximum(65535); - static_cast(widget)->setValue(std::get<2>(fieldInfo).toInt()); - break; - case QVariant::String: - widget = new QLineEdit(std::get<2>(fieldInfo).toString(), fieldBox); - // Here we assume that fields named something with "password" are actual password inputs - if (std::get<0>(fieldInfo).toLower().contains("password")) - static_cast(widget)->setEchoMode(QLineEdit::Password); - break; - default: - qWarning() << "Unsupported type for backend property" << std::get<0>(fieldInfo); + case QVariant::Int: + widget = new QSpinBox(fieldBox); + // Here we assume that int fields are always in 16 bit range, like ports + static_cast(widget)->setMinimum(0); + static_cast(widget)->setMaximum(65535); + static_cast(widget)->setValue(std::get<2>(fieldInfo).toInt()); + break; + case QVariant::String: + widget = new QLineEdit(std::get<2>(fieldInfo).toString(), fieldBox); + // Here we assume that fields named something with "password" are actual password inputs + if (std::get<0>(fieldInfo).toLower().contains("password")) + static_cast(widget)->setEchoMode(QLineEdit::Password); + break; + default: + qWarning() << "Unsupported type for backend property" << std::get<0>(fieldInfo); } if (widget) { widget->setObjectName(std::get<0>(fieldInfo)); @@ -86,48 +86,46 @@ QGroupBox *createFieldBox(const QString &title, const std::vector &fi return fieldBox; } - template -QVariantMap propertiesFromFieldWidgets(QGroupBox *fieldBox, const std::vector &fieldInfos) +QVariantMap propertiesFromFieldWidgets(QGroupBox* fieldBox, const std::vector& fieldInfos) { QVariantMap properties; if (!fieldBox) return properties; - for (auto &&fieldInfo : fieldInfos) { + for (auto&& fieldInfo : fieldInfos) { QString key = std::get<0>(fieldInfo); QVariant value; switch (std::get<2>(fieldInfo).type()) { - case QVariant::Int: { - QSpinBox *spinBox = fieldBox->findChild(key); - if (spinBox) - value = spinBox->value(); - else - qWarning() << "Could not find child widget for field" << key; - break; - } - case QVariant::String: { - QLineEdit *lineEdit = fieldBox->findChild(key); - if (lineEdit) - value = lineEdit->text(); - else - qWarning() << "Could not find child widget for field" << key; - break; - } - default: - qWarning() << "Unsupported type for backend property" << key; + case QVariant::Int: { + auto* spinBox = fieldBox->findChild(key); + if (spinBox) + value = spinBox->value(); + else + qWarning() << "Could not find child widget for field" << key; + break; + } + case QVariant::String: { + auto* lineEdit = fieldBox->findChild(key); + if (lineEdit) + value = lineEdit->text(); + else + qWarning() << "Could not find child widget for field" << key; + break; + } + default: + qWarning() << "Unsupported type for backend property" << key; } properties[key] = std::move(value); } return properties; } -} // anon - +} // namespace -CoreConfigWizard::CoreConfigWizard(CoreConnection *connection, const QVariantList &backendInfos, const QVariantList &authInfos, QWidget *parent) - : QWizard(parent), - _connection{connection} +CoreConfigWizard::CoreConfigWizard(CoreConnection* connection, const QVariantList& backendInfos, const QVariantList& authInfos, QWidget* parent) + : QWizard(parent) + , _connection{connection} { setModal(true); setAttribute(Qt::WA_DeleteOnClose); @@ -137,11 +135,10 @@ CoreConfigWizard::CoreConfigWizard(CoreConnection *connection, const QVariantLis setPage(AuthenticationSelectionPage, new CoreConfigWizardPages::AuthenticationSelectionPage(authInfos, this)); setPage(StorageSelectionPage, new CoreConfigWizardPages::StorageSelectionPage(backendInfos, 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, &CoreConfigWizardPages::SyncPage::setupCore, this, &CoreConfigWizard::prepareCoreSetup); setPage(SyncPage, syncPage); syncRelayPage = new CoreConfigWizardPages::SyncRelayPage(this); - connect(syncRelayPage, SIGNAL(startOver()), this, SLOT(startOver())); + connect(syncRelayPage, &CoreConfigWizardPages::SyncRelayPage::startOver, this, &CoreConfigWizard::startOver); setPage(SyncRelayPage, syncRelayPage); setStartId(IntroPage); @@ -162,11 +159,10 @@ CoreConfigWizard::CoreConfigWizard(CoreConnection *connection, const QVariantLis setWindowTitle(CoreConfigWizard::tr("Core Configuration Wizard")); setPixmap(QWizard::LogoPixmap, icon::get("quassel").pixmap(48)); - connect(connection, SIGNAL(coreSetupSuccess()), SLOT(coreSetupSuccess())); - connect(connection, SIGNAL(coreSetupFailed(QString)), SLOT(coreSetupFailed(QString))); - connect(connection, SIGNAL(synchronized()), SLOT(syncFinished())); - connect(this, SIGNAL(rejected()), connection, SLOT(disconnectFromCore())); - + connect(connection, &CoreConnection::coreSetupSuccess, this, &CoreConfigWizard::coreSetupSuccess); + connect(connection, &CoreConnection::coreSetupFailed, this, &CoreConfigWizard::coreSetupFailed); + connect(connection, &CoreConnection::synchronized, this, &CoreConfigWizard::syncFinished); + connect(this, &QDialog::rejected, connection, selectOverload<>(&CoreConnection::disconnectFromCore)); // Resize all pages to the size hint of the largest one, so the wizard is large enough QSize maxSize; @@ -180,79 +176,85 @@ CoreConfigWizard::CoreConfigWizard(CoreConnection *connection, const QVariantLis } } - -void CoreConfigWizard::prepareCoreSetup(const QString &backend, const QVariantMap &properties, const QString &authenticator, 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... - for (auto &&idx : visitedPages()) + for (auto&& idx : visitedPages()) page(idx)->setEnabled(false); // 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::isCoreFeatureEnabled(Quassel::Feature::Authenticators)) { - coreConnection()->setupCore(Protocol::SetupData(field("adminUser.user").toString(), field("adminUser.password").toString(), backend, properties)); + 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)); + coreConnection()->setupCore(Protocol::SetupData(field("adminUser.user").toString(), + field("adminUser.password").toString(), + backend, + properties, + authenticator, + authProperties)); } } - void CoreConfigWizard::coreSetupSuccess() { syncPage->setStatus(tr("Your core has been successfully configured. Logging you in...")); syncPage->setError(false); syncRelayPage->setMode(CoreConfigWizardPages::SyncRelayPage::Success); - coreConnection()->loginToCore(field("adminUser.user").toString(), field("adminUser.password").toString(), field("adminUser.rememberPasswd").toBool()); + coreConnection()->loginToCore(field("adminUser.user").toString(), + field("adminUser.password").toString(), + field("adminUser.rememberPasswd").toBool()); } - -void CoreConfigWizard::coreSetupFailed(const QString &error) +void CoreConfigWizard::coreSetupFailed(const QString& error) { syncPage->setStatus(tr("Core configuration failed:
%1
Press Next to start over.").arg(error)); syncPage->setError(true); syncRelayPage->setMode(CoreConfigWizardPages::SyncRelayPage::Error); - //foreach(int idx, visitedPages()) page(idx)->setEnabled(true); - //setStartId(SyncPage); - //restart(); + // foreach(int idx, visitedPages()) page(idx)->setEnabled(true); + // setStartId(SyncPage); + // restart(); } - void CoreConfigWizard::startOver() { - foreach(int idx, visitedPages()) page(idx)->setEnabled(true); + foreach (int idx, visitedPages()) + page(idx)->setEnabled(true); setStartId(CoreConfigWizard::AdminUserPage); restart(); } - void CoreConfigWizard::syncFinished() { accept(); } - namespace CoreConfigWizardPages { /*** Intro Page ***/ -IntroPage::IntroPage(QWidget *parent) : QWizardPage(parent) +IntroPage::IntroPage(QWidget* parent) + : QWizardPage(parent) { ui.setupUi(this); setTitle(tr("Introduction")); - //setSubTitle(tr("foobar")); - //setPixmap(QWizard::WatermarkPixmap, QPixmap(":icons/quassel-icon.png")); + // setSubTitle(tr("foobar")); + // setPixmap(QWizard::WatermarkPixmap, QPixmap(":icons/quassel-icon.png")); } - int IntroPage::nextId() const { return CoreConfigWizard::AdminUserPage; } - /*** Admin User Page ***/ -AdminUserPage::AdminUserPage(QWidget *parent) : QWizardPage(parent) +AdminUserPage::AdminUserPage(QWidget* parent) + : QWizardPage(parent) { ui.setupUi(this); setTitle(tr("Create Admin User")); @@ -264,7 +266,6 @@ AdminUserPage::AdminUserPage(QWidget *parent) : QWizardPage(parent) registerField("adminUser.rememberPasswd", ui.rememberPasswd); } - int AdminUserPage::nextId() const { // If the core doesn't support auth backends, skip that page! @@ -276,7 +277,6 @@ int AdminUserPage::nextId() const } } - bool AdminUserPage::isComplete() const { bool ok = !ui.user->text().isEmpty() && !ui.password->text().isEmpty() && ui.password->text() == ui.password2->text(); @@ -285,7 +285,7 @@ bool AdminUserPage::isComplete() const /*** Authentication Selection Page ***/ -AuthenticationSelectionPage::AuthenticationSelectionPage(const QVariantList &authInfos, QWidget *parent) +AuthenticationSelectionPage::AuthenticationSelectionPage(const QVariantList& authInfos, QWidget* parent) : QWizardPage(parent) { ui.setupUi(this); @@ -295,13 +295,13 @@ AuthenticationSelectionPage::AuthenticationSelectionPage(const QVariantList &aut registerField("authentication.backend", ui.backendList); - for (auto &&authInfo : authInfos) { + for (auto&& authInfo : authInfos) { auto props = authInfo.toMap(); // Extract field infos to avoid having to reparse the list std::vector fields; - const auto &list = props["SetupData"].toList(); + 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])); + fields.emplace_back(std::make_tuple(list[i].toString(), list[i + 1].toString(), list[i + 2])); } props.remove("SetupData"); @@ -318,11 +318,7 @@ AuthenticationSelectionPage::AuthenticationSelectionPage(const QVariantList &aut setSizePolicy({QSizePolicy::Fixed, QSizePolicy::Fixed}); QSizePolicy sp{QSizePolicy::MinimumExpanding, QSizePolicy::Fixed}; -#if QT_VERSION >= 0x050200 sp.setRetainSizeWhenHidden(true); -#else - ui.authSettingsStack->setVisible(true); // ugly hack that will show an empty box, but we'll deprecate Qt4 soon anyway -#endif ui.descriptionStack->setSizePolicy(sp); ui.authSettingsStack->setSizePolicy(sp); @@ -332,36 +328,27 @@ AuthenticationSelectionPage::AuthenticationSelectionPage(const QVariantList &aut ui.backendList->setCurrentIndex(0); } - int AuthenticationSelectionPage::nextId() const { return CoreConfigWizard::StorageSelectionPage; } - QString AuthenticationSelectionPage::displayName() const { return ui.backendList->currentText(); } - QString AuthenticationSelectionPage::authenticator() const { -#if QT_VERSION >= 0x050200 return ui.backendList->currentData().toString(); -#else - return ui.backendList->itemData(ui.backendList->currentIndex()).toString(); -#endif } - QVariantMap AuthenticationSelectionPage::authProperties() const { - return propertiesFromFieldWidgets(qobject_cast(ui.authSettingsStack->currentWidget()), + return propertiesFromFieldWidgets(qobject_cast(ui.authSettingsStack->currentWidget()), _authFields[ui.backendList->currentIndex()]); } - void AuthenticationSelectionPage::on_backendList_currentIndexChanged(int index) { ui.descriptionStack->setCurrentIndex(index); @@ -371,7 +358,7 @@ void AuthenticationSelectionPage::on_backendList_currentIndexChanged(int index) /*** Storage Selection Page ***/ -StorageSelectionPage::StorageSelectionPage(const QVariantList &backendInfos, QWidget *parent) +StorageSelectionPage::StorageSelectionPage(const QVariantList& backendInfos, QWidget* parent) : QWizardPage(parent) { ui.setupUi(this); @@ -382,17 +369,17 @@ StorageSelectionPage::StorageSelectionPage(const QVariantList &backendInfos, QWi registerField("storage.backend", ui.backendList); - int defaultIndex {0}; // Legacy cores send backend infos in arbitrary order + int defaultIndex{0}; // Legacy cores send backend infos in arbitrary order - for (auto &&backendInfo : backendInfos) { + for (auto&& backendInfo : backendInfos) { auto props = backendInfo.toMap(); // Extract field infos to avoid having to reparse the list std::vector 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()) { + 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()) { @@ -400,9 +387,9 @@ StorageSelectionPage::StorageSelectionPage(const QVariantList &backendInfos, QWi } } else { - const auto &list = props["SetupData"].toList(); + 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])); + fields.emplace_back(std::make_tuple(list[i].toString(), list[i + 1].toString(), list[i + 2])); } props.remove("SetupData"); } @@ -424,11 +411,7 @@ StorageSelectionPage::StorageSelectionPage(const QVariantList &backendInfos, QWi setSizePolicy({QSizePolicy::Fixed, QSizePolicy::Fixed}); QSizePolicy sp{QSizePolicy::MinimumExpanding, QSizePolicy::Fixed}; -#if QT_VERSION >= 0x050200 sp.setRetainSizeWhenHidden(true); -#else - ui.storageSettingsStack->setVisible(true); // ugly hack that will show an empty box, but we'll deprecate Qt4 soon anyway -#endif ui.descriptionStack->setSizePolicy(sp); ui.storageSettingsStack->setSizePolicy(sp); @@ -438,36 +421,27 @@ StorageSelectionPage::StorageSelectionPage(const QVariantList &backendInfos, QWi ui.backendList->setCurrentIndex(defaultIndex); } - int StorageSelectionPage::nextId() const { return CoreConfigWizard::SyncPage; } - QString StorageSelectionPage::displayName() const { return ui.backendList->currentText(); } - QString StorageSelectionPage::backend() const { -#if QT_VERSION >= 0x050200 return ui.backendList->currentData().toString(); -#else - return ui.backendList->itemData(ui.backendList->currentIndex()).toString(); -#endif } - QVariantMap StorageSelectionPage::backendProperties() const { - return propertiesFromFieldWidgets(qobject_cast(ui.storageSettingsStack->currentWidget()), + return propertiesFromFieldWidgets(qobject_cast(ui.storageSettingsStack->currentWidget()), _backendFields[ui.backendList->currentIndex()]); } - void StorageSelectionPage::on_backendList_currentIndexChanged(int index) { ui.descriptionStack->setCurrentIndex(index); @@ -475,17 +449,16 @@ void StorageSelectionPage::on_backendList_currentIndexChanged(int index) ui.storageSettingsStack->setVisible(!_backendFields[index].empty()); } - /*** Sync Page ***/ -SyncPage::SyncPage(QWidget *parent) : QWizardPage(parent) +SyncPage::SyncPage(QWidget* parent) + : QWizardPage(parent) { ui.setupUi(this); setTitle(tr("Storing Your Settings")); setSubTitle(tr("Your settings are now being stored in the core, and you will be logged in automatically.")); } - void SyncPage::initializePage() { _complete = false; @@ -493,13 +466,13 @@ void SyncPage::initializePage() emit completeChanged(); // Fill in sync info about the storage layer. - StorageSelectionPage *storagePage = qobject_cast(wizard()->page(CoreConfigWizard::StorageSelectionPage)); + auto* storagePage = qobject_cast(wizard()->page(CoreConfigWizard::StorageSelectionPage)); QString backend = storagePage->backend(); QVariantMap backendProperties = storagePage->backendProperties(); ui.backend->setText(storagePage->displayName()); // Fill in sync info about the authentication layer. - AuthenticationSelectionPage *authPage = qobject_cast(wizard()->page(CoreConfigWizard::AuthenticationSelectionPage)); + auto* authPage = qobject_cast(wizard()->page(CoreConfigWizard::AuthenticationSelectionPage)); QString authenticator = authPage->authenticator(); QVariantMap authProperties = authPage->authProperties(); ui.authenticator->setText(authPage->displayName()); @@ -509,7 +482,6 @@ void SyncPage::initializePage() emit setupCore(backend, backendProperties, authenticator, authProperties); } - int SyncPage::nextId() const { if (!_hasError) @@ -517,19 +489,16 @@ int SyncPage::nextId() const return CoreConfigWizard::SyncRelayPage; } - bool SyncPage::isComplete() const { return _complete || _hasError; } - -void SyncPage::setStatus(const QString &status) +void SyncPage::setStatus(const QString& status) { ui.status->setText(status); } - void SyncPage::setError(bool e) { _hasError = e; @@ -537,22 +506,20 @@ void SyncPage::setError(bool e) emit completeChanged(); } - void SyncPage::setComplete(bool c) { _complete = c; completeChanged(); } - /*** Sync Relay Page ***/ -SyncRelayPage::SyncRelayPage(QWidget *parent) : QWizardPage(parent) +SyncRelayPage::SyncRelayPage(QWidget* parent) + : QWizardPage(parent) { mode = Success; } - void SyncRelayPage::setMode(Mode m) { mode = m; @@ -563,4 +530,4 @@ int SyncRelayPage::nextId() const emit startOver(); return 0; } -}; /* namespace CoreConfigWizardPages */ +} /* namespace CoreConfigWizardPages */