diff --git a/src/modules/finished/Config.cpp b/src/modules/finished/Config.cpp index b8f30be05..e382478a3 100644 --- a/src/modules/finished/Config.cpp +++ b/src/modules/finished/Config.cpp @@ -9,10 +9,15 @@ #include "Config.h" +#include "Branding.h" +#include "Settings.h" #include "utils/Logger.h" #include "utils/Variant.h" #include +#include +#include +#include const NamedEnumTable< Config::RestartMode >& restartModes() @@ -88,6 +93,38 @@ Config::doRestart() } +void +Config::doNotify() +{ + QDBusInterface notify( + "org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications" ); + if ( notify.isValid() ) + { + const auto* branding = Calamares::Branding::instance(); + QDBusReply< uint > r = notify.call( + "Notify", + QString( "Calamares" ), + QVariant( 0U ), + QString( "calamares" ), + Calamares::Settings::instance()->isSetupMode() ? tr( "Setup Complete" ) : tr( "Installation Complete" ), + Calamares::Settings::instance()->isSetupMode() + ? tr( "The setup of %1 is complete." ).arg( branding->versionedName() ) + : tr( "The installation of %1 is complete." ).arg( branding->versionedName() ), + QStringList(), + QVariantMap(), + QVariant( 0 ) ); + if ( !r.isValid() ) + { + cWarning() << "Could not call org.freedesktop.Notifications.Notify at end of installation." << r.error(); + } + } + else + { + cWarning() << "Could not get dbus interface for notifications at end of installation." << notify.lastError(); + } +} + + void Config::setConfigurationMap( const QVariantMap& configurationMap ) { diff --git a/src/modules/finished/Config.h b/src/modules/finished/Config.h index 718a3fae2..d5335df83 100644 --- a/src/modules/finished/Config.h +++ b/src/modules/finished/Config.h @@ -56,6 +56,17 @@ public slots: */ void doRestart(); + /** @brief Send DBus notification, if desired. + * + * This takes notifyOnFinished() into account. + * + * At the end of installation (when the FinishedViewStep is activated), + * send a desktop notification via DBus that the install is done. + * If the installation failed, don't call this method because + * the notification is a positive one. + */ + void doNotify(); + signals: void restartModeChanged( RestartMode m ); void restartNowWantedChanged( bool w ); diff --git a/src/modules/finished/FinishedViewStep.cpp b/src/modules/finished/FinishedViewStep.cpp index 146a7c215..70eb4127a 100644 --- a/src/modules/finished/FinishedViewStep.cpp +++ b/src/modules/finished/FinishedViewStep.cpp @@ -14,17 +14,9 @@ #include "Config.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 -#include -#include -#include FinishedViewStep::FinishedViewStep( QObject* parent ) : Calamares::ViewStep( parent ) @@ -90,53 +82,15 @@ FinishedViewStep::isAtEnd() const return true; } -void -FinishedViewStep::sendNotification() -{ - // If the installation failed, don't send notification popup; - // there's a (modal) dialog popped up with the failure notice. - if ( m_installFailed ) - { - return; - } - - QDBusInterface notify( - "org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications" ); - if ( notify.isValid() ) - { - const auto* branding = Calamares::Branding::instance(); - QDBusReply< uint > r = notify.call( - "Notify", - QString( "Calamares" ), - QVariant( 0U ), - QString( "calamares" ), - Calamares::Settings::instance()->isSetupMode() ? tr( "Setup Complete" ) : tr( "Installation Complete" ), - Calamares::Settings::instance()->isSetupMode() - ? tr( "The setup of %1 is complete." ).arg( branding->versionedName() ) - : tr( "The installation of %1 is complete." ).arg( branding->versionedName() ), - QStringList(), - QVariantMap(), - QVariant( 0 ) ); - if ( !r.isValid() ) - { - cWarning() << "Could not call org.freedesktop.Notifications.Notify at end of installation." << r.error(); - } - } - else - { - cWarning() << "Could not get dbus interface for notifications at end of installation." << notify.lastError(); - } -} - void FinishedViewStep::onActivate() { - if ( m_config->notifyOnFinished() ) + if ( !m_installFailed ) { - sendNotification(); + m_config->doNotify(); + connect( qApp, &QApplication::aboutToQuit, m_config, &Config::doRestart ); } - connect( qApp, &QApplication::aboutToQuit, m_config, &Config::doRestart ); } diff --git a/src/modules/finished/FinishedViewStep.h b/src/modules/finished/FinishedViewStep.h index e2ce8ba55..a35d7fac8 100644 --- a/src/modules/finished/FinishedViewStep.h +++ b/src/modules/finished/FinishedViewStep.h @@ -46,15 +46,6 @@ public slots: void onInstallationFailed( const QString& message, const QString& details ); private: - /** - * @brief Send notification at the end via DBus - * - * At the end of installation (when this step is activated), - * send a desktop notification via DBus that the install is done. - * If the installation failed, no notification is sent. - */ - void sendNotification(); - Config* m_config; FinishedPage* m_widget; bool m_installFailed; // Track if onInstallationFailed() was called