X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fcoreconfigwizard.cpp;h=ebb23b833bdefe8933a6455933628c08677ad982;hp=18133f07bd8760467409946713d4c8aa02810a82;hb=ab7ef4d24f62b5848b628482b7762ebfc0b53e1a;hpb=cfbd4daee17dbb3c4052d938bf33edd08711d728 diff --git a/src/qtui/coreconfigwizard.cpp b/src/qtui/coreconfigwizard.cpp index 18133f07..ebb23b83 100644 --- a/src/qtui/coreconfigwizard.cpp +++ b/src/qtui/coreconfigwizard.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2016 by the Quassel Project * + * Copyright (C) 2005-2018 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -18,21 +18,35 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ +#include "coreconfigwizard.h" + #include #include +#include #include -#include #include -#include "coreconfigwizard.h" -#include "coreconnection.h" - #include "client.h" +#include "coreconnection.h" +#include "icon.h" namespace { +QGroupBox *createDescriptionBox(const QString &description) +{ + auto box = new QGroupBox; + auto layout = new QVBoxLayout(box); + auto label = new QLabel(description, box); + label->setWordWrap(true); + layout->addWidget(label); + layout->setAlignment(label, Qt::AlignTop); + box->setTitle(QCoreApplication::translate("CoreConfigWizard", "Description")); + return box; +} + + template -void createFieldWidgets(QGroupBox *fieldBox, 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 @@ -40,7 +54,11 @@ void createFieldWidgets(QGroupBox *fieldBox, const std::vector &field // provide specialized config widgets for those (which may be a good idea anyway, e.g. if we // think about client-side translations...) - QFormLayout *formLayout = new QFormLayout; + auto *fieldBox = new QGroupBox; + fieldBox->setTitle(title); + auto *formLayout = new QFormLayout; + fieldBox->setLayout(formLayout); + for (auto &&fieldInfo : fieldInfos) { QWidget *widget {nullptr}; switch (std::get<2>(fieldInfo).type()) { @@ -65,7 +83,7 @@ void createFieldWidgets(QGroupBox *fieldBox, const std::vector &field formLayout->addRow(std::get<1>(fieldInfo) + ":", widget); } } - fieldBox->setLayout(formLayout); + return fieldBox; } @@ -125,11 +143,8 @@ CoreConfigWizard::CoreConfigWizard(CoreConnection *connection, const QVariantLis syncRelayPage = new CoreConfigWizardPages::SyncRelayPage(this); connect(syncRelayPage, SIGNAL(startOver()), this, SLOT(startOver())); setPage(SyncRelayPage, syncRelayPage); - //setPage(Page_StorageDetails, new StorageDetailsPage()); - //setPage(Page_Conclusion, new ConclusionPage(storageProviders)); setStartId(IntroPage); - //setStartId(StorageSelectionPage); #ifndef Q_OS_MAC setWizardStyle(ModernStyle); @@ -141,30 +156,40 @@ CoreConfigWizard::CoreConfigWizard(CoreConnection *connection, const QVariantLis setOption(HaveFinishButtonOnEarlyPages, false); setOption(NoCancelButton, true); setOption(IndependentPages, true); - //setOption(ExtendedWatermarkPixmap, true); setModal(true); - setWindowTitle(tr("Core Configuration Wizard")); - setPixmap(QWizard::LogoPixmap, QIcon::fromTheme("quassel", QIcon(":/icons/quassel.png")).pixmap(48)); + 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(loginSuccess()), SLOT(loginSuccess())); connect(connection, SIGNAL(synchronized()), SLOT(syncFinished())); connect(this, SIGNAL(rejected()), connection, SLOT(disconnectFromCore())); + + + // Resize all pages to the size hint of the largest one, so the wizard is large enough + QSize maxSize; + for (int id : pageIds()) { + auto p = page(id); + p->adjustSize(); + maxSize = maxSize.expandedTo(p->sizeHint()); + } + for (int id : pageIds()) { + page(id)->setFixedSize(maxSize); + } } 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); + 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::coreFeatures() & Quassel::Authenticators)) { + if (!Client::isCoreFeatureEnabled(Quassel::Feature::Authenticators)) { coreConnection()->setupCore(Protocol::SetupData(field("adminUser.user").toString(), field("adminUser.password").toString(), backend, properties)); } else { @@ -201,15 +226,6 @@ void CoreConfigWizard::startOver() } -void CoreConfigWizard::loginSuccess() -{ - syncPage->setStatus(tr("Your are now logged into your freshly configured Quassel Core!
" - "Please remember to configure your identities and networks now.")); - syncPage->setComplete(true); - syncPage->setFinalPage(true); -} - - void CoreConfigWizard::syncFinished() { accept(); @@ -252,7 +268,7 @@ AdminUserPage::AdminUserPage(QWidget *parent) : QWizardPage(parent) int AdminUserPage::nextId() const { // If the core doesn't support auth backends, skip that page! - if (!(Client::coreFeatures() & Quassel::Authenticators)) { + if (!Client::isCoreFeatureEnabled(Quassel::Feature::Authenticators)) { return CoreConfigWizard::StorageSelectionPage; } else { @@ -289,13 +305,26 @@ AuthenticationSelectionPage::AuthenticationSelectionPage(const QVariantList &aut } props.remove("SetupData"); - _authProperties.emplace_back(props); + _authProperties.emplace_back(std::move(props)); _authFields.emplace_back(std::move(fields)); - // Create entry in authenticator selector - ui.backendList->addItem(props["DisplayName"].toString(), props["BackendId"].toString()); + // Create widgets + ui.backendList->addItem(_authProperties.back()["DisplayName"].toString(), _authProperties.back()["BackendId"].toString()); + ui.descriptionStack->addWidget(createDescriptionBox(_authProperties.back()["Description"].toString())); + ui.authSettingsStack->addWidget(createFieldBox(tr("Authentication Settings"), _authFields.back())); } + // Do some trickery to make the page large enough + setSizePolicy({QSizePolicy::Fixed, QSizePolicy::Fixed}); + + QSizePolicy sp{QSizePolicy::MinimumExpanding, QSizePolicy::Fixed}; + sp.setRetainSizeWhenHidden(true); + ui.descriptionStack->setSizePolicy(sp); + ui.authSettingsStack->setSizePolicy(sp); + + ui.descriptionStack->adjustSize(); + ui.authSettingsStack->adjustSize(); + ui.backendList->setCurrentIndex(0); } @@ -314,35 +343,22 @@ QString AuthenticationSelectionPage::displayName() const 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(_fieldBox, _authFields[ui.backendList->currentIndex()]); + return propertiesFromFieldWidgets(qobject_cast(ui.authSettingsStack->currentWidget()), + _authFields[ui.backendList->currentIndex()]); } void AuthenticationSelectionPage::on_backendList_currentIndexChanged(int index) { - ui.description->setText(_authProperties[index]["Description"].toString()); - - if (_fieldBox) { - layout()->removeWidget(_fieldBox); - _fieldBox->deleteLater(); - _fieldBox = nullptr; - } - if (!_authFields[index].empty()) { - _fieldBox = new QGroupBox(this); - _fieldBox->setTitle(tr("Authentication Settings")); - createFieldWidgets(_fieldBox, _authFields[index]); - static_cast(layout())->insertWidget(layout()->indexOf(ui.descriptionBox) + 1, _fieldBox); - } + ui.descriptionStack->setCurrentIndex(index); + ui.authSettingsStack->setCurrentIndex(index); + ui.authSettingsStack->setVisible(!_authFields[index].empty()); } /*** Storage Selection Page ***/ @@ -387,13 +403,26 @@ StorageSelectionPage::StorageSelectionPage(const QVariantList &backendInfos, QWi // Legacy cores (prior to 0.13) don't send the BackendId property if (!props.contains("BackendId")) props["BackendId"] = props["DisplayName"]; - _backendProperties.emplace_back(props); + _backendProperties.emplace_back(std::move(props)); _backendFields.emplace_back(std::move(fields)); - // Create entry in backend selector - ui.backendList->addItem(props["DisplayName"].toString(), props["BackendId"].toString()); + // 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())); } + // Do some trickery to make the page large enough + setSizePolicy({QSizePolicy::Fixed, QSizePolicy::Fixed}); + + QSizePolicy sp{QSizePolicy::MinimumExpanding, QSizePolicy::Fixed}; + sp.setRetainSizeWhenHidden(true); + ui.descriptionStack->setSizePolicy(sp); + ui.storageSettingsStack->setSizePolicy(sp); + + ui.descriptionStack->adjustSize(); + ui.storageSettingsStack->adjustSize(); + ui.backendList->setCurrentIndex(defaultIndex); } @@ -412,35 +441,22 @@ QString StorageSelectionPage::displayName() const 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(_fieldBox, _backendFields[ui.backendList->currentIndex()]); + return propertiesFromFieldWidgets(qobject_cast(ui.storageSettingsStack->currentWidget()), + _backendFields[ui.backendList->currentIndex()]); } void StorageSelectionPage::on_backendList_currentIndexChanged(int index) { - ui.description->setText(_backendProperties[index]["Description"].toString()); - - if (_fieldBox) { - layout()->removeWidget(_fieldBox); - _fieldBox->deleteLater(); - _fieldBox = nullptr; - } - if (!_backendFields[index].empty()) { - _fieldBox = new QGroupBox(this); - _fieldBox->setTitle(tr("Storage Settings")); - createFieldWidgets(_fieldBox, _backendFields[index]); - static_cast(layout())->insertWidget(layout()->indexOf(ui.descriptionBox) + 1, _fieldBox); - } + ui.descriptionStack->setCurrentIndex(index); + ui.storageSettingsStack->setCurrentIndex(index); + ui.storageSettingsStack->setVisible(!_backendFields[index].empty()); }