[finished] Move notification to Config
This commit is contained in:
parent
76a2791b12
commit
ec4b6752d6
@ -9,10 +9,15 @@
|
||||
|
||||
#include "Config.h"
|
||||
|
||||
#include "Branding.h"
|
||||
#include "Settings.h"
|
||||
#include "utils/Logger.h"
|
||||
#include "utils/Variant.h"
|
||||
|
||||
#include <QProcess>
|
||||
#include <QtDBus/QDBusConnection>
|
||||
#include <QtDBus/QDBusInterface>
|
||||
#include <QtDBus/QDBusReply>
|
||||
|
||||
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 )
|
||||
{
|
||||
|
@ -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 );
|
||||
|
@ -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 <QApplication>
|
||||
#include <QtDBus/QDBusConnection>
|
||||
#include <QtDBus/QDBusInterface>
|
||||
#include <QtDBus/QDBusReply>
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user