1/*
2 SPDX-FileCopyrightText: Pranav Gade <pranavgade20@gmail.com>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#include "usersetting.h"
8#include "usersetting_p.h"
9
10#include <QDebug>
11
12#if !NM_CHECK_VERSION(1, 8, 0)
13#define NM_SETTING_USER_SETTING_NAME "user"
14#define NM_SETTING_USER_DATA "data"
15#endif
16
17NetworkManager::UserSettingPrivate::UserSettingPrivate()
18 : name(NM_SETTING_USER_SETTING_NAME)
19{
20}
21
22NetworkManager::UserSetting::UserSetting()
23 : Setting(Setting::User)
24 , d_ptr(new UserSettingPrivate())
25{
26}
27
28NetworkManager::UserSetting::UserSetting(const Ptr &other)
29 : Setting(other)
30 , d_ptr(new UserSettingPrivate())
31{
32 setData(other->data());
33}
34
35NetworkManager::UserSetting::~UserSetting()
36{
37 delete d_ptr;
38}
39
40QString NetworkManager::UserSetting::name() const
41{
42 Q_D(const UserSetting);
43
44 return d->name;
45}
46
47void NetworkManager::UserSetting::addData(const QString &data, const QString &value)
48{
49 Q_D(UserSetting);
50
51 d->data.insert(key: data, value);
52}
53
54void NetworkManager::UserSetting::setData(const NMStringMap &data)
55{
56 Q_D(UserSetting);
57
58 d->data = data;
59}
60
61NMStringMap NetworkManager::UserSetting::data() const
62{
63 Q_D(const UserSetting);
64
65 return d->data;
66}
67
68void NetworkManager::UserSetting::fromMap(const QVariantMap &setting)
69{
70 if (setting.contains(key: QLatin1String(NM_SETTING_USER_DATA))) {
71 setData(qdbus_cast<NMStringMap>(v: setting.value(key: QLatin1String(NM_SETTING_USER_DATA))));
72 }
73}
74
75QVariantMap NetworkManager::UserSetting::toMap() const
76{
77 QVariantMap setting;
78
79 if (!data().isEmpty()) {
80 setting.insert(key: QLatin1String(NM_SETTING_USER_DATA), value: QVariant::fromValue<NMStringMap>(value: data()));
81 }
82
83 return setting;
84}
85
86QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::UserSetting &setting)
87{
88 dbg.nospace() << "type: " << setting.typeAsString(type: setting.type()) << '\n';
89 dbg.nospace() << "initialized: " << !setting.isNull() << '\n';
90
91 dbg.nospace() << NM_SETTING_USER_DATA << ": " << setting.data() << '\n';
92
93 return dbg.maybeSpace();
94}
95

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