From bd775a16e27f460a6c0337df172c765a1c097729 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sat, 6 Mar 2021 13:51:45 +0100 Subject: [PATCH] [finished] Add a restart-anyway API to Config It's possible to ignore the "user setting" for restart-now and call doRestart(true) directly. This is intended for use with specific UIs that make that choice clear for the user. Hook up both [finished] and [finishedq] to the "traditional" restart-if-the-box-is-ticked logic although the example QML doesn't expose that box. --- src/modules/finished/Config.cpp | 9 +++++---- src/modules/finished/Config.h | 7 ++++++- src/modules/finished/FinishedViewStep.cpp | 2 +- src/modules/finishedq/FinishedQmlViewStep.cpp | 1 + src/modules/finishedq/finishedq.qml | 7 +------ 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/modules/finished/Config.cpp b/src/modules/finished/Config.cpp index 03616d05a..5d824a8f3 100644 --- a/src/modules/finished/Config.cpp +++ b/src/modules/finished/Config.cpp @@ -109,12 +109,13 @@ Config::onInstallationFailed( const QString& message, const QString& details ) void -Config::doRestart() +Config::doRestart( bool restartAnyway ) { - cDebug() << "Restart requested, mode=" << restartModes().find( restartNowMode() ) << " want?" << restartNowWanted(); - if ( restartNowWanted() ) + cDebug() << "mode=" << restartModes().find( restartNowMode() ) << " user?" << restartNowWanted() << "arg?" + << restartAnyway; + if ( restartNowMode() != RestartMode::Never && restartAnyway ) { - cDebug() << "Running restart command" << m_restartNowCommand; + cDebug() << Logger::SubEntry << "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 b4f93fd91..1349b7445 100644 --- a/src/modules/finished/Config.h +++ b/src/modules/finished/Config.h @@ -73,8 +73,13 @@ public Q_SLOTS: * 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()). + * + * - The one-argument form ignores what the user wants and restarts + * if @p restartAnyway is @c true **unless** the mode is Never + * - The no-argument form uses the user setting */ - void doRestart(); + void doRestart( bool restartAnyway ); + void doRestart() { doRestart( restartNowWanted() ); } /** @brief Send DBus notification * diff --git a/src/modules/finished/FinishedViewStep.cpp b/src/modules/finished/FinishedViewStep.cpp index 05cac473d..5ba9c1897 100644 --- a/src/modules/finished/FinishedViewStep.cpp +++ b/src/modules/finished/FinishedViewStep.cpp @@ -86,7 +86,7 @@ void FinishedViewStep::onActivate() { m_config->doNotify(); - connect( qApp, &QApplication::aboutToQuit, m_config, &Config::doRestart ); + connect( qApp, &QApplication::aboutToQuit, m_config, qOverload<>( &Config::doRestart ) ); } diff --git a/src/modules/finishedq/FinishedQmlViewStep.cpp b/src/modules/finishedq/FinishedQmlViewStep.cpp index e1a681372..531d7380e 100644 --- a/src/modules/finishedq/FinishedQmlViewStep.cpp +++ b/src/modules/finishedq/FinishedQmlViewStep.cpp @@ -67,6 +67,7 @@ void FinishedQmlViewStep::onActivate() { m_config->doNotify(); + connect( qApp, &QApplication::aboutToQuit, m_config, qOverload<>( &Config::doRestart ) ); QmlViewStep::onActivate(); } diff --git a/src/modules/finishedq/finishedq.qml b/src/modules/finishedq/finishedq.qml index 1969c4c82..789ac4cfb 100644 --- a/src/modules/finishedq/finishedq.qml +++ b/src/modules/finishedq/finishedq.qml @@ -70,7 +70,7 @@ Page { Button { text: qsTr("Restart System") icon.name: "system-reboot" - onClicked: { config.doRestart(); } + onClicked: { config.doRestart(true); } } } @@ -93,11 +93,6 @@ 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()