X-Git-Url: http://git.maemo.org/git/?p=confmgr;a=blobdiff_plain;f=src%2Fdbusutility.cpp;fp=src%2Fdbusutility.cpp;h=74126671c418771b8f1e813e5ca405ffbf5cf0ae;hp=0000000000000000000000000000000000000000;hb=6f0e06a23515e795b75e08161487d60c9fc4f933;hpb=8cdf509abbdb8654def1e0df79e1f607e9a41807 diff --git a/src/dbusutility.cpp b/src/dbusutility.cpp new file mode 100644 index 0000000..7412667 --- /dev/null +++ b/src/dbusutility.cpp @@ -0,0 +1,71 @@ +/* +@version: 0.1 +@author: Sudheer K. +@license: GNU General Public License +*/ + +#include "dbusutility.h" +#include +#include + + +//Construction is available in the header file due to a peculiar issue with systemBus() function. + + +//Destructor for Dbus Utility object. +DbusUtility::~DbusUtility(){ + this->connection.disconnectFromBus(this->connection.baseService()); + qDebug() << "Disconnected from system bus"; +} + +QDBusConnection DbusUtility::getConnection(){ + if (!this->connection.isConnected()){ + qDebug() << "Not connected to Dbus"; + } + return this->connection; +} + +void DbusUtility::setConnection(QDBusConnection connection){ + this->connection = connection; +} + +//Utility method to send a dbus signal. +bool DbusUtility::sendSignal(QString strPath,QString strInterface,QString strName){ + QDBusMessage dbusSignal = QDBusMessage::createSignal(strPath,strInterface,strName); + bool status = DbusUtility::connection.send(dbusSignal); + return status; +} + +//Utility method to call a dbus method with parameters +bool DbusUtility::sendMethodCall(QString strService,QString strPath, + QString strInterface,QString strMethodName, + QList & arguments){ + QDBusMessage dbusMethodCall = QDBusMessage::createMethodCall(strService,strPath,strInterface,strMethodName); + dbusMethodCall.setArguments(arguments); + bool status = DbusUtility::connection.send(dbusMethodCall); + return status; +} + +//Utility method to display a notification (Orange sliding banner in Maemo) with custom message +bool DbusUtility::displayNotification(QString strMessage){ + QList arguments; + arguments.append(strMessage); + + bool status = this->sendMethodCall(NOTIFICATION_SERVICE, + NOTIFICATION_PATH, + NOTIFICATION_INTERFACE, + QString("SystemNoteInfoprint"), + arguments); + return status; +} + + +//Utility method to retrieve the last dbus error +QString DbusUtility::getErrorMessage(){ + QString strErrorMessage; + QDBusError dbusError = this->connection.lastError(); + if (dbusError.isValid()){ + strErrorMessage = qPrintable(dbusError.message()); + } + return strErrorMessage; +}