+#include <QtDBus>
+
#include "connection.hpp"
+#include "icd2_light.h"
+
static ConnectionChecker *_instance = NULL;
ConnectionChecker::ConnectionChecker ()
+ : _bus (QDBusConnection::systemBus ())
+{
+ _connected = true;
+
+ _itf = new QDBusInterface (ICD_DBUS_API_INTERFACE, ICD_DBUS_API_PATH, ICD_DBUS_API_INTERFACE, _bus);
+ _bus.connect (ICD_DBUS_API_INTERFACE, ICD_DBUS_API_PATH, ICD_DBUS_API_INTERFACE, ICD_DBUS_API_STATE_SIG,
+ this, SLOT (stateSignal (const QDBusMessage&)));
+
+ requestState ();
+}
+
+
+void ConnectionChecker::requestState ()
{
- // start timer which will check connection
- startTimer (15*1000);
+ QDBusMessage msg = QDBusMessage::createSignal (ICD_DBUS_API_PATH, ICD_DBUS_API_INTERFACE, ICD_DBUS_API_STATE_REQ);
+
+ _bus.send (msg);
}
-void ConnectionChecker::timerEvent (QTimerEvent *)
+void ConnectionChecker::stateSignal (const QDBusMessage& msg)
{
- // check for connection
+ unsigned int status = msg.arguments ().value (7).value<unsigned int>();
+
+ if (status == ICD_STATE_CONNECTED) {
+ if (!_connected) {
+ _connected = true;
+ emit connected (true);
+ }
+ }
+ else {
+ if (_connected) {
+ _connected = false;
+ emit connected (false);
+ }
+ }
}
#define __CONNECTION_H__
#include <QtCore>
+#include <QtDBus>
-// Singleton, which periodically checks for connection state and notifies when it changed.
+// Singleton, which listens for ICD DBUS events about connection change
class ConnectionChecker : public QObject
{
Q_OBJECT
private:
+ bool _connected;
+ QDBusConnection _bus;
+ QDBusInterface *_itf;
+
ConnectionChecker ();
protected:
- void timerEvent (QTimerEvent *event);
+ void requestState ();
+
+protected slots:
+ void stateSignal (const QDBusMessage& msg);
public:
static ConnectionChecker *instance ();
+ bool isConnected () const
+ { return _connected; };
+
signals:
void connected (bool active);
};
--- /dev/null
+#ifndef __ICD2_LIGHT_H__
+#define __ICD2_LIGHT_H__
+
+/*
+ * This is truncated version of file /usr/include/icd/dbus_api.h
+ * I created it because of glib.h inclusion in the original file
+ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define ICD_DBUS_API_INTERFACE "com.nokia.icd2"
+#define ICD_DBUS_API_PATH "/com/nokia/icd2"
+#define ICD_DBUS_API_STATE_SIG "state_sig"
+#define ICD_DBUS_API_STATE_REQ "state_req"
+
+
+/** Connection state */
+enum icd_connection_state {
+ /** Network is or became disconnected */
+ ICD_STATE_DISCONNECTED = 0,
+ /** Establishing network connection */
+ ICD_STATE_CONNECTING = 1,
+ /** Network is connected */
+ ICD_STATE_CONNECTED = 2,
+ /** Network is being disconnected */
+ ICD_STATE_DISCONNECTING = 3,
+ /** service provider module informs about enabled limited connectivity */
+ ICD_STATE_LIMITED_CONN_ENABLED = 4,
+ /** service provider module informs about disabled limited connectivity */
+ ICD_STATE_LIMITED_CONN_DISABLED = 5,
+
+ /** Network searching started */
+ ICD_STATE_SEARCH_START = 8,
+ /** Network searching stopped */
+ ICD_STATE_SEARCH_STOP = 9,
+
+ /** Internal network state, IP address(es) has/have been acquired */
+ ICD_STATE_INTERNAL_ADDRESS_ACQUIRED = 15
+};
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __ICD2_LIGHT_H__ */
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/icd2_light.h
+
QT += network xml dbus
CONFIG += qdbus