From d4a784f52186e5310440095a91506a9aae5ccf68 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 27 Jul 2020 17:52:46 +0200 Subject: [PATCH] [users] Hook up full name to Config --- src/modules/users/Config.cpp | 20 +++++++++++++++---- src/modules/users/Config.h | 8 ++++---- src/modules/users/UsersPage.cpp | 34 +++++++++++---------------------- 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/modules/users/Config.cpp b/src/modules/users/Config.cpp index 24b14faf1..d4fdb16c5 100644 --- a/src/modules/users/Config.cpp +++ b/src/modules/users/Config.cpp @@ -166,14 +166,26 @@ makeHostnameSuggestion( const QStringList& parts ) } void -Config::setUserName( const QString& name ) +Config::setFullName( const QString& name ) { - // TODO: handle "empty" case - // TODO: rename to "FullName" + if ( name.isEmpty() && !m_fullName.isEmpty() ) + { + if ( !m_customHostName ) + { + setHostName( name ); + } + if ( !m_customLoginName ) + { + setLoginName( name ); + } + m_fullName = name; + emit fullNameChanged( name ); + } + if ( name != m_fullName ) { m_fullName = name; - emit userNameChanged( name ); + emit fullNameChanged( name ); // Build login and hostname, if needed QRegExp rx( "[^a-zA-Z0-9 ]", Qt::CaseInsensitive ); diff --git a/src/modules/users/Config.h b/src/modules/users/Config.h index 59f0e8d68..6a5ff0105 100644 --- a/src/modules/users/Config.h +++ b/src/modules/users/Config.h @@ -33,7 +33,7 @@ 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( QString userName READ userName WRITE setUserName NOTIFY userNameChanged ) + Q_PROPERTY( QString fullName READ fullName WRITE setFullName NOTIFY fullNameChanged ) Q_PROPERTY( QString loginName READ loginName WRITE setLoginName NOTIFY loginNameChanged ) Q_PROPERTY( QString hostName READ hostName WRITE setHostName NOTIFY hostNameChanged ) @@ -57,7 +57,7 @@ public: QString sudoersGroup() const { return m_sudoersGroup; } /// The full (GECOS) name of the user - QString userName() const { return m_fullName; } + QString fullName() const { return m_fullName; } /// The login name of the user QString loginName() const { return m_loginName; } @@ -81,7 +81,7 @@ public Q_SLOTS: void setSudoersGroup( const QString& group ); /// Sets the full name, may guess a loginName - void setUserName( const QString& name ); + void setFullName( const QString& name ); /// Sets the login name (flags it as "custom") void setLoginName( const QString& login ); @@ -92,7 +92,7 @@ signals: void userShellChanged( const QString& ); void autologinGroupChanged( const QString& ); void sudoersGroupChanged( const QString& ); - void userNameChanged( const QString& ); + void fullNameChanged( const QString& ); void loginNameChanged( const QString& ); void hostNameChanged( const QString& ); diff --git a/src/modules/users/UsersPage.cpp b/src/modules/users/UsersPage.cpp index 60afa1bb3..ee2719091 100644 --- a/src/modules/users/UsersPage.cpp +++ b/src/modules/users/UsersPage.cpp @@ -92,7 +92,6 @@ UsersPage::UsersPage( Config* config, QWidget* parent ) ui->setupUi( this ); // Connect signals and slots - connect( ui->textBoxFullName, &QLineEdit::textEdited, this, &UsersPage::onFullNameTextEdited ); connect( ui->textBoxUserPassword, &QLineEdit::textChanged, this, &UsersPage::onPasswordTextChanged ); connect( ui->textBoxUserVerifiedPassword, &QLineEdit::textChanged, this, &UsersPage::onPasswordTextChanged ); connect( ui->textBoxRootPassword, &QLineEdit::textChanged, this, &UsersPage::onRootPasswordTextChanged ); @@ -121,7 +120,10 @@ UsersPage::UsersPage( Config* config, QWidget* parent ) checkReady( isReady() ); } ); - connect( ui->textBoxHostName, &QLineEdit::textEdited, config, &Config::setHostName); + connect( ui->textBoxFullName, &QLineEdit::textEdited, config, &Config::setFullName ); + connect( config, &Config::fullNameChanged, this, &UsersPage::onFullNameTextEdited ); + + connect( ui->textBoxHostName, &QLineEdit::textEdited, config, &Config::setHostName ); connect( config, &Config::hostNameChanged, ui->textBoxHostName, &QLineEdit::setText ); connect( config, &Config::hostNameChanged, this, &UsersPage::validateHostnameText ); @@ -150,14 +152,14 @@ UsersPage::retranslate() if ( Calamares::Settings::instance()->isSetupMode() ) { ui->textBoxLoginName->setToolTip( tr( "If more than one person will " - "use this computer, you can create multiple " - "accounts after setup." ) ); + "use this computer, you can create multiple " + "accounts after setup." ) ); } else { ui->textBoxLoginName->setToolTip( tr( "If more than one person will " - "use this computer, you can create multiple " - "accounts after installation." ) ); + "use this computer, you can create multiple " + "accounts after installation." ) ); } // Re-do password checks (with output messages) as well. // .. the password-checking methods get their values from the text boxes, @@ -218,8 +220,7 @@ UsersPage::createJobs( const QStringList& defaultGroupsList ) Calamares::Job* j; j = new CreateUserJob( m_config->loginName(), - m_config->userName().isEmpty() ? m_config->loginName() - : m_config->userName(), + m_config->fullName().isEmpty() ? m_config->loginName() : m_config->fullName(), ui->checkBoxAutoLogin->isChecked(), defaultGroupsList ); list.append( Calamares::job_ptr( j ) ); @@ -265,16 +266,6 @@ UsersPage::onFullNameTextEdited( const QString& textRef ) { ui->labelFullNameError->clear(); ui->labelFullName->clear(); -#if 0 - if ( !m_customUsername ) - { - ui->textBoxUsername->clear(); - } - if ( !m_customHostname ) - { - ui->textBoxHostname->clear(); - } -#endif m_readyFullName = false; } else @@ -287,7 +278,6 @@ UsersPage::onFullNameTextEdited( const QString& textRef ) } - void UsersPage::validateUsernameText( const QString& textRef ) { @@ -321,11 +311,9 @@ UsersPage::validateUsernameText( const QString& textRef ) tr( "Only lowercase letters, numbers, underscore and hyphen are allowed." ) ); m_readyUsername = false; } - else if ( 0 == QString::compare("root", text, Qt::CaseSensitive ) ) + else if ( 0 == QString::compare( "root", text, Qt::CaseSensitive ) ) { - labelError( ui->labelUsername, - ui->labelUsernameError, - tr( "'root' is not allowed as user name." ) ); + labelError( ui->labelUsername, ui->labelUsernameError, tr( "'root' is not allowed as user name." ) ); m_readyUsername = false; } else