Use dialog instead of popup menu.
[yandex-traffic] / devstate.cpp
1 #include <QtDBus>
2
3 #include "devstate.hpp"
4
5 #ifdef Q_WS_MAEMO_5
6 #include <mce/dbus-names.h>
7 #include <mce/mode-names.h>
8
9 #define MCE_AVAILABLE 1
10 #else
11 #define MCE_AVAILABLE 0
12 #endif
13
14 static DeviceState *_instance = NULL;
15
16
17 // --------------------------------------------------
18 // DeviceState
19 // --------------------------------------------------
20 DeviceState* DeviceState::instance ()
21 {
22     if (!_instance)
23         _instance = new DeviceState;
24     return _instance;
25 }
26
27
28 DeviceState::DeviceState ()
29     : _bus (QDBusConnection::systemBus ())
30 {
31     _locked = false;
32
33 #if MCE_AVAILABLE
34     _itf = new QDBusInterface (MCE_SERVICE, MCE_REQUEST_PATH, MCE_REQUEST_IF, _bus);
35     _bus.connect (MCE_SERVICE, MCE_SIGNAL_PATH, MCE_SIGNAL_IF, MCE_TKLOCK_MODE_SIG,
36                   this, SLOT (tkLockMessage (const QDBusMessage&)));
37     requestState ();
38 #endif
39 }
40
41
42 void DeviceState::requestState ()
43 {
44 #if MCE_AVAILABLE
45     tkLockMessage (_itf->call (MCE_TKLOCK_MODE_GET));
46 #endif
47 }
48
49
50 void DeviceState::tkLockMessage (const QDBusMessage &msg)
51 {
52 #if MCE_AVAILABLE
53     QString s;
54
55     if (msg.arguments ().count () > 0) {
56         s = msg.arguments ().value (0).toString ();
57         setLocked (s == QString (MCE_TK_LOCKED));
58     }
59 #endif
60 }
61
62
63 void DeviceState::setLocked (bool new_val)
64 {
65     if (_locked != new_val) {
66         _locked = new_val;
67         lockChanged (_locked);
68     }
69 }