X-Git-Url: http://git.maemo.org/git/?p=vicar;a=blobdiff_plain;f=src%2Fvicar-lib%2Fcpp%2Fdbusutility.cpp;fp=src%2Fvicar-lib%2Fcpp%2Fdbusutility.cpp;h=6e7b9fff45c70227599161248d0d71ce757b6f43;hp=0000000000000000000000000000000000000000;hb=38440679f13b8dc528a9aff93cbf4935011fdb22;hpb=89f0017e6a73945ea83247472a6fa07d6ee536b5 diff --git a/src/vicar-lib/cpp/dbusutility.cpp b/src/vicar-lib/cpp/dbusutility.cpp new file mode 100755 index 0000000..6e7b9ff --- /dev/null +++ b/src/vicar-lib/cpp/dbusutility.cpp @@ -0,0 +1,81 @@ +/* +@version: 0.6 +@author: Sudheer K. +@license: GNU General Public License +*/ + +#include "dbusutility.h" +#include +#include + + +DbusUtility::DbusUtility(QObject *parent): + QObject(parent), + connection(QDBusConnection::systemBus()){ +} + +//Destructor for Dbus Utility object. +DbusUtility::~DbusUtility(){ + //this->connection.disconnectFromBus(this->connection.baseService()); + //qDebug() << "Disconnected from system bus"; +} + +QDBusConnection DbusUtility::getConnection(bool systemBus){ + if (systemBus){ + if (!this->connection.isConnected()){ + qDebug() << "Not connected to Dbus"; + } + return this->connection; + } + else{ + return QDBusConnection::sessionBus(); + } +} + +void DbusUtility::setConnection(QDBusConnection connection){ + this->connection = connection; +} + +//Utility method to send a dbus signal. +bool DbusUtility::sendSignal(QString strPath,QString strInterface,QString strName,bool systemBus){ + QDBusMessage dbusSignal = QDBusMessage::createSignal(strPath,strInterface,strName); + QDBusConnection dbusConnection = getConnection(systemBus); + bool status = dbusConnection.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, + bool systemBus){ + QDBusMessage dbusMethodCall = QDBusMessage::createMethodCall(strService,strPath,strInterface,strMethodName); + dbusMethodCall.setArguments(arguments); + QDBusConnection dbusConnection = getConnection(systemBus); + bool status = dbusConnection.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; +}