[users] Move job creation from widget to viewstep

- This is a half-step: the ViewStep shouldn't do job creation either,
  eventually it needs to be the Config object, but this is better
  than asking the widget (UI) to create some jobs.
- When updating login- or host-name, or the autologin setting,
  set it in GS as well. This is a minor improvement over doing
  it only when leaving the page.
- Since the Config object isn't complete, there are leftovers in
  the widget, which has a fillGlobalStorage() for the not-jobs-related
  bits previously in createJobs().
main
Adriaan de Groot 5 years ago
parent 6a03bcb25e
commit cc2e3f79ff

@ -87,6 +87,16 @@ Config::setLoginName( const QString& login )
{
if ( login != m_loginName )
{
Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage();
if ( login.isEmpty() )
{
gs->remove( "username" );
}
else
{
gs->insert( "username", login );
}
m_customLoginName = !login.isEmpty();
m_loginName = login;
emit loginNameChanged( login );
@ -143,6 +153,16 @@ Config::setHostName( const QString& host )
{
if ( host != m_hostName )
{
Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage();
if ( host.isEmpty() )
{
gs->remove( "hostname" );
}
else
{
gs->insert( "hostname", host );
}
m_customHostName = !host.isEmpty();
m_hostName = host;
emit hostNameChanged( host );
@ -317,6 +337,15 @@ Config::setAutoLogin( bool b )
{
if ( b != m_doAutoLogin )
{
Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage();
if ( b )
{
gs->insert( "autologinUser", loginName() );
}
else
{
gs->remove( "autologinUser" );
}
m_doAutoLogin = b;
emit autoLoginChanged( b );
}

@ -24,12 +24,9 @@
*/
#include "UsersPage.h"
#include "ui_page_usersetup.h"
#include "Config.h"
#include "CreateUserJob.h"
#include "SetHostNameJob.h"
#include "SetPasswordJob.h"
#include "ui_page_usersetup.h"
#include "GlobalStorage.h"
#include "JobQueue.h"
@ -189,7 +186,7 @@ UsersPage::retranslate()
bool
UsersPage::isReady()
UsersPage::isReady() const
{
bool readyFields = m_readyFullName && m_readyHostname && m_readyPassword && m_readyUsername;
// If we're going to write a root password, we need a valid one (or reuse the user's password)
@ -224,38 +221,21 @@ UsersPage::getUserPassword() const
return QPair< QString, QString >( m_config->loginName(), ui->textBoxUserPassword->text() );
}
QList< Calamares::job_ptr >
UsersPage::createJobs( const QStringList& defaultGroupsList )
void
UsersPage::fillGlobalStorage() const
{
QList< Calamares::job_ptr > list;
if ( !isReady() )
{
return list;
return;
}
Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage();
Calamares::Job* j;
j = new CreateUserJob( m_config->loginName(),
m_config->fullName().isEmpty() ? m_config->loginName() : m_config->fullName(),
m_config->doAutoLogin(),
defaultGroupsList );
list.append( Calamares::job_ptr( j ) );
if ( m_config->writeRootPassword() )
{
gs->insert( "reuseRootPassword", ui->checkBoxReusePassword->isChecked() );
}
gs->insert( "hostname", m_config->hostName() );
if ( m_config->doAutoLogin() )
{
gs->insert( "autologinUser", m_config->loginName() );
}
gs->insert( "username", m_config->loginName() );
gs->insert( "password", CalamaresUtils::obscure( ui->textBoxUserPassword->text() ) );
return list;
}

@ -25,7 +25,6 @@
#define USERSPAGE_H
#include "CheckPWQuality.h"
#include "Job.h"
#include <QWidget>
@ -45,9 +44,9 @@ public:
explicit UsersPage( Config* config, QWidget* parent = nullptr );
virtual ~UsersPage();
bool isReady();
bool isReady() const;
Calamares::JobList createJobs( const QStringList& defaultGroupsList );
void fillGlobalStorage() const;
void onActivate();

@ -21,6 +21,7 @@
#include "UsersViewStep.h"
#include "Config.h"
#include "CreateUserJob.h"
#include "SetHostNameJob.h"
#include "SetPasswordJob.h"
#include "UsersPage.h"
@ -138,13 +139,16 @@ void
UsersViewStep::onLeave()
{
m_jobs.clear();
if ( !m_widget )
if ( !m_widget || !m_widget->isReady() )
{
return;
}
m_jobs.append( m_widget->createJobs( m_defaultGroups ) );
Calamares::Job* j;
j = new CreateUserJob( m_config->loginName(),
m_config->fullName().isEmpty() ? m_config->loginName() : m_config->fullName(),
m_config->doAutoLogin(),
m_defaultGroups );
auto userPW = m_widget->getUserPassword();
j = new SetPasswordJob( userPW.first, userPW.second );
@ -155,6 +159,8 @@ UsersViewStep::onLeave()
j = new SetHostNameJob( m_config->hostName(), m_actions );
m_jobs.append( Calamares::job_ptr( j ) );
m_widget->fillGlobalStorage();
}

Loading…
Cancel
Save