Skip to content

Latest commit

 

History

History
188 lines (157 loc) · 6.31 KB

declarativeconnectionagent.cpp

File metadata and controls

188 lines (157 loc) · 6.31 KB
 
Mar 19, 2013
Mar 19, 2013
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/****************************************************************************
**
** 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.
**
****************************************************************************/
Mar 19, 2013
Mar 19, 2013
16
Jul 7, 2015
Jul 7, 2015
17
#include "declarativeconnectionagent.h"
Jul 11, 2014
Jul 11, 2014
18
#include "connectiond_interface.h"
Mar 18, 2013
Mar 18, 2013
19
May 4, 2013
May 4, 2013
20
21
22
#include <connman-qt5/networkmanager.h>
#include <connman-qt5/networktechnology.h>
#include <connman-qt5/networkservice.h>
Mar 20, 2013
Mar 20, 2013
23
Mar 18, 2013
Mar 18, 2013
24
25
26
27
28
#include <qobject.h>
#define CONND_SERVICE "com.jolla.Connectiond"
#define CONND_PATH "/Connectiond"
Jul 7, 2015
Jul 7, 2015
29
DeclarativeConnectionAgent::DeclarativeConnectionAgent(QObject *parent):
May 28, 2013
May 28, 2013
30
31
QObject(parent),
connManagerInterface(0)
Mar 18, 2013
Mar 18, 2013
32
33
34
35
36
37
38
39
40
41
{
connectiondWatcher = new QDBusServiceWatcher(CONND_SERVICE,QDBusConnection::sessionBus(),
QDBusServiceWatcher::WatchForRegistration |
QDBusServiceWatcher::WatchForUnregistration, this);
connect(connectiondWatcher, SIGNAL(serviceRegistered(QString)),
this, SLOT(connectToConnectiond(QString)));
connect(connectiondWatcher, SIGNAL(serviceUnregistered(QString)),
this, SLOT(connectiondUnregistered(QString)));
Mar 19, 2013
Mar 19, 2013
42
connectToConnectiond();
Mar 18, 2013
Mar 18, 2013
43
44
}
Jul 7, 2015
Jul 7, 2015
45
DeclarativeConnectionAgent::~DeclarativeConnectionAgent()
Mar 18, 2013
Mar 18, 2013
46
47
48
{
}
Jul 7, 2015
Jul 7, 2015
49
void DeclarativeConnectionAgent::connectToConnectiond(QString)
Apr 4, 2013
Apr 4, 2013
50
51
52
53
54
55
56
{
if (connManagerInterface) {
delete connManagerInterface;
connManagerInterface = 0;
}
if (!QDBusConnection::sessionBus().interface()->isServiceRegistered(CONND_SERVICE)) {
Apr 8, 2013
Apr 8, 2013
57
qDebug() << Q_FUNC_INFO << QString("connection service not available").arg(CONND_SERVICE);
Apr 19, 2013
Apr 19, 2013
58
QDBusReply<void> reply = QDBusConnection::sessionBus().interface()->startService(CONND_SERVICE);
May 30, 2013
May 30, 2013
59
Apr 19, 2013
Apr 19, 2013
60
61
62
63
if (!reply.isValid()) {
qDebug() << Q_FUNC_INFO << reply.error().message();
return;
}
Apr 4, 2013
Apr 4, 2013
64
65
66
67
68
69
70
71
72
}
connManagerInterface = new com::jolla::Connectiond(CONND_SERVICE, CONND_PATH,
QDBusConnection::sessionBus(), this);
if (!connManagerInterface->isValid()) {
qDebug() << Q_FUNC_INFO << "is not valid interface";
}
connect(connManagerInterface,SIGNAL(connectionRequest()),
this,SLOT(onConnectionRequested()));
Apr 11, 2013
Apr 11, 2013
73
74
connect(connManagerInterface,SIGNAL(configurationNeeded(QString)),
this,SIGNAL(configurationNeeded(QString)));
Apr 4, 2013
Apr 4, 2013
75
76
77
78
connect(connManagerInterface,SIGNAL(userInputCanceled()),
this,SIGNAL(userInputCanceled()));
Jun 7, 2013
Jun 7, 2013
79
80
connect(connManagerInterface, SIGNAL(errorReported(QString, QString)),
this, SLOT(onErrorReported(QString, QString)));
Apr 4, 2013
Apr 4, 2013
81
82
83
84
85
86
87
88
89
connect(connManagerInterface,SIGNAL(connectionState(QString, QString)),
this,SLOT(onConnectionState(QString, QString)));
connect(connManagerInterface,SIGNAL(requestBrowser(QString)),
this,SLOT(onRequestBrowser(QString)));
connect(connManagerInterface,SIGNAL(userInputRequested(QString,QVariantMap)),
this,SLOT(onUserInputRequested(QString,QVariantMap)), Qt::UniqueConnection);
Apr 30, 2014
Apr 30, 2014
90
91
92
connect(connManagerInterface,SIGNAL(tetheringFinished(bool)),
this,SLOT(onTetheringFinished(bool)));
Apr 4, 2013
Apr 4, 2013
93
94
}
Jul 7, 2015
Jul 7, 2015
95
void DeclarativeConnectionAgent::sendUserReply(const QVariantMap &input)
Apr 30, 2014
Apr 30, 2014
96
{
May 30, 2013
May 30, 2013
97
if (!connManagerInterface || !connManagerInterface->isValid()) {
Jun 7, 2013
Jun 7, 2013
98
Q_EMIT errorReported("","ConnectionAgent not available");
May 30, 2013
May 30, 2013
99
100
return;
}
Mar 18, 2013
Mar 18, 2013
101
QDBusPendingReply<> reply = connManagerInterface->sendUserReply(input);
May 30, 2013
May 30, 2013
102
reply.waitForFinished();
Mar 18, 2013
Mar 18, 2013
103
if (reply.isError()) {
Apr 8, 2013
Apr 8, 2013
104
qDebug() << Q_FUNC_INFO << reply.error().message();
Jun 7, 2013
Jun 7, 2013
105
Q_EMIT errorReported("",reply.error().message());
Mar 18, 2013
Mar 18, 2013
106
107
108
}
}
Jul 7, 2015
Jul 7, 2015
109
void DeclarativeConnectionAgent::sendConnectReply(const QString &replyMessage, int timeout)
Mar 18, 2013
Mar 18, 2013
110
{
May 30, 2013
May 30, 2013
111
if (!connManagerInterface || !connManagerInterface->isValid()) {
Jun 7, 2013
Jun 7, 2013
112
Q_EMIT errorReported("","ConnectionAgent not available");
May 30, 2013
May 30, 2013
113
114
return;
}
Apr 19, 2013
Apr 19, 2013
115
connManagerInterface->sendConnectReply(replyMessage,timeout);
Mar 18, 2013
Mar 18, 2013
116
117
}
Jul 7, 2015
Jul 7, 2015
118
void DeclarativeConnectionAgent::connectToType(const QString &type)
Mar 20, 2013
Mar 20, 2013
119
{
May 30, 2013
May 30, 2013
120
if (!connManagerInterface || !connManagerInterface->isValid()) {
Jun 7, 2013
Jun 7, 2013
121
Q_EMIT errorReported("","ConnectionAgent not available");
May 30, 2013
May 30, 2013
122
123
124
return;
}
Mar 20, 2013
Mar 20, 2013
125
126
127
connManagerInterface->connectToType(type);
}
Jul 7, 2015
Jul 7, 2015
128
void DeclarativeConnectionAgent::onErrorReported(const QString &servicePath, const QString &error)
Mar 18, 2013
Mar 18, 2013
129
{
Jun 7, 2013
Jun 7, 2013
130
Q_EMIT errorReported(servicePath, error);
Mar 18, 2013
Mar 18, 2013
131
132
}
Jul 7, 2015
Jul 7, 2015
133
void DeclarativeConnectionAgent::onRequestBrowser(const QString &url)
Mar 18, 2013
Mar 18, 2013
134
135
{
qDebug() << Q_FUNC_INFO <<url;
Sep 16, 2013
Sep 16, 2013
136
Q_EMIT browserRequested(url);
Mar 18, 2013
Mar 18, 2013
137
138
}
Jul 7, 2015
Jul 7, 2015
139
void DeclarativeConnectionAgent::onUserInputRequested(const QString &service, const QVariantMap &fields)
Mar 18, 2013
Mar 18, 2013
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
{
// we do this as qtdbus does not understand QVariantMap very well.
// we need to manually demarshall
QVariantMap map;
QMapIterator<QString, QVariant> i(fields);
// this works for Passphrase at least. anything else?
while (i.hasNext()) {
i.next();
QDBusArgument arg = fields.value(i.key()).value<QDBusArgument>();
QVariantMap vmap = qdbus_cast<QVariantMap>(arg);
map.insert(i.key(), vmap);
}
Q_EMIT userInputRequested(service, map);
}
Jul 7, 2015
Jul 7, 2015
155
void DeclarativeConnectionAgent::onConnectionRequested()
Mar 18, 2013
Mar 18, 2013
156
{
May 28, 2013
May 28, 2013
157
qDebug() << Q_FUNC_INFO;
Mar 18, 2013
Mar 18, 2013
158
159
160
Q_EMIT connectionRequest();
}
Jul 7, 2015
Jul 7, 2015
161
void DeclarativeConnectionAgent::connectiondUnregistered(QString)
Mar 18, 2013
Mar 18, 2013
162
163
164
165
166
167
{
if (connManagerInterface) {
delete connManagerInterface;
connManagerInterface = 0;
}
}
Mar 20, 2013
Mar 20, 2013
168
Jul 7, 2015
Jul 7, 2015
169
void DeclarativeConnectionAgent::onConnectionState(const QString &state, const QString &type)
Mar 23, 2013
Mar 23, 2013
170
{
Jul 3, 2013
Jul 3, 2013
171
qDebug() << Q_FUNC_INFO << state;
Apr 4, 2013
Apr 4, 2013
172
Q_EMIT connectionState(state, type);
Mar 23, 2013
Mar 23, 2013
173
}
Apr 16, 2013
Apr 16, 2013
174
Jul 7, 2015
Jul 7, 2015
175
void DeclarativeConnectionAgent::startTethering(const QString &type)
Apr 30, 2014
Apr 30, 2014
176
177
178
179
{
connManagerInterface->startTethering(type);
}
Jul 7, 2015
Jul 7, 2015
180
void DeclarativeConnectionAgent::onTetheringFinished(bool success)
Apr 30, 2014
Apr 30, 2014
181
182
183
184
{
Q_EMIT tetheringFinished(success);
}
Jul 7, 2015
Jul 7, 2015
185
void DeclarativeConnectionAgent::stopTethering(bool keepPowered)
Apr 30, 2014
Apr 30, 2014
186
{
Jul 11, 2014
Jul 11, 2014
187
connManagerInterface->stopTethering(keepPowered);
Apr 30, 2014
Apr 30, 2014
188
}