From 3ad3a9adfc76d13f1ff582a5cd8649ab8e45360f Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 5 Mar 2021 22:27:24 +0100 Subject: [PATCH 1/6] [finished] Move the business logic to the Configt object --- src/modules/finished/Config.cpp | 26 ++++++++++++++++ src/modules/finished/Config.h | 38 +++++++++++++++++++---- src/modules/finished/FinishedViewStep.cpp | 14 ++------- src/modules/finished/FinishedViewStep.h | 4 --- 4 files changed, 61 insertions(+), 21 deletions(-) diff --git a/src/modules/finished/Config.cpp b/src/modules/finished/Config.cpp index 5119da942..4b54988e6 100644 --- a/src/modules/finished/Config.cpp +++ b/src/modules/finished/Config.cpp @@ -82,6 +82,32 @@ Config::setRestartNowWanted( bool w ) } } +void +Config::onInstallationFailed( const QString& message, const QString& details ) +{ + const bool msgChange = message != m_failureMessage; + const bool detChange = details != m_failureDetails; + m_failureMessage = message; + m_failureDetails = details; + if ( msgChange ) + { + emit failureMessageChanged( message ); + } + if ( detChange ) + { + emit failureDetailsChanged( message ); + } + if ( ( msgChange || detChange ) ) + { + emit failureChanged( hasFailed() ); + if ( hasFailed() ) + { + setRestartNowMode( Config::RestartMode::Never ); + } + } +} + + void Config::doRestart() { diff --git a/src/modules/finished/Config.h b/src/modules/finished/Config.h index 78078b99b..a5676990d 100644 --- a/src/modules/finished/Config.h +++ b/src/modules/finished/Config.h @@ -24,6 +24,10 @@ class Config : public QObject Q_PROPERTY( QString restartNowCommand READ restartNowCommand CONSTANT FINAL ) Q_PROPERTY( bool notifyOnFinished READ notifyOnFinished CONSTANT FINAL ) + Q_PROPERTY( QString failureMessage READ failureMessage NOTIFY failureMessageChanged ) + Q_PROPERTY( QString failureDetails READ failureDetails NOTIFY failureDetailsChanged ) + Q_PROPERTY( bool failed READ hasFailed NOTIFY failureChanged ) + public: Config( QObject* parent = nullptr ); @@ -36,17 +40,22 @@ public: }; Q_ENUM( RestartMode ) + void setConfigurationMap( const QVariantMap& configurationMap ); + +public Q_SLOTS: RestartMode restartNowMode() const { return m_restartNowMode; } + void setRestartNowMode( RestartMode m ); + bool restartNowWanted() const { return m_userWantsRestart; } + void setRestartNowWanted( bool w ); QString restartNowCommand() const { return m_restartNowCommand; } bool notifyOnFinished() const { return m_notifyOnFinished; } - void setConfigurationMap( const QVariantMap& configurationMap ); - -public slots: - void setRestartNowMode( RestartMode m ); - void setRestartNowWanted( bool w ); + QString failureMessage() const { return m_failureMessage; } + QString failureDetails() const { return m_failureDetails; } + /// Failure is if any of the failure messages is non-empty + bool hasFailed() const { return !m_failureMessage.isEmpty() || !m_failureDetails.isEmpty(); } /** @brief Run the restart command, if desired. * @@ -63,17 +72,34 @@ public slots: * At the end of installation (when the FinishedViewStep is activated), * send a desktop notification via DBus that the install is done. */ - void doNotify( bool hasFailed = false ); + void doNotify( bool hasFailed ); + void doNotify() { doNotify( hasFailed() ); } + + /** @brief Tell the config the install failed + * + * This should be connected to the JobQueue and is called by + * the queue when the installation fails, with a suitable message. + */ + void onInstallationFailed( const QString& message, const QString& details ); signals: void restartModeChanged( RestartMode m ); void restartNowWantedChanged( bool w ); + void failureMessageChanged( const QString& ); + void failureDetailsChanged( const QString& ); + void failureChanged( bool ); private: + // Configuration parts QString m_restartNowCommand; RestartMode m_restartNowMode = RestartMode::Never; bool m_userWantsRestart = false; bool m_notifyOnFinished = false; + + // Dynamic parts + bool m_hasFailed = false; + QString m_failureMessage; + QString m_failureDetails; }; const NamedEnumTable< Config::RestartMode >& restartModes(); diff --git a/src/modules/finished/FinishedViewStep.cpp b/src/modules/finished/FinishedViewStep.cpp index 3f9fd3aab..05cac473d 100644 --- a/src/modules/finished/FinishedViewStep.cpp +++ b/src/modules/finished/FinishedViewStep.cpp @@ -22,10 +22,10 @@ FinishedViewStep::FinishedViewStep( QObject* parent ) : Calamares::ViewStep( parent ) , m_config( new Config( this ) ) , m_widget( new FinishedPage( m_config ) ) - , m_installFailed( false ) { auto jq = Calamares::JobQueue::instance(); - connect( jq, &Calamares::JobQueue::failed, this, &FinishedViewStep::onInstallationFailed ); + connect( jq, &Calamares::JobQueue::failed, m_config, &Config::onInstallationFailed ); + connect( jq, &Calamares::JobQueue::failed, m_widget, &FinishedPage::onInstallationFailed ); emit nextStatusChanged( true ); } @@ -85,7 +85,7 @@ FinishedViewStep::isAtEnd() const void FinishedViewStep::onActivate() { - m_config->doNotify( m_installFailed ); + m_config->doNotify(); connect( qApp, &QApplication::aboutToQuit, m_config, &Config::doRestart ); } @@ -96,14 +96,6 @@ FinishedViewStep::jobs() const return Calamares::JobList(); } -void -FinishedViewStep::onInstallationFailed( const QString& message, const QString& details ) -{ - m_installFailed = true; - m_config->setRestartNowMode( Config::RestartMode::Never ); - m_widget->onInstallationFailed( message, details ); -} - void FinishedViewStep::setConfigurationMap( const QVariantMap& configurationMap ) { diff --git a/src/modules/finished/FinishedViewStep.h b/src/modules/finished/FinishedViewStep.h index a35d7fac8..c0f64153d 100644 --- a/src/modules/finished/FinishedViewStep.h +++ b/src/modules/finished/FinishedViewStep.h @@ -42,13 +42,9 @@ public: void setConfigurationMap( const QVariantMap& configurationMap ) override; -public slots: - void onInstallationFailed( const QString& message, const QString& details ); - private: Config* m_config; FinishedPage* m_widget; - bool m_installFailed; // Track if onInstallationFailed() was called }; CALAMARES_PLUGIN_FACTORY_DECLARATION( FinishedViewStepFactory ) From 5b376b41bf08f0d1a6f17cba14426795a5c06a52 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 5 Mar 2021 22:40:38 +0100 Subject: [PATCH 2/6] [finishedq] Chase business logic in Config object --- src/modules/finishedq/FinishedQmlViewStep.cpp | 13 ++----------- src/modules/finishedq/FinishedQmlViewStep.h | 3 --- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/src/modules/finishedq/FinishedQmlViewStep.cpp b/src/modules/finishedq/FinishedQmlViewStep.cpp index 81a8004ca..e1a681372 100644 --- a/src/modules/finishedq/FinishedQmlViewStep.cpp +++ b/src/modules/finishedq/FinishedQmlViewStep.cpp @@ -22,10 +22,9 @@ CALAMARES_PLUGIN_FACTORY_DEFINITION( FinishedQmlViewStepFactory, registerPlugin< FinishedQmlViewStep::FinishedQmlViewStep( QObject* parent ) : Calamares::QmlViewStep( parent ) , m_config( new Config( this ) ) - , m_installFailed( false ) { auto jq = Calamares::JobQueue::instance(); - connect( jq, &Calamares::JobQueue::failed, this, &FinishedQmlViewStep::onInstallationFailed ); + connect( jq, &Calamares::JobQueue::failed, m_config, &Config::onInstallationFailed ); emit nextStatusChanged( true ); } @@ -67,8 +66,7 @@ FinishedQmlViewStep::isAtEnd() const void FinishedQmlViewStep::onActivate() { - m_config->doNotify( m_installFailed ); - //connect( qApp, &QApplication::aboutToQuit, m_config, &Config::doRestart ); + m_config->doNotify(); QmlViewStep::onActivate(); } @@ -85,13 +83,6 @@ FinishedQmlViewStep::getConfig() return m_config; } -void -FinishedQmlViewStep::onInstallationFailed( const QString& message, const QString& details ) -{ - m_installFailed = true; - m_config->setRestartNowMode( Config::RestartMode::Never ); -} - void FinishedQmlViewStep::setConfigurationMap( const QVariantMap& configurationMap ) { diff --git a/src/modules/finishedq/FinishedQmlViewStep.h b/src/modules/finishedq/FinishedQmlViewStep.h index e8eb58215..7bcf0e67f 100644 --- a/src/modules/finishedq/FinishedQmlViewStep.h +++ b/src/modules/finishedq/FinishedQmlViewStep.h @@ -46,9 +46,6 @@ public: void setConfigurationMap( const QVariantMap& configurationMap ) override; QObject* getConfig() override; -public slots: - void onInstallationFailed( const QString& message, const QString& details ); - private: Config* m_config; From 0d7c1ec13003c644acb456b72a69c9ce7ccd1eb8 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 5 Mar 2021 22:59:04 +0100 Subject: [PATCH 3/6] [finishedq] Port QML back to using Config object --- src/modules/finishedq/finishedq.qml | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/modules/finishedq/finishedq.qml b/src/modules/finishedq/finishedq.qml index 215626a1c..92559569c 100644 --- a/src/modules/finishedq/finishedq.qml +++ b/src/modules/finishedq/finishedq.qml @@ -18,8 +18,6 @@ import org.kde.kirigami 2.7 as Kirigami import QtGraphicalEffects 1.0 import QtQuick.Window 2.3 -import org.kde.plasma.core 2.0 as PlasmaCore - Page { id: finished @@ -62,27 +60,17 @@ Page { anchors.centerIn: parent spacing: 6 - PlasmaCore.DataSource { - id: executer - engine: "executable" - onNewData: {executer.disconnectSource(sourceName);} - } - Button { id: button text: qsTr("Close Installer") icon.name: "application-exit" onClicked: { ViewManager.quit(); } - //onClicked: console.log("close calamares"); } Button { text: qsTr("Restart System") icon.name: "system-reboot" - //onClicked: { config.doRestart(); } - onClicked: { - executer.connectSource("systemctl -i reboot"); - } + onClicked: { config.doRestart(); } } } From 075a28a06d6b71bf04733aec47b38c0201d42921 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 5 Mar 2021 22:59:53 +0100 Subject: [PATCH 4/6] [finished] Log the doRestart() attempt --- src/modules/finished/Config.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/modules/finished/Config.cpp b/src/modules/finished/Config.cpp index 4b54988e6..be2c729b1 100644 --- a/src/modules/finished/Config.cpp +++ b/src/modules/finished/Config.cpp @@ -111,6 +111,7 @@ Config::onInstallationFailed( const QString& message, const QString& details ) void Config::doRestart() { + cDebug() << "Restart requested, mode=" << restartModes().find( restartNowMode() ) << " want?" << restartNowWanted(); if ( restartNowMode() != RestartMode::Never && restartNowWanted() ) { cDebug() << "Running restart command" << m_restartNowCommand; From f94853eb28c8a2f87e132b6c15dc9795adc907a3 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 5 Mar 2021 23:17:57 +0100 Subject: [PATCH 5/6] [finishedq] Always restart if possible --- src/modules/finishedq/finishedq.qml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/modules/finishedq/finishedq.qml b/src/modules/finishedq/finishedq.qml index 92559569c..1969c4c82 100644 --- a/src/modules/finishedq/finishedq.qml +++ b/src/modules/finishedq/finishedq.qml @@ -91,4 +91,16 @@ Page { } } + function onActivate() + { + // This QML page has a **button** for restarting, + // so just pretend the setting is clicked; this is a + // poor solution, recommended is to set restartNowMode to Always + // in the config. + config.setRestartNowWanted(true); + } + + function onLeave() + { + } } From 19874ebc3a7bac09a092e5ffabd9174aadcf7045 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 5 Mar 2021 23:19:56 +0100 Subject: [PATCH 6/6] [finished] Document doRestart() better - move all the 'really want restart' logic to restartNowWanted() --- src/modules/finished/Config.cpp | 2 +- src/modules/finished/Config.h | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/modules/finished/Config.cpp b/src/modules/finished/Config.cpp index be2c729b1..bf156303d 100644 --- a/src/modules/finished/Config.cpp +++ b/src/modules/finished/Config.cpp @@ -112,7 +112,7 @@ void Config::doRestart() { cDebug() << "Restart requested, mode=" << restartModes().find( restartNowMode() ) << " want?" << restartNowWanted(); - if ( restartNowMode() != RestartMode::Never && restartNowWanted() ) + if ( restartNowWanted() ) { cDebug() << "Running restart command" << m_restartNowCommand; QProcess::execute( "/bin/sh", { "-c", m_restartNowCommand } ); diff --git a/src/modules/finished/Config.h b/src/modules/finished/Config.h index a5676990d..cf1d8eb73 100644 --- a/src/modules/finished/Config.h +++ b/src/modules/finished/Config.h @@ -46,7 +46,14 @@ public Q_SLOTS: RestartMode restartNowMode() const { return m_restartNowMode; } void setRestartNowMode( RestartMode m ); - bool restartNowWanted() const { return m_userWantsRestart; } + bool restartNowWanted() const + { + if ( restartNowMode() == RestartMode::Never ) + { + return false; + } + return ( restartNowMode() == RestartMode::Always ) || m_userWantsRestart; + } void setRestartNowWanted( bool w ); QString restartNowCommand() const { return m_restartNowCommand; } @@ -62,6 +69,10 @@ public Q_SLOTS: * This should generally not be called somewhere during the * application's execution, but only in response to QApplication::quit() * or something like that when the user expects the system to restart. + * + * The "if desired" part is: only if the restart mode allows it, + * **and** the user has checked the box (or done whatever to + * turn on restartNowWanted()). */ void doRestart();