1 // Copyright 2010 Jochen Becher
3 // This file is part of MovieSchedule.
5 // MovieSchedule is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // MovieSchedule is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with MovieSchedule. If not, see <http://www.gnu.org/licenses/>.
18 #include "connectivitymanager.h"
20 #include <QDBusMessage>
21 #include <QDBusInterface>
23 #include <icd/dbus_api.h>
26 ConnectivityManager::ConnectivityManager(QObject *parent)
28 _dbus_connection(QDBusConnection::systemBus()),
30 _interface(new QDBusInterface(ICD_DBUS_API_INTERFACE,
32 ICD_DBUS_API_INTERFACE,
39 _dbus_connection.connect(ICD_DBUS_API_INTERFACE, ICD_DBUS_API_PATH, ICD_DBUS_API_INTERFACE,
40 ICD_DBUS_API_STATISTICS_SIG, this, SLOT(StatisticsSentResult(const QDBusMessage&)));
41 _dbus_connection.connect(ICD_DBUS_API_INTERFACE, ICD_DBUS_API_PATH, ICD_DBUS_API_INTERFACE,
42 ICD_DBUS_API_STATE_SIG, this, SLOT(ChangeState(const QDBusMessage&)));
46 ConnectivityManager::~ConnectivityManager()
49 _dbus_connection.disconnect(ICD_DBUS_API_INTERFACE, ICD_DBUS_API_PATH, ICD_DBUS_API_INTERFACE,
50 ICD_DBUS_API_STATE_SIG, this, SLOT(ChangeState(const QDBusMessage&)));
51 _dbus_connection.disconnect(ICD_DBUS_API_INTERFACE, ICD_DBUS_API_PATH, ICD_DBUS_API_INTERFACE,
52 ICD_DBUS_API_STATISTICS_SIG, this, SLOT(StatisticsSentResult(const QDBusMessage&)));
56 void ConnectivityManager::Connect()
59 _interface->call(ICD_DBUS_API_CONNECT_REQ,
60 QVariant((unsigned int) ICD_CONNECTION_FLAG_USER_EVENT));
62 UpdateConnectionState();
65 void ConnectivityManager::Disconnect()
68 _interface->call(ICD_DBUS_API_DISCONNECT_REQ,
69 QVariant((unsigned int) ICD_CONNECTION_FLAG_USER_EVENT));
73 void ConnectivityManager::UpdateConnectionState()
76 _interface->call(ICD_DBUS_API_STATE_REQ);
81 void ConnectivityManager::StatisticsSentResult(const QDBusMessage &rep)
86 void ConnectivityManager::ChangeState(const QDBusMessage &rep)
89 QString connection_error = rep.arguments().value(6).value<QString>();
91 if (!connection_error.isEmpty()) {
96 unsigned int connection_status = rep.arguments().value(7).value<unsigned int>();
98 switch (connection_status) {
99 case ICD_STATE_DISCONNECTED:
102 case ICD_STATE_CONNECTING:
104 case ICD_STATE_CONNECTED:
107 case ICD_STATE_DISCONNECTING:
109 case ICD_STATE_LIMITED_CONN_ENABLED:
111 case ICD_STATE_LIMITED_CONN_DISABLED:
113 case ICD_STATE_SEARCH_START:
115 case ICD_STATE_SEARCH_STOP:
117 case ICD_STATE_INTERNAL_ADDRESS_ACQUIRED: