NetworkManagerQt

vpnsetting.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 "vpnsetting.h"
8#include "nmdebug.h"
9#include "vpnsetting_p.h"
10
11NetworkManager::VpnSettingPrivate::VpnSettingPrivate()
12 : name(NM_SETTING_VPN_SETTING_NAME)
13 , persistent(false)
14 , timeout(0)
15{
16}
17
18NetworkManager::VpnSetting::VpnSetting()
19 : Setting(Setting::Vpn)
20 , d_ptr(new VpnSettingPrivate())
21{
22}
23
24NetworkManager::VpnSetting::VpnSetting(const Ptr &other)
25 : Setting(other)
26 , d_ptr(new VpnSettingPrivate())
27{
28 setServiceType(other->serviceType());
29 setUsername(other->username());
30 setData(other->data());
31 setSecrets(other->secrets());
32 setPersistent(other->persistent());
33 setTimeout(other->timeout());
34}
35
36NetworkManager::VpnSetting::~VpnSetting()
37{
38 delete d_ptr;
39}
40
42{
43 Q_D(const VpnSetting);
44
45 return d->name;
46}
47
48bool NetworkManager::VpnSetting::persistent() const
49{
50 Q_D(const VpnSetting);
51
52 return d->persistent;
53}
54
55void NetworkManager::VpnSetting::setPersistent(bool persistent)
56{
57 Q_D(VpnSetting);
58
59 d->persistent = persistent;
60}
61
62uint NetworkManager::VpnSetting::timeout() const
63{
64 Q_D(const VpnSetting);
65
66 return d->timeout;
67}
68
69void NetworkManager::VpnSetting::setTimeout(uint timeout)
70{
71 Q_D(VpnSetting);
72
73 d->timeout = timeout;
74}
75
76void NetworkManager::VpnSetting::setServiceType(const QString &type)
77{
78 Q_D(VpnSetting);
79
80 d->serviceType = type;
81}
82
83QString NetworkManager::VpnSetting::serviceType() const
84{
85 Q_D(const VpnSetting);
86
87 return d->serviceType;
88}
89
90void NetworkManager::VpnSetting::setUsername(const QString &username)
91{
92 Q_D(VpnSetting);
93
94 d->username = username;
95}
96
97QString NetworkManager::VpnSetting::username() const
98{
99 Q_D(const VpnSetting);
100
101 return d->username;
102}
103
104void NetworkManager::VpnSetting::setData(const NMStringMap &data)
105{
106 Q_D(VpnSetting);
107
108 d->data = data;
109}
110
111NMStringMap NetworkManager::VpnSetting::data() const
112{
113 Q_D(const VpnSetting);
114
115 return d->data;
116}
117
118void NetworkManager::VpnSetting::setSecrets(const NMStringMap &secrets)
119{
120 Q_D(VpnSetting);
121
122 d->secrets = secrets;
123}
124
125NMStringMap NetworkManager::VpnSetting::secrets() const
126{
127 Q_D(const VpnSetting);
128
129 return d->secrets;
130}
131
132void NetworkManager::VpnSetting::secretsFromMap(const QVariantMap &secrets)
133{
134 if (secrets.contains(QLatin1String(NM_SETTING_VPN_SECRETS))) {
135 setSecrets(qdbus_cast<NMStringMap>(secrets.value(QLatin1String(NM_SETTING_VPN_SECRETS))));
136 }
137}
138
139QVariantMap NetworkManager::VpnSetting::secretsToMap() const
140{
141 QVariantMap secretsMap;
142 if (!secrets().isEmpty()) {
143 secretsMap.insert(QLatin1String(NM_SETTING_VPN_SECRETS), QVariant::fromValue<NMStringMap>(secrets()));
144 }
145
146 // qCDebug(NMQT) << secretsMap;
147 return secretsMap;
148}
149
150void NetworkManager::VpnSetting::fromMap(const QVariantMap &setting)
151{
152 if (setting.contains(QLatin1String(NM_SETTING_VPN_SERVICE_TYPE))) {
153 setServiceType(setting.value(QLatin1String(NM_SETTING_VPN_SERVICE_TYPE)).toString());
154 }
155
156 if (setting.contains(QLatin1String(NM_SETTING_VPN_USER_NAME))) {
157 setUsername(setting.value(QLatin1String(NM_SETTING_VPN_USER_NAME)).toString());
158 }
159
160 if (setting.contains(QLatin1String(NM_SETTING_VPN_DATA))) {
161 setData(qdbus_cast<NMStringMap>(setting.value(QLatin1String(NM_SETTING_VPN_DATA))));
162 }
163
164 if (setting.contains(QLatin1String(NM_SETTING_VPN_SECRETS))) {
165 setSecrets(qdbus_cast<NMStringMap>(setting.value(QLatin1String(NM_SETTING_VPN_SECRETS))));
166 }
167
168 if (setting.contains(QLatin1String(NM_SETTING_VPN_PERSISTENT))) {
169 setPersistent(setting.value(QLatin1String(NM_SETTING_VPN_PERSISTENT)).toBool());
170 }
171
172 if (setting.contains(QLatin1String(NM_SETTING_VPN_TIMEOUT))) {
173 setTimeout(setting.value(QLatin1String(NM_SETTING_VPN_TIMEOUT)).toUInt());
174 }
175}
176
178{
179 QVariantMap setting;
180
181 if (!serviceType().isEmpty()) {
182 setting.insert(QLatin1String(NM_SETTING_VPN_SERVICE_TYPE), serviceType());
183 }
184
185 if (!username().isEmpty()) {
186 setting.insert(QLatin1String(NM_SETTING_VPN_USER_NAME), username());
187 }
188
189 if (!data().isEmpty()) {
190 setting.insert(QLatin1String(NM_SETTING_VPN_DATA), QVariant::fromValue<NMStringMap>(data()));
191 }
192
193 if (!secrets().isEmpty()) {
194 setting.insert(QLatin1String(NM_SETTING_VPN_SECRETS), QVariant::fromValue<NMStringMap>(secrets()));
195 }
196
197 setting.insert(QLatin1String(NM_SETTING_VPN_PERSISTENT), persistent());
198 setting.insert(QLatin1String(NM_SETTING_VPN_TIMEOUT), timeout());
199
200 return setting;
201}
202
204{
206
207 if (map.contains(QLatin1String("VpnSecrets"))) {
208 const QStringList list = map.value(QLatin1String("VpnSecrets")).split("%SEP%");
209 if (list.count() % 2 == 0) {
210 for (int i = 0; i < list.count(); i += 2) {
211 if (d->secrets.contains(list[i])) {
212 d->secrets.remove(list[i]);
213 }
214 d->secrets.insert(list[i], list[i + 1]);
215 }
216 }
217 }
218}
219
221{
222 NMStringMap ret;
223 QStringList list;
224 const QMap<QString, QString> values = secrets();
225 for (auto it = values.begin(); it != values.end(); ++it) {
226 list << it.key() << it.value();
227 }
228 ret.insert(QLatin1String("VpnSecrets"), list.join("%SEP%"));
229 return ret;
230}
231
232QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::VpnSetting &setting)
233{
234 dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n';
235 dbg.nospace() << "initialized: " << !setting.isNull() << '\n';
236
237 dbg.nospace() << NM_SETTING_VPN_SERVICE_TYPE << ": " << setting.serviceType() << '\n';
238 dbg.nospace() << NM_SETTING_VPN_USER_NAME << ": " << setting.username() << '\n';
239 dbg.nospace() << NM_SETTING_VPN_DATA << ": " << setting.data() << '\n';
240 dbg.nospace() << NM_SETTING_VPN_PERSISTENT << ": " << setting.persistent() << '\n';
241 dbg.nospace() << NM_SETTING_VPN_TIMEOUT << ": " << setting.timeout() << '\n';
242
243 return dbg.maybeSpace();
244}
Represents vpn setting.
Definition vpnsetting.h:23
void fromMap(const QVariantMap &setting) override
Must be reimplemented, default implementation does nothing.
QString name() const override
Must be reimplemented, default implementationd does nothing.
QVariantMap toMap() const override
Must be reimplemented, default implementationd does nothing.
NMStringMap secretsToStringMap() const override
secretsToStringMap is a convenience function to get the secrets to map of strings.
void secretsFromStringMap(const NMStringMap &map) override
secretsFromStringMap is a convenience function to set the secrets from a map of strings.
Type type(const QSqlDatabase &db)
QDebug & maybeSpace()
QDebug & nospace()
qsizetype count() const const
T value(qsizetype i) const const
iterator begin()
iterator end()
iterator insert(const Key &key, const T &value)
QString join(QChar separator) const const
QVariant fromValue(T &&value)
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.