--- /dev/null
+/*
+ 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));
+}
--- /dev/null
+/*
+ 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