1 | /* |
2 | SPDX-FileCopyrightText: 2011 Ilia Kats <ilia-kats@gmx.net> |
3 | SPDX-FileCopyrightText: 2013 Daniel Nicoletti <dantti12@gmail.com> |
4 | |
5 | SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
6 | */ |
7 | |
8 | #include "manager_p.h" |
9 | #include "nmdebug.h" |
10 | #include "wimaxdevice.h" |
11 | #include "wimaxnsp_p.h" |
12 | |
13 | namespace NetworkManager |
14 | { |
15 | NetworkManager::WimaxNsp::NetworkType convertNetworkType(uint type) |
16 | { |
17 | switch (type) { |
18 | case 0: |
19 | return NetworkManager::WimaxNsp::Unknown; |
20 | case 1: |
21 | return NetworkManager::WimaxNsp::Home; |
22 | case 2: |
23 | return NetworkManager::WimaxNsp::Partner; |
24 | case 3: |
25 | return NetworkManager::WimaxNsp::RoamingPartner; |
26 | } |
27 | return NetworkManager::WimaxNsp::Unknown; |
28 | } |
29 | |
30 | } |
31 | |
32 | NetworkManager::WimaxNspPrivate::WimaxNspPrivate(const QString &path, WimaxNsp *q) |
33 | #ifdef NMQT_STATIC |
34 | : iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::sessionBus()) |
35 | #else |
36 | : iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::systemBus()) |
37 | #endif |
38 | , networkType(WimaxNsp::Unknown) |
39 | , signalQuality(0) |
40 | , q_ptr(q) |
41 | { |
42 | } |
43 | |
44 | NetworkManager::WimaxNsp::WimaxNsp(const QString &path, QObject *parent) |
45 | : QObject(parent) |
46 | , d_ptr(new WimaxNspPrivate(path, this)) |
47 | { |
48 | Q_D(WimaxNsp); |
49 | d->uni = path; |
50 | if (d->iface.isValid()) { |
51 | connect(sender: &d->iface, signal: &OrgFreedesktopNetworkManagerWiMaxNspInterface::PropertiesChanged, context: d, slot: &WimaxNspPrivate::propertiesChanged); |
52 | d->networkType = convertNetworkType(type: d->iface.networkType()); |
53 | d->name = d->iface.name(); |
54 | d->signalQuality = d->iface.signalQuality(); |
55 | } |
56 | } |
57 | |
58 | NetworkManager::WimaxNsp::~WimaxNsp() |
59 | { |
60 | Q_D(WimaxNsp); |
61 | delete d; |
62 | } |
63 | |
64 | QString NetworkManager::WimaxNsp::uni() const |
65 | { |
66 | Q_D(const WimaxNsp); |
67 | return d->uni; |
68 | } |
69 | |
70 | NetworkManager::WimaxNsp::NetworkType NetworkManager::WimaxNsp::networkType() const |
71 | { |
72 | Q_D(const WimaxNsp); |
73 | return d->networkType; |
74 | } |
75 | |
76 | QString NetworkManager::WimaxNsp::name() const |
77 | { |
78 | Q_D(const WimaxNsp); |
79 | return d->name; |
80 | } |
81 | |
82 | uint NetworkManager::WimaxNsp::signalQuality() const |
83 | { |
84 | Q_D(const WimaxNsp); |
85 | return d->signalQuality; |
86 | } |
87 | |
88 | void NetworkManager::WimaxNspPrivate::propertiesChanged(const QVariantMap &properties) |
89 | { |
90 | Q_Q(WimaxNsp); |
91 | |
92 | QVariantMap::const_iterator it = properties.constBegin(); |
93 | while (it != properties.constEnd()) { |
94 | const QString property = it.key(); |
95 | if (property == QLatin1String("Name" )) { |
96 | name = it->toString(); |
97 | Q_EMIT q->nameChanged(name); |
98 | } else if (property == QLatin1String("NetworkType" )) { |
99 | networkType = convertNetworkType(type: it->toUInt()); |
100 | Q_EMIT q->networkTypeChanged(type: networkType); |
101 | } else if (property == QLatin1String("SignalQuality" )) { |
102 | signalQuality = it->toUInt(); |
103 | Q_EMIT q->signalQualityChanged(quality: signalQuality); |
104 | } else { |
105 | qCWarning(NMQT) << Q_FUNC_INFO << "Unhandled property" << property; |
106 | } |
107 | ++it; |
108 | } |
109 | } |
110 | |
111 | #include "moc_wimaxnsp.cpp" |
112 | #include "moc_wimaxnsp_p.cpp" |
113 | |