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