[finished] Move config from viewstep to config object

- the configuration is still duplicated in the widget, and
  functionality still needs to move to the Config object
- the ViewStep is cut down to almost nothing
This commit is contained in:
Adriaan de Groot 2021-02-03 17:14:49 +01:00
parent c82b802f4e
commit cb4248e56d
4 changed files with 25 additions and 91 deletions

View File

@ -10,10 +10,12 @@
*/
#include "FinishedPage.h"
#include "ui_FinishedPage.h"
#include "Branding.h"
#include "Settings.h"
#include "CalamaresVersion.h"
#include "ViewManager.h"
#include "ui_FinishedPage.h"
#include "utils/CalamaresUtilsGui.h"
#include "utils/Logger.h"
#include "utils/Retranslator.h"
@ -24,13 +26,11 @@
#include <QLabel>
#include <QProcess>
#include "Branding.h"
#include "Settings.h"
FinishedPage::FinishedPage( QWidget* parent )
: QWidget( parent )
, ui( new Ui::FinishedPage )
, m_mode( FinishedViewStep::RestartMode::UserUnchecked )
, m_mode( Config::RestartMode::UserDefaultUnchecked )
{
ui->setupUi( this );
@ -66,15 +66,15 @@ FinishedPage::FinishedPage( QWidget* parent )
void
FinishedPage::setRestart( FinishedViewStep::RestartMode mode )
FinishedPage::setRestart( Config::RestartMode mode )
{
using Mode = FinishedViewStep::RestartMode;
using Mode = Config::RestartMode;
m_mode = mode;
ui->restartCheckBox->setVisible( mode != Mode::Never );
ui->restartCheckBox->setEnabled( mode != Mode::Always );
ui->restartCheckBox->setChecked( ( mode == Mode::Always ) || ( mode == Mode::UserChecked ) );
ui->restartCheckBox->setChecked( ( mode == Mode::Always ) || ( mode == Mode::UserDefaultChecked ) );
}
@ -89,7 +89,7 @@ void
FinishedPage::setUpRestart()
{
cDebug() << "FinishedPage::setUpRestart(), Quit button"
<< "setup=" << FinishedViewStep::modeName( m_mode ) << "command=" << m_restartNowCommand;
<< "setup=" << restartModes().find( m_mode ) << "command=" << m_restartNowCommand;
connect( qApp, &QApplication::aboutToQuit, [this]() {
if ( ui->restartCheckBox->isVisible() && ui->restartCheckBox->isChecked() )
@ -124,5 +124,5 @@ FinishedPage::onInstallationFailed( const QString& message, const QString& detai
"The error message was: %2." )
.arg( branding->versionedName() )
.arg( message ) );
setRestart( FinishedViewStep::RestartMode::Never );
setRestart( Config::RestartMode::Never );
}

View File

@ -11,9 +11,10 @@
#ifndef FINISHEDPAGE_H
#define FINISHEDPAGE_H
#include <QWidget>
#include "FinishedViewStep.h"
#include "Config.h"
#include <QWidget>
namespace Ui
{
@ -26,7 +27,7 @@ class FinishedPage : public QWidget
public:
explicit FinishedPage( QWidget* parent = nullptr );
void setRestart( FinishedViewStep::RestartMode mode );
void setRestart( Config::RestartMode mode );
void setRestartNowCommand( const QString& command );
void setUpRestart();
@ -40,7 +41,7 @@ protected:
private:
Ui::FinishedPage* ui;
FinishedViewStep::RestartMode m_mode;
Config::RestartMode m_mode;
QString m_restartNowCommand;
};

View File

@ -25,24 +25,11 @@
#include <QtDBus/QDBusInterface>
#include <QtDBus/QDBusReply>
static const NamedEnumTable< FinishedViewStep::RestartMode >&
modeNames()
{
using Mode = FinishedViewStep::RestartMode;
static const NamedEnumTable< Mode > names { { QStringLiteral( "never" ), Mode::Never },
{ QStringLiteral( "user-unchecked" ), Mode::UserUnchecked },
{ QStringLiteral( "user-checked" ), Mode::UserChecked },
{ QStringLiteral( "always" ), Mode::Always } };
return names;
}
FinishedViewStep::FinishedViewStep( QObject* parent )
: Calamares::ViewStep( parent )
, m_config( new Config( this ))
, m_widget( new FinishedPage() )
, installFailed( false )
, m_notifyOnFinished( false )
{
auto jq = Calamares::JobQueue::instance();
connect( jq, &Calamares::JobQueue::failed, m_widget, &FinishedPage::onInstallationFailed );
@ -146,7 +133,7 @@ FinishedViewStep::onActivate()
{
m_widget->setUpRestart();
if ( m_notifyOnFinished )
if ( m_config->notifyOnFinished() )
{
sendNotification();
}
@ -170,59 +157,13 @@ FinishedViewStep::onInstallationFailed( const QString& message, const QString& d
void
FinishedViewStep::setConfigurationMap( const QVariantMap& configurationMap )
{
RestartMode mode = RestartMode::Never;
m_config->setConfigurationMap(configurationMap);
m_widget->setRestart( m_config->restartNowMode() );
QString restartMode = CalamaresUtils::getString( configurationMap, "restartNowMode" );
if ( restartMode.isEmpty() )
if ( m_config->restartNowMode() != Config::RestartMode::Never )
{
if ( configurationMap.contains( "restartNowEnabled" ) )
{
cWarning() << "Configuring the finished module with deprecated restartNowEnabled settings";
}
bool restartNowEnabled = CalamaresUtils::getBool( configurationMap, "restartNowEnabled", false );
bool restartNowChecked = CalamaresUtils::getBool( configurationMap, "restartNowChecked", false );
if ( !restartNowEnabled )
{
mode = RestartMode::Never;
}
else
{
mode = restartNowChecked ? RestartMode::UserChecked : RestartMode::UserUnchecked;
}
m_widget->setRestartNowCommand( m_config->restartNowCommand() );
}
else
{
bool ok = false;
mode = modeNames().find( restartMode, ok );
if ( !ok )
{
cWarning() << "Configuring the finished module with bad restartNowMode" << restartMode;
}
}
m_widget->setRestart( mode );
if ( mode != RestartMode::Never )
{
QString restartNowCommand = CalamaresUtils::getString( configurationMap, "restartNowCommand" );
if ( restartNowCommand.isEmpty() )
{
restartNowCommand = QStringLiteral( "shutdown -r now" );
}
m_widget->setRestartNowCommand( restartNowCommand );
}
m_notifyOnFinished = CalamaresUtils::getBool( configurationMap, "notifyOnFinished", false );
}
QString
FinishedViewStep::modeName( FinishedViewStep::RestartMode m )
{
bool ok = false;
return modeNames().find( m, ok ); // May be QString()
}
CALAMARES_PLUGIN_FACTORY_DEFINITION( FinishedViewStepFactory, registerPlugin< FinishedViewStep >(); )

View File

@ -11,12 +11,14 @@
#ifndef FINISHEDVIEWSTEP_H
#define FINISHEDVIEWSTEP_H
#include <QObject>
#include "Config.h"
#include "DllMacro.h"
#include "utils/PluginFactory.h"
#include "viewpages/ViewStep.h"
#include "DllMacro.h"
#include <QObject>
class FinishedPage;
@ -25,16 +27,6 @@ class PLUGINDLLEXPORT FinishedViewStep : public Calamares::ViewStep
Q_OBJECT
public:
enum class RestartMode
{
Never = 0, ///< @brief Don't show button, just exit
UserUnchecked, ///< @brief Show button, starts unchecked
UserChecked, ///< @brief Show button, starts checked
Always ///< @brief Show button, can't change, checked
};
/// @brief Returns the config-name of the given restart-mode @p m
static QString modeName( RestartMode m );
explicit FinishedViewStep( QObject* parent = nullptr );
~FinishedViewStep() override;
@ -58,6 +50,7 @@ public slots:
void onInstallationFailed( const QString& message, const QString& details );
private:
Config* m_config;
FinishedPage* m_widget;
/**
@ -67,7 +60,6 @@ private:
void sendNotification();
bool installFailed;
bool m_notifyOnFinished;
};
CALAMARES_PLUGIN_FACTORY_DECLARATION( FinishedViewStepFactory )