Changed the old code to work as a daemon
[googlelatitude] / src / common / dbusclient.cpp
1 #include "dbusclient.h"
2
3 #ifdef Q_WS_MAEMO_5
4 #include <QDebug>
5 #include <QDBusReply>
6 #include <icd/dbus_api.h>
7
8 QDBusConnection DBusClient::system_bus(QDBusConnection::systemBus());
9 QDBusConnection DBusClient::session_bus(QDBusConnection::sessionBus());
10 QDBusInterface* DBusClient::icd_interface = new QDBusInterface(ICD_DBUS_API_INTERFACE,
11                                                               ICD_DBUS_API_PATH,
12                                                               ICD_DBUS_API_INTERFACE,
13                                                               system_bus);
14 QDBusInterface* DBusClient::gl_interface = new QDBusInterface("com.linfati.GoogleLatitude",
15                                                               "/",
16                                                               "com.linfati.GoogleLatitude",
17                                                               session_bus);
18
19 DBusClient::DBusClient(QObject *parent) :
20     QObject(parent)
21 {
22     QDBusConnection::systemBus().connect(ICD_DBUS_API_INTERFACE,
23                                          ICD_DBUS_API_PATH,
24                                          ICD_DBUS_API_INTERFACE,
25                                          ICD_DBUS_API_CONNECT_SIG,
26                                          this,
27                                          SLOT(networkStateChanged()));
28 }
29
30 bool DBusClient::daemonRunning()
31 {
32     return ((QDBusReply<bool>)gl_interface->call("running")).value();
33 }
34
35 bool DBusClient::networkConnected()
36 {
37     QDBusReply<uint> reply = icd_interface->call(ICD_DBUS_API_STATE_REQ);
38
39     return (reply.value() > 0) ? true : false;
40 }
41
42 void DBusClient::networkStateChanged()
43 {
44     networkConnected() ? emit sigNetworkConnected() : sigNetworkDisconnected();
45 }
46
47
48 void DBusClient::quitDaemon()
49 {
50     gl_interface->call("quit");
51 }
52
53 void DBusClient::reloadDaemonConfig()
54 {
55     gl_interface->call("reparseConfiguration");
56 }
57
58 void DBusClient::showWindow()
59 {
60     gl_interface->call("show");
61 }
62 #endif