[users] Hook up strong- and reuse- password checkboxes

- setup the visibility and initial checked-state of the reuse-user-
  password-for-root near where it gets connected; do similar
  for the require-strong-password
- squash the lambda slot into the regular slot: no sense in
  connecting twice to the same signal with the same receiver.
- only connect config->ui once
- only connect at all if the setting is visible (e.g. when weak
  passwords are allowed for the require-strong checkbox, or
  when root's password will be written for the reuse-password)
This commit is contained in:
Adriaan de Groot 2020-08-28 22:23:36 +02:00
parent d584a96335
commit 15b5ef467e

View File

@ -84,12 +84,6 @@ UsersPage::UsersPage( Config* config, QWidget* parent )
{
ui->setupUi( this );
ui->checkBoxReusePassword->setVisible( m_config->writeRootPassword() );
ui->checkBoxReusePassword->setChecked( m_config->reuseUserPasswordForRoot() );
ui->checkBoxRequireStrongPassword->setVisible( m_config->permitWeakPasswords() );
ui->checkBoxRequireStrongPassword->setChecked( m_config->requireStrongPasswords() );
// Connect signals and slots
ui->textBoxUserPassword->setText( config->userPassword() );
connect( ui->textBoxUserPassword, &QLineEdit::textChanged, config, &Config::setUserPassword );
@ -107,10 +101,6 @@ UsersPage::UsersPage( Config* config, QWidget* parent )
connect( config, &Config::rootPasswordSecondaryChanged, ui->textBoxVerifiedRootPassword, &QLineEdit::setText );
connect( config, &Config::rootPasswordStatusChanged, this, &UsersPage::reportRootPasswordStatus );
connect( ui->checkBoxRequireStrongPassword, &QCheckBox::stateChanged, this, [this]( int checked ) {
m_config->setRequireStrongPasswords( checked != Qt::Unchecked );
} );
connect( ui->textBoxFullName, &QLineEdit::textEdited, config, &Config::setFullName );
connect( config, &Config::fullNameChanged, this, &UsersPage::onFullNameTextEdited );
@ -127,21 +117,23 @@ UsersPage::UsersPage( Config* config, QWidget* parent )
} );
connect( config, &Config::autoLoginChanged, ui->checkBoxDoAutoLogin, &QCheckBox::setChecked );
ui->checkBoxReusePassword->setVisible( m_config->writeRootPassword() );
ui->checkBoxReusePassword->setChecked( m_config->reuseUserPasswordForRoot() );
if ( m_config->writeRootPassword() )
{
connect( ui->checkBoxReusePassword, &QCheckBox::stateChanged, this, [this]( int checked ) {
m_config->setReuseUserPasswordForRoot( checked != Qt::Unchecked );
} );
connect( config, &Config::reuseUserPasswordForRootChanged, ui->checkBoxReusePassword, &QCheckBox::setChecked );
connect( ui->checkBoxReusePassword, &QCheckBox::stateChanged, this, &UsersPage::onReuseUserPasswordChanged );
}
ui->checkBoxRequireStrongPassword->setVisible( m_config->permitWeakPasswords() );
ui->checkBoxRequireStrongPassword->setChecked( m_config->requireStrongPasswords() );
if ( m_config->permitWeakPasswords() )
{
connect( ui->checkBoxRequireStrongPassword, &QCheckBox::stateChanged, this, [this]( int checked ) {
m_config->setRequireStrongPasswords( checked != Qt::Unchecked );
} );
connect( config, &Config::requireStrongPasswordsChanged, ui->checkBoxRequireStrongPassword, &QCheckBox::setChecked );
connect(
config, &Config::requireStrongPasswordsChanged, ui->checkBoxRequireStrongPassword, &QCheckBox::setChecked );
}
CALAMARES_RETRANSLATE_SLOT( &UsersPage::retranslate )
@ -241,6 +233,8 @@ UsersPage::reportUserPasswordStatus( int validity, const QString& message )
void
UsersPage::onReuseUserPasswordChanged( const int checked )
{
// Pass the change on to config
m_config->setReuseUserPasswordForRoot( checked != Qt::Unchecked );
/* 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