NetworkManagerQt

gsmsetting.cpp
1/*
2 SPDX-FileCopyrightText: 2012-2013 Jan Grulich <jgrulich@redhat.com>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#include "gsmsetting.h"
8#include "gsmsetting_p.h"
9
10#define NM_SETTING_GSM_NETWORK_TYPE "network-type"
11#define NM_SETTING_GSM_ALLOWED_BANDS "allowed-bands"
12
13#include <QDebug>
14
15NetworkManager::GsmSettingPrivate::GsmSettingPrivate()
16 : name(NM_SETTING_GSM_SETTING_NAME)
17 , passwordFlags(NetworkManager::GsmSetting::None)
18 , networkType(NetworkManager::GsmSetting::Any)
19 , pinFlags(NetworkManager::GsmSetting::None)
20 , allowedBand(1)
21 , homeOnly(false)
22{
23}
24
25NetworkManager::GsmSetting::GsmSetting()
26 : Setting(Setting::Gsm)
27 , d_ptr(new GsmSettingPrivate())
28{
29}
30
31NetworkManager::GsmSetting::GsmSetting(const Ptr &other)
32 : Setting(other)
33 , d_ptr(new GsmSettingPrivate())
34{
35 setNumber(other->number());
36 setUsername(other->username());
37 setPassword(other->password());
38 setPasswordFlags(other->passwordFlags());
39 setApn(other->apn());
40 setNetworkId(other->networkId());
41 setNetworkType(other->networkType());
42 setPin(other->pin());
43 setPinFlags(other->pinFlags());
44 setAllowedBand(other->allowedBand());
45 setHomeOnly(other->homeOnly());
46 setDeviceId(other->deviceId());
47 setSimId(other->simId());
48 setSimOperatorId(other->simOperatorId());
49}
50
51NetworkManager::GsmSetting::~GsmSetting()
52{
53 delete d_ptr;
54}
55
57{
58 Q_D(const GsmSetting);
59
60 return d->name;
61}
62
63void NetworkManager::GsmSetting::setNumber(const QString &number)
64{
66
67 d->number = number;
68}
69
70QString NetworkManager::GsmSetting::number() const
71{
72 Q_D(const GsmSetting);
73
74 return d->number;
75}
76
77void NetworkManager::GsmSetting::setUsername(const QString &username)
78{
79 Q_D(GsmSetting);
80
81 d->username = username;
82}
83
84QString NetworkManager::GsmSetting::username() const
85{
86 Q_D(const GsmSetting);
87
88 return d->username;
89}
90
91void NetworkManager::GsmSetting::setPassword(const QString &password)
92{
93 Q_D(GsmSetting);
94
95 d->password = password;
96}
97
98QString NetworkManager::GsmSetting::password() const
99{
100 Q_D(const GsmSetting);
101
102 return d->password;
103}
104
105void NetworkManager::GsmSetting::setPasswordFlags(GsmSetting::SecretFlags flags)
106{
107 Q_D(GsmSetting);
108
109 d->passwordFlags = flags;
110}
111
112NetworkManager::GsmSetting::SecretFlags NetworkManager::GsmSetting::passwordFlags() const
113{
114 Q_D(const GsmSetting);
115
116 return d->passwordFlags;
117}
118
119void NetworkManager::GsmSetting::setApn(const QString &apn)
120{
121 Q_D(GsmSetting);
122
123 d->apn = apn;
124}
125
126QString NetworkManager::GsmSetting::apn() const
127{
128 Q_D(const GsmSetting);
129
130 return d->apn;
131}
132
133void NetworkManager::GsmSetting::setNetworkId(const QString &id)
134{
135 Q_D(GsmSetting);
136
137 d->networkId = id;
138}
139
140QString NetworkManager::GsmSetting::networkId() const
141{
142 Q_D(const GsmSetting);
143
144 return d->networkId;
145}
146
148{
150
151 d->networkType = type;
152}
153
154NetworkManager::GsmSetting::NetworkType NetworkManager::GsmSetting::networkType() const
155{
156 Q_D(const GsmSetting);
157
158 return d->networkType;
159}
160
161void NetworkManager::GsmSetting::setPin(const QString &pin)
162{
163 Q_D(GsmSetting);
164
165 d->pin = pin;
166}
167
168QString NetworkManager::GsmSetting::pin() const
169{
170 Q_D(const GsmSetting);
171
172 return d->pin;
173}
174
175void NetworkManager::GsmSetting::setPinFlags(GsmSetting::SecretFlags flags)
176{
177 Q_D(GsmSetting);
178
179 d->pinFlags = flags;
180}
181
182NetworkManager::GsmSetting::SecretFlags NetworkManager::GsmSetting::pinFlags() const
183{
184 Q_D(const GsmSetting);
185
186 return d->pinFlags;
187}
188
190{
192
193 d->allowedBand = band;
194}
195
196quint32 NetworkManager::GsmSetting::allowedBand() const
197{
198 Q_D(const GsmSetting);
199
200 return d->allowedBand;
201}
202
203void NetworkManager::GsmSetting::setHomeOnly(bool homeOnly)
204{
205 Q_D(GsmSetting);
206
207 d->homeOnly = homeOnly;
208}
209
210bool NetworkManager::GsmSetting::homeOnly() const
211{
212 Q_D(const GsmSetting);
213
214 return d->homeOnly;
215}
216
217void NetworkManager::GsmSetting::setDeviceId(const QString &id)
218{
219 Q_D(GsmSetting);
220
221 d->deviceId = id;
222}
223
224QString NetworkManager::GsmSetting::deviceId() const
225{
226 Q_D(const GsmSetting);
227
228 return d->deviceId;
229}
230
231void NetworkManager::GsmSetting::setSimId(const QString &id)
232{
233 Q_D(GsmSetting);
234
235 d->simId = id;
236}
237
238QString NetworkManager::GsmSetting::simId() const
239{
240 Q_D(const GsmSetting);
241
242 return d->simId;
243}
244
245void NetworkManager::GsmSetting::setSimOperatorId(const QString &id)
246{
247 Q_D(GsmSetting);
248
249 d->simOperatorId = id;
250}
251
252QString NetworkManager::GsmSetting::simOperatorId() const
253{
254 Q_D(const GsmSetting);
255
256 return d->simOperatorId;
257}
258
259void NetworkManager::GsmSetting::secretsFromMap(const QVariantMap &secrets)
260{
261 if (secrets.contains(QLatin1String(NM_SETTING_GSM_PASSWORD))) {
262 setPassword(secrets.value(QLatin1String(NM_SETTING_GSM_PASSWORD)).toString());
263 }
264
265 if (secrets.contains(QLatin1String(NM_SETTING_GSM_PIN))) {
266 setPin(secrets.value(QLatin1String(NM_SETTING_GSM_PIN)).toString());
267 }
268}
269
270QVariantMap NetworkManager::GsmSetting::secretsToMap() const
271{
272 QVariantMap secrets;
273
274 if (!password().isEmpty()) {
275 secrets.insert(QLatin1String(NM_SETTING_GSM_PASSWORD), password());
276 }
277
278 if (!pin().isEmpty()) {
279 secrets.insert(QLatin1String(NM_SETTING_GSM_PIN), pin());
280 }
281
282 return secrets;
283}
284
285QStringList NetworkManager::GsmSetting::needSecrets(bool requestNew) const
286{
288
289 if ((password().isEmpty() || requestNew) && !passwordFlags().testFlag(NotRequired)) {
290 list << QLatin1String(NM_SETTING_GSM_PASSWORD);
291 }
292
293 if ((pin().isEmpty() || requestNew) && !pinFlags().testFlag(NotRequired)) {
294 list << QLatin1String(NM_SETTING_GSM_PIN);
295 }
296
297 return list;
298}
299
300void NetworkManager::GsmSetting::fromMap(const QVariantMap &setting)
301{
302 if (setting.contains(QLatin1String(NM_SETTING_GSM_NUMBER))) {
303 setNumber(setting.value(QLatin1String(NM_SETTING_GSM_NUMBER)).toString());
304 }
305
306 if (setting.contains(QLatin1String(NM_SETTING_GSM_USERNAME))) {
307 setUsername(setting.value(QLatin1String(NM_SETTING_GSM_USERNAME)).toString());
308 }
309
310 // Secrets
311 if (setting.contains(QLatin1String(NM_SETTING_GSM_PASSWORD))) {
312 setPassword(setting.value(QLatin1String(NM_SETTING_GSM_PASSWORD)).toString());
313 }
314
315 if (setting.contains(QLatin1String(NM_SETTING_GSM_PASSWORD_FLAGS))) {
316 setPasswordFlags((SecretFlags)setting.value(QLatin1String(NM_SETTING_GSM_PASSWORD_FLAGS)).toInt());
317 }
318
319 if (setting.contains(QLatin1String(NM_SETTING_GSM_APN))) {
320 setApn(setting.value(QLatin1String(NM_SETTING_GSM_APN)).toString());
321 }
322
323 if (setting.contains(QLatin1String(NM_SETTING_GSM_NETWORK_ID))) {
324 setNetworkId(setting.value(QLatin1String(NM_SETTING_GSM_NETWORK_ID)).toString());
325 }
326
327 if (setting.contains(QLatin1String(NM_SETTING_GSM_NETWORK_TYPE))) {
328 setNetworkType((NetworkType)setting.value(QLatin1String(NM_SETTING_GSM_NETWORK_TYPE)).toInt());
329 }
330
331 // Secrets
332 if (setting.contains(QLatin1String(NM_SETTING_GSM_PIN))) {
333 setPin(setting.value(QLatin1String(NM_SETTING_GSM_PIN)).toString());
334 }
335
336 if (setting.contains(QLatin1String(NM_SETTING_GSM_PIN_FLAGS))) {
337 setPinFlags((SecretFlags)setting.value(QLatin1String(NM_SETTING_GSM_PIN_FLAGS)).toInt());
338 }
339
340 if (setting.contains(QLatin1String(NM_SETTING_GSM_ALLOWED_BANDS))) {
341 setAllowedBand(setting.value(QLatin1String(NM_SETTING_GSM_ALLOWED_BANDS)).toUInt());
342 }
343
344 if (setting.contains(QLatin1String(NM_SETTING_GSM_HOME_ONLY))) {
345 setHomeOnly(setting.value(QLatin1String(NM_SETTING_GSM_HOME_ONLY)).toBool());
346 }
347
348 if (setting.contains(QLatin1String(NM_SETTING_GSM_DEVICE_ID))) {
349 setDeviceId(setting.value(QLatin1String(NM_SETTING_GSM_DEVICE_ID)).toString());
350 }
351
352 if (setting.contains(QLatin1String(NM_SETTING_GSM_SIM_ID))) {
353 setSimId(setting.value(QLatin1String(NM_SETTING_GSM_SIM_ID)).toString());
354 }
355
356 if (setting.contains(QLatin1String(NM_SETTING_GSM_SIM_OPERATOR_ID))) {
357 setSimOperatorId(setting.value(QLatin1String(NM_SETTING_GSM_SIM_OPERATOR_ID)).toString());
358 }
359}
360
362{
363 QVariantMap setting;
364
365 if (!number().isEmpty()) {
366 setting.insert(QLatin1String(NM_SETTING_GSM_NUMBER), number());
367 }
368
369 if (!username().isEmpty()) {
370 setting.insert(QLatin1String(NM_SETTING_GSM_USERNAME), username());
371 }
372
373 // Secrets
374 if (!password().isEmpty()) {
375 setting.insert(QLatin1String(NM_SETTING_GSM_PASSWORD), password());
376 }
377
378 setting.insert(QLatin1String(NM_SETTING_GSM_PASSWORD_FLAGS), (int)passwordFlags());
379
380 if (!apn().isEmpty()) {
381 setting.insert(QLatin1String(NM_SETTING_GSM_APN), apn());
382 }
383
384 if (!networkId().isEmpty()) {
385 setting.insert(QLatin1String(NM_SETTING_GSM_NETWORK_ID), networkId());
386 }
387
388 if (networkType() != -1) {
389 setting.insert(QLatin1String(NM_SETTING_GSM_NETWORK_TYPE), networkType());
390 }
391 // Secrets
392 if (!pin().isEmpty()) {
393 setting.insert(QLatin1String(NM_SETTING_GSM_PIN), pin());
394 }
395
396 setting.insert(QLatin1String(NM_SETTING_GSM_PIN_FLAGS), (int)pinFlags());
397
398 if (allowedBand() != 1) {
399 setting.insert(QLatin1String(NM_SETTING_GSM_ALLOWED_BANDS), allowedBand());
400 }
401 if (homeOnly()) {
402 setting.insert(QLatin1String(NM_SETTING_GSM_HOME_ONLY), homeOnly());
403 }
404
405 if (!deviceId().isEmpty()) {
406 setting.insert(QLatin1String(NM_SETTING_GSM_DEVICE_ID), deviceId());
407 }
408
409 if (!simId().isEmpty()) {
410 setting.insert(QLatin1String(NM_SETTING_GSM_SIM_ID), simId());
411 }
412
413 if (!simOperatorId().isEmpty()) {
414 setting.insert(QLatin1String(NM_SETTING_GSM_SIM_OPERATOR_ID), simOperatorId());
415 }
416
417 return setting;
418}
419
420QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::GsmSetting &setting)
421{
422 dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n';
423 dbg.nospace() << "initialized: " << !setting.isNull() << '\n';
424
425 dbg.nospace() << NM_SETTING_GSM_NUMBER << ": " << setting.number() << '\n';
426 dbg.nospace() << NM_SETTING_GSM_USERNAME << ": " << setting.username() << '\n';
427 dbg.nospace() << NM_SETTING_GSM_PASSWORD << ": " << setting.password() << '\n';
428 dbg.nospace() << NM_SETTING_GSM_PASSWORD_FLAGS << ": " << setting.passwordFlags() << '\n';
429 dbg.nospace() << NM_SETTING_GSM_APN << ": " << setting.apn() << '\n';
430 dbg.nospace() << NM_SETTING_GSM_NETWORK_ID << ": " << setting.networkId() << '\n';
431 dbg.nospace() << NM_SETTING_GSM_NETWORK_TYPE << ": " << setting.networkType() << '\n';
432 dbg.nospace() << NM_SETTING_GSM_ALLOWED_BANDS << ": " << setting.allowedBand() << '\n';
433 dbg.nospace() << NM_SETTING_GSM_PIN << ": " << setting.pin() << '\n';
434 dbg.nospace() << NM_SETTING_GSM_PIN_FLAGS << ": " << setting.pinFlags() << '\n';
435 dbg.nospace() << NM_SETTING_GSM_HOME_ONLY << ": " << setting.homeOnly() << '\n';
436 dbg.nospace() << NM_SETTING_GSM_DEVICE_ID << ": " << setting.deviceId() << '\n';
437 dbg.nospace() << NM_SETTING_GSM_SIM_ID << ": " << setting.simId() << '\n';
438 dbg.nospace() << NM_SETTING_GSM_SIM_OPERATOR_ID << ": " << setting.simOperatorId() << '\n';
439
440 return dbg.maybeSpace();
441}
Represents gsm setting.
Definition gsmsetting.h:23
void setNetworkType(NetworkType type)
QVariantMap toMap() const override
Must be reimplemented, default implementationd does nothing.
void fromMap(const QVariantMap &setting) override
Must be reimplemented, default implementation does nothing.
QString name() const override
Must be reimplemented, default implementationd does nothing.
void setAllowedBand(quint32 band)
char * toString(const EngineQuery &query)
KIOCORE_EXPORT QStringList list(const QString &fileClass)
This class allows querying the underlying system to discover the available network interfaces and rea...
Definition accesspoint.h:21
QDebug & maybeSpace()
QDebug & nospace()
iterator insert(const_iterator before, parameter_type value)
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:56:21 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.