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 "tunsetting.h"
8#include "tunsetting_p.h"
9
10#include <QDebug>
11
12NetworkManager::TunSettingPrivate::TunSettingPrivate()
13 : name(NM_SETTING_TUN_SETTING_NAME)
14 , mode(TunSetting::Tun)
15 , multiQueue(false)
16 , pi(false)
17 , vnetHdr(false)
18{
19}
20
21NetworkManager::TunSetting::TunSetting()
22 : Setting(Setting::Tun)
23 , d_ptr(new TunSettingPrivate())
24{
25}
26
27NetworkManager::TunSetting::TunSetting(const Ptr &other)
28 : Setting(other)
29 , d_ptr(new TunSettingPrivate())
30{
31 setGroup(other->group());
32 setMode(other->mode());
33 setMultiQueue(other->multiQueue());
34 setOwner(other->owner());
35 setPi(other->pi());
36 setVnetHdr(other->vnetHdr());
37}
38
39NetworkManager::TunSetting::~TunSetting()
40{
41 delete d_ptr;
42}
43
44QString NetworkManager::TunSetting::name() const
45{
46 Q_D(const TunSetting);
47
48 return d->name;
49}
50
51void NetworkManager::TunSetting::setGroup(const QString &group)
52{
53 Q_D(TunSetting);
54
55 d->group = group;
56}
57
58QString NetworkManager::TunSetting::group() const
59{
60 Q_D(const TunSetting);
61
62 return d->group;
63}
64
65void NetworkManager::TunSetting::setMode(NetworkManager::TunSetting::Mode mode)
66{
67 Q_D(TunSetting);
68
69 d->mode = mode;
70}
71
72NetworkManager::TunSetting::Mode NetworkManager::TunSetting::mode() const
73{
74 Q_D(const TunSetting);
75
76 return d->mode;
77}
78
79void NetworkManager::TunSetting::setMultiQueue(bool multiQueue)
80{
81 Q_D(TunSetting);
82
83 d->multiQueue = multiQueue;
84}
85
86bool NetworkManager::TunSetting::multiQueue() const
87{
88 Q_D(const TunSetting);
89
90 return d->multiQueue;
91}
92
93void NetworkManager::TunSetting::setOwner(const QString &owner)
94{
95 Q_D(TunSetting);
96
97 d->owner = owner;
98}
99
100QString NetworkManager::TunSetting::owner() const
101{
102 Q_D(const TunSetting);
103
104 return d->owner;
105}
106
107void NetworkManager::TunSetting::setPi(bool pi)
108{
109 Q_D(TunSetting);
110
111 d->pi = pi;
112}
113
114bool NetworkManager::TunSetting::pi() const
115{
116 Q_D(const TunSetting);
117
118 return d->pi;
119}
120
121void NetworkManager::TunSetting::setVnetHdr(bool vnetHdr)
122{
123 Q_D(TunSetting);
124
125 d->vnetHdr = vnetHdr;
126}
127
128bool NetworkManager::TunSetting::vnetHdr() const
129{
130 Q_D(const TunSetting);
131
132 return d->vnetHdr;
133}
134
135void NetworkManager::TunSetting::fromMap(const QVariantMap &setting)
136{
137 if (setting.contains(key: QLatin1String(NM_SETTING_TUN_GROUP))) {
138 setGroup(setting.value(key: QLatin1String(NM_SETTING_TUN_GROUP)).toString());
139 }
140
141 if (setting.contains(key: QLatin1String(NM_SETTING_TUN_MODE))) {
142 setMode((Mode)setting.value(key: QLatin1String(NM_SETTING_TUN_MODE)).toUInt());
143 }
144
145 if (setting.contains(key: QLatin1String(NM_SETTING_TUN_MULTI_QUEUE))) {
146 setMultiQueue(setting.value(key: QLatin1String(NM_SETTING_TUN_MULTI_QUEUE)).toBool());
147 }
148
149 if (setting.contains(key: QLatin1String(NM_SETTING_TUN_OWNER))) {
150 setOwner(setting.value(key: QLatin1String(NM_SETTING_TUN_OWNER)).toString());
151 }
152
153 if (setting.contains(key: QLatin1String(NM_SETTING_TUN_PI))) {
154 setPi(setting.value(key: QLatin1String(NM_SETTING_TUN_PI)).toBool());
155 }
156
157 if (setting.contains(key: QLatin1String(NM_SETTING_TUN_VNET_HDR))) {
158 setVnetHdr(setting.value(key: QLatin1String(NM_SETTING_TUN_VNET_HDR)).toBool());
159 }
160}
161
162QVariantMap NetworkManager::TunSetting::toMap() const
163{
164 QVariantMap setting;
165
166 if (!group().isEmpty()) {
167 setting.insert(key: QLatin1String(NM_SETTING_TUN_GROUP), value: group());
168 }
169
170 setting.insert(key: QLatin1String(NM_SETTING_TUN_MODE), value: (int)mode());
171 setting.insert(key: QLatin1String(NM_SETTING_TUN_MULTI_QUEUE), value: multiQueue());
172
173 if (!owner().isEmpty()) {
174 setting.insert(key: QLatin1String(NM_SETTING_TUN_OWNER), value: owner());
175 }
176
177 setting.insert(key: QLatin1String(NM_SETTING_TUN_PI), value: pi());
178 setting.insert(key: QLatin1String(NM_SETTING_TUN_VNET_HDR), value: vnetHdr());
179
180 return setting;
181}
182
183QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::TunSetting &setting)
184{
185 dbg.nospace() << "type: " << setting.typeAsString(type: setting.type()) << '\n';
186 dbg.nospace() << "initialized: " << !setting.isNull() << '\n';
187
188 dbg.nospace() << NM_SETTING_TUN_GROUP << ": " << setting.group() << '\n';
189 dbg.nospace() << NM_SETTING_TUN_MODE << ": " << setting.mode() << '\n';
190 dbg.nospace() << NM_SETTING_TUN_MULTI_QUEUE << ": " << setting.multiQueue() << '\n';
191 dbg.nospace() << NM_SETTING_TUN_OWNER << ": " << setting.owner() << '\n';
192 dbg.nospace() << NM_SETTING_TUN_PI << ": " << setting.pi() << '\n';
193 dbg.nospace() << NM_SETTING_TUN_VNET_HDR << ": " << setting.vnetHdr() << '\n';
194
195 return dbg.maybeSpace();
196}
197

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