ModemManagerQt

modem3gpp.cpp
1/*
2 SPDX-FileCopyrightText: 2008, 2011 Will Stephenson <wstephenson@kde.org>
3 SPDX-FileCopyrightText: 2010 Lamarque Souza <lamarque@kde.org>
4 SPDX-FileCopyrightText: 2013 Lukas Tinkl <ltinkl@redhat.com>
5 SPDX-FileCopyrightText: 2013-2015 Jan Grulich <jgrulich@redhat.com>
6
7 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
8*/
9
10#include "modem3gpp.h"
11#include "mmdebug_p.h"
12#include "modem3gpp_p.h"
13#ifdef MMQT_STATIC
14#include "dbus/fakedbus.h"
15#else
16#include "dbus/dbus.h"
17#endif
18
19ModemManager::Modem3gppPrivate::Modem3gppPrivate(const QString &path, Modem3gpp *q)
20 : InterfacePrivate(path, q)
21#ifdef MMQT_STATIC
22 , modem3gppIface(QLatin1String(MMQT_DBUS_SERVICE), path, QDBusConnection::sessionBus())
23#else
24 , modem3gppIface(QLatin1String(MMQT_DBUS_SERVICE), path, QDBusConnection::systemBus())
25#endif
26 , q_ptr(q)
27{
28 if (modem3gppIface.isValid()) {
29 imei = modem3gppIface.imei();
30 registrationState = (MMModem3gppRegistrationState)modem3gppIface.registrationState();
31 operatorCode = modem3gppIface.operatorCode();
32 operatorName = modem3gppIface.operatorName();
33 enabledFacilityLocks = (QFlags<MMModem3gppFacility>)modem3gppIface.enabledFacilityLocks();
34#if MM_CHECK_VERSION(1, 2, 0)
35 subscriptionState = (MMModem3gppSubscriptionState)modem3gppIface.subscriptionState();
36#endif
37
38 QStringView mcc(operatorCode);
39 if (!operatorCode.isEmpty() && operatorCode.size() > 3) {
40 mcc = mcc.sliced(0, 3);
41 }
42 QString cc = mobileCountryCodeToAlpha2CountryCode(mcc.toInt());
43 if (cc != countryCode) {
44 countryCode = cc;
45 }
46 }
47}
48
49ModemManager::Modem3gpp::Modem3gpp(const QString &path, QObject *parent)
50 : Interface(*new Modem3gppPrivate(path, this), parent)
51{
52 Q_D(Modem3gpp);
53
54 qRegisterMetaType<QFlags<MMModem3gppFacility>>();
55 qRegisterMetaType<MMModem3gppRegistrationState>();
56#if MM_CHECK_VERSION(1, 2, 0)
57 qRegisterMetaType<MMModem3gppSubscriptionState>();
58#endif
59#ifdef MMQT_STATIC
61 d->uni,
62 QLatin1String(DBUS_INTERFACE_PROPS),
63 QStringLiteral("PropertiesChanged"),
64 d,
65 SLOT(onPropertiesChanged(QString, QVariantMap, QStringList)));
66#else
68 d->uni,
69 QLatin1String(DBUS_INTERFACE_PROPS),
70 QStringLiteral("PropertiesChanged"),
71 d,
72 SLOT(onPropertiesChanged(QString, QVariantMap, QStringList)));
73#endif
74}
75
76ModemManager::Modem3gpp::~Modem3gpp()
77{
78}
79
81{
82 Q_D(const Modem3gpp);
83 return d->imei;
84}
85
86MMModem3gppRegistrationState ModemManager::Modem3gpp::registrationState() const
87{
88 Q_D(const Modem3gpp);
89 return d->registrationState;
90}
91
93{
94 Q_D(const Modem3gpp);
95 return d->operatorCode;
96}
97
99{
100 Q_D(const Modem3gpp);
101 return d->operatorName;
102}
103
105{
106 Q_D(const Modem3gpp);
107 return d->countryCode;
108}
109
111{
112 Q_D(const Modem3gpp);
113 return d->enabledFacilityLocks;
114}
115
116#if MM_CHECK_VERSION(1, 2, 0)
117MMModem3gppSubscriptionState ModemManager::Modem3gpp::subscriptionState() const
118{
119 Q_D(const Modem3gpp);
120 return d->subscriptionState;
121}
122#endif
123
125{
126 Q_D(Modem3gpp);
127 d->modem3gppIface.Register(networkId);
128}
129
135
137{
138 Q_D(Modem3gpp);
139 d->modem3gppIface.setTimeout(timeout);
140}
141
143{
144 Q_D(const Modem3gpp);
145 return d->modem3gppIface.timeout();
146}
147
148void ModemManager::Modem3gppPrivate::onPropertiesChanged(const QString &interface, const QVariantMap &properties, const QStringList &invalidatedProps)
149{
150 Q_Q(Modem3gpp);
151 Q_UNUSED(invalidatedProps);
152 qCDebug(MMQT) << interface << properties.keys();
153
154 if (interface == QLatin1String(MMQT_DBUS_INTERFACE_MODEM_MODEM3GPP)) {
155 QVariantMap::const_iterator it = properties.constFind(QLatin1String(MM_MODEM_MODEM3GPP_PROPERTY_IMEI));
156 if (it != properties.constEnd()) {
157 imei = it->toString();
158 Q_EMIT q->imeiChanged(imei);
159 }
160 it = properties.constFind(QLatin1String(MM_MODEM_MODEM3GPP_PROPERTY_REGISTRATIONSTATE));
161 if (it != properties.constEnd()) {
162 registrationState = (MMModem3gppRegistrationState)it->toUInt();
163 Q_EMIT q->registrationStateChanged(registrationState);
164 }
165 it = properties.constFind(QLatin1String(MM_MODEM_MODEM3GPP_PROPERTY_OPERATORCODE));
166 if (it != properties.constEnd()) {
167 operatorCode = it->toString();
168 Q_EMIT q->operatorCodeChanged(operatorCode);
169 QStringView mcc(operatorCode);
170 if (!operatorCode.isEmpty() && operatorCode.size() > 3) {
171 mcc = mcc.sliced(0, 3);
172 }
173 QString cc = mobileCountryCodeToAlpha2CountryCode(mcc.toInt());
174 if (cc != countryCode) {
175 countryCode = cc;
176 Q_EMIT q->countryCodeChanged(countryCode);
177 }
178 }
179 it = properties.constFind(QLatin1String(MM_MODEM_MODEM3GPP_PROPERTY_OPERATORNAME));
180 if (it != properties.constEnd()) {
181 operatorName = it->toString();
182 Q_EMIT q->operatorNameChanged(operatorName);
183 }
184 it = properties.constFind(QLatin1String(MM_MODEM_MODEM3GPP_PROPERTY_ENABLEDFACILITYLOCKS));
185 if (it != properties.constEnd()) {
186 enabledFacilityLocks = (QFlags<MMModem3gppFacility>)it->toUInt();
187 Q_EMIT q->enabledFacilityLocksChanged(enabledFacilityLocks);
188 }
189#if MM_CHECK_VERSION(1, 2, 0)
190 it = properties.constFind(QLatin1String(MM_MODEM_MODEM3GPP_PROPERTY_SUBSCRIPTIONSTATE));
191 if (it != properties.constEnd()) {
192 subscriptionState = (MMModem3gppSubscriptionState)it->toUInt();
193 Q_EMIT q->subscriptionStateChanged(subscriptionState);
194 }
195#endif
196 }
197}
198
199// The logic ported from the Qt wrapper for ofono from Jolla's Sailfish OS
200// https://github.com/sailfishos/libqofono/blob/94e793860debe9c73c70de94cc3510e7609137b9/src/qofono.cpp#L2379
201
202QString ModemManager::Modem3gppPrivate::mobileCountryCodeToAlpha2CountryCode(int mcc) const
203{
204 const int n = sizeof(mccList) / sizeof(mccList[0]);
205
206 int low = 0;
207 int high = n;
208
209 while (low < high) {
210 const int mid = (low + high) / 2;
211 if (mccList[mid].mcc >= mcc) {
212 high = mid;
213 } else {
214 low = mid + 1;
215 }
216 }
217
218 if (high < n && mccList[high].mcc == mcc) {
219 return QString::fromLatin1(mccList[high].cc);
220 } else {
221 qCWarning(MMQT) << "Unknown Mobile Country Code:" << mcc;
222 return QString();
223 }
224}
225
226#include "moc_modem3gpp.cpp"
The Modem3gpp class.
Definition modem3gpp.h:32
QString countryCode() const
FacilityLocks enabledFacilityLocks() const
int timeout() const
Returns the current value of the DBus timeout in milliseconds.
void setTimeout(int timeout)
Sets the timeout in milliseconds for all async method DBus calls.
void registerToNetwork(const QString &networkId=QString())
Register the device to network.
QString operatorName() const
Definition modem3gpp.cpp:98
QString imei() const
Definition modem3gpp.cpp:80
MMModem3gppRegistrationState registrationState() const
Definition modem3gpp.cpp:86
QString operatorCode() const
Definition modem3gpp.cpp:92
QDBusPendingReply< QVariantMapList > scan()
Scan for available networks.
QString path(const QString &relativePath)
QStringView countryCode(QStringView coachNumber)
KGuiItem properties()
bool connect(const QString &service, const QString &path, const QString &interface, const QString &name, QObject *receiver, const char *slot)
QDBusConnection sessionBus()
QDBusConnection systemBus()
QString fromLatin1(QByteArrayView str)
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:59:51 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.