From f9b114a67ad7d6b27bd90148493b82575c838460 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sat, 25 Jul 2020 15:21:04 +0200 Subject: [PATCH] [users] Pass the Config object to the Page - delay construction of the Page (widget) until it's needed - hand the Config object to the Page on construction This is prep-work for putting the configuration information into the Config object, rather than in the UI elements. --- src/modules/users/UsersPage.cpp | 7 ++++--- src/modules/users/UsersPage.h | 5 ++++- src/modules/users/UsersViewStep.cpp | 28 +++++++++++++++++++++------- src/modules/users/UsersViewStep.h | 3 +++ 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/modules/users/UsersPage.cpp b/src/modules/users/UsersPage.cpp index 5c649d622..62b8920e7 100644 --- a/src/modules/users/UsersPage.cpp +++ b/src/modules/users/UsersPage.cpp @@ -79,9 +79,10 @@ labelOk( QLabel* pix, QLabel* label ) pix->setPixmap( CalamaresUtils::defaultPixmap( CalamaresUtils::Yes, CalamaresUtils::Original, label->size() ) ); } -UsersPage::UsersPage( QWidget* parent ) +UsersPage::UsersPage( Config* config, QWidget* parent ) : QWidget( parent ) , ui( new Ui::Page_UserSetup ) + , m_config( config ) , m_readyFullName( false ) , m_readyUsername( false ) , m_readyHostname( false ) @@ -99,12 +100,12 @@ UsersPage::UsersPage( QWidget* parent ) connect( ui->textBoxUserVerifiedPassword, &QLineEdit::textChanged, this, &UsersPage::onPasswordTextChanged ); connect( ui->textBoxRootPassword, &QLineEdit::textChanged, this, &UsersPage::onRootPasswordTextChanged ); connect( ui->textBoxVerifiedRootPassword, &QLineEdit::textChanged, this, &UsersPage::onRootPasswordTextChanged ); - connect( ui->checkBoxValidatePassword, &QCheckBox::stateChanged, this, [ this ]( int ) { + connect( ui->checkBoxValidatePassword, &QCheckBox::stateChanged, this, [this]( int ) { onPasswordTextChanged( ui->textBoxUserPassword->text() ); onRootPasswordTextChanged( ui->textBoxRootPassword->text() ); checkReady( isReady() ); } ); - connect( ui->checkBoxReusePassword, &QCheckBox::stateChanged, this, [ this ]( int checked ) { + connect( ui->checkBoxReusePassword, &QCheckBox::stateChanged, this, [this]( int checked ) { /* When "reuse" is checked, hide the fields for explicitly * entering the root password. However, if we're going to * disable the root password anyway, hide them all regardless of diff --git a/src/modules/users/UsersPage.h b/src/modules/users/UsersPage.h index 3382e9335..a13886de6 100644 --- a/src/modules/users/UsersPage.h +++ b/src/modules/users/UsersPage.h @@ -29,6 +29,8 @@ #include +class Config; + class QLabel; namespace Ui @@ -40,7 +42,7 @@ class UsersPage : public QWidget { Q_OBJECT public: - explicit UsersPage( QWidget* parent = nullptr ); + explicit UsersPage( Config* config, QWidget* parent = nullptr ); virtual ~UsersPage(); bool isReady(); @@ -95,6 +97,7 @@ private: void retranslate(); Ui::Page_UserSetup* ui; + Config* m_config; PasswordCheckList m_passwordChecks; bool m_passwordChecksChanged = false; diff --git a/src/modules/users/UsersViewStep.cpp b/src/modules/users/UsersViewStep.cpp index fe633b1c2..3fc86eb91 100644 --- a/src/modules/users/UsersViewStep.cpp +++ b/src/modules/users/UsersViewStep.cpp @@ -20,17 +20,17 @@ #include "UsersViewStep.h" +#include "Config.h" #include "SetHostNameJob.h" #include "SetPasswordJob.h" #include "UsersPage.h" +#include "GlobalStorage.h" +#include "JobQueue.h" #include "utils/Logger.h" #include "utils/NamedEnum.h" #include "utils/Variant.h" -#include "GlobalStorage.h" -#include "JobQueue.h" - CALAMARES_PLUGIN_FACTORY_DEFINITION( UsersViewStepFactory, registerPlugin< UsersViewStep >(); ) static const NamedEnumTable< SetHostNameJob::Action >& @@ -53,11 +53,11 @@ hostnameActions() UsersViewStep::UsersViewStep( QObject* parent ) : Calamares::ViewStep( parent ) - , m_widget( new UsersPage() ) + , m_widget( nullptr ) , m_actions( SetHostNameJob::Action::None ) + , m_config( new Config( this ) ) { emit nextStatusChanged( true ); - connect( m_widget, &UsersPage::checkReady, this, &UsersViewStep::nextStatusChanged ); } @@ -80,6 +80,11 @@ UsersViewStep::prettyName() const QWidget* UsersViewStep::widget() { + if ( !m_widget ) + { + m_widget = new UsersPage( m_config ); + connect( m_widget, &UsersPage::checkReady, this, &UsersViewStep::nextStatusChanged ); + } return m_widget; } @@ -87,7 +92,7 @@ UsersViewStep::widget() bool UsersViewStep::isNextEnabled() const { - return m_widget->isReady(); + return m_widget ? m_widget->isReady() : true; } @@ -122,7 +127,10 @@ UsersViewStep::jobs() const void UsersViewStep::onActivate() { - m_widget->onActivate(); + if ( m_widget ) + { + m_widget->onActivate(); + } } @@ -130,6 +138,10 @@ void UsersViewStep::onLeave() { m_jobs.clear(); + if ( !m_widget ) + { + return; + } m_jobs.append( m_widget->createJobs( m_defaultGroups ) ); Calamares::Job* j; @@ -222,4 +234,6 @@ UsersViewStep::setConfigurationMap( const QVariantMap& configurationMap ) Action hostsfileAction = getBool( configurationMap, "writeHostsFile", true ) ? Action::WriteEtcHosts : Action::None; m_actions = hostsfileAction | hostnameAction; + + m_config->setConfigurationMap( configurationMap ); } diff --git a/src/modules/users/UsersViewStep.h b/src/modules/users/UsersViewStep.h index 03cc83819..aacf11f2a 100644 --- a/src/modules/users/UsersViewStep.h +++ b/src/modules/users/UsersViewStep.h @@ -29,6 +29,7 @@ #include #include +class Config; class UsersPage; class PLUGINDLLEXPORT UsersViewStep : public Calamares::ViewStep @@ -62,6 +63,8 @@ private: QStringList m_defaultGroups; SetHostNameJob::Actions m_actions; + + Config* m_config; }; CALAMARES_PLUGIN_FACTORY_DECLARATION( UsersViewStepFactory )