[users] Pass the Config object to the Page

- delay construction of the Page (widget) until it's needed
- hand the Config object to the Page on construction

This is prep-work for putting the configuration information into the
Config object, rather than in the UI elements.
main
Adriaan de Groot 5 years ago
parent dab831b2ff
commit f9b114a67a

@ -79,9 +79,10 @@ labelOk( QLabel* pix, QLabel* label )
pix->setPixmap( CalamaresUtils::defaultPixmap( CalamaresUtils::Yes, CalamaresUtils::Original, label->size() ) );
}
UsersPage::UsersPage( QWidget* parent )
UsersPage::UsersPage( Config* config, QWidget* parent )
: QWidget( parent )
, ui( new Ui::Page_UserSetup )
, m_config( config )
, m_readyFullName( false )
, m_readyUsername( false )
, m_readyHostname( false )
@ -99,12 +100,12 @@ UsersPage::UsersPage( QWidget* parent )
connect( ui->textBoxUserVerifiedPassword, &QLineEdit::textChanged, this, &UsersPage::onPasswordTextChanged );
connect( ui->textBoxRootPassword, &QLineEdit::textChanged, this, &UsersPage::onRootPasswordTextChanged );
connect( ui->textBoxVerifiedRootPassword, &QLineEdit::textChanged, this, &UsersPage::onRootPasswordTextChanged );
connect( ui->checkBoxValidatePassword, &QCheckBox::stateChanged, this, [ this ]( int ) {
connect( ui->checkBoxValidatePassword, &QCheckBox::stateChanged, this, [this]( int ) {
onPasswordTextChanged( ui->textBoxUserPassword->text() );
onRootPasswordTextChanged( ui->textBoxRootPassword->text() );
checkReady( isReady() );
} );
connect( ui->checkBoxReusePassword, &QCheckBox::stateChanged, this, [ this ]( int checked ) {
connect( ui->checkBoxReusePassword, &QCheckBox::stateChanged, this, [this]( int checked ) {
/* 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

@ -29,6 +29,8 @@
#include <QWidget>
class Config;
class QLabel;
namespace Ui
@ -40,7 +42,7 @@ class UsersPage : public QWidget
{
Q_OBJECT
public:
explicit UsersPage( QWidget* parent = nullptr );
explicit UsersPage( Config* config, QWidget* parent = nullptr );
virtual ~UsersPage();
bool isReady();
@ -95,6 +97,7 @@ private:
void retranslate();
Ui::Page_UserSetup* ui;
Config* m_config;
PasswordCheckList m_passwordChecks;
bool m_passwordChecksChanged = false;

@ -20,17 +20,17 @@
#include "UsersViewStep.h"
#include "Config.h"
#include "SetHostNameJob.h"
#include "SetPasswordJob.h"
#include "UsersPage.h"
#include "GlobalStorage.h"
#include "JobQueue.h"
#include "utils/Logger.h"
#include "utils/NamedEnum.h"
#include "utils/Variant.h"
#include "GlobalStorage.h"
#include "JobQueue.h"
CALAMARES_PLUGIN_FACTORY_DEFINITION( UsersViewStepFactory, registerPlugin< UsersViewStep >(); )
static const NamedEnumTable< SetHostNameJob::Action >&
@ -53,11 +53,11 @@ hostnameActions()
UsersViewStep::UsersViewStep( QObject* parent )
: Calamares::ViewStep( parent )
, m_widget( new UsersPage() )
, m_widget( nullptr )
, m_actions( SetHostNameJob::Action::None )
, m_config( new Config( this ) )
{
emit nextStatusChanged( true );
connect( m_widget, &UsersPage::checkReady, this, &UsersViewStep::nextStatusChanged );
}
@ -80,6 +80,11 @@ UsersViewStep::prettyName() const
QWidget*
UsersViewStep::widget()
{
if ( !m_widget )
{
m_widget = new UsersPage( m_config );
connect( m_widget, &UsersPage::checkReady, this, &UsersViewStep::nextStatusChanged );
}
return m_widget;
}
@ -87,7 +92,7 @@ UsersViewStep::widget()
bool
UsersViewStep::isNextEnabled() const
{
return m_widget->isReady();
return m_widget ? m_widget->isReady() : true;
}
@ -122,7 +127,10 @@ UsersViewStep::jobs() const
void
UsersViewStep::onActivate()
{
m_widget->onActivate();
if ( m_widget )
{
m_widget->onActivate();
}
}
@ -130,6 +138,10 @@ void
UsersViewStep::onLeave()
{
m_jobs.clear();
if ( !m_widget )
{
return;
}
m_jobs.append( m_widget->createJobs( m_defaultGroups ) );
Calamares::Job* j;
@ -222,4 +234,6 @@ UsersViewStep::setConfigurationMap( const QVariantMap& configurationMap )
Action hostsfileAction = getBool( configurationMap, "writeHostsFile", true ) ? Action::WriteEtcHosts : Action::None;
m_actions = hostsfileAction | hostnameAction;
m_config->setConfigurationMap( configurationMap );
}

@ -29,6 +29,7 @@
#include <QObject>
#include <QVariant>
class Config;
class UsersPage;
class PLUGINDLLEXPORT UsersViewStep : public Calamares::ViewStep
@ -62,6 +63,8 @@ private:
QStringList m_defaultGroups;
SetHostNameJob::Actions m_actions;
Config* m_config;
};
CALAMARES_PLUGIN_FACTORY_DECLARATION( UsersViewStepFactory )

Loading…
Cancel
Save