Popup notification when the installation is done.

- Use DBus and FreeDesktop interface to popup message
 - Code style / formatting

FIXES #599
This commit is contained in:
Adriaan de Groot 2017-08-21 17:48:27 -04:00
parent 40c3b3dd04
commit 93115b7385
3 changed files with 45 additions and 11 deletions

View File

@ -1,4 +1,7 @@
find_package( Qt5 ${QT_VERSION} CONFIG REQUIRED DBus Network )
include_directories( ${PROJECT_BINARY_DIR}/src/libcalamaresui )
calamares_add_plugin( finished
TYPE viewmodule
EXPORT_MACRO PLUGINDLLEXPORT_PRO
@ -9,5 +12,6 @@ calamares_add_plugin( finished
FinishedPage.ui
LINK_PRIVATE_LIBRARIES
calamaresui
Qt5::DBus
SHARED_LIB
)

View File

@ -23,8 +23,13 @@
#include "utils/Logger.h"
#include <QtDBus/QDBusConnection>
#include <QtDBus/QDBusInterface>
#include <QtDBus/QDBusReply>
#include <QVariantMap>
#include "Branding.h"
FinishedViewStep::FinishedViewStep( QObject* parent )
: Calamares::ViewStep( parent )
, m_widget( new FinishedPage() )
@ -99,12 +104,37 @@ FinishedViewStep::isAtEnd() const
return true;
}
void
FinishedViewStep::sendNotification()
{
QDBusInterface notify( "org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications" );
if ( notify.isValid() )
{
QDBusReply<uint> r = notify.call( "Notify",
QString( "Calamares" ),
QVariant( 0U ),
QString( "calamares" ),
tr( "Installation Complete" ),
tr( "The installation of %1 is complete." ).arg( *Calamares::Branding::VersionedName ),
QStringList(),
QVariantMap(),
QVariant( 0 )
);
if ( !r.isValid() )
cDebug() << "Could not call notify for end of installation." << r.error();
}
else
cDebug() << "Could not get dbus interface for notifications." << notify.lastError();
}
void
FinishedViewStep::onActivate()
{
cDebug() << "FinishedViewStep::onActivate()";
m_widget->setUpRestart();
sendNotification();
}
@ -129,21 +159,15 @@ FinishedViewStep::setConfigurationMap( const QVariantMap& configurationMap )
{
if ( configurationMap.contains( "restartNowChecked" ) &&
configurationMap.value( "restartNowChecked" ).type() == QVariant::Bool )
{
m_widget->setRestartNowChecked( configurationMap.value( "restartNowChecked" ).toBool() );
}
if ( configurationMap.contains( "restartNowCommand" ) &&
configurationMap.value( "restartNowCommand" ).type() == QVariant::String )
{
m_widget->setRestartNowCommand( configurationMap.value( "restartNowCommand" ).toString() );
}
else
{
m_widget->setRestartNowCommand( "systemctl -i reboot" );
}
}
}
}
CALAMARES_PLUGIN_FACTORY_DEFINITION( FinishedViewStepFactory, registerPlugin<FinishedViewStep>(); )

View File

@ -57,6 +57,12 @@ public:
private:
FinishedPage* m_widget;
/**
* @brief At the end of installation (when this step is activated),
* send a desktop notification via DBus that the install is done.
*/
void sendNotification();
};
CALAMARES_PLUGIN_FACTORY_DECLARATION( FinishedViewStepFactory )