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 ) include_directories( ${PROJECT_BINARY_DIR}/src/libcalamaresui )
calamares_add_plugin( finished calamares_add_plugin( finished
TYPE viewmodule TYPE viewmodule
EXPORT_MACRO PLUGINDLLEXPORT_PRO EXPORT_MACRO PLUGINDLLEXPORT_PRO
@ -9,5 +12,6 @@ calamares_add_plugin( finished
FinishedPage.ui FinishedPage.ui
LINK_PRIVATE_LIBRARIES LINK_PRIVATE_LIBRARIES
calamaresui calamaresui
Qt5::DBus
SHARED_LIB SHARED_LIB
) )

View File

@ -23,8 +23,13 @@
#include "utils/Logger.h" #include "utils/Logger.h"
#include <QtDBus/QDBusConnection>
#include <QtDBus/QDBusInterface>
#include <QtDBus/QDBusReply>
#include <QVariantMap> #include <QVariantMap>
#include "Branding.h"
FinishedViewStep::FinishedViewStep( QObject* parent ) FinishedViewStep::FinishedViewStep( QObject* parent )
: Calamares::ViewStep( parent ) : Calamares::ViewStep( parent )
, m_widget( new FinishedPage() ) , m_widget( new FinishedPage() )
@ -32,7 +37,7 @@ FinishedViewStep::FinishedViewStep( QObject* parent )
cDebug() << "FinishedViewStep()"; cDebug() << "FinishedViewStep()";
connect( Calamares::JobQueue::instance(), &Calamares::JobQueue::failed, connect( Calamares::JobQueue::instance(), &Calamares::JobQueue::failed,
m_widget, &FinishedPage::onInstallationFailed ); m_widget, &FinishedPage::onInstallationFailed );
emit nextStatusChanged( true ); emit nextStatusChanged( true );
} }
@ -99,12 +104,37 @@ FinishedViewStep::isAtEnd() const
return true; 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 void
FinishedViewStep::onActivate() FinishedViewStep::onActivate()
{ {
cDebug() << "FinishedViewStep::onActivate()"; cDebug() << "FinishedViewStep::onActivate()";
m_widget->setUpRestart(); m_widget->setUpRestart();
sendNotification();
} }
@ -120,7 +150,7 @@ void
FinishedViewStep::setConfigurationMap( const QVariantMap& configurationMap ) FinishedViewStep::setConfigurationMap( const QVariantMap& configurationMap )
{ {
if ( configurationMap.contains( "restartNowEnabled" ) && if ( configurationMap.contains( "restartNowEnabled" ) &&
configurationMap.value( "restartNowEnabled" ).type() == QVariant::Bool ) configurationMap.value( "restartNowEnabled" ).type() == QVariant::Bool )
{ {
bool restartNowEnabled = configurationMap.value( "restartNowEnabled" ).toBool(); bool restartNowEnabled = configurationMap.value( "restartNowEnabled" ).toBool();
@ -128,20 +158,14 @@ FinishedViewStep::setConfigurationMap( const QVariantMap& configurationMap )
if ( restartNowEnabled ) if ( restartNowEnabled )
{ {
if ( configurationMap.contains( "restartNowChecked" ) && if ( configurationMap.contains( "restartNowChecked" ) &&
configurationMap.value( "restartNowChecked" ).type() == QVariant::Bool ) configurationMap.value( "restartNowChecked" ).type() == QVariant::Bool )
{
m_widget->setRestartNowChecked( configurationMap.value( "restartNowChecked" ).toBool() ); m_widget->setRestartNowChecked( configurationMap.value( "restartNowChecked" ).toBool() );
}
if ( configurationMap.contains( "restartNowCommand" ) && if ( configurationMap.contains( "restartNowCommand" ) &&
configurationMap.value( "restartNowCommand" ).type() == QVariant::String ) configurationMap.value( "restartNowCommand" ).type() == QVariant::String )
{
m_widget->setRestartNowCommand( configurationMap.value( "restartNowCommand" ).toString() ); m_widget->setRestartNowCommand( configurationMap.value( "restartNowCommand" ).toString() );
}
else else
{ m_widget->setRestartNowCommand( "systemctl -i reboot" );
m_widget->setRestartNowCommand( "systemctl -i reboot");
}
} }
} }
} }

View File

@ -57,6 +57,12 @@ public:
private: private:
FinishedPage* m_widget; 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 ) CALAMARES_PLUGIN_FACTORY_DECLARATION( FinishedViewStepFactory )