diff --git a/src/modules/finished/Config.cpp b/src/modules/finished/Config.cpp index a612661a8..b8f30be05 100644 --- a/src/modules/finished/Config.cpp +++ b/src/modules/finished/Config.cpp @@ -12,6 +12,8 @@ #include "utils/Logger.h" #include "utils/Variant.h" +#include + const NamedEnumTable< Config::RestartMode >& restartModes() { @@ -75,6 +77,16 @@ Config::setRestartNowWanted( bool w ) } } +void +Config::doRestart() +{ + if ( restartNowMode() != RestartMode::Never && restartNowWanted() ) + { + cDebug() << "Running restart command" << m_restartNowCommand; + QProcess::execute( "/bin/sh", { "-c", m_restartNowCommand } ); + } +} + void Config::setConfigurationMap( const QVariantMap& configurationMap ) diff --git a/src/modules/finished/Config.h b/src/modules/finished/Config.h index 32cc7bf22..718a3fae2 100644 --- a/src/modules/finished/Config.h +++ b/src/modules/finished/Config.h @@ -14,8 +14,6 @@ #include -#include - class Config : public QObject { Q_OBJECT @@ -50,6 +48,14 @@ public slots: void setRestartNowMode( RestartMode m ); void setRestartNowWanted( bool w ); + /** @brief Run the restart command, if desired. + * + * 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. + */ + void doRestart(); + signals: void restartModeChanged( RestartMode m ); void restartNowWantedChanged( bool w ); diff --git a/src/modules/finished/FinishedViewStep.cpp b/src/modules/finished/FinishedViewStep.cpp index 48e2c47d5..176b27cb4 100644 --- a/src/modules/finished/FinishedViewStep.cpp +++ b/src/modules/finished/FinishedViewStep.cpp @@ -20,7 +20,7 @@ #include "utils/NamedEnum.h" #include "utils/Variant.h" -#include +#include #include #include #include @@ -128,34 +128,14 @@ FinishedViewStep::sendNotification() } -#if 0 -void -FinishedPage::setUpRestart() -{ - cDebug() << "FinishedPage::setUpRestart(), Quit button" - << "setup=" << restartModes().find( m_mode ) << "command=" << m_restartNowCommand; - - connect( qApp, &QApplication::aboutToQuit, [this]() - { - if ( ui->restartCheckBox->isVisible() && ui->restartCheckBox->isChecked() ) - { - cDebug() << "Running restart command" << m_restartNowCommand; - QProcess::execute( "/bin/sh", { "-c", m_restartNowCommand } ); - } - } ); -} -#endif - - void FinishedViewStep::onActivate() { - // m_widget->setUpRestart(); - if ( m_config->notifyOnFinished() ) { sendNotification(); } + connect( qApp, &QApplication::aboutToQuit, m_config, &Config::doRestart ); }