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