From f3c86810a15155eb4e633c38b66de288d761325f Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 6 May 2019 10:35:09 +0200 Subject: [PATCH] [finished] More (display) modes for restarting - Use a named enum instead of a collection of booleans - Support old-style configuration but complain about it - Update AppImage config as well The new setup allows four different restart modes: never, always, user-unchecked and user-checked. The user-modes are interactive and give the user a choice (defaulting to unchecked-don't-restart and checked-do-restart respectively). The non-interactive versions vary in how they are displayed. --- data/config-appimage/modules/finished.conf | 26 +++++++++---- src/modules/finished/FinishedPage.cpp | 15 +++----- src/modules/finished/FinishedPage.h | 5 ++- src/modules/finished/FinishedViewStep.cpp | 43 ++++++++++++++++++---- src/modules/finished/FinishedViewStep.h | 8 ++++ src/modules/finished/finished.conf | 27 +++++++++++++- 6 files changed, 96 insertions(+), 28 deletions(-) diff --git a/data/config-appimage/modules/finished.conf b/data/config-appimage/modules/finished.conf index 29e5e49b4..48bbdc031 100644 --- a/data/config-appimage/modules/finished.conf +++ b/data/config-appimage/modules/finished.conf @@ -1,14 +1,24 @@ # Configuration for the "finished" page, which is usually shown only at # the end of the installation (successful or not). --- -# The finished page can hold a "restart system now" checkbox. -# If this is false, no checkbox is shown and the system is not restarted -# when Calamares exits. -restartNowEnabled: true - -# Initial state of the checkbox "restart now". Only relevant when the -# checkbox is shown by restartNowEnabled. -restartNowChecked: false +# Behavior of the "restart system now" button. +# +# There are four usable values: +# - never +# Does not show the button and does not restart. +# This matches the old behavior with restartNowEnabled=false. +# - user-unchecked +# Shows the button, defaults to unchecked, restarts if it is checked. +# This matches the old behavior with restartNowEnabled=true and restartNowChecked=false. +# - user-checked +# Shows the button, defaults to checked, restarts if it is checked. +# This matches the old behavior with restartNowEnabled=true and restartNowChecked=true. +# - always +# Shows the button, checked, but the user cannot change it. +# This is new behavior. +# +# The three combinations of legacy values are still supported. +restartNowMode: user-unchecked # If the checkbox is shown, and the checkbox is checked, then when # Calamares exits from the finished-page it will run this command. diff --git a/src/modules/finished/FinishedPage.cpp b/src/modules/finished/FinishedPage.cpp index 1bc935d0d..c49bb9538 100644 --- a/src/modules/finished/FinishedPage.cpp +++ b/src/modules/finished/FinishedPage.cpp @@ -79,16 +79,13 @@ FinishedPage::FinishedPage( QWidget* parent ) void -FinishedPage::setRestartNowEnabled( bool enabled ) +FinishedPage::setRestart( FinishedViewStep::RestartMode mode ) { - ui->restartCheckBox->setVisible( enabled ); -} + using Mode = FinishedViewStep::RestartMode; - -void -FinishedPage::setRestartNowChecked( bool checked ) -{ - ui->restartCheckBox->setChecked( checked ); + ui->restartCheckBox->setVisible( mode != Mode::Never ); + ui->restartCheckBox->setEnabled( mode != Mode::Always ); + ui->restartCheckBox->setChecked( ( mode == Mode::Always ) || ( mode == Mode::UserChecked ) ); } @@ -138,5 +135,5 @@ FinishedPage::onInstallationFailed( const QString& message, const QString& detai "The error message was: %2." ) .arg( *Calamares::Branding::VersionedName ) .arg( message ) ); - setRestartNowEnabled( false ); + setRestart( FinishedViewStep::RestartMode::Never ); } diff --git a/src/modules/finished/FinishedPage.h b/src/modules/finished/FinishedPage.h index 493c29f34..9954e6fa0 100644 --- a/src/modules/finished/FinishedPage.h +++ b/src/modules/finished/FinishedPage.h @@ -22,6 +22,8 @@ #include +#include "FinishedViewStep.h" + namespace Ui { class FinishedPage; @@ -33,8 +35,7 @@ class FinishedPage : public QWidget public: explicit FinishedPage( QWidget* parent = nullptr ); - void setRestartNowEnabled( bool enabled ); - void setRestartNowChecked( bool checked ); + void setRestart( FinishedViewStep::RestartMode mode ); void setRestartNowCommand( const QString& command ); void setUpRestart(); diff --git a/src/modules/finished/FinishedViewStep.cpp b/src/modules/finished/FinishedViewStep.cpp index ad7ea3ede..521250df5 100644 --- a/src/modules/finished/FinishedViewStep.cpp +++ b/src/modules/finished/FinishedViewStep.cpp @@ -20,9 +20,13 @@ #include "FinishedViewStep.h" #include "FinishedPage.h" + +#include "Branding.h" #include "JobQueue.h" +#include "Settings.h" #include "utils/Logger.h" +#include "utils/NamedEnum.h" #include "utils/Variant.h" #include @@ -30,8 +34,20 @@ #include #include -#include "Branding.h" -#include "Settings.h" +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 ) @@ -157,13 +173,26 @@ FinishedViewStep::onInstallationFailed( const QString& message, const QString& d void FinishedViewStep::setConfigurationMap( const QVariantMap& configurationMap ) { - bool restartNowEnabled = CalamaresUtils::getBool( configurationMap, "restartNowEnabled", false ); - m_widget->setRestartNowEnabled( restartNowEnabled ); + RestartMode mode = RestartMode::Never; - bool restartNowChecked = restartNowEnabled && CalamaresUtils::getBool( configurationMap, "restartNowChecked", false ); - m_widget->setRestartNowChecked( restartNowChecked ); + QString restartMode = CalamaresUtils::getString( configurationMap, "restartNowMode" ); + if ( restartMode.isEmpty() ) + { + if ( configurationMap.contains( "restartNowEnabled" ) ) + cWarning() << "Configuring the finished module with deprecated restartNowEnabled settings"; - if ( restartNowEnabled ) + 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->setRestart( mode ); + + if ( mode != RestartMode::Never ) { QString restartNowCommand = CalamaresUtils::getString( configurationMap, "restartNowCommand" ); if ( restartNowCommand.isEmpty() ) diff --git a/src/modules/finished/FinishedViewStep.h b/src/modules/finished/FinishedViewStep.h index d4e0606bb..314f6acc6 100644 --- a/src/modules/finished/FinishedViewStep.h +++ b/src/modules/finished/FinishedViewStep.h @@ -34,6 +34,14 @@ 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 + }; + explicit FinishedViewStep( QObject* parent = nullptr ); virtual ~FinishedViewStep() override; diff --git a/src/modules/finished/finished.conf b/src/modules/finished/finished.conf index 29e5e49b4..3b6dd9dd1 100644 --- a/src/modules/finished/finished.conf +++ b/src/modules/finished/finished.conf @@ -1,14 +1,37 @@ # Configuration for the "finished" page, which is usually shown only at # the end of the installation (successful or not). --- +# DEPRECATED +# # The finished page can hold a "restart system now" checkbox. # If this is false, no checkbox is shown and the system is not restarted # when Calamares exits. -restartNowEnabled: true +# restartNowEnabled: true +# DEPRECATED +# # Initial state of the checkbox "restart now". Only relevant when the # checkbox is shown by restartNowEnabled. -restartNowChecked: false +# restartNowChecked: false + +# Behavior of the "restart system now" button. +# +# There are four usable values: +# - never +# Does not show the button and does not restart. +# This matches the old behavior with restartNowEnabled=false. +# - user-unchecked +# Shows the button, defaults to unchecked, restarts if it is checked. +# This matches the old behavior with restartNowEnabled=true and restartNowChecked=false. +# - user-checked +# Shows the button, defaults to checked, restarts if it is checked. +# This matches the old behavior with restartNowEnabled=true and restartNowChecked=true. +# - always +# Shows the button, checked, but the user cannot change it. +# This is new behavior. +# +# The three combinations of legacy values are still supported. +restartNowMode: user-unchecked # If the checkbox is shown, and the checkbox is checked, then when # Calamares exits from the finished-page it will run this command.