ModemManagerQt

sim.cpp
1/*
2 SPDX-FileCopyrightText: 2008, 2011 Will Stephenson <wstephenson@kde.org>
3 SPDX-FileCopyrightText: 2010-2011 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 "sim.h"
11#include "mmdebug_p.h"
12#include "sim_p.h"
13#ifdef MMQT_STATIC
14#include "dbus/fakedbus.h"
15#else
16#include "dbus/dbus.h"
17#endif
18
19ModemManager::SimPrivate::SimPrivate(const QString &path, Sim *q)
20#ifdef MMQT_STATIC
21 : simIface(QLatin1String(MMQT_DBUS_SERVICE), path, QDBusConnection::sessionBus())
22#else
23 : simIface(QLatin1String(MMQT_DBUS_SERVICE), path, QDBusConnection::systemBus())
24#endif
25 , uni(path)
26 , q_ptr(q)
27{
28 if (simIface.isValid()) {
29 active = simIface.active();
30 simIdentifier = simIface.simIdentifier();
31 imsi = simIface.imsi();
32 eid = simIface.eid();
33 operatorIdentifier = simIface.operatorIdentifier();
34 operatorName = simIface.operatorName();
35 emergencyNumbers = simIface.emergencyNumbers();
36 preferredNetworks = simIface.preferredNetworks();
37#if MM_CHECK_VERSION(1, 20, 0)
38 gid1 = simIface.gid1();
39 gid2 = simIface.gid2();
40 simType = (MMSimType)simIface.simType();
41 esimStatus = (MMSimEsimStatus)simIface.esimStatus();
42 removability = (MMSimRemovability)simIface.removability();
43#endif
44 }
45}
46
47ModemManager::Sim::Sim(const QString &path, QObject *parent)
48 : QObject(parent)
49 , d_ptr(new SimPrivate(path, this))
50{
51 Q_D(Sim);
52#ifdef MMQT_STATIC
54 path,
55 QLatin1String(DBUS_INTERFACE_PROPS),
56 QStringLiteral("PropertiesChanged"),
57 d,
58 SLOT(onPropertiesChanged(QString, QVariantMap, QStringList)));
59#else
61 path,
62 QLatin1String(DBUS_INTERFACE_PROPS),
63 QStringLiteral("PropertiesChanged"),
64 d,
65 SLOT(onPropertiesChanged(QString, QVariantMap, QStringList)));
66#endif
67}
68
69ModemManager::Sim::~Sim()
70{
71 delete d_ptr;
72}
73
75{
76 Q_D(const Sim);
77 return d->active;
78}
79
81{
82 Q_D(const Sim);
83 return d->simIdentifier;
84}
85
87{
88 Q_D(const Sim);
89 return d->imsi;
90}
91
93{
94 Q_D(const Sim);
95 return d->eid;
96}
97
99{
100 Q_D(const Sim);
101 return d->operatorIdentifier;
102}
103
105{
106 Q_D(const Sim);
107 return d->operatorName;
108}
109
111{
112 Q_D(const Sim);
113 return d->emergencyNumbers;
114}
115
117{
118 Q_D(const Sim);
119 return d->preferredNetworks;
120}
121
122#if MM_CHECK_VERSION(1, 20, 0)
123QByteArray ModemManager::Sim::gid1() const
124{
125 Q_D(const Sim);
126 return d->gid1;
127}
128
129QByteArray ModemManager::Sim::gid2() const
130{
131 Q_D(const Sim);
132 return d->gid2;
133}
134
135MMSimType ModemManager::Sim::simType() const
136{
137 Q_D(const Sim);
138 return d->simType;
139}
140
141MMSimEsimStatus ModemManager::Sim::esimStatus() const
142{
143 Q_D(const Sim);
144 return d->esimStatus;
145}
146
147MMSimRemovability ModemManager::Sim::removability() const
148{
149 Q_D(const Sim);
150 return d->removability;
151}
152#endif
153
155{
156 Q_D(Sim);
157 return d->simIface.SendPuk(puk, pin);
158}
159
161{
162 Q_D(Sim);
163 return d->simIface.SendPin(pin);
164}
165
167{
168 Q_D(Sim);
169 return d->simIface.EnablePin(pin, enabled);
170}
171
173{
174 Q_D(Sim);
175 return d->simIface.ChangePin(oldPin, newPin);
176}
177
179{
180 Q_D(Sim);
181 return d->simIface.SetPreferredNetworks(preferredNetworks);
182}
183
184QString ModemManager::Sim::uni() const
185{
186 Q_D(const Sim);
187 return d->uni;
188}
189
191{
192 Q_D(Sim);
193 d->simIface.setTimeout(timeout);
194}
195
197{
198 Q_D(const Sim);
199 return d->simIface.timeout();
200}
201
202void ModemManager::SimPrivate::onPropertiesChanged(const QString &interface, const QVariantMap &properties, const QStringList &invalidatedProps)
203{
204 Q_Q(Sim);
205 Q_UNUSED(invalidatedProps);
206 qCDebug(MMQT) << interface << properties.keys();
207
208 if (interface == QLatin1String(MMQT_DBUS_INTERFACE_SIM)) {
209 QVariantMap::const_iterator it = properties.constFind(QLatin1String(MM_SIM_PROPERTY_ACTIVE));
210 if (it != properties.constEnd()) {
211 active = it->toBool();
212 Q_EMIT q->activeChanged(active);
213 }
214 it = properties.constFind(QLatin1String(MM_SIM_PROPERTY_SIMIDENTIFIER));
215 if (it != properties.constEnd()) {
216 simIdentifier = it->toString();
217 Q_EMIT q->simIdentifierChanged(simIdentifier);
218 }
219 it = properties.constFind(QLatin1String(MM_SIM_PROPERTY_IMSI));
220 if (it != properties.constEnd()) {
221 imsi = it->toString();
222 Q_EMIT q->imsiChanged(imsi);
223 }
224 it = properties.constFind(QLatin1String(MM_SIM_PROPERTY_EID));
225 if (it != properties.constEnd()) {
226 eid = it->toString();
227 Q_EMIT q->eidChanged(eid);
228 }
229 it = properties.constFind(QLatin1String(MM_SIM_PROPERTY_OPERATORIDENTIFIER));
230 if (it != properties.constEnd()) {
231 operatorIdentifier = it->toString();
232 Q_EMIT q->operatorIdentifierChanged(operatorIdentifier);
233 }
234 it = properties.constFind(QLatin1String(MM_SIM_PROPERTY_OPERATORNAME));
235 if (it != properties.constEnd()) {
236 operatorName = it->toString();
237 Q_EMIT q->operatorNameChanged(operatorName);
238 }
239 it = properties.constFind(QLatin1String(MM_SIM_PROPERTY_EMERGENCYNUMBERS));
240 if (it != properties.constEnd()) {
241 emergencyNumbers = it->toStringList();
242 Q_EMIT q->emergencyNumbersChanged(emergencyNumbers);
243 }
244 it = properties.constFind(QLatin1String(MM_SIM_PROPERTY_PREFERREDNETWORKS));
245 if (it != properties.constEnd()) {
246 preferredNetworks = it->toMap();
247 Q_EMIT q->preferredNetworksChanged(preferredNetworks);
248 }
249#if MM_CHECK_VERSION(1, 20, 0)
250 it = properties.constFind(QLatin1String(MM_SIM_PROPERTY_GID1));
251 if (it != properties.constEnd()) {
252 gid1 = it->toByteArray();
253 Q_EMIT q->gid1Changed(gid1);
254 }
255 it = properties.constFind(QLatin1String(MM_SIM_PROPERTY_GID2));
256 if (it != properties.constEnd()) {
257 gid2 = it->toByteArray();
258 Q_EMIT q->gid1Changed(gid2);
259 }
260 it = properties.constFind(QLatin1String(MM_SIM_PROPERTY_SIMTYPE));
261 if (it != properties.constEnd()) {
262 simType = (MMSimType)it->toUInt();
263 Q_EMIT q->simTypeChanged(simType);
264 }
265 it = properties.constFind(QLatin1String(MM_SIM_PROPERTY_ESIMSTATUS));
266 if (it != properties.constEnd()) {
267 esimStatus = (MMSimEsimStatus)it->toUInt();
268 Q_EMIT q->esimStatusChanged(esimStatus);
269 }
270 it = properties.constFind(QLatin1String(MM_SIM_PROPERTY_REMOVABILITY));
271 if (it != properties.constEnd()) {
272 removability = (MMSimRemovability)it->toUInt();
273 Q_EMIT q->removabilityChanged(removability);
274 }
275#endif
276 }
277}
278
279#include "moc_sim.cpp"
280#include "moc_sim_p.cpp"
The Sim class.
Definition sim.h:31
QDBusPendingReply sendPin(const QString &pin)
Send the PIN to unlock the SIM card.
Definition sim.cpp:160
QString operatorName() const
Definition sim.cpp:104
QVariantMap preferredNetworks() const
Definition sim.cpp:116
QDBusPendingReply sendPuk(const QString &puk, const QString &pin)
Send the PUK and a new PIN to unlock the SIM card.
Definition sim.cpp:154
QString eid() const
Definition sim.cpp:92
QString operatorIdentifier() const
Definition sim.cpp:98
int timeout() const
Returns the current value of the DBus timeout in milliseconds.
Definition sim.cpp:196
QStringList emergencyNumbers() const
Definition sim.cpp:110
QDBusPendingReply changePin(const QString &oldPin, const QString &newPin)
Change the PIN code.
Definition sim.cpp:172
QString imsi() const
Definition sim.cpp:86
QString simIdentifier() const
Definition sim.cpp:80
bool active() const
Definition sim.cpp:74
QDBusPendingReply enablePin(const QString &pin, bool enabled)
Enable or disable the PIN checking.
Definition sim.cpp:166
QDBusPendingReply setPreferredNetworks(QVariantMap preferredNetworks)
Definition sim.cpp:178
void setTimeout(int timeout)
Sets the timeout in milliseconds for all async method DBus calls.
Definition sim.cpp:190
QString path(const QString &relativePath)
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()
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:15:10 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.