2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Jussi Laitinen - jussi.laitinen@ixonos.com
7 Situare is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 version 2 as published by the Free Software Foundation.
11 Situare is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Situare; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22 #include <icd/dbus_api.h>
24 #include "networkhandler.h"
26 static QDBusConnection dBusConnection = QDBusConnection::systemBus();
27 const int CONNECTION_STATE_INDEX = 7;
29 NetworkHandler::NetworkHandler(QObject *parent)
34 dBusInterface = new QDBusInterface(ICD_DBUS_API_INTERFACE, ICD_DBUS_API_PATH,
35 ICD_DBUS_API_INTERFACE, dBusConnection);
37 dBusConnection.connect(ICD_DBUS_API_INTERFACE, ICD_DBUS_API_PATH, ICD_DBUS_API_INTERFACE,
38 ICD_DBUS_API_STATE_SIG,
39 this, SLOT(stateChanged(const QDBusMessage &)));
44 void NetworkHandler::stateChanged(const QDBusMessage &message)
46 qDebug() << __PRETTY_FUNCTION__ << message.arguments();
48 if (message.arguments().count() >= 8) {
51 int connectionState = message.arguments().at(CONNECTION_STATE_INDEX).toInt(&conversionOk);
52 qWarning() << __PRETTY_FUNCTION__ << "Connection state: " << connectionState;
55 if ((connectionState == ICD_STATE_DISCONNECTED) && (isConnected())) {
60 else if ((connectionState == ICD_STATE_CONNECTED) &&(!isConnected())) {
69 void NetworkHandler::connect()
71 qDebug() << __PRETTY_FUNCTION__;
73 if (!m_connecting && !m_connected) {
75 dBusInterface->call(ICD_DBUS_API_CONNECT_REQ,
76 QVariant((unsigned int)ICD_CONNECTION_FLAG_USER_EVENT));
80 void NetworkHandler::disconnect()
82 qDebug() << __PRETTY_FUNCTION__;
84 dBusInterface->call(ICD_DBUS_API_DISCONNECT_REQ,
85 QVariant((unsigned int)ICD_CONNECTION_FLAG_USER_EVENT));
88 bool NetworkHandler::isConnected()
90 qDebug() << __PRETTY_FUNCTION__;
95 void NetworkHandler::state()
97 qDebug() << __PRETTY_FUNCTION__;
99 dBusInterface->call(ICD_DBUS_API_STATE_REQ);