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

View file

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

View file

@ -25,24 +25,11 @@
#include <QtDBus/QDBusInterface> #include <QtDBus/QDBusInterface>
#include <QtDBus/QDBusReply> #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 ) FinishedViewStep::FinishedViewStep( QObject* parent )
: Calamares::ViewStep( parent ) : Calamares::ViewStep( parent )
, m_config( new Config( this ))
, m_widget( new FinishedPage() ) , m_widget( new FinishedPage() )
, installFailed( false ) , installFailed( false )
, m_notifyOnFinished( false )
{ {
auto jq = Calamares::JobQueue::instance(); auto jq = Calamares::JobQueue::instance();
connect( jq, &Calamares::JobQueue::failed, m_widget, &FinishedPage::onInstallationFailed ); connect( jq, &Calamares::JobQueue::failed, m_widget, &FinishedPage::onInstallationFailed );
@ -146,7 +133,7 @@ FinishedViewStep::onActivate()
{ {
m_widget->setUpRestart(); m_widget->setUpRestart();
if ( m_notifyOnFinished ) if ( m_config->notifyOnFinished() )
{ {
sendNotification(); sendNotification();
} }
@ -170,59 +157,13 @@ FinishedViewStep::onInstallationFailed( const QString& message, const QString& d
void void
FinishedViewStep::setConfigurationMap( const QVariantMap& configurationMap ) 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 ( m_config->restartNowMode() != Config::RestartMode::Never )
if ( restartMode.isEmpty() )
{ {
if ( configurationMap.contains( "restartNowEnabled" ) ) m_widget->setRestartNowCommand( m_config->restartNowCommand() );
{
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;
}
} }
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 >(); ) CALAMARES_PLUGIN_FACTORY_DEFINITION( FinishedViewStepFactory, registerPlugin< FinishedViewStep >(); )

View file

@ -11,12 +11,14 @@
#ifndef FINISHEDVIEWSTEP_H #ifndef FINISHEDVIEWSTEP_H
#define FINISHEDVIEWSTEP_H #define FINISHEDVIEWSTEP_H
#include <QObject> #include "Config.h"
#include "DllMacro.h"
#include "utils/PluginFactory.h" #include "utils/PluginFactory.h"
#include "viewpages/ViewStep.h" #include "viewpages/ViewStep.h"
#include "DllMacro.h"
#include <QObject>
class FinishedPage; class FinishedPage;
@ -25,16 +27,6 @@ class PLUGINDLLEXPORT FinishedViewStep : public Calamares::ViewStep
Q_OBJECT Q_OBJECT
public: 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 ); explicit FinishedViewStep( QObject* parent = nullptr );
~FinishedViewStep() override; ~FinishedViewStep() override;
@ -58,6 +50,7 @@ public slots:
void onInstallationFailed( const QString& message, const QString& details ); void onInstallationFailed( const QString& message, const QString& details );
private: private:
Config* m_config;
FinishedPage* m_widget; FinishedPage* m_widget;
/** /**
@ -67,7 +60,6 @@ private:
void sendNotification(); void sendNotification();
bool installFailed; bool installFailed;
bool m_notifyOnFinished;
}; };
CALAMARES_PLUGIN_FACTORY_DECLARATION( FinishedViewStepFactory ) CALAMARES_PLUGIN_FACTORY_DECLARATION( FinishedViewStepFactory )