NetworkManagerQt

adslsetting.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 "adslsetting.h"
8#include "adslsetting_p.h"
9#include <manager.h>
10
11#include <QDebug>
12
13NetworkManager::AdslSettingPrivate::AdslSettingPrivate()
14 : name(NM_SETTING_ADSL_SETTING_NAME)
15 , passwordFlags(Setting::None)
16 , protocol(AdslSetting::UnknownProtocol)
17 , encapsulation(AdslSetting::UnknownEncapsulation)
18 , vpi(0)
19 , vci(0)
20{
21}
22
23NetworkManager::AdslSetting::AdslSetting()
24 : Setting(Setting::Adsl)
25 , d_ptr(new AdslSettingPrivate())
26{
27}
28
29NetworkManager::AdslSetting::AdslSetting(const AdslSetting::Ptr &other)
30 : Setting(other)
31 , d_ptr(new AdslSettingPrivate())
32{
33 setUsername(other->username());
34 setPassword(other->password());
35 setProtocol(other->protocol());
36 setPasswordFlags(other->passwordFlags());
37 setProtocol(other->protocol());
38 setEncapsulation(other->encapsulation());
39 setVpi(other->vpi());
40 setVci(other->vci());
41}
42
43NetworkManager::AdslSetting::~AdslSetting()
44{
45 delete d_ptr;
46}
47
49{
50 Q_D(const AdslSetting);
51
52 return d->name;
53}
54
55void NetworkManager::AdslSetting::setUsername(const QString &username)
56{
58
59 d->username = username;
60}
61
62QString NetworkManager::AdslSetting::username() const
63{
64 Q_D(const AdslSetting);
65
66 return d->username;
67}
68
69void NetworkManager::AdslSetting::setPassword(const QString &password)
70{
71 Q_D(AdslSetting);
72
73 d->password = password;
74}
75
76QString NetworkManager::AdslSetting::password() const
77{
78 Q_D(const AdslSetting);
79
80 return d->password;
81}
82
83void NetworkManager::AdslSetting::setPasswordFlags(NetworkManager::Setting::SecretFlags flags)
84{
85 Q_D(AdslSetting);
86
87 d->passwordFlags = flags;
88}
89
90NetworkManager::Setting::SecretFlags NetworkManager::AdslSetting::passwordFlags() const
91{
92 Q_D(const AdslSetting);
93
94 return d->passwordFlags;
95}
96
97void NetworkManager::AdslSetting::setProtocol(NetworkManager::AdslSetting::Protocol protocol)
98{
99 Q_D(AdslSetting);
100
101 d->protocol = protocol;
102}
103
104NetworkManager::AdslSetting::Protocol NetworkManager::AdslSetting::protocol() const
105{
106 Q_D(const AdslSetting);
107
108 return d->protocol;
109}
110
111void NetworkManager::AdslSetting::setEncapsulation(NetworkManager::AdslSetting::Encapsulation encapsulation)
112{
113 Q_D(AdslSetting);
114
115 d->encapsulation = encapsulation;
116}
117
118NetworkManager::AdslSetting::Encapsulation NetworkManager::AdslSetting::encapsulation() const
119{
120 Q_D(const AdslSetting);
121
122 return d->encapsulation;
123}
124
125void NetworkManager::AdslSetting::setVpi(quint32 vpi)
126{
127 Q_D(AdslSetting);
128
129 d->vpi = vpi;
130}
131
132quint32 NetworkManager::AdslSetting::vpi() const
133{
134 Q_D(const AdslSetting);
135
136 return d->vpi;
137}
138
139void NetworkManager::AdslSetting::setVci(quint32 vci)
140{
141 Q_D(AdslSetting);
142
143 d->vci = vci;
144}
145
146quint32 NetworkManager::AdslSetting::vci() const
147{
148 Q_D(const AdslSetting);
149
150 return d->vci;
151}
152
153QStringList NetworkManager::AdslSetting::needSecrets(bool requestNew) const
154{
155 QStringList secrets;
156
157 if ((password().isEmpty() || requestNew) && !passwordFlags().testFlag(NotRequired)) {
158 secrets << QLatin1String(NM_SETTING_ADSL_PASSWORD);
159 }
160
161 return secrets;
162}
163
164void NetworkManager::AdslSetting::fromMap(const QVariantMap &setting)
165{
166 if (setting.contains(QLatin1String(NM_SETTING_ADSL_USERNAME))) {
167 setUsername(setting.value(QLatin1String(NM_SETTING_ADSL_USERNAME)).toString());
168 }
169
170 if (setting.contains(QLatin1String(NM_SETTING_ADSL_PASSWORD))) {
171 setPassword(setting.value(QLatin1String(NM_SETTING_ADSL_PASSWORD)).toString());
172 }
173
174 if (setting.contains(QLatin1String(NM_SETTING_ADSL_PASSWORD_FLAGS))) {
175 setPasswordFlags((Setting::SecretFlags)setting.value(QLatin1String(NM_SETTING_ADSL_PASSWORD_FLAGS)).toInt());
176 }
177
178 if (setting.contains(QLatin1String(NM_SETTING_ADSL_PROTOCOL))) {
179 const QString protocol = setting.value(QLatin1String(NM_SETTING_ADSL_PROTOCOL)).toString();
180
181 if (protocol == QLatin1String(NM_SETTING_ADSL_PROTOCOL_PPPOA)) {
182 setProtocol(Pppoa);
183 } else if (protocol == QLatin1String(NM_SETTING_ADSL_PROTOCOL_PPPOE)) {
184 setProtocol(Pppoe);
185 } else if (protocol == QLatin1String(NM_SETTING_ADSL_PROTOCOL_IPOATM)) {
186 setProtocol(Ipoatm);
187 }
188 }
189
190 if (setting.contains(QLatin1String(NM_SETTING_ADSL_ENCAPSULATION))) {
191 const QString encapsulation = setting.value(QLatin1String(NM_SETTING_ADSL_ENCAPSULATION)).toString();
192
193 if (encapsulation == QLatin1String(NM_SETTING_ADSL_ENCAPSULATION_VCMUX)) {
194 setEncapsulation(Vcmux);
195 } else if (encapsulation == QLatin1String(NM_SETTING_ADSL_ENCAPSULATION_LLC)) {
196 setEncapsulation(Llc);
197 }
198 }
199
200 if (setting.contains(QLatin1String(NM_SETTING_ADSL_VPI))) {
201 setVpi(setting.value(QLatin1String(NM_SETTING_ADSL_VPI)).toUInt());
202 }
203
204 if (setting.contains(QLatin1String(NM_SETTING_ADSL_VCI))) {
205 setVci(setting.value(QLatin1String(NM_SETTING_ADSL_VCI)).toUInt());
206 }
207}
208
210{
211 QVariantMap setting;
212
213 if (!username().isEmpty()) {
214 setting.insert(QLatin1String(NM_SETTING_ADSL_USERNAME), username());
215 }
216
217 if (!password().isEmpty()) {
218 setting.insert(QLatin1String(NM_SETTING_ADSL_PASSWORD), password());
219 }
220
221 if (passwordFlags() != None) {
222 setting.insert(QLatin1String(NM_SETTING_ADSL_PASSWORD_FLAGS), (int)passwordFlags());
223 }
224
225 switch (protocol()) {
226 case Pppoa:
227 setting.insert(QLatin1String(NM_SETTING_ADSL_PROTOCOL), QLatin1String(NM_SETTING_ADSL_PROTOCOL_PPPOA));
228 break;
229 case Pppoe:
230 setting.insert(QLatin1String(NM_SETTING_ADSL_PROTOCOL), QLatin1String(NM_SETTING_ADSL_PROTOCOL_PPPOE));
231 break;
232 case Ipoatm:
233 setting.insert(QLatin1String(NM_SETTING_ADSL_PROTOCOL), QLatin1String(NM_SETTING_ADSL_PROTOCOL_IPOATM));
234 break;
235 case UnknownProtocol:
236 break;
237 }
238
239 switch (encapsulation()) {
240 case Vcmux:
241 setting.insert(QLatin1String(NM_SETTING_ADSL_ENCAPSULATION), QLatin1String(NM_SETTING_ADSL_ENCAPSULATION_VCMUX));
242 break;
243 case Llc:
244 setting.insert(QLatin1String(NM_SETTING_ADSL_ENCAPSULATION), QLatin1String(NM_SETTING_ADSL_ENCAPSULATION_LLC));
245 break;
246 case UnknownEncapsulation:
247 break;
248 }
249
250 if (vpi()) {
251 setting.insert(QLatin1String(NM_SETTING_ADSL_VPI), vpi());
252 }
253
254 if (vci()) {
255 setting.insert(QLatin1String(NM_SETTING_ADSL_VCI), vci());
256 }
257
258 return setting;
259}
260
261QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::AdslSetting &setting)
262{
263 dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n';
264 dbg.nospace() << "initialized: " << !setting.isNull() << '\n';
265
266 dbg.nospace() << NM_SETTING_ADSL_USERNAME << ": " << setting.username() << '\n';
267 dbg.nospace() << NM_SETTING_ADSL_PASSWORD << ": " << setting.password() << '\n';
268 dbg.nospace() << NM_SETTING_ADSL_PASSWORD_FLAGS << ": " << setting.passwordFlags() << '\n';
269 dbg.nospace() << NM_SETTING_ADSL_PROTOCOL << ": " << setting.protocol() << '\n';
270 dbg.nospace() << NM_SETTING_ADSL_ENCAPSULATION << ": " << setting.encapsulation() << '\n';
271 dbg.nospace() << NM_SETTING_ADSL_VPI << ": " << setting.vpi() << '\n';
272 dbg.nospace() << NM_SETTING_ADSL_VCI << ": " << setting.vci() << '\n';
273
274 return dbg.maybeSpace();
275}
Represents adsl setting.
Definition adslsetting.h:23
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.
QDebug & maybeSpace()
QDebug & nospace()
UnknownProtocol
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:08:13 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.