Proper README and changelog commits.
[confmgr] / dbusutility.cpp
1 /*
2 @version: 0.1
3 @author: Sudheer K. <scifi.guy@hotmail.com>
4 @license: GNU General Public License
5 */
6
7 #include "dbusutility.h"
8 #include <QDBusMessage>
9 #include <QDebug>
10
11
12 //Construction is available in the header file due to a peculiar issue with systemBus() function.
13
14
15 //Destructor for Dbus Utility object.
16 DbusUtility::~DbusUtility(){
17     this->connection.disconnectFromBus(this->connection.baseService());
18     qDebug() << "Disconnected from system bus";
19 }
20
21 QDBusConnection DbusUtility::getConnection(){
22     if (!this->connection.isConnected()){
23         qDebug() << "Not connected to Dbus";
24     }
25     return this->connection;
26 }
27
28 void DbusUtility::setConnection(QDBusConnection connection){
29     this->connection = connection;
30 }
31
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);
36     return status;
37 }
38
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);
46     return status;
47 }
48
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);
53
54     bool status = this->sendMethodCall(NOTIFICATION_SERVICE,
55                                           NOTIFICATION_PATH,
56                                           NOTIFICATION_INTERFACE,
57                                           QString("SystemNoteInfoprint"),
58                                           arguments);
59     return status;
60 }
61
62
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());
69     }
70     return strErrorMessage;
71 }