[users] Move some configuration from Page to Config object
- make the HostName textbox just a view on the Config's HostName - make the username and login textboxes view onto Config - query the Config rather than the UI for job data
This commit is contained in:
parent
5ffa09000a
commit
8a14cc7ffc
@ -168,6 +168,8 @@ makeHostnameSuggestion( const QStringList& parts )
|
|||||||
void
|
void
|
||||||
Config::setUserName( const QString& name )
|
Config::setUserName( const QString& name )
|
||||||
{
|
{
|
||||||
|
// TODO: handle "empty" case
|
||||||
|
// TODO: rename to "FullName"
|
||||||
if ( name != m_fullName )
|
if ( name != m_fullName )
|
||||||
{
|
{
|
||||||
m_fullName = name;
|
m_fullName = name;
|
||||||
|
@ -24,9 +24,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "UsersPage.h"
|
#include "UsersPage.h"
|
||||||
|
|
||||||
#include "ui_page_usersetup.h"
|
#include "ui_page_usersetup.h"
|
||||||
|
|
||||||
|
#include "Config.h"
|
||||||
#include "CreateUserJob.h"
|
#include "CreateUserJob.h"
|
||||||
#include "SetHostNameJob.h"
|
#include "SetHostNameJob.h"
|
||||||
#include "SetPasswordJob.h"
|
#include "SetPasswordJob.h"
|
||||||
@ -34,7 +34,6 @@
|
|||||||
#include "GlobalStorage.h"
|
#include "GlobalStorage.h"
|
||||||
#include "JobQueue.h"
|
#include "JobQueue.h"
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
|
|
||||||
#include "utils/CalamaresUtilsGui.h"
|
#include "utils/CalamaresUtilsGui.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/Retranslator.h"
|
#include "utils/Retranslator.h"
|
||||||
@ -94,8 +93,6 @@ UsersPage::UsersPage( Config* config, QWidget* parent )
|
|||||||
|
|
||||||
// Connect signals and slots
|
// Connect signals and slots
|
||||||
connect( ui->textBoxFullName, &QLineEdit::textEdited, this, &UsersPage::onFullNameTextEdited );
|
connect( ui->textBoxFullName, &QLineEdit::textEdited, this, &UsersPage::onFullNameTextEdited );
|
||||||
connect( ui->textBoxUsername, &QLineEdit::textEdited, this, &UsersPage::onUsernameTextEdited );
|
|
||||||
connect( ui->textBoxHostname, &QLineEdit::textEdited, this, &UsersPage::onHostnameTextEdited );
|
|
||||||
connect( ui->textBoxUserPassword, &QLineEdit::textChanged, this, &UsersPage::onPasswordTextChanged );
|
connect( ui->textBoxUserPassword, &QLineEdit::textChanged, this, &UsersPage::onPasswordTextChanged );
|
||||||
connect( ui->textBoxUserVerifiedPassword, &QLineEdit::textChanged, this, &UsersPage::onPasswordTextChanged );
|
connect( ui->textBoxUserVerifiedPassword, &QLineEdit::textChanged, this, &UsersPage::onPasswordTextChanged );
|
||||||
connect( ui->textBoxRootPassword, &QLineEdit::textChanged, this, &UsersPage::onRootPasswordTextChanged );
|
connect( ui->textBoxRootPassword, &QLineEdit::textChanged, this, &UsersPage::onRootPasswordTextChanged );
|
||||||
@ -124,8 +121,13 @@ UsersPage::UsersPage( Config* config, QWidget* parent )
|
|||||||
checkReady( isReady() );
|
checkReady( isReady() );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
m_customUsername = false;
|
connect( ui->textBoxHostName, &QLineEdit::textEdited, config, &Config::setHostName);
|
||||||
m_customHostname = false;
|
connect( config, &Config::hostNameChanged, ui->textBoxHostName, &QLineEdit::setText );
|
||||||
|
connect( config, &Config::hostNameChanged, this, &UsersPage::validateHostnameText );
|
||||||
|
|
||||||
|
connect( ui->textBoxLoginName, &QLineEdit::textEdited, config, &Config::setLoginName );
|
||||||
|
connect( config, &Config::loginNameChanged, ui->textBoxLoginName, &QLineEdit::setText );
|
||||||
|
connect( config, &Config::loginNameChanged, this, &UsersPage::validateUsernameText );
|
||||||
|
|
||||||
setWriteRootPassword( true );
|
setWriteRootPassword( true );
|
||||||
ui->checkBoxReusePassword->setChecked( true );
|
ui->checkBoxReusePassword->setChecked( true );
|
||||||
@ -147,13 +149,13 @@ UsersPage::retranslate()
|
|||||||
ui->retranslateUi( this );
|
ui->retranslateUi( this );
|
||||||
if ( Calamares::Settings::instance()->isSetupMode() )
|
if ( Calamares::Settings::instance()->isSetupMode() )
|
||||||
{
|
{
|
||||||
ui->textBoxUsername->setToolTip( tr( "<small>If more than one person will "
|
ui->textBoxLoginName->setToolTip( tr( "<small>If more than one person will "
|
||||||
"use this computer, you can create multiple "
|
"use this computer, you can create multiple "
|
||||||
"accounts after setup.</small>" ) );
|
"accounts after setup.</small>" ) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ui->textBoxUsername->setToolTip( tr( "<small>If more than one person will "
|
ui->textBoxLoginName->setToolTip( tr( "<small>If more than one person will "
|
||||||
"use this computer, you can create multiple "
|
"use this computer, you can create multiple "
|
||||||
"accounts after installation.</small>" ) );
|
"accounts after installation.</small>" ) );
|
||||||
}
|
}
|
||||||
@ -177,12 +179,6 @@ UsersPage::isReady()
|
|||||||
return readyFields && m_readyRootPassword;
|
return readyFields && m_readyRootPassword;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString
|
|
||||||
UsersPage::getHostname() const
|
|
||||||
{
|
|
||||||
return ui->textBoxHostname->text();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString
|
QString
|
||||||
UsersPage::getRootPassword() const
|
UsersPage::getRootPassword() const
|
||||||
{
|
{
|
||||||
@ -206,7 +202,7 @@ UsersPage::getRootPassword() const
|
|||||||
QPair< QString, QString >
|
QPair< QString, QString >
|
||||||
UsersPage::getUserPassword() const
|
UsersPage::getUserPassword() const
|
||||||
{
|
{
|
||||||
return QPair< QString, QString >( ui->textBoxUsername->text(), ui->textBoxUserPassword->text() );
|
return QPair< QString, QString >( m_config->loginName(), ui->textBoxUserPassword->text() );
|
||||||
}
|
}
|
||||||
|
|
||||||
QList< Calamares::job_ptr >
|
QList< Calamares::job_ptr >
|
||||||
@ -221,9 +217,9 @@ UsersPage::createJobs( const QStringList& defaultGroupsList )
|
|||||||
Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage();
|
Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage();
|
||||||
|
|
||||||
Calamares::Job* j;
|
Calamares::Job* j;
|
||||||
j = new CreateUserJob( ui->textBoxUsername->text(),
|
j = new CreateUserJob( m_config->loginName(),
|
||||||
ui->textBoxFullName->text().isEmpty() ? ui->textBoxUsername->text()
|
m_config->userName().isEmpty() ? m_config->loginName()
|
||||||
: ui->textBoxFullName->text(),
|
: m_config->userName(),
|
||||||
ui->checkBoxAutoLogin->isChecked(),
|
ui->checkBoxAutoLogin->isChecked(),
|
||||||
defaultGroupsList );
|
defaultGroupsList );
|
||||||
list.append( Calamares::job_ptr( j ) );
|
list.append( Calamares::job_ptr( j ) );
|
||||||
@ -232,13 +228,13 @@ UsersPage::createJobs( const QStringList& defaultGroupsList )
|
|||||||
{
|
{
|
||||||
gs->insert( "reuseRootPassword", ui->checkBoxReusePassword->isChecked() );
|
gs->insert( "reuseRootPassword", ui->checkBoxReusePassword->isChecked() );
|
||||||
}
|
}
|
||||||
gs->insert( "hostname", ui->textBoxHostname->text() );
|
gs->insert( "hostname", m_config->hostName() );
|
||||||
if ( ui->checkBoxAutoLogin->isChecked() )
|
if ( ui->checkBoxAutoLogin->isChecked() )
|
||||||
{
|
{
|
||||||
gs->insert( "autologinUser", ui->textBoxUsername->text() );
|
gs->insert( "autologinUser", m_config->loginName() );
|
||||||
}
|
}
|
||||||
|
|
||||||
gs->insert( "username", ui->textBoxUsername->text() );
|
gs->insert( "username", m_config->loginName() );
|
||||||
gs->insert( "password", CalamaresUtils::obscure( ui->textBoxUserPassword->text() ) );
|
gs->insert( "password", CalamaresUtils::obscure( ui->textBoxUserPassword->text() ) );
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
@ -269,6 +265,7 @@ UsersPage::onFullNameTextEdited( const QString& textRef )
|
|||||||
{
|
{
|
||||||
ui->labelFullNameError->clear();
|
ui->labelFullNameError->clear();
|
||||||
ui->labelFullName->clear();
|
ui->labelFullName->clear();
|
||||||
|
#if 0
|
||||||
if ( !m_customUsername )
|
if ( !m_customUsername )
|
||||||
{
|
{
|
||||||
ui->textBoxUsername->clear();
|
ui->textBoxUsername->clear();
|
||||||
@ -277,6 +274,7 @@ UsersPage::onFullNameTextEdited( const QString& textRef )
|
|||||||
{
|
{
|
||||||
ui->textBoxHostname->clear();
|
ui->textBoxHostname->clear();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
m_readyFullName = false;
|
m_readyFullName = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -284,97 +282,10 @@ UsersPage::onFullNameTextEdited( const QString& textRef )
|
|||||||
ui->labelFullName->setPixmap(
|
ui->labelFullName->setPixmap(
|
||||||
CalamaresUtils::defaultPixmap( CalamaresUtils::Yes, CalamaresUtils::Original, ui->labelFullName->size() ) );
|
CalamaresUtils::defaultPixmap( CalamaresUtils::Yes, CalamaresUtils::Original, ui->labelFullName->size() ) );
|
||||||
m_readyFullName = true;
|
m_readyFullName = true;
|
||||||
fillSuggestions();
|
|
||||||
}
|
}
|
||||||
checkReady( isReady() );
|
checkReady( isReady() );
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @brief Guess the machine's name
|
|
||||||
*
|
|
||||||
* If there is DMI data, use that; otherwise, just call the machine "-pc".
|
|
||||||
* Reads the DMI data just once.
|
|
||||||
*/
|
|
||||||
static QString
|
|
||||||
guessProductName()
|
|
||||||
{
|
|
||||||
static bool tried = false;
|
|
||||||
static QString dmiProduct;
|
|
||||||
|
|
||||||
if ( !tried )
|
|
||||||
{
|
|
||||||
// yes validateHostnameText() but these files can be a mess
|
|
||||||
QRegExp dmirx( "[^a-zA-Z0-9]", Qt::CaseInsensitive );
|
|
||||||
QFile dmiFile( QStringLiteral( "/sys/devices/virtual/dmi/id/product_name" ) );
|
|
||||||
|
|
||||||
if ( dmiFile.exists() && dmiFile.open( QIODevice::ReadOnly ) )
|
|
||||||
{
|
|
||||||
dmiProduct = QString::fromLocal8Bit( dmiFile.readAll().simplified().data() )
|
|
||||||
.toLower()
|
|
||||||
.replace( dmirx, " " )
|
|
||||||
.remove( ' ' );
|
|
||||||
}
|
|
||||||
if ( dmiProduct.isEmpty() )
|
|
||||||
{
|
|
||||||
dmiProduct = QStringLiteral( "-pc" );
|
|
||||||
}
|
|
||||||
tried = true;
|
|
||||||
}
|
|
||||||
return dmiProduct;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
UsersPage::fillSuggestions()
|
|
||||||
{
|
|
||||||
QString fullName = ui->textBoxFullName->text();
|
|
||||||
QRegExp rx( "[^a-zA-Z0-9 ]", Qt::CaseInsensitive );
|
|
||||||
QString cleanName = CalamaresUtils::removeDiacritics( fullName ).toLower().replace( rx, " " ).simplified();
|
|
||||||
QStringList cleanParts = cleanName.split( ' ' );
|
|
||||||
|
|
||||||
if ( !m_customUsername )
|
|
||||||
{
|
|
||||||
if ( !cleanParts.isEmpty() && !cleanParts.first().isEmpty() )
|
|
||||||
{
|
|
||||||
QString usernameSuggestion = cleanParts.first();
|
|
||||||
for ( int i = 1; i < cleanParts.length(); ++i )
|
|
||||||
{
|
|
||||||
if ( !cleanParts.value( i ).isEmpty() )
|
|
||||||
{
|
|
||||||
usernameSuggestion.append( cleanParts.value( i ).at( 0 ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( USERNAME_RX.indexIn( usernameSuggestion ) != -1 )
|
|
||||||
{
|
|
||||||
ui->textBoxUsername->setText( usernameSuggestion );
|
|
||||||
validateUsernameText( usernameSuggestion );
|
|
||||||
m_customUsername = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !m_customHostname )
|
|
||||||
{
|
|
||||||
if ( !cleanParts.isEmpty() && !cleanParts.first().isEmpty() )
|
|
||||||
{
|
|
||||||
QString hostnameSuggestion;
|
|
||||||
QString productName = guessProductName();
|
|
||||||
hostnameSuggestion = QString( "%1-%2" ).arg( cleanParts.first() ).arg( productName );
|
|
||||||
if ( HOSTNAME_RX.indexIn( hostnameSuggestion ) != -1 )
|
|
||||||
{
|
|
||||||
ui->textBoxHostname->setText( hostnameSuggestion );
|
|
||||||
validateHostnameText( hostnameSuggestion );
|
|
||||||
m_customHostname = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
UsersPage::onUsernameTextEdited( const QString& textRef )
|
|
||||||
{
|
|
||||||
m_customUsername = true;
|
|
||||||
validateUsernameText( textRef );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -427,14 +338,6 @@ UsersPage::validateUsernameText( const QString& textRef )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
UsersPage::onHostnameTextEdited( const QString& textRef )
|
|
||||||
{
|
|
||||||
m_customHostname = true;
|
|
||||||
validateHostnameText( textRef );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
UsersPage::validateHostnameText( const QString& textRef )
|
UsersPage::validateHostnameText( const QString& textRef )
|
||||||
{
|
{
|
||||||
|
@ -65,8 +65,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
void addPasswordCheck( const QString& key, const QVariant& value );
|
void addPasswordCheck( const QString& key, const QVariant& value );
|
||||||
|
|
||||||
///@brief Hostname as entered / auto-filled
|
|
||||||
QString getHostname() const;
|
|
||||||
///@brief Root password, depends on settings, may be empty
|
///@brief Root password, depends on settings, may be empty
|
||||||
QString getRootPassword() const;
|
QString getRootPassword() const;
|
||||||
///@brief User name and password
|
///@brief User name and password
|
||||||
@ -74,10 +72,7 @@ public:
|
|||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void onFullNameTextEdited( const QString& );
|
void onFullNameTextEdited( const QString& );
|
||||||
void fillSuggestions();
|
|
||||||
void onUsernameTextEdited( const QString& );
|
|
||||||
void validateUsernameText( const QString& );
|
void validateUsernameText( const QString& );
|
||||||
void onHostnameTextEdited( const QString& );
|
|
||||||
void validateHostnameText( const QString& );
|
void validateHostnameText( const QString& );
|
||||||
void onPasswordTextChanged( const QString& );
|
void onPasswordTextChanged( const QString& );
|
||||||
void onRootPasswordTextChanged( const QString& );
|
void onRootPasswordTextChanged( const QString& );
|
||||||
@ -104,9 +99,7 @@ private:
|
|||||||
|
|
||||||
bool m_readyFullName;
|
bool m_readyFullName;
|
||||||
bool m_readyUsername;
|
bool m_readyUsername;
|
||||||
bool m_customUsername;
|
|
||||||
bool m_readyHostname;
|
bool m_readyHostname;
|
||||||
bool m_customHostname;
|
|
||||||
bool m_readyPassword;
|
bool m_readyPassword;
|
||||||
bool m_readyRootPassword;
|
bool m_readyRootPassword;
|
||||||
|
|
||||||
|
@ -153,7 +153,7 @@ UsersViewStep::onLeave()
|
|||||||
j = new SetPasswordJob( "root", m_widget->getRootPassword() );
|
j = new SetPasswordJob( "root", m_widget->getRootPassword() );
|
||||||
m_jobs.append( Calamares::job_ptr( j ) );
|
m_jobs.append( Calamares::job_ptr( j ) );
|
||||||
|
|
||||||
j = new SetHostNameJob( m_widget->getHostname(), m_actions );
|
j = new SetHostNameJob( m_config->hostName(), m_actions );
|
||||||
m_jobs.append( Calamares::job_ptr( j ) );
|
m_jobs.append( Calamares::job_ptr( j ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,7 +127,7 @@
|
|||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLineEdit" name="textBoxUsername">
|
<widget class="QLineEdit" name="textBoxLoginName">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
@ -226,7 +226,7 @@
|
|||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLineEdit" name="textBoxHostname">
|
<widget class="QLineEdit" name="textBoxHostName">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
|
Loading…
Reference in New Issue
Block a user