From 45b71c24e771d69d22699337bbd030590eb1ed4f Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 28 Jul 2020 11:41:52 +0200 Subject: [PATCH] [users] Move autologin setting to Config --- src/modules/users/Config.cpp | 12 ++++++++++++ src/modules/users/Config.h | 11 +++++++++++ src/modules/users/UsersPage.cpp | 16 +++++++--------- src/modules/users/UsersPage.h | 1 - src/modules/users/UsersViewStep.cpp | 1 - src/modules/users/page_usersetup.ui | 2 +- 6 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/modules/users/Config.cpp b/src/modules/users/Config.cpp index 9a9ebe693..f245aa866 100644 --- a/src/modules/users/Config.cpp +++ b/src/modules/users/Config.cpp @@ -312,6 +312,16 @@ Config::setFullName( const QString& name ) } } +void +Config::setAutoLogin( bool b ) +{ + if ( b != m_doAutoLogin ) + { + m_doAutoLogin = b; + emit autoLoginChanged( b ); + } +} + void Config::setConfigurationMap( const QVariantMap& configurationMap ) { @@ -325,4 +335,6 @@ Config::setConfigurationMap( const QVariantMap& configurationMap ) setAutologinGroup( CalamaresUtils::getString( configurationMap, "autologinGroup" ) ); setSudoersGroup( CalamaresUtils::getString( configurationMap, "sudoersGroup" ) ); + + m_doAutoLogin = CalamaresUtils::getBool( configurationMap, "doAutologin", false ); } diff --git a/src/modules/users/Config.h b/src/modules/users/Config.h index 824b70ba8..e7ab8a736 100644 --- a/src/modules/users/Config.h +++ b/src/modules/users/Config.h @@ -33,6 +33,8 @@ class Config : public QObject Q_PROPERTY( QString autologinGroup READ autologinGroup WRITE setAutologinGroup NOTIFY autologinGroupChanged ) Q_PROPERTY( QString sudoersGroup READ sudoersGroup WRITE setSudoersGroup NOTIFY sudoersGroupChanged ) + Q_PROPERTY( bool doAutoLogin READ doAutoLogin WRITE setAutoLogin NOTIFY autoLoginChanged ) + Q_PROPERTY( QString fullName READ fullName WRITE setFullName NOTIFY fullNameChanged ) Q_PROPERTY( QString loginName READ loginName WRITE setLoginName NOTIFY loginNameChanged ) Q_PROPERTY( QString loginNameStatus READ loginNameStatus NOTIFY loginNameStatusChanged ) @@ -70,6 +72,9 @@ public: /// Status message about hostname -- empty for "ok" QString hostNameStatus() const; + /// Should the user be automatically logged-in? + bool doAutoLogin() const { return m_doAutoLogin; } + static const QStringList& forbiddenLoginNames(); static const QStringList& forbiddenHostNames(); @@ -97,6 +102,9 @@ public Q_SLOTS: /// Sets the host name (flags it as "custom") void setHostName( const QString& host ); + /// Sets the autologin flag + void setAutoLogin( bool b ); + signals: void userShellChanged( const QString& ); void autologinGroupChanged( const QString& ); @@ -106,6 +114,7 @@ signals: void loginNameStatusChanged( const QString& ); void hostNameChanged( const QString& ); void hostNameStatusChanged( const QString& ); + void autoLoginChanged( bool ); private: QString m_userShell; @@ -114,6 +123,8 @@ private: QString m_fullName; QString m_loginName; QString m_hostName; + bool m_doAutoLogin = false; + bool m_customLoginName = false; bool m_customHostName = false; }; diff --git a/src/modules/users/UsersPage.cpp b/src/modules/users/UsersPage.cpp index 0877bf0e3..c9eb227e7 100644 --- a/src/modules/users/UsersPage.cpp +++ b/src/modules/users/UsersPage.cpp @@ -149,6 +149,11 @@ UsersPage::UsersPage( Config* config, QWidget* parent ) connect( config, &Config::loginNameChanged, ui->textBoxLoginName, &QLineEdit::setText ); connect( config, &Config::loginNameStatusChanged, this, &UsersPage::reportLoginNameStatus ); + connect( ui->checkBoxDoAutoLogin, &QCheckBox::stateChanged, this, [this]( int checked ) { + m_config->setAutoLogin( checked != Qt::Unchecked ); + } ); + connect( config, &Config::autoLoginChanged, ui->checkBoxDoAutoLogin, &QCheckBox::setChecked ); + setWriteRootPassword( true ); ui->checkBoxReusePassword->setChecked( true ); ui->checkBoxValidatePassword->setChecked( true ); @@ -239,7 +244,7 @@ UsersPage::createJobs( const QStringList& defaultGroupsList ) Calamares::Job* j; j = new CreateUserJob( m_config->loginName(), m_config->fullName().isEmpty() ? m_config->loginName() : m_config->fullName(), - ui->checkBoxAutoLogin->isChecked(), + m_config->doAutoLogin(), defaultGroupsList ); list.append( Calamares::job_ptr( j ) ); @@ -248,7 +253,7 @@ UsersPage::createJobs( const QStringList& defaultGroupsList ) gs->insert( "reuseRootPassword", ui->checkBoxReusePassword->isChecked() ); } gs->insert( "hostname", m_config->hostName() ); - if ( ui->checkBoxAutoLogin->isChecked() ) + if ( m_config->doAutoLogin() ) { gs->insert( "autologinUser", m_config->loginName() ); } @@ -378,13 +383,6 @@ UsersPage::setValidatePasswordDefault( bool checked ) emit checkReady( isReady() ); } -void -UsersPage::setAutologinDefault( bool checked ) -{ - ui->checkBoxAutoLogin->setChecked( checked ); - emit checkReady( isReady() ); -} - void UsersPage::setReusePasswordDefault( bool checked ) { diff --git a/src/modules/users/UsersPage.h b/src/modules/users/UsersPage.h index 7e0830dc0..7cd522498 100644 --- a/src/modules/users/UsersPage.h +++ b/src/modules/users/UsersPage.h @@ -54,7 +54,6 @@ public: void setWriteRootPassword( bool show ); void setPasswordCheckboxVisible( bool visible ); void setValidatePasswordDefault( bool checked ); - void setAutologinDefault( bool checked ); void setReusePasswordDefault( bool checked ); /** @brief Process entries in the passwordRequirements config entry diff --git a/src/modules/users/UsersViewStep.cpp b/src/modules/users/UsersViewStep.cpp index 03256d419..0826b8a28 100644 --- a/src/modules/users/UsersViewStep.cpp +++ b/src/modules/users/UsersViewStep.cpp @@ -180,7 +180,6 @@ UsersViewStep::setConfigurationMap( const QVariantMap& configurationMap ) Calamares::JobQueue::instance()->globalStorage()->insert( "setRootPassword", setRootPassword ); m_widget->setWriteRootPassword( setRootPassword ); - m_widget->setAutologinDefault( getBool( configurationMap, "doAutologin", false ) ); m_widget->setReusePasswordDefault( getBool( configurationMap, "doReusePassword", false ) ); if ( configurationMap.contains( "passwordRequirements" ) diff --git a/src/modules/users/page_usersetup.ui b/src/modules/users/page_usersetup.ui index 4aefa9981..d880673b8 100644 --- a/src/modules/users/page_usersetup.ui +++ b/src/modules/users/page_usersetup.ui @@ -456,7 +456,7 @@ - + Log in automatically without asking for the password.