NetworkManagerQt

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