From cc2e3f79ff045cd577ebc28e8f89c19350aadd58 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 28 Jul 2020 12:16:03 +0200 Subject: [PATCH] [users] Move job creation from widget to viewstep - This is a half-step: the ViewStep shouldn't do job creation either, eventually it needs to be the Config object, but this is better than asking the widget (UI) to create some jobs. - When updating login- or host-name, or the autologin setting, set it in GS as well. This is a minor improvement over doing it only when leaving the page. - Since the Config object isn't complete, there are leftovers in the widget, which has a fillGlobalStorage() for the not-jobs-related bits previously in createJobs(). --- src/modules/users/Config.cpp | 29 ++++++++++++++++++++++++++++ src/modules/users/UsersPage.cpp | 30 +++++------------------------ src/modules/users/UsersPage.h | 5 ++--- src/modules/users/UsersViewStep.cpp | 10 ++++++++-- 4 files changed, 44 insertions(+), 30 deletions(-) diff --git a/src/modules/users/Config.cpp b/src/modules/users/Config.cpp index 1219c2a3c..bb739cbd1 100644 --- a/src/modules/users/Config.cpp +++ b/src/modules/users/Config.cpp @@ -87,6 +87,16 @@ Config::setLoginName( const QString& login ) { if ( login != m_loginName ) { + Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage(); + if ( login.isEmpty() ) + { + gs->remove( "username" ); + } + else + { + gs->insert( "username", login ); + } + m_customLoginName = !login.isEmpty(); m_loginName = login; emit loginNameChanged( login ); @@ -143,6 +153,16 @@ Config::setHostName( const QString& host ) { if ( host != m_hostName ) { + Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage(); + if ( host.isEmpty() ) + { + gs->remove( "hostname" ); + } + else + { + gs->insert( "hostname", host ); + } + m_customHostName = !host.isEmpty(); m_hostName = host; emit hostNameChanged( host ); @@ -317,6 +337,15 @@ Config::setAutoLogin( bool b ) { if ( b != m_doAutoLogin ) { + Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage(); + if ( b ) + { + gs->insert( "autologinUser", loginName() ); + } + else + { + gs->remove( "autologinUser" ); + } m_doAutoLogin = b; emit autoLoginChanged( b ); } diff --git a/src/modules/users/UsersPage.cpp b/src/modules/users/UsersPage.cpp index 268e6099e..c4502256a 100644 --- a/src/modules/users/UsersPage.cpp +++ b/src/modules/users/UsersPage.cpp @@ -24,12 +24,9 @@ */ #include "UsersPage.h" -#include "ui_page_usersetup.h" #include "Config.h" -#include "CreateUserJob.h" -#include "SetHostNameJob.h" -#include "SetPasswordJob.h" +#include "ui_page_usersetup.h" #include "GlobalStorage.h" #include "JobQueue.h" @@ -189,7 +186,7 @@ UsersPage::retranslate() bool -UsersPage::isReady() +UsersPage::isReady() const { bool readyFields = m_readyFullName && m_readyHostname && m_readyPassword && m_readyUsername; // If we're going to write a root password, we need a valid one (or reuse the user's password) @@ -224,38 +221,21 @@ UsersPage::getUserPassword() const return QPair< QString, QString >( m_config->loginName(), ui->textBoxUserPassword->text() ); } -QList< Calamares::job_ptr > -UsersPage::createJobs( const QStringList& defaultGroupsList ) +void +UsersPage::fillGlobalStorage() const { - QList< Calamares::job_ptr > list; if ( !isReady() ) { - return list; + return; } Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage(); - Calamares::Job* j; - j = new CreateUserJob( m_config->loginName(), - m_config->fullName().isEmpty() ? m_config->loginName() : m_config->fullName(), - m_config->doAutoLogin(), - defaultGroupsList ); - list.append( Calamares::job_ptr( j ) ); - if ( m_config->writeRootPassword() ) { gs->insert( "reuseRootPassword", ui->checkBoxReusePassword->isChecked() ); } - gs->insert( "hostname", m_config->hostName() ); - if ( m_config->doAutoLogin() ) - { - gs->insert( "autologinUser", m_config->loginName() ); - } - - gs->insert( "username", m_config->loginName() ); gs->insert( "password", CalamaresUtils::obscure( ui->textBoxUserPassword->text() ) ); - - return list; } diff --git a/src/modules/users/UsersPage.h b/src/modules/users/UsersPage.h index 35f7f0938..b8cb0f06a 100644 --- a/src/modules/users/UsersPage.h +++ b/src/modules/users/UsersPage.h @@ -25,7 +25,6 @@ #define USERSPAGE_H #include "CheckPWQuality.h" -#include "Job.h" #include @@ -45,9 +44,9 @@ public: explicit UsersPage( Config* config, QWidget* parent = nullptr ); virtual ~UsersPage(); - bool isReady(); + bool isReady() const; - Calamares::JobList createJobs( const QStringList& defaultGroupsList ); + void fillGlobalStorage() const; void onActivate(); diff --git a/src/modules/users/UsersViewStep.cpp b/src/modules/users/UsersViewStep.cpp index 713811246..ddaf4837b 100644 --- a/src/modules/users/UsersViewStep.cpp +++ b/src/modules/users/UsersViewStep.cpp @@ -21,6 +21,7 @@ #include "UsersViewStep.h" #include "Config.h" +#include "CreateUserJob.h" #include "SetHostNameJob.h" #include "SetPasswordJob.h" #include "UsersPage.h" @@ -138,13 +139,16 @@ void UsersViewStep::onLeave() { m_jobs.clear(); - if ( !m_widget ) + if ( !m_widget || !m_widget->isReady() ) { return; } - m_jobs.append( m_widget->createJobs( m_defaultGroups ) ); Calamares::Job* j; + j = new CreateUserJob( m_config->loginName(), + m_config->fullName().isEmpty() ? m_config->loginName() : m_config->fullName(), + m_config->doAutoLogin(), + m_defaultGroups ); auto userPW = m_widget->getUserPassword(); j = new SetPasswordJob( userPW.first, userPW.second ); @@ -155,6 +159,8 @@ UsersViewStep::onLeave() j = new SetHostNameJob( m_config->hostName(), m_actions ); m_jobs.append( Calamares::job_ptr( j ) ); + + m_widget->fillGlobalStorage(); }