/
qconnectionmanager.cpp
193 lines (158 loc) · 6.02 KB
/
qconnectionmanager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/****************************************************************************
**
** Copyright (C) 2013 Jolla Ltd
** Contact: lorn.potter@gmail.com
**
**
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
****************************************************************************/
#include "qconnectionmanager.h"
#include "connadaptor.h"
#include <connman-qt/useragent.h>
#include <connman-qt/service.h>
//#include <connman-qt/counter.h>
//#include <connman-qt/session.h>
//#include <connman-qt/networksession.h>
//#include <connman-qt/sessionagent.h>
#include <connman-qt/networkmanager.h>
#include <connman-qt/networktechnology.h>
#include <connman-qt/networkservice.h>
//#include <lipstick/notificationmanager.h>
QConnectionManager* QConnectionManager::self = NULL;
QConnectionManager::QConnectionManager(QObject *parent) :
QObject(parent),
netman(NetworkManagerFactory::createInstance())
{
connectionAdaptor = new ConnAdaptor(this);
QDBusConnection dbus = QDBusConnection::sessionBus();
if (!dbus.registerObject("/Connectiond", this)) {
qDebug() << "XXXXXXXXXXX could not register object XXXXXXXXXXXXXXXXXX";
}
if (!dbus.registerService("com.jolla.Connectiond")) {
qDebug() << "XXXXXXXXXXX could not register service XXXXXXXXXXXXXXXXXX";
}
qDebug() << "XXXXXXXXXXX everything hunky dory XXXXXXXXXXXXXXXXXX";
ua = new UserAgent(this);
connect(ua,SIGNAL(userInputRequested(QString,QVariantMap)),
this,SLOT(onUserInputRequested(QString,QVariantMap)));
connect(ua,SIGNAL(connectionRequest()),this,SLOT(onConnectionRequest()));
connect(ua,SIGNAL(errorReported(QString)),this,SLOT(onErrorReported(QString)));
connect(ua,SIGNAL(userInputCanceled()),this,SLOT(onUserInputCanceled()));
connect(ua,SIGNAL(userInputRequested(QString,QVariantMap)),
this,SLOT(onUserInputRequested(QString,QVariantMap)), Qt::UniqueConnection);
ua->sendConnectReply("Clear");
connect(netman,SIGNAL(serviceAdded(QString)),this,SLOT(onServiceAdded(QString)));
connect(netman,SIGNAL(stateChanged(QString)),this,SLOT(networkStateChanged(QString)));
currentNetworkState = netman->state();
}
QConnectionManager::~QConnectionManager()
{
delete self;
}
QConnectionManager & QConnectionManager::instance()
{
if (!self) {
self = new QConnectionManager;
}
return *self;
}
// from useragent
void QConnectionManager::onUserInputRequested(const QString &servicePath, const QVariantMap &fields)
{
// gets called when a connman service gets called to connect and needs more configurations.
Q_EMIT userInputRequested(servicePath, fields);
}
// from useragent
void QConnectionManager::onUserInputCanceled()
{
Q_EMIT userInputCanceled();
}
// from useragent
void QConnectionManager::onErrorReported(const QString &error)
{
Q_EMIT errorReported(error);
}
// from useragent
void QConnectionManager::onConnectionRequest()
{
// if (!autoConnect()) {
Q_EMIT connectionRequest();
// }
}
void QConnectionManager::sendMessage()
{
// ua->sendConnectReply(QLatin1String("Suppress"));
}
void QConnectionManager::sendConnectReply(const QString &in0, int in1)
{
ua->sendConnectReply(in0, in1);
}
void QConnectionManager::sendUserReply(const QVariantMap &input)
{
ua->sendUserReply(input);
}
void QConnectionManager::networkStateChanged(const QString &state)
{
QString msg;
if (currentNetworkState == "idle" && state == "association") {
msg = "Connecting...";
} else if (currentNetworkState == "ready" && state == "online") {
msg = "Connected";
} else if (state == "offline") {
msg = "Offline";
}
qDebug() << Q_FUNC_INFO << currentNetworkState << state << msg;
// NotificationManager *manager = NotificationManager::instance();
// QVariantHash hints;
// hints.insert(NotificationManager::HINT_URGENCY, 2);
// hints.insert(NotificationManager::HINT_CATEGORY, "device.error");
// hints.insert(NotificationManager::HINT_PREVIEW_BODY, msg);
// manager->Notify(qApp->applicationName(), 0, QString(), QString(), QString(), QStringList(), hints, -1);
// if (!msg.isEmpty()) {
// emit serviceStateChanged(msg);
// }
currentNetworkState = state;
}
void QConnectionManager::onServiceAdded(const QString &servicePath)
{
// qDebug() << Q_FUNC_INFO << servicePath;
}
void QConnectionManager::serviceErrorChanged(const QString &error)
{
qDebug() << Q_FUNC_INFO << error;
// NotificationManager *manager = NotificationManager::instance();
// QVariantHash hints;
// hints.insert(NotificationManager::HINT_URGENCY, 1);
// hints.insert(NotificationManager::HINT_CATEGORY, "device.error");
// hints.insert(NotificationManager::HINT_PREVIEW_BODY, error);
// manager->Notify(qApp->applicationName(), 0, QString(), QString(), QString(), QStringList(), hints, -1);
}
void QConnectionManager::stateChanged(const QString &state)
{
Q_UNUSED(state)
}
bool QConnectionManager::autoConnect()
{
QStringList techList = netman->technologiesList();
Q_FOREACH (const QString &tech, techList) {
QVector<NetworkService*> serviceList = netman->getServices(tech);
Q_FOREACH (NetworkService *service, serviceList) {
if(service->autoConnect() && service->favorite()) {
QObject::connect(service, SIGNAL(stateChanged(QString)),
this,SLOT(stateChanged(QString)));
QObject::connect(service, SIGNAL(connectRequestFailed(QString)),
this,SLOT(serviceErrorChanged(QString)));
service->requestConnect();
return true;
}
}
}
return false;
}