3 @author: Sudheer K. <scifi1947 at gmail.com>
4 @license: GNU General Public License
7 #include "dbusutility.h"
8 #include <QDBusMessage>
12 DbusUtility::DbusUtility(QObject *parent):
14 connection(QDBusConnection::systemBus()){
17 //Destructor for Dbus Utility object.
18 DbusUtility::~DbusUtility(){
19 //this->connection.disconnectFromBus(this->connection.baseService());
20 //qDebug() << "Disconnected from system bus";
23 QDBusConnection DbusUtility::getConnection(bool systemBus){
25 if (!this->connection.isConnected()){
26 qDebug() << "Not connected to Dbus";
28 return this->connection;
31 return QDBusConnection::sessionBus();
35 void DbusUtility::setConnection(QDBusConnection connection){
36 this->connection = connection;
39 //Utility method to send a dbus signal.
40 bool DbusUtility::sendSignal(QString strPath,QString strInterface,QString strName,bool systemBus){
41 QDBusMessage dbusSignal = QDBusMessage::createSignal(strPath,strInterface,strName);
42 QDBusConnection dbusConnection = getConnection(systemBus);
43 bool status = dbusConnection.send(dbusSignal);
47 //Utility method to call a dbus method with parameters
48 bool DbusUtility::sendMethodCall(QString strService,QString strPath,
49 QString strInterface,QString strMethodName,
50 QList<QVariant> & arguments,
52 QDBusMessage dbusMethodCall = QDBusMessage::createMethodCall(strService,strPath,strInterface,strMethodName);
53 dbusMethodCall.setArguments(arguments);
54 QDBusConnection dbusConnection = getConnection(systemBus);
55 bool status = dbusConnection.send(dbusMethodCall);
59 //Utility method to display a notification (Orange sliding banner in Maemo) with custom message
60 bool DbusUtility::displayNotification(QString strMessage){
61 QList <QVariant> arguments;
62 arguments.append(strMessage);
64 bool status = this->sendMethodCall(NOTIFICATION_SERVICE,
66 NOTIFICATION_INTERFACE,
67 QString("SystemNoteInfoprint"),
73 //Utility method to retrieve the last dbus error
74 QString DbusUtility::getErrorMessage(){
75 QString strErrorMessage;
76 QDBusError dbusError = this->connection.lastError();
77 if (dbusError.isValid()){
78 strErrorMessage = qPrintable(dbusError.message());
80 return strErrorMessage;