[users] Remove calculation of 'ready' from Page

- simplify UI update methods
- drop all the m_ready* members, that should live in Config
main
Adriaan de Groot 5 years ago
parent eb44d0c6be
commit 36cefe3be1

@ -41,25 +41,15 @@
#include <QLabel> #include <QLabel>
#include <QLineEdit> #include <QLineEdit>
/** @brief How bad is the error for labelError() ? */ /** @brief Add an error message and pixmap to a label. */
enum class Badness
{
Fatal,
Warning
};
/** Add an error message and pixmap to a label. */
static inline void static inline void
labelError( QLabel* pix, QLabel* label, const QString& message, Badness bad ) labelError( QLabel* pix, QLabel* label, CalamaresUtils::ImageType icon, const QString& message )
{ {
label->setText( message ); label->setText( message );
pix->setPixmap( CalamaresUtils::defaultPixmap( ( bad == Badness::Fatal ) ? CalamaresUtils::StatusError pix->setPixmap( CalamaresUtils::defaultPixmap( icon, CalamaresUtils::Original, label->size() ) );
: CalamaresUtils::StatusWarning,
CalamaresUtils::Original,
label->size() ) );
} }
/** Clear error, indicate OK on a label. */ /** @brief Clear error, set happy pixmap on a label to indicate "ok". */
static inline void static inline void
labelOk( QLabel* pix, QLabel* label ) labelOk( QLabel* pix, QLabel* label )
{ {
@ -67,9 +57,14 @@ labelOk( QLabel* pix, QLabel* label )
pix->setPixmap( CalamaresUtils::defaultPixmap( CalamaresUtils::Yes, CalamaresUtils::Original, label->size() ) ); pix->setPixmap( CalamaresUtils::defaultPixmap( CalamaresUtils::Yes, CalamaresUtils::Original, label->size() ) );
} }
/** Indicate error, update @p ok based on @p status */ /** @brief Sets error or ok on a label depending on @p status and @p value
*
* - An **empty** @p value gets no message and no icon.
* - A non-empty @p value, with an **empty** @p status gets an "ok".
* - A non-empty @p value with a non-empty @p status gets an error indicator.
*/
static inline void static inline void
labelStatus( QLabel* pix, QLabel* label, const QString& value, const QString& status, bool& ok ) labelStatus( QLabel* pix, QLabel* label, const QString& value, const QString& status )
{ {
if ( status.isEmpty() ) if ( status.isEmpty() )
{ {
@ -78,18 +73,15 @@ labelStatus( QLabel* pix, QLabel* label, const QString& value, const QString& st
// This is different from labelOK() because no checkmark is shown // This is different from labelOK() because no checkmark is shown
label->clear(); label->clear();
pix->clear(); pix->clear();
ok = false;
} }
else else
{ {
labelOk( pix, label ); labelOk( pix, label );
ok = true;
} }
} }
else else
{ {
labelError( pix, label, status, Badness::Fatal ); labelError( pix, label, CalamaresUtils::ImageType::StatusError, status );
ok = false;
} }
} }
@ -97,11 +89,6 @@ UsersPage::UsersPage( Config* config, QWidget* parent )
: QWidget( parent ) : QWidget( parent )
, ui( new Ui::Page_UserSetup ) , ui( new Ui::Page_UserSetup )
, m_config( config ) , m_config( config )
, m_readyFullName( false )
, m_readyUsername( false )
, m_readyHostname( false )
, m_readyPassword( false )
, m_readyRootPassword( false )
{ {
ui->setupUi( this ); ui->setupUi( this );
@ -202,11 +189,12 @@ UsersPage::retranslate()
bool bool
UsersPage::isReady() const UsersPage::isReady() const
{ {
bool readyFields = m_readyFullName && m_readyHostname && m_readyPassword && m_readyUsername; bool readyFullName = !m_config->fullName().isEmpty(); // Needs some text
// If we're going to write a root password, we need a valid one (or reuse the user's password) bool readyHostname = m_config->hostNameStatus().isEmpty(); // .. no warning message
readyFields bool readyUsername = m_config->loginNameStatus().isEmpty(); // .. no warning message
&= m_config->writeRootPassword() ? ( m_readyRootPassword || ui->checkBoxReusePassword->isChecked() ) : true; bool readyUserPassword = m_config->userPasswordValidity() != Config::PasswordValidity::Invalid;
return readyFields; bool readyRootPassword = m_config->rootPasswordValidity() != Config::PasswordValidity::Invalid;
return readyFullName && readyHostname && readyUsername && readyUserPassword && readyRootPassword;
} }
@ -224,21 +212,21 @@ UsersPage::onActivate()
void void
UsersPage::onFullNameTextEdited( const QString& fullName ) UsersPage::onFullNameTextEdited( const QString& fullName )
{ {
labelStatus( ui->labelFullName, ui->labelFullNameError, fullName, QString(), m_readyFullName ); labelStatus( ui->labelFullName, ui->labelFullNameError, fullName, QString() );
checkReady( isReady() ); checkReady( isReady() );
} }
void void
UsersPage::reportLoginNameStatus( const QString& status ) UsersPage::reportLoginNameStatus( const QString& status )
{ {
labelStatus( ui->labelUsername, ui->labelUsernameError, m_config->loginName(), status, m_readyUsername ); labelStatus( ui->labelUsername, ui->labelUsernameError, m_config->loginName(), status );
emit checkReady( isReady() ); emit checkReady( isReady() );
} }
void void
UsersPage::reportHostNameStatus( const QString& status ) UsersPage::reportHostNameStatus( const QString& status )
{ {
labelStatus( ui->labelHostname, ui->labelHostnameError, m_config->hostName(), status, m_readyHostname ); labelStatus( ui->labelHostname, ui->labelHostnameError, m_config->hostName(), status );
emit checkReady( isReady() ); emit checkReady( isReady() );
} }
@ -248,20 +236,14 @@ passwordStatus( QLabel* iconLabel, QLabel* messageLabel, int validity, const QSt
switch ( validity ) switch ( validity )
{ {
case Config::PasswordValidity::Valid: case Config::PasswordValidity::Valid:
messageLabel->clear(); labelOk( iconLabel, messageLabel );
iconLabel->setPixmap(
CalamaresUtils::defaultPixmap( CalamaresUtils::Yes, CalamaresUtils::Original, messageLabel->size() ) );
break; break;
case Config::PasswordValidity::Weak: case Config::PasswordValidity::Weak:
messageLabel->setText( message ); labelError( iconLabel, messageLabel, CalamaresUtils::StatusWarning, message );
iconLabel->setPixmap( CalamaresUtils::defaultPixmap(
CalamaresUtils::StatusWarning, CalamaresUtils::Original, messageLabel->size() ) );
break; break;
case Config::PasswordValidity::Invalid: case Config::PasswordValidity::Invalid:
default: default:
messageLabel->setText( message ); labelError( iconLabel, messageLabel, CalamaresUtils::StatusError, message );
iconLabel->setPixmap( CalamaresUtils::defaultPixmap(
CalamaresUtils::StatusError, CalamaresUtils::Original, messageLabel->size() ) );
break; break;
} }
} }

@ -62,12 +62,6 @@ private:
Ui::Page_UserSetup* ui; Ui::Page_UserSetup* ui;
Config* m_config; Config* m_config;
bool m_readyFullName;
bool m_readyUsername;
bool m_readyHostname;
bool m_readyPassword;
bool m_readyRootPassword;
}; };
#endif // USERSPAGE_H #endif // USERSPAGE_H

Loading…
Cancel
Save