Added NetworkHandler class.
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Fri, 21 May 2010 09:30:55 +0000 (12:30 +0300)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Fri, 21 May 2010 09:30:55 +0000 (12:30 +0300)
src/engine/networkhandler.cpp [new file with mode: 0644]
src/engine/networkhandler.h [new file with mode: 0644]
src/src.pro

diff --git a/src/engine/networkhandler.cpp b/src/engine/networkhandler.cpp
new file mode 100644 (file)
index 0000000..bab737d
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+   Situare - A location system for Facebook
+   Copyright (C) 2010  Ixonos Plc. Authors:
+
+       Jussi Laitinen - jussi.laitinen@ixonos.com
+
+   Situare is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License
+   version 2 as published by the Free Software Foundation.
+
+   Situare is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with Situare; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+   USA.
+*/
+
+#include <icd/dbus_api.h>
+
+#include "networkhandler.h"
+
+static QDBusConnection dBusConnection = QDBusConnection::systemBus();
+const int CONNECTION_STATE_INDEX = 7;
+enum ConnectionState {DISCONNECTED, CONNECTING, CONNECTED, DISCONNECTING};
+
+NetworkHandler::NetworkHandler(QObject *parent)
+    : QObject(parent)
+{
+    dBusInterface = new QDBusInterface(ICD_DBUS_API_INTERFACE, ICD_DBUS_API_PATH,
+                                       ICD_DBUS_API_INTERFACE, dBusConnection);
+
+    dBusConnection.connect(ICD_DBUS_API_INTERFACE, ICD_DBUS_API_PATH, ICD_DBUS_API_INTERFACE,
+                           ICD_DBUS_API_STATE_SIG,
+                           this, SLOT(stateChanged(const QDBusMessage &)));
+}
+
+void NetworkHandler::stateChanged(const QDBusMessage &message)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if (message.arguments().count() >= 8) {
+
+        bool conversionOk;
+        int connectionState = message.arguments().at(CONNECTION_STATE_INDEX).toInt(&conversionOk);
+
+        if (conversionOk) {
+            if (connectionState == DISCONNECTED)
+                emit disconnected();
+            else if (connectionState == CONNECTED)
+                emit connected();
+        }
+    }
+}
+
+void NetworkHandler::connect()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    dBusInterface->call(ICD_DBUS_API_CONNECT_REQ,
+                        QVariant((unsigned int)ICD_CONNECTION_FLAG_USER_EVENT));
+}
+
+void NetworkHandler::disconnect()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    dBusInterface->call(ICD_DBUS_API_DISCONNECT_REQ,
+                        QVariant((unsigned int)ICD_CONNECTION_FLAG_USER_EVENT));
+}
diff --git a/src/engine/networkhandler.h b/src/engine/networkhandler.h
new file mode 100644 (file)
index 0000000..d70410d
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+   Situare - A location system for Facebook
+   Copyright (C) 2010  Ixonos Plc. Authors:
+
+       Jussi Laitinen - jussi.laitinen@ixonos.com
+
+   Situare is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License
+   version 2 as published by the Free Software Foundation.
+
+   Situare is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with Situare; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+   USA.
+*/
+
+#ifndef NETWORKHANDLER_H
+#define NETWORKHANDLER_H
+
+#include <QtDBus>
+
+/**
+* @brief NetworkHandler class.
+*
+* This class handles network connection. Class notifies about
+* network connection states.
+*/
+class NetworkHandler : public QObject
+{
+    Q_OBJECT
+
+public:
+    /**
+    * @brief Constructor.
+    *
+    * Creates ICD D-Bus interface.
+    */
+    NetworkHandler(QObject *parent = 0);
+
+/*******************************************************************************
+ * MEMBER FUNCTIONS AND SLOTS
+ ******************************************************************************/
+public:
+    /**
+    * @brief Requests network connection.
+    *
+    * Request is done via ICD D-Bus.
+    */
+    void connect();
+
+    /**
+    * @brief Requests to disconnect a connection.
+    *
+    * Request is done via ICD D-Bus.
+    */
+    void disconnect();
+
+private slots:
+    /**
+    * @brief Slot for ICD D-Bus state change.
+    *
+    * @param message received D-Bus message
+    */
+    void stateChanged(const QDBusMessage &message);
+
+/*******************************************************************************
+ * SIGNALS
+ ******************************************************************************/
+signals:
+    /**
+    * @brief Signals when connected to network.
+    */
+    void connected();
+
+    /**
+    * @brief Signals when disconnected from network.
+    */
+    void disconnected();
+
+/*******************************************************************************
+ * DATA MEMBERS
+ ******************************************************************************/
+private:
+    QDBusInterface *dBusInterface;  ///< D-Bus interface
+};
+
+#endif // NETWORKHANDLER_H
index 81d3bae..089132a 100644 (file)
@@ -41,7 +41,8 @@ SOURCES += main.cpp \
     gps/gpsposition.cpp \
     map/gpslocationitem.cpp \
     ui/zoombuttonpanel.cpp \
-    ui/userinfo.cpp
+    ui/userinfo.cpp \
+    engine/networkhandler.cpp
 HEADERS += ui/mainwindow.h \
     ui/mapviewscreen.h \
     map/mapengine.h \
@@ -82,7 +83,8 @@ HEADERS += ui/mainwindow.h \
     gps/gpscommon.h \
     ui/zoombuttonpanel.h \
     common.h \
-    ui/userinfo.h
+    ui/userinfo.h \
+    engine/networkhandler.h
 QT += network \
     webkit