--- /dev/null
+#include <QtDBus>
+
+#include "devstate.hpp"
+
+#ifdef Q_WS_MAEMO_5
+#include <mce/dbus-names.h>
+#include <mce/mode-names.h>
+
+#define MCE_AVAILABLE 1
+#else
+#define MCE_AVAILABLE 0
+#endif
+
+static DeviceState *_instance = NULL;
+
+
+// --------------------------------------------------
+// DeviceState
+// --------------------------------------------------
+DeviceState* DeviceState::instance ()
+{
+ if (!_instance)
+ _instance = new DeviceState;
+ return _instance;
+}
+
+
+DeviceState::DeviceState ()
+ : _bus (QDBusConnection::systemBus ())
+{
+ _locked = false;
+
+#if MCE_AVAILABLE
+ _itf = new QDBusInterface (MCE_SERVICE, MCE_REQUEST_PATH, MCE_REQUEST_IF, _bus);
+ _bus.connect (MCE_SERVICE, MCE_SIGNAL_PATH, MCE_SIGNAL_IF, MCE_TKLOCK_MODE_SIG,
+ this, SLOT (tkLockMessage (const QDBusMessage&)));
+ requestState ();
+#endif
+}
+
+
+void DeviceState::requestState ()
+{
+#if MCE_AVAILABLE
+ tkLockMessage (_itf->call (MCE_TKLOCK_MODE_GET));
+#endif
+}
+
+
+void DeviceState::tkLockMessage (const QDBusMessage &msg)
+{
+#if MCE_AVAILABLE
+ QString s;
+
+ if (msg.arguments ().count () > 0) {
+ s = msg.arguments ().value (0).toString ();
+ printf ("Reply = %s\n", s.toUtf8 ().data ());
+ setLocked (s == QString (MCE_TK_LOCKED));
+ }
+#endif
+}
+
+
+void DeviceState::setLocked (bool new_val)
+{
+ if (_locked != new_val) {
+ _locked = new_val;
+ lockChanged (_locked);
+ }
+}
--- /dev/null
+#ifndef __DEVSTATE_H__
+#define __DEVSTATE_H__
+
+#include <QtCore>
+#include <QtDBus>
+
+
+// Singleton which handles device lock state (and, possibly, other MCE stuff)
+class DeviceState : public QObject
+{
+ Q_OBJECT
+
+private:
+ bool _locked;
+
+ QDBusConnection _bus;
+ QDBusInterface *_itf;
+
+protected:
+ DeviceState ();
+
+ void setLocked (bool new_val);
+
+protected slots:
+ void tkLockMessage (const QDBusMessage &msg);
+
+public:
+ static DeviceState *instance ();
+
+ bool locked () const
+ { return _locked; };
+
+ void requestState ();
+
+signals:
+ void lockChanged (bool locked);
+};
+
+#endif // __DEVSTATE_H__
--- /dev/null
+#include <QtGui>
+#include "mainwindow.hpp"
+
+
+int main(int argc, char *argv[])
+{
+ QApplication app (argc, argv);
+ MainWindow w;
+
+ w.show ();
+
+ return app.exec ();
+}
--- /dev/null
+#ifndef __MAINWINDOW_H__
+#define __MAINWINDOW_H__
+
+#include <QtGui>
+
+#include "devstate.hpp"
+
+class MainWindow : public QPushButton
+{
+ Q_OBJECT
+
+protected slots:
+ void clicked ()
+ {
+ printf ("Clicked, request state\n");
+ DeviceState::instance ()->requestState ();
+ }
+
+ void lockChanged (bool state)
+ {
+ printf (state ? "device locked\n" : "device unlocked\n");
+ }
+
+public:
+ MainWindow ()
+ : QPushButton ()
+ {
+ setText ("Push me to get state");
+ connect (this, SIGNAL (clicked ()), this, SLOT (clicked ()));
+ connect (DeviceState::instance (), SIGNAL (lockChanged (bool)), this, SLOT (lockChanged (bool)));
+ }
+};
+
+#endif // __MAINWINDOW_H__
--- /dev/null
+TEMPLATE = app
+
+SOURCES += main.cpp
+HEADERS += mainwindow.hpp
+
+include (../../yandex-traffic-core.pri)
TEMPLATE = subdirs
-SUBDIRS = regions traffic widget conn
+SUBDIRS = regions traffic widget conn state
-HEADERS += $$PWD/regions.hpp $$PWD/settings.hpp $$PWD/traffic.hpp $$PWD/http_fetcher.hpp $$PWD/connection.hpp
-SOURCES += $$PWD/regions.cpp $$PWD/settings.cpp $$PWD/traffic.cpp $$PWD/http_fetcher.cpp $$PWD/connection.cpp
+HEADERS += $$PWD/regions.hpp $$PWD/settings.hpp $$PWD/traffic.hpp $$PWD/http_fetcher.hpp $$PWD/connection.hpp $$PWD/devstate.hpp
+SOURCES += $$PWD/regions.cpp $$PWD/settings.cpp $$PWD/traffic.cpp $$PWD/http_fetcher.cpp $$PWD/connection.cpp $$PWD/devstate.cpp
HEADERS += $$PWD/icd2_light.h $$PWD/globals.hpp