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,
24 #include <icd/dbus_api.h>
26 #include "networkhandler.h"
27 #include "networkhandlerprivate.h"
29 const int CONNECTION_STATE_INDEX = 7;
31 static QDBusConnection dBusConnection = QDBusConnection::systemBus();
33 NetworkHandlerPrivate::NetworkHandlerPrivate(QObject *parent)
38 qDebug() << __PRETTY_FUNCTION__;
40 m_parent = static_cast<NetworkHandler*>(parent);
42 dBusInterface = new QDBusInterface(ICD_DBUS_API_INTERFACE, ICD_DBUS_API_PATH,
43 ICD_DBUS_API_INTERFACE, dBusConnection);
45 dBusConnection.connect(ICD_DBUS_API_INTERFACE, ICD_DBUS_API_PATH, ICD_DBUS_API_INTERFACE,
46 ICD_DBUS_API_STATE_SIG,
47 this, SLOT(stateChanged(const QDBusMessage &)));
52 void NetworkHandlerPrivate::stateChanged(const QDBusMessage &message)
54 qDebug() << __PRETTY_FUNCTION__ << message;
56 if (message.arguments().count() > CONNECTION_STATE_INDEX) {
59 int connectionState = message.arguments().at(CONNECTION_STATE_INDEX).toInt(&conversionOk);
62 if ((connectionState == ICD_STATE_DISCONNECTED) && (isConnected())) {
65 emit m_parent->disconnected();
67 if (connectionState == ICD_STATE_DISCONNECTING) {
70 else if ((connectionState == ICD_STATE_CONNECTED) &&(!isConnected())) {
73 emit m_parent->connected();
79 void NetworkHandlerPrivate::connect()
81 qDebug() << __PRETTY_FUNCTION__;
83 if (!m_connecting && !m_connected) {
85 dBusInterface->call(ICD_DBUS_API_CONNECT_REQ,
86 QVariant((unsigned int)ICD_CONNECTION_FLAG_USER_EVENT));
90 void NetworkHandlerPrivate::disconnect()
92 qDebug() << __PRETTY_FUNCTION__;
94 dBusInterface->call(ICD_DBUS_API_DISCONNECT_REQ,
95 QVariant((unsigned int)ICD_CONNECTION_FLAG_USER_EVENT));
98 bool NetworkHandlerPrivate::isConnected()
100 qDebug() << __PRETTY_FUNCTION__ << m_connected;
105 void NetworkHandlerPrivate::state()
107 qDebug() << __PRETTY_FUNCTION__;
109 dBusInterface->call(ICD_DBUS_API_STATE_REQ);