3 @author: Sudheer K. <scifi.guy@hotmail.com>
4 @license: GNU General Public License
7 #include "dbusutility.h"
8 #include <QDBusMessage>
12 //Construction is available in the header file due to a peculiar issue with systemBus() function.
15 //Destructor for Dbus Utility object.
16 DbusUtility::~DbusUtility(){
17 this->connection.disconnectFromBus(this->connection.baseService());
18 qDebug() << "Disconnected from system bus";
21 QDBusConnection DbusUtility::getConnection(){
22 if (!this->connection.isConnected()){
23 qDebug() << "Not connected to Dbus";
25 return this->connection;
28 void DbusUtility::setConnection(QDBusConnection connection){
29 this->connection = connection;
32 //Utility method to send a dbus signal.
33 bool DbusUtility::sendSignal(QString strPath,QString strInterface,QString strName){
34 QDBusMessage dbusSignal = QDBusMessage::createSignal(strPath,strInterface,strName);
35 bool status = DbusUtility::connection.send(dbusSignal);
39 //Utility method to call a dbus method with parameters
40 bool DbusUtility::sendMethodCall(QString strService,QString strPath,
41 QString strInterface,QString strMethodName,
42 QList<QVariant> & arguments){
43 QDBusMessage dbusMethodCall = QDBusMessage::createMethodCall(strService,strPath,strInterface,strMethodName);
44 dbusMethodCall.setArguments(arguments);
45 bool status = DbusUtility::connection.send(dbusMethodCall);
49 //Utility method to display a notification (Orange sliding banner in Maemo) with custom message
50 bool DbusUtility::displayNotification(QString strMessage){
51 QList <QVariant> arguments;
52 arguments.append(strMessage);
54 bool status = this->sendMethodCall(NOTIFICATION_SERVICE,
56 NOTIFICATION_INTERFACE,
57 QString("SystemNoteInfoprint"),
63 //Utility method to retrieve the last dbus error
64 QString DbusUtility::getErrorMessage(){
65 QString strErrorMessage;
66 QDBusError dbusError = this->connection.lastError();
67 if (dbusError.isValid()){
68 strErrorMessage = qPrintable(dbusError.message());
70 return strErrorMessage;