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){
41 QDBusMessage dbusSignal = QDBusMessage::createSignal(strPath,strInterface,strName);
42 bool status = DbusUtility::connection.send(dbusSignal);
46 //Utility method to call a dbus method with parameters
47 bool DbusUtility::sendMethodCall(QString strService,QString strPath,
48 QString strInterface,QString strMethodName,
49 QList<QVariant> & arguments){
50 QDBusMessage dbusMethodCall = QDBusMessage::createMethodCall(strService,strPath,strInterface,strMethodName);
51 dbusMethodCall.setArguments(arguments);
52 bool status = DbusUtility::connection.send(dbusMethodCall);
56 //Utility method to display a notification (Orange sliding banner in Maemo) with custom message
57 bool DbusUtility::displayNotification(QString strMessage){
58 QList <QVariant> arguments;
59 arguments.append(strMessage);
61 bool status = this->sendMethodCall(NOTIFICATION_SERVICE,
63 NOTIFICATION_INTERFACE,
64 QString("SystemNoteInfoprint"),
70 //Utility method to retrieve the last dbus error
71 QString DbusUtility::getErrorMessage(){
72 QString strErrorMessage;
73 QDBusError dbusError = this->connection.lastError();
74 if (dbusError.isValid()){
75 strErrorMessage = qPrintable(dbusError.message());
77 return strErrorMessage;