1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the plugins of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #include <QObject>
|
---|
43 | #include <QList>
|
---|
44 | #include <QtDBus/QtDBus>
|
---|
45 | #include <QtDBus/QDBusConnection>
|
---|
46 | #include <QtDBus/QDBusError>
|
---|
47 | #include <QtDBus/QDBusInterface>
|
---|
48 | #include <QtDBus/QDBusMessage>
|
---|
49 | #include <QtDBus/QDBusReply>
|
---|
50 | #include <QtDBus/QDBusPendingCallWatcher>
|
---|
51 | #include <QtDBus/QDBusObjectPath>
|
---|
52 | #include <QtDBus/QDBusPendingCall>
|
---|
53 |
|
---|
54 | #include "qnetworkmanagerservice.h"
|
---|
55 | #include "qnmdbushelper.h"
|
---|
56 |
|
---|
57 | #ifndef QT_NO_DBUS
|
---|
58 |
|
---|
59 | QT_BEGIN_NAMESPACE
|
---|
60 |
|
---|
61 | static QDBusConnection dbusConnection = QDBusConnection::systemBus();
|
---|
62 |
|
---|
63 | class QNetworkManagerInterfacePrivate
|
---|
64 | {
|
---|
65 | public:
|
---|
66 | QDBusInterface *connectionInterface;
|
---|
67 | bool valid;
|
---|
68 | };
|
---|
69 |
|
---|
70 | QNetworkManagerInterface::QNetworkManagerInterface(QObject *parent)
|
---|
71 | : QObject(parent)
|
---|
72 | {
|
---|
73 | d = new QNetworkManagerInterfacePrivate();
|
---|
74 | d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE),
|
---|
75 | QLatin1String(NM_DBUS_PATH),
|
---|
76 | QLatin1String(NM_DBUS_INTERFACE),
|
---|
77 | dbusConnection);
|
---|
78 | if (!d->connectionInterface->isValid()) {
|
---|
79 | d->valid = false;
|
---|
80 | return;
|
---|
81 | }
|
---|
82 | d->valid = true;
|
---|
83 | nmDBusHelper = new QNmDBusHelper(this);
|
---|
84 | connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap<QString,QVariant>)),
|
---|
85 | this,SIGNAL(propertiesChanged( const QString &, QMap<QString,QVariant>)));
|
---|
86 | connect(nmDBusHelper,SIGNAL(pathForStateChanged(const QString &, quint32)),
|
---|
87 | this, SIGNAL(stateChanged(const QString&, quint32)));
|
---|
88 |
|
---|
89 | }
|
---|
90 |
|
---|
91 | QNetworkManagerInterface::~QNetworkManagerInterface()
|
---|
92 | {
|
---|
93 | delete d->connectionInterface;
|
---|
94 | delete d;
|
---|
95 | }
|
---|
96 |
|
---|
97 | bool QNetworkManagerInterface::isValid()
|
---|
98 | {
|
---|
99 | return d->valid;
|
---|
100 | }
|
---|
101 |
|
---|
102 | bool QNetworkManagerInterface::setConnections()
|
---|
103 | {
|
---|
104 | if(!isValid() )
|
---|
105 | return false;
|
---|
106 | bool allOk = false;
|
---|
107 | if (!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE),
|
---|
108 | QLatin1String(NM_DBUS_PATH),
|
---|
109 | QLatin1String(NM_DBUS_INTERFACE),
|
---|
110 | QLatin1String("PropertiesChanged"),
|
---|
111 | nmDBusHelper,SLOT(slotPropertiesChanged( QMap<QString,QVariant>)))) {
|
---|
112 | allOk = true;
|
---|
113 | }
|
---|
114 | if (!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE),
|
---|
115 | QLatin1String(NM_DBUS_PATH),
|
---|
116 | QLatin1String(NM_DBUS_INTERFACE),
|
---|
117 | QLatin1String("DeviceAdded"),
|
---|
118 | this,SIGNAL(deviceAdded(QDBusObjectPath)))) {
|
---|
119 | allOk = true;
|
---|
120 | }
|
---|
121 | if (!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE),
|
---|
122 | QLatin1String(NM_DBUS_PATH),
|
---|
123 | QLatin1String(NM_DBUS_INTERFACE),
|
---|
124 | QLatin1String("DeviceRemoved"),
|
---|
125 | this,SIGNAL(deviceRemoved(QDBusObjectPath)))) {
|
---|
126 | allOk = true;
|
---|
127 | }
|
---|
128 |
|
---|
129 | return allOk;
|
---|
130 | }
|
---|
131 |
|
---|
132 | QDBusInterface *QNetworkManagerInterface::connectionInterface() const
|
---|
133 | {
|
---|
134 | return d->connectionInterface;
|
---|
135 | }
|
---|
136 |
|
---|
137 | QList <QDBusObjectPath> QNetworkManagerInterface::getDevices() const
|
---|
138 | {
|
---|
139 | QDBusReply<QList<QDBusObjectPath> > reply = d->connectionInterface->call(QLatin1String("GetDevices"));
|
---|
140 | return reply.value();
|
---|
141 | }
|
---|
142 |
|
---|
143 | void QNetworkManagerInterface::activateConnection( const QString &serviceName,
|
---|
144 | QDBusObjectPath connectionPath,
|
---|
145 | QDBusObjectPath devicePath,
|
---|
146 | QDBusObjectPath specificObject)
|
---|
147 | {
|
---|
148 | QDBusPendingCall pendingCall = d->connectionInterface->asyncCall(QLatin1String("ActivateConnection"),
|
---|
149 | QVariant(serviceName),
|
---|
150 | QVariant::fromValue(connectionPath),
|
---|
151 | QVariant::fromValue(devicePath),
|
---|
152 | QVariant::fromValue(specificObject));
|
---|
153 |
|
---|
154 | QDBusPendingCallWatcher *callWatcher = new QDBusPendingCallWatcher(pendingCall, this);
|
---|
155 | connect(callWatcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
|
---|
156 | this, SIGNAL(activationFinished(QDBusPendingCallWatcher*)));
|
---|
157 | }
|
---|
158 |
|
---|
159 | void QNetworkManagerInterface::deactivateConnection(QDBusObjectPath connectionPath) const
|
---|
160 | {
|
---|
161 | d->connectionInterface->call(QLatin1String("DeactivateConnection"), QVariant::fromValue(connectionPath));
|
---|
162 | }
|
---|
163 |
|
---|
164 | bool QNetworkManagerInterface::wirelessEnabled() const
|
---|
165 | {
|
---|
166 | return d->connectionInterface->property("WirelessEnabled").toBool();
|
---|
167 | }
|
---|
168 |
|
---|
169 | bool QNetworkManagerInterface::wirelessHardwareEnabled() const
|
---|
170 | {
|
---|
171 | return d->connectionInterface->property("WirelessHardwareEnabled").toBool();
|
---|
172 | }
|
---|
173 |
|
---|
174 | QList <QDBusObjectPath> QNetworkManagerInterface::activeConnections() const
|
---|
175 | {
|
---|
176 | QVariant prop = d->connectionInterface->property("ActiveConnections");
|
---|
177 | return prop.value<QList<QDBusObjectPath> >();
|
---|
178 | }
|
---|
179 |
|
---|
180 | quint32 QNetworkManagerInterface::state()
|
---|
181 | {
|
---|
182 | return d->connectionInterface->property("State").toUInt();
|
---|
183 | }
|
---|
184 |
|
---|
185 | class QNetworkManagerInterfaceAccessPointPrivate
|
---|
186 | {
|
---|
187 | public:
|
---|
188 | QDBusInterface *connectionInterface;
|
---|
189 | QString path;
|
---|
190 | bool valid;
|
---|
191 | };
|
---|
192 |
|
---|
193 | QNetworkManagerInterfaceAccessPoint::QNetworkManagerInterfaceAccessPoint(const QString &dbusPathName, QObject *parent)
|
---|
194 | : QObject(parent), nmDBusHelper(0)
|
---|
195 | {
|
---|
196 | d = new QNetworkManagerInterfaceAccessPointPrivate();
|
---|
197 | d->path = dbusPathName;
|
---|
198 | d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE),
|
---|
199 | d->path,
|
---|
200 | QLatin1String(NM_DBUS_INTERFACE_ACCESS_POINT),
|
---|
201 | dbusConnection);
|
---|
202 | if (!d->connectionInterface->isValid()) {
|
---|
203 | d->valid = false;
|
---|
204 | return;
|
---|
205 | }
|
---|
206 | d->valid = true;
|
---|
207 |
|
---|
208 | }
|
---|
209 |
|
---|
210 | QNetworkManagerInterfaceAccessPoint::~QNetworkManagerInterfaceAccessPoint()
|
---|
211 | {
|
---|
212 | delete d->connectionInterface;
|
---|
213 | delete d;
|
---|
214 | }
|
---|
215 |
|
---|
216 | bool QNetworkManagerInterfaceAccessPoint::isValid()
|
---|
217 | {
|
---|
218 | return d->valid;
|
---|
219 | }
|
---|
220 |
|
---|
221 | bool QNetworkManagerInterfaceAccessPoint::setConnections()
|
---|
222 | {
|
---|
223 | if(!isValid() )
|
---|
224 | return false;
|
---|
225 |
|
---|
226 | bool allOk = false;
|
---|
227 | delete nmDBusHelper;
|
---|
228 | nmDBusHelper = new QNmDBusHelper(this);
|
---|
229 | connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap<QString,QVariant>)),
|
---|
230 | this,SIGNAL(propertiesChanged( const QString &, QMap<QString,QVariant>)));
|
---|
231 |
|
---|
232 | if(dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE),
|
---|
233 | d->path,
|
---|
234 | QLatin1String(NM_DBUS_INTERFACE_ACCESS_POINT),
|
---|
235 | QLatin1String("PropertiesChanged"),
|
---|
236 | nmDBusHelper,SLOT(slotPropertiesChanged( QMap<QString,QVariant>))) ) {
|
---|
237 | allOk = true;
|
---|
238 |
|
---|
239 | }
|
---|
240 | return allOk;
|
---|
241 | }
|
---|
242 |
|
---|
243 | QDBusInterface *QNetworkManagerInterfaceAccessPoint::connectionInterface() const
|
---|
244 | {
|
---|
245 | return d->connectionInterface;
|
---|
246 | }
|
---|
247 |
|
---|
248 | quint32 QNetworkManagerInterfaceAccessPoint::flags() const
|
---|
249 | {
|
---|
250 | return d->connectionInterface->property("Flags").toUInt();
|
---|
251 | }
|
---|
252 |
|
---|
253 | quint32 QNetworkManagerInterfaceAccessPoint::wpaFlags() const
|
---|
254 | {
|
---|
255 | return d->connectionInterface->property("WpaFlags").toUInt();
|
---|
256 | }
|
---|
257 |
|
---|
258 | quint32 QNetworkManagerInterfaceAccessPoint::rsnFlags() const
|
---|
259 | {
|
---|
260 | return d->connectionInterface->property("RsnFlags").toUInt();
|
---|
261 | }
|
---|
262 |
|
---|
263 | QString QNetworkManagerInterfaceAccessPoint::ssid() const
|
---|
264 | {
|
---|
265 | return d->connectionInterface->property("Ssid").toString();
|
---|
266 | }
|
---|
267 |
|
---|
268 | quint32 QNetworkManagerInterfaceAccessPoint::frequency() const
|
---|
269 | {
|
---|
270 | return d->connectionInterface->property("Frequency").toUInt();
|
---|
271 | }
|
---|
272 |
|
---|
273 | QString QNetworkManagerInterfaceAccessPoint::hwAddress() const
|
---|
274 | {
|
---|
275 | return d->connectionInterface->property("HwAddress").toString();
|
---|
276 | }
|
---|
277 |
|
---|
278 | quint32 QNetworkManagerInterfaceAccessPoint::mode() const
|
---|
279 | {
|
---|
280 | return d->connectionInterface->property("Mode").toUInt();
|
---|
281 | }
|
---|
282 |
|
---|
283 | quint32 QNetworkManagerInterfaceAccessPoint::maxBitrate() const
|
---|
284 | {
|
---|
285 | return d->connectionInterface->property("MaxBitrate").toUInt();
|
---|
286 | }
|
---|
287 |
|
---|
288 | quint32 QNetworkManagerInterfaceAccessPoint::strength() const
|
---|
289 | {
|
---|
290 | return d->connectionInterface->property("Strength").toUInt();
|
---|
291 | }
|
---|
292 |
|
---|
293 | class QNetworkManagerInterfaceDevicePrivate
|
---|
294 | {
|
---|
295 | public:
|
---|
296 | QDBusInterface *connectionInterface;
|
---|
297 | QString path;
|
---|
298 | bool valid;
|
---|
299 | };
|
---|
300 |
|
---|
301 | QNetworkManagerInterfaceDevice::QNetworkManagerInterfaceDevice(const QString &deviceObjectPath, QObject *parent)
|
---|
302 | : QObject(parent), nmDBusHelper(0)
|
---|
303 | {
|
---|
304 | d = new QNetworkManagerInterfaceDevicePrivate();
|
---|
305 | d->path = deviceObjectPath;
|
---|
306 | d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE),
|
---|
307 | d->path,
|
---|
308 | QLatin1String(NM_DBUS_INTERFACE_DEVICE),
|
---|
309 | dbusConnection);
|
---|
310 | if (!d->connectionInterface->isValid()) {
|
---|
311 | d->valid = false;
|
---|
312 | return;
|
---|
313 | }
|
---|
314 | d->valid = true;
|
---|
315 | }
|
---|
316 |
|
---|
317 | QNetworkManagerInterfaceDevice::~QNetworkManagerInterfaceDevice()
|
---|
318 | {
|
---|
319 | delete d->connectionInterface;
|
---|
320 | delete d;
|
---|
321 | }
|
---|
322 |
|
---|
323 | bool QNetworkManagerInterfaceDevice::isValid()
|
---|
324 | {
|
---|
325 | return d->valid;
|
---|
326 | }
|
---|
327 |
|
---|
328 | bool QNetworkManagerInterfaceDevice::setConnections()
|
---|
329 | {
|
---|
330 | if(!isValid() )
|
---|
331 | return false;
|
---|
332 |
|
---|
333 | bool allOk = false;
|
---|
334 | delete nmDBusHelper;
|
---|
335 | nmDBusHelper = new QNmDBusHelper(this);
|
---|
336 | connect(nmDBusHelper,SIGNAL(pathForStateChanged(const QString &, quint32)),
|
---|
337 | this, SIGNAL(stateChanged(const QString&, quint32)));
|
---|
338 | if(dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE),
|
---|
339 | d->path,
|
---|
340 | QLatin1String(NM_DBUS_INTERFACE_DEVICE),
|
---|
341 | QLatin1String("StateChanged"),
|
---|
342 | nmDBusHelper,SLOT(deviceStateChanged(quint32)))) {
|
---|
343 | allOk = true;
|
---|
344 | }
|
---|
345 | return allOk;
|
---|
346 | }
|
---|
347 |
|
---|
348 | QDBusInterface *QNetworkManagerInterfaceDevice::connectionInterface() const
|
---|
349 | {
|
---|
350 | return d->connectionInterface;
|
---|
351 | }
|
---|
352 |
|
---|
353 | QString QNetworkManagerInterfaceDevice::udi() const
|
---|
354 | {
|
---|
355 | return d->connectionInterface->property("Udi").toString();
|
---|
356 | }
|
---|
357 |
|
---|
358 | QString QNetworkManagerInterfaceDevice::networkInterface() const
|
---|
359 | {
|
---|
360 | return d->connectionInterface->property("Interface").toString();
|
---|
361 | }
|
---|
362 |
|
---|
363 | quint32 QNetworkManagerInterfaceDevice::ip4Address() const
|
---|
364 | {
|
---|
365 | return d->connectionInterface->property("Ip4Address").toUInt();
|
---|
366 | }
|
---|
367 |
|
---|
368 | quint32 QNetworkManagerInterfaceDevice::state() const
|
---|
369 | {
|
---|
370 | return d->connectionInterface->property("State").toUInt();
|
---|
371 | }
|
---|
372 |
|
---|
373 | quint32 QNetworkManagerInterfaceDevice::deviceType() const
|
---|
374 | {
|
---|
375 | return d->connectionInterface->property("DeviceType").toUInt();
|
---|
376 | }
|
---|
377 |
|
---|
378 | QDBusObjectPath QNetworkManagerInterfaceDevice::ip4config() const
|
---|
379 | {
|
---|
380 | QVariant prop = d->connectionInterface->property("Ip4Config");
|
---|
381 | return prop.value<QDBusObjectPath>();
|
---|
382 | }
|
---|
383 |
|
---|
384 | class QNetworkManagerInterfaceDeviceWiredPrivate
|
---|
385 | {
|
---|
386 | public:
|
---|
387 | QDBusInterface *connectionInterface;
|
---|
388 | QString path;
|
---|
389 | bool valid;
|
---|
390 | };
|
---|
391 |
|
---|
392 | QNetworkManagerInterfaceDeviceWired::QNetworkManagerInterfaceDeviceWired(const QString &ifaceDevicePath, QObject *parent)
|
---|
393 | : QObject(parent), nmDBusHelper(0)
|
---|
394 | {
|
---|
395 | d = new QNetworkManagerInterfaceDeviceWiredPrivate();
|
---|
396 | d->path = ifaceDevicePath;
|
---|
397 | d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE),
|
---|
398 | d->path,
|
---|
399 | QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRED),
|
---|
400 | dbusConnection, parent);
|
---|
401 | if (!d->connectionInterface->isValid()) {
|
---|
402 | d->valid = false;
|
---|
403 | return;
|
---|
404 | }
|
---|
405 | d->valid = true;
|
---|
406 | }
|
---|
407 |
|
---|
408 | QNetworkManagerInterfaceDeviceWired::~QNetworkManagerInterfaceDeviceWired()
|
---|
409 | {
|
---|
410 | delete d->connectionInterface;
|
---|
411 | delete d;
|
---|
412 | }
|
---|
413 |
|
---|
414 | bool QNetworkManagerInterfaceDeviceWired::isValid()
|
---|
415 | {
|
---|
416 |
|
---|
417 | return d->valid;
|
---|
418 | }
|
---|
419 |
|
---|
420 | bool QNetworkManagerInterfaceDeviceWired::setConnections()
|
---|
421 | {
|
---|
422 | if(!isValid() )
|
---|
423 | return false;
|
---|
424 |
|
---|
425 | bool allOk = false;
|
---|
426 |
|
---|
427 | delete nmDBusHelper;
|
---|
428 | nmDBusHelper = new QNmDBusHelper(this);
|
---|
429 | connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap<QString,QVariant>)),
|
---|
430 | this,SIGNAL(propertiesChanged( const QString &, QMap<QString,QVariant>)));
|
---|
431 | if(dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE),
|
---|
432 | d->path,
|
---|
433 | QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRED),
|
---|
434 | QLatin1String("PropertiesChanged"),
|
---|
435 | nmDBusHelper,SLOT(slotPropertiesChanged( QMap<QString,QVariant>))) ) {
|
---|
436 | allOk = true;
|
---|
437 | }
|
---|
438 | return allOk;
|
---|
439 | }
|
---|
440 |
|
---|
441 | QDBusInterface *QNetworkManagerInterfaceDeviceWired::connectionInterface() const
|
---|
442 | {
|
---|
443 | return d->connectionInterface;
|
---|
444 | }
|
---|
445 |
|
---|
446 | QString QNetworkManagerInterfaceDeviceWired::hwAddress() const
|
---|
447 | {
|
---|
448 | return d->connectionInterface->property("HwAddress").toString();
|
---|
449 | }
|
---|
450 |
|
---|
451 | quint32 QNetworkManagerInterfaceDeviceWired::speed() const
|
---|
452 | {
|
---|
453 | return d->connectionInterface->property("Speed").toUInt();
|
---|
454 | }
|
---|
455 |
|
---|
456 | bool QNetworkManagerInterfaceDeviceWired::carrier() const
|
---|
457 | {
|
---|
458 | return d->connectionInterface->property("Carrier").toBool();
|
---|
459 | }
|
---|
460 |
|
---|
461 | class QNetworkManagerInterfaceDeviceWirelessPrivate
|
---|
462 | {
|
---|
463 | public:
|
---|
464 | QDBusInterface *connectionInterface;
|
---|
465 | QString path;
|
---|
466 | bool valid;
|
---|
467 | };
|
---|
468 |
|
---|
469 | QNetworkManagerInterfaceDeviceWireless::QNetworkManagerInterfaceDeviceWireless(const QString &ifaceDevicePath, QObject *parent)
|
---|
470 | : QObject(parent), nmDBusHelper(0)
|
---|
471 | {
|
---|
472 | d = new QNetworkManagerInterfaceDeviceWirelessPrivate();
|
---|
473 | d->path = ifaceDevicePath;
|
---|
474 | d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE),
|
---|
475 | d->path,
|
---|
476 | QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRELESS),
|
---|
477 | dbusConnection, parent);
|
---|
478 | if (!d->connectionInterface->isValid()) {
|
---|
479 | d->valid = false;
|
---|
480 | return;
|
---|
481 | }
|
---|
482 | d->valid = true;
|
---|
483 | }
|
---|
484 |
|
---|
485 | QNetworkManagerInterfaceDeviceWireless::~QNetworkManagerInterfaceDeviceWireless()
|
---|
486 | {
|
---|
487 | delete d->connectionInterface;
|
---|
488 | delete d;
|
---|
489 | }
|
---|
490 |
|
---|
491 | bool QNetworkManagerInterfaceDeviceWireless::isValid()
|
---|
492 | {
|
---|
493 | return d->valid;
|
---|
494 | }
|
---|
495 |
|
---|
496 | bool QNetworkManagerInterfaceDeviceWireless::setConnections()
|
---|
497 | {
|
---|
498 | if(!isValid() )
|
---|
499 | return false;
|
---|
500 |
|
---|
501 | bool allOk = false;
|
---|
502 | delete nmDBusHelper;
|
---|
503 | nmDBusHelper = new QNmDBusHelper(this);
|
---|
504 | connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap<QString,QVariant>)),
|
---|
505 | this,SIGNAL(propertiesChanged( const QString &, QMap<QString,QVariant>)));
|
---|
506 |
|
---|
507 | connect(nmDBusHelper, SIGNAL(pathForAccessPointAdded(const QString &,QDBusObjectPath)),
|
---|
508 | this,SIGNAL(accessPointAdded(const QString &,QDBusObjectPath)));
|
---|
509 |
|
---|
510 | connect(nmDBusHelper, SIGNAL(pathForAccessPointRemoved(const QString &,QDBusObjectPath)),
|
---|
511 | this,SIGNAL(accessPointRemoved(const QString &,QDBusObjectPath)));
|
---|
512 |
|
---|
513 | if(!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE),
|
---|
514 | d->path,
|
---|
515 | QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRELESS),
|
---|
516 | QLatin1String("AccessPointAdded"),
|
---|
517 | nmDBusHelper, SLOT(slotAccessPointAdded( QDBusObjectPath )))) {
|
---|
518 | allOk = true;
|
---|
519 | }
|
---|
520 |
|
---|
521 |
|
---|
522 | if(!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE),
|
---|
523 | d->path,
|
---|
524 | QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRELESS),
|
---|
525 | QLatin1String("AccessPointRemoved"),
|
---|
526 | nmDBusHelper, SLOT(slotAccessPointRemoved( QDBusObjectPath )))) {
|
---|
527 | allOk = true;
|
---|
528 | }
|
---|
529 |
|
---|
530 |
|
---|
531 | if(!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE),
|
---|
532 | d->path,
|
---|
533 | QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRELESS),
|
---|
534 | QLatin1String("PropertiesChanged"),
|
---|
535 | nmDBusHelper,SLOT(slotPropertiesChanged( QMap<QString,QVariant>)))) {
|
---|
536 | allOk = true;
|
---|
537 | }
|
---|
538 |
|
---|
539 | return allOk;
|
---|
540 | }
|
---|
541 |
|
---|
542 | QDBusInterface *QNetworkManagerInterfaceDeviceWireless::connectionInterface() const
|
---|
543 | {
|
---|
544 | return d->connectionInterface;
|
---|
545 | }
|
---|
546 |
|
---|
547 | QList <QDBusObjectPath> QNetworkManagerInterfaceDeviceWireless::getAccessPoints()
|
---|
548 | {
|
---|
549 | QDBusReply<QList<QDBusObjectPath> > reply = d->connectionInterface->call(QLatin1String("GetAccessPoints"));
|
---|
550 | return reply.value();
|
---|
551 | }
|
---|
552 |
|
---|
553 | QString QNetworkManagerInterfaceDeviceWireless::hwAddress() const
|
---|
554 | {
|
---|
555 | return d->connectionInterface->property("HwAddress").toString();
|
---|
556 | }
|
---|
557 |
|
---|
558 | quint32 QNetworkManagerInterfaceDeviceWireless::mode() const
|
---|
559 | {
|
---|
560 | return d->connectionInterface->property("Mode").toUInt();
|
---|
561 | }
|
---|
562 |
|
---|
563 | quint32 QNetworkManagerInterfaceDeviceWireless::bitrate() const
|
---|
564 | {
|
---|
565 | return d->connectionInterface->property("Bitrate").toUInt();
|
---|
566 | }
|
---|
567 |
|
---|
568 | QDBusObjectPath QNetworkManagerInterfaceDeviceWireless::activeAccessPoint() const
|
---|
569 | {
|
---|
570 | return d->connectionInterface->property("ActiveAccessPoint").value<QDBusObjectPath>();
|
---|
571 | }
|
---|
572 |
|
---|
573 | quint32 QNetworkManagerInterfaceDeviceWireless::wirelessCapabilities() const
|
---|
574 | {
|
---|
575 | return d->connectionInterface->property("WirelelessCapabilities").toUInt();
|
---|
576 | }
|
---|
577 |
|
---|
578 | class QNetworkManagerSettingsPrivate
|
---|
579 | {
|
---|
580 | public:
|
---|
581 | QDBusInterface *connectionInterface;
|
---|
582 | QString path;
|
---|
583 | bool valid;
|
---|
584 | };
|
---|
585 |
|
---|
586 | QNetworkManagerSettings::QNetworkManagerSettings(const QString &settingsService, QObject *parent)
|
---|
587 | : QObject(parent)
|
---|
588 | {
|
---|
589 | d = new QNetworkManagerSettingsPrivate();
|
---|
590 | d->path = settingsService;
|
---|
591 | d->connectionInterface = new QDBusInterface(settingsService,
|
---|
592 | QLatin1String(NM_DBUS_PATH_SETTINGS),
|
---|
593 | QLatin1String(NM_DBUS_IFACE_SETTINGS),
|
---|
594 | dbusConnection);
|
---|
595 | if (!d->connectionInterface->isValid()) {
|
---|
596 | d->valid = false;
|
---|
597 | return;
|
---|
598 | }
|
---|
599 | d->valid = true;
|
---|
600 | }
|
---|
601 |
|
---|
602 | QNetworkManagerSettings::~QNetworkManagerSettings()
|
---|
603 | {
|
---|
604 | delete d->connectionInterface;
|
---|
605 | delete d;
|
---|
606 | }
|
---|
607 |
|
---|
608 | bool QNetworkManagerSettings::isValid()
|
---|
609 | {
|
---|
610 | return d->valid;
|
---|
611 | }
|
---|
612 |
|
---|
613 | bool QNetworkManagerSettings::setConnections()
|
---|
614 | {
|
---|
615 | bool allOk = false;
|
---|
616 |
|
---|
617 | if (!dbusConnection.connect(d->path, QLatin1String(NM_DBUS_PATH_SETTINGS),
|
---|
618 | QLatin1String(NM_DBUS_IFACE_SETTINGS), QLatin1String("NewConnection"),
|
---|
619 | this, SIGNAL(newConnection(QDBusObjectPath)))) {
|
---|
620 | allOk = true;
|
---|
621 | }
|
---|
622 |
|
---|
623 | return allOk;
|
---|
624 | }
|
---|
625 |
|
---|
626 | QList <QDBusObjectPath> QNetworkManagerSettings::listConnections()
|
---|
627 | {
|
---|
628 | QDBusReply<QList<QDBusObjectPath> > reply = d->connectionInterface->call(QLatin1String("ListConnections"));
|
---|
629 | return reply.value();
|
---|
630 | }
|
---|
631 |
|
---|
632 | QDBusInterface *QNetworkManagerSettings::connectionInterface() const
|
---|
633 | {
|
---|
634 | return d->connectionInterface;
|
---|
635 | }
|
---|
636 |
|
---|
637 |
|
---|
638 | class QNetworkManagerSettingsConnectionPrivate
|
---|
639 | {
|
---|
640 | public:
|
---|
641 | QDBusInterface *connectionInterface;
|
---|
642 | QString path;
|
---|
643 | QString service;
|
---|
644 | QNmSettingsMap settingsMap;
|
---|
645 | bool valid;
|
---|
646 | };
|
---|
647 |
|
---|
648 | QNetworkManagerSettingsConnection::QNetworkManagerSettingsConnection(const QString &settingsService, const QString &connectionObjectPath, QObject *parent)
|
---|
649 | : QObject(parent), nmDBusHelper(0)
|
---|
650 | {
|
---|
651 | qDBusRegisterMetaType<QNmSettingsMap>();
|
---|
652 | d = new QNetworkManagerSettingsConnectionPrivate();
|
---|
653 | d->path = connectionObjectPath;
|
---|
654 | d->service = settingsService;
|
---|
655 | d->connectionInterface = new QDBusInterface(settingsService,
|
---|
656 | d->path,
|
---|
657 | QLatin1String(NM_DBUS_IFACE_SETTINGS_CONNECTION),
|
---|
658 | dbusConnection, parent);
|
---|
659 | if (!d->connectionInterface->isValid()) {
|
---|
660 | d->valid = false;
|
---|
661 | return;
|
---|
662 | }
|
---|
663 | d->valid = true;
|
---|
664 | QDBusReply< QNmSettingsMap > rep = d->connectionInterface->call(QLatin1String("GetSettings"));
|
---|
665 | d->settingsMap = rep.value();
|
---|
666 | }
|
---|
667 |
|
---|
668 | QNetworkManagerSettingsConnection::~QNetworkManagerSettingsConnection()
|
---|
669 | {
|
---|
670 | delete d->connectionInterface;
|
---|
671 | delete d;
|
---|
672 | }
|
---|
673 |
|
---|
674 | bool QNetworkManagerSettingsConnection::isValid()
|
---|
675 | {
|
---|
676 | return d->valid;
|
---|
677 | }
|
---|
678 |
|
---|
679 | bool QNetworkManagerSettingsConnection::setConnections()
|
---|
680 | {
|
---|
681 | if(!isValid() )
|
---|
682 | return false;
|
---|
683 |
|
---|
684 | bool allOk = false;
|
---|
685 | if(!dbusConnection.connect(d->service, d->path,
|
---|
686 | QLatin1String(NM_DBUS_IFACE_SETTINGS_CONNECTION), QLatin1String("Updated"),
|
---|
687 | this, SIGNAL(updated(QNmSettingsMap)))) {
|
---|
688 | allOk = true;
|
---|
689 | } else {
|
---|
690 | QDBusError error = dbusConnection.lastError();
|
---|
691 | }
|
---|
692 |
|
---|
693 | delete nmDBusHelper;
|
---|
694 | nmDBusHelper = new QNmDBusHelper(this);
|
---|
695 | connect(nmDBusHelper, SIGNAL(pathForSettingsRemoved(const QString &)),
|
---|
696 | this,SIGNAL(removed( const QString &)));
|
---|
697 |
|
---|
698 | if (!dbusConnection.connect(d->service, d->path,
|
---|
699 | QLatin1String(NM_DBUS_IFACE_SETTINGS_CONNECTION), QLatin1String("Removed"),
|
---|
700 | nmDBusHelper, SIGNAL(slotSettingsRemoved()))) {
|
---|
701 | allOk = true;
|
---|
702 | }
|
---|
703 |
|
---|
704 | return allOk;
|
---|
705 | }
|
---|
706 |
|
---|
707 | QDBusInterface *QNetworkManagerSettingsConnection::connectionInterface() const
|
---|
708 | {
|
---|
709 | return d->connectionInterface;
|
---|
710 | }
|
---|
711 |
|
---|
712 | QNmSettingsMap QNetworkManagerSettingsConnection::getSettings()
|
---|
713 | {
|
---|
714 | QDBusReply< QNmSettingsMap > rep = d->connectionInterface->call(QLatin1String("GetSettings"));
|
---|
715 | d->settingsMap = rep.value();
|
---|
716 | return d->settingsMap;
|
---|
717 | }
|
---|
718 |
|
---|
719 | NMDeviceType QNetworkManagerSettingsConnection::getType()
|
---|
720 | {
|
---|
721 | const QString devType =
|
---|
722 | d->settingsMap.value(QLatin1String("connection")).value(QLatin1String("type")).toString();
|
---|
723 |
|
---|
724 | if (devType == QLatin1String("802-3-ethernet"))
|
---|
725 | return DEVICE_TYPE_802_3_ETHERNET;
|
---|
726 | else if (devType == QLatin1String("802-11-wireless"))
|
---|
727 | return DEVICE_TYPE_802_11_WIRELESS;
|
---|
728 | else
|
---|
729 | return DEVICE_TYPE_UNKNOWN;
|
---|
730 | }
|
---|
731 |
|
---|
732 | bool QNetworkManagerSettingsConnection::isAutoConnect()
|
---|
733 | {
|
---|
734 | const QVariant autoConnect =
|
---|
735 | d->settingsMap.value(QLatin1String("connection")).value(QLatin1String("autoconnect"));
|
---|
736 |
|
---|
737 | // NetworkManager default is to auto connect
|
---|
738 | if (!autoConnect.isValid())
|
---|
739 | return true;
|
---|
740 |
|
---|
741 | return autoConnect.toBool();
|
---|
742 | }
|
---|
743 |
|
---|
744 | quint64 QNetworkManagerSettingsConnection::getTimestamp()
|
---|
745 | {
|
---|
746 | return d->settingsMap.value(QLatin1String("connection"))
|
---|
747 | .value(QLatin1String("timestamp")).toUInt();
|
---|
748 | }
|
---|
749 |
|
---|
750 | QString QNetworkManagerSettingsConnection::getId()
|
---|
751 | {
|
---|
752 | return d->settingsMap.value(QLatin1String("connection")).value(QLatin1String("id")).toString();
|
---|
753 | }
|
---|
754 |
|
---|
755 | QString QNetworkManagerSettingsConnection::getUuid()
|
---|
756 | {
|
---|
757 | const QString id = d->settingsMap.value(QLatin1String("connection"))
|
---|
758 | .value(QLatin1String("uuid")).toString();
|
---|
759 |
|
---|
760 | // is no uuid, return the connection path
|
---|
761 | return id.isEmpty() ? d->connectionInterface->path() : id;
|
---|
762 | }
|
---|
763 |
|
---|
764 | QString QNetworkManagerSettingsConnection::getSsid()
|
---|
765 | {
|
---|
766 | return d->settingsMap.value(QLatin1String("802-11-wireless"))
|
---|
767 | .value(QLatin1String("ssid")).toString();
|
---|
768 | }
|
---|
769 |
|
---|
770 | QString QNetworkManagerSettingsConnection::getMacAddress()
|
---|
771 | {
|
---|
772 | NMDeviceType type = getType();
|
---|
773 |
|
---|
774 | if (type == DEVICE_TYPE_802_3_ETHERNET) {
|
---|
775 | return d->settingsMap.value(QLatin1String("802-3-ethernet"))
|
---|
776 | .value(QLatin1String("mac-address")).toString();
|
---|
777 | } else if (type == DEVICE_TYPE_802_11_WIRELESS) {
|
---|
778 | return d->settingsMap.value(QLatin1String("802-11-wireless"))
|
---|
779 | .value(QLatin1String("mac-address")).toString();
|
---|
780 | } else {
|
---|
781 | return QString();
|
---|
782 | }
|
---|
783 | }
|
---|
784 |
|
---|
785 | QStringList QNetworkManagerSettingsConnection::getSeenBssids()
|
---|
786 | {
|
---|
787 | if (getType() == DEVICE_TYPE_802_11_WIRELESS) {
|
---|
788 | return d->settingsMap.value(QLatin1String("802-11-wireless"))
|
---|
789 | .value(QLatin1String("seen-bssids")).toStringList();
|
---|
790 | } else {
|
---|
791 | return QStringList();
|
---|
792 | }
|
---|
793 | }
|
---|
794 |
|
---|
795 | class QNetworkManagerConnectionActivePrivate
|
---|
796 | {
|
---|
797 | public:
|
---|
798 | QDBusInterface *connectionInterface;
|
---|
799 | QString path;
|
---|
800 | bool valid;
|
---|
801 | };
|
---|
802 |
|
---|
803 | QNetworkManagerConnectionActive::QNetworkManagerConnectionActive( const QString &activeConnectionObjectPath, QObject *parent)
|
---|
804 | : QObject(parent), nmDBusHelper(0)
|
---|
805 | {
|
---|
806 | d = new QNetworkManagerConnectionActivePrivate();
|
---|
807 | d->path = activeConnectionObjectPath;
|
---|
808 | d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE),
|
---|
809 | d->path,
|
---|
810 | QLatin1String(NM_DBUS_INTERFACE_ACTIVE_CONNECTION),
|
---|
811 | dbusConnection, parent);
|
---|
812 | if (!d->connectionInterface->isValid()) {
|
---|
813 | d->valid = false;
|
---|
814 | return;
|
---|
815 | }
|
---|
816 | d->valid = true;
|
---|
817 | }
|
---|
818 |
|
---|
819 | QNetworkManagerConnectionActive::~QNetworkManagerConnectionActive()
|
---|
820 | {
|
---|
821 | delete d->connectionInterface;
|
---|
822 | delete d;
|
---|
823 | }
|
---|
824 |
|
---|
825 | bool QNetworkManagerConnectionActive::isValid()
|
---|
826 | {
|
---|
827 | return d->valid;
|
---|
828 | }
|
---|
829 |
|
---|
830 | bool QNetworkManagerConnectionActive::setConnections()
|
---|
831 | {
|
---|
832 | if(!isValid() )
|
---|
833 | return false;
|
---|
834 |
|
---|
835 | bool allOk = false;
|
---|
836 | delete nmDBusHelper;
|
---|
837 | nmDBusHelper = new QNmDBusHelper(this);
|
---|
838 | connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap<QString,QVariant>)),
|
---|
839 | this,SIGNAL(propertiesChanged( const QString &, QMap<QString,QVariant>)));
|
---|
840 | if(dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE),
|
---|
841 | d->path,
|
---|
842 | QLatin1String(NM_DBUS_INTERFACE_ACTIVE_CONNECTION),
|
---|
843 | QLatin1String("PropertiesChanged"),
|
---|
844 | nmDBusHelper,SLOT(slotPropertiesChanged( QMap<QString,QVariant>))) ) {
|
---|
845 | allOk = true;
|
---|
846 | }
|
---|
847 |
|
---|
848 | return allOk;
|
---|
849 | }
|
---|
850 |
|
---|
851 | QDBusInterface *QNetworkManagerConnectionActive::connectionInterface() const
|
---|
852 | {
|
---|
853 | return d->connectionInterface;
|
---|
854 | }
|
---|
855 |
|
---|
856 | QString QNetworkManagerConnectionActive::serviceName() const
|
---|
857 | {
|
---|
858 | return d->connectionInterface->property("ServiceName").toString();
|
---|
859 | }
|
---|
860 |
|
---|
861 | QDBusObjectPath QNetworkManagerConnectionActive::connection() const
|
---|
862 | {
|
---|
863 | QVariant prop = d->connectionInterface->property("Connection");
|
---|
864 | return prop.value<QDBusObjectPath>();
|
---|
865 | }
|
---|
866 |
|
---|
867 | QDBusObjectPath QNetworkManagerConnectionActive::specificObject() const
|
---|
868 | {
|
---|
869 | QVariant prop = d->connectionInterface->property("SpecificObject");
|
---|
870 | return prop.value<QDBusObjectPath>();
|
---|
871 | }
|
---|
872 |
|
---|
873 | QList<QDBusObjectPath> QNetworkManagerConnectionActive::devices() const
|
---|
874 | {
|
---|
875 | QVariant prop = d->connectionInterface->property("Devices");
|
---|
876 | return prop.value<QList<QDBusObjectPath> >();
|
---|
877 | }
|
---|
878 |
|
---|
879 | quint32 QNetworkManagerConnectionActive::state() const
|
---|
880 | {
|
---|
881 | return d->connectionInterface->property("State").toUInt();
|
---|
882 | }
|
---|
883 |
|
---|
884 | bool QNetworkManagerConnectionActive::defaultRoute() const
|
---|
885 | {
|
---|
886 | return d->connectionInterface->property("Default").toBool();
|
---|
887 | }
|
---|
888 |
|
---|
889 | class QNetworkManagerIp4ConfigPrivate
|
---|
890 | {
|
---|
891 | public:
|
---|
892 | QDBusInterface *connectionInterface;
|
---|
893 | QString path;
|
---|
894 | bool valid;
|
---|
895 | };
|
---|
896 |
|
---|
897 | QNetworkManagerIp4Config::QNetworkManagerIp4Config( const QString &deviceObjectPath, QObject *parent)
|
---|
898 | : QObject(parent)
|
---|
899 | {
|
---|
900 | d = new QNetworkManagerIp4ConfigPrivate();
|
---|
901 | d->path = deviceObjectPath;
|
---|
902 | d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE),
|
---|
903 | d->path,
|
---|
904 | QLatin1String(NM_DBUS_INTERFACE_IP4_CONFIG),
|
---|
905 | dbusConnection, parent);
|
---|
906 | if (!d->connectionInterface->isValid()) {
|
---|
907 | d->valid = false;
|
---|
908 | return;
|
---|
909 | }
|
---|
910 | d->valid = true;
|
---|
911 | }
|
---|
912 |
|
---|
913 | QNetworkManagerIp4Config::~QNetworkManagerIp4Config()
|
---|
914 | {
|
---|
915 | delete d->connectionInterface;
|
---|
916 | delete d;
|
---|
917 | }
|
---|
918 |
|
---|
919 | bool QNetworkManagerIp4Config::isValid()
|
---|
920 | {
|
---|
921 | return d->valid;
|
---|
922 | }
|
---|
923 |
|
---|
924 | QStringList QNetworkManagerIp4Config::domains() const
|
---|
925 | {
|
---|
926 | return d->connectionInterface->property("Domains").toStringList();
|
---|
927 | }
|
---|
928 |
|
---|
929 | QT_END_NAMESPACE
|
---|
930 |
|
---|
931 | #endif // QT_NO_DBUS
|
---|