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 "cdmasetting.h"
8#include "cdmasetting_p.h"
9
10#include <QDebug>
11
12NetworkManager::CdmaSettingPrivate::CdmaSettingPrivate()
13 : name(NM_SETTING_CDMA_SETTING_NAME)
14 , passwordFlags(Setting::None)
15{
16}
17
18NetworkManager::CdmaSetting::CdmaSetting()
19 : Setting(Setting::Cdma)
20 , d_ptr(new CdmaSettingPrivate())
21{
22}
23
24NetworkManager::CdmaSetting::CdmaSetting(const Ptr &other)
25 : Setting(other)
26 , d_ptr(new CdmaSettingPrivate())
27{
28 setUsername(other->username());
29 setNumber(other->number());
30 setPassword(other->password());
31 setPasswordFlags(other->passwordFlags());
32}
33
34NetworkManager::CdmaSetting::~CdmaSetting()
35{
36 delete d_ptr;
37}
38
39QString NetworkManager::CdmaSetting::name() const
40{
41 Q_D(const CdmaSetting);
42
43 return d->name;
44}
45
46void NetworkManager::CdmaSetting::setNumber(const QString &number)
47{
48 Q_D(CdmaSetting);
49
50 d->number = number;
51}
52
53QString NetworkManager::CdmaSetting::number() const
54{
55 Q_D(const CdmaSetting);
56
57 return d->number;
58}
59
60void NetworkManager::CdmaSetting::setUsername(const QString &username)
61{
62 Q_D(CdmaSetting);
63
64 d->username = username;
65}
66
67QString NetworkManager::CdmaSetting::username() const
68{
69 Q_D(const CdmaSetting);
70
71 return d->username;
72}
73
74void NetworkManager::CdmaSetting::setPassword(const QString &password)
75{
76 Q_D(CdmaSetting);
77
78 d->password = password;
79}
80
81QString NetworkManager::CdmaSetting::password() const
82{
83 Q_D(const CdmaSetting);
84
85 return d->password;
86}
87
88void NetworkManager::CdmaSetting::setPasswordFlags(NetworkManager::Setting::SecretFlags flags)
89{
90 Q_D(CdmaSetting);
91
92 d->passwordFlags = flags;
93}
94
95NetworkManager::Setting::SecretFlags NetworkManager::CdmaSetting::passwordFlags() const
96{
97 Q_D(const CdmaSetting);
98
99 return d->passwordFlags;
100}
101
102QStringList NetworkManager::CdmaSetting::needSecrets(bool requestNew) const
103{
104 QStringList secrets;
105 if (!username().isEmpty()) {
106 if ((password().isEmpty() || requestNew) && !passwordFlags().testFlag(flag: NotRequired)) {
107 secrets << QLatin1String(NM_SETTING_CDMA_PASSWORD);
108 }
109 }
110
111 return secrets;
112}
113
114void NetworkManager::CdmaSetting::secretsFromMap(const QVariantMap &secrets)
115{
116 if (secrets.contains(key: QLatin1String(NM_SETTING_CDMA_PASSWORD))) {
117 setPassword(secrets.value(key: QLatin1String(NM_SETTING_CDMA_PASSWORD)).toString());
118 }
119}
120
121QVariantMap NetworkManager::CdmaSetting::secretsToMap() const
122{
123 QVariantMap secrets;
124
125 if (!password().isEmpty()) {
126 secrets.insert(key: QLatin1String(NM_SETTING_CDMA_PASSWORD), value: password());
127 }
128
129 return secrets;
130}
131
132void NetworkManager::CdmaSetting::fromMap(const QVariantMap &setting)
133{
134 if (setting.contains(key: QLatin1String(NM_SETTING_CDMA_NUMBER))) {
135 setNumber(setting.value(key: QLatin1String(NM_SETTING_CDMA_NUMBER)).toString());
136 }
137
138 if (setting.contains(key: QLatin1String(NM_SETTING_CDMA_USERNAME))) {
139 setUsername(setting.value(key: QLatin1String(NM_SETTING_CDMA_USERNAME)).toString());
140 }
141
142 // SECRETS
143 if (setting.contains(key: QLatin1String(NM_SETTING_CDMA_PASSWORD))) {
144 setPassword(setting.value(key: QLatin1String(NM_SETTING_CDMA_PASSWORD)).toString());
145 }
146
147 if (setting.contains(key: QLatin1String(NM_SETTING_CDMA_PASSWORD_FLAGS))) {
148 setPasswordFlags((Setting::SecretFlags)setting.value(key: QLatin1String(NM_SETTING_CDMA_PASSWORD_FLAGS)).toInt());
149 }
150}
151
152QVariantMap NetworkManager::CdmaSetting::toMap() const
153{
154 QVariantMap setting;
155
156 if (!number().isEmpty()) {
157 setting.insert(key: QLatin1String(NM_SETTING_CDMA_NUMBER), value: number());
158 }
159
160 if (!username().isEmpty()) {
161 setting.insert(key: QLatin1String(NM_SETTING_CDMA_USERNAME), value: username());
162 }
163
164 // SECRETS
165 if (!password().isEmpty()) {
166 setting.insert(key: QLatin1String(NM_SETTING_CDMA_PASSWORD), value: password());
167 }
168
169 if (passwordFlags() != None) {
170 setting.insert(key: QLatin1String(NM_SETTING_CDMA_PASSWORD_FLAGS), value: (int)passwordFlags());
171 }
172
173 return setting;
174}
175
176QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::CdmaSetting &setting)
177{
178 dbg.nospace() << "type: " << setting.typeAsString(type: setting.type()) << '\n';
179 dbg.nospace() << "initialized: " << !setting.isNull() << '\n';
180
181 dbg.nospace() << NM_SETTING_CDMA_NUMBER << ": " << setting.number() << '\n';
182 dbg.nospace() << NM_SETTING_CDMA_USERNAME << ": " << setting.username() << '\n';
183 dbg.nospace() << NM_SETTING_CDMA_PASSWORD << ": " << setting.password() << '\n';
184 dbg.nospace() << NM_SETTING_CDMA_PASSWORD_FLAGS << ": " << setting.passwordFlags() << '\n';
185
186 return dbg.maybeSpace();
187}
188

source code of networkmanager-qt/src/settings/cdmasetting.cpp