NetworkManagerQt

tunsetting.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 "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
45{
46 Q_D(const TunSetting);
47
48 return d->name;
49}
50
51void NetworkManager::TunSetting::setGroup(const QString &group)
52{
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(QLatin1String(NM_SETTING_TUN_GROUP))) {
138 setGroup(setting.value(QLatin1String(NM_SETTING_TUN_GROUP)).toString());
139 }
140
141 if (setting.contains(QLatin1String(NM_SETTING_TUN_MODE))) {
142 setMode((Mode)setting.value(QLatin1String(NM_SETTING_TUN_MODE)).toUInt());
143 }
144
145 if (setting.contains(QLatin1String(NM_SETTING_TUN_MULTI_QUEUE))) {
146 setMultiQueue(setting.value(QLatin1String(NM_SETTING_TUN_MULTI_QUEUE)).toBool());
147 }
148
149 if (setting.contains(QLatin1String(NM_SETTING_TUN_OWNER))) {
150 setOwner(setting.value(QLatin1String(NM_SETTING_TUN_OWNER)).toString());
151 }
152
153 if (setting.contains(QLatin1String(NM_SETTING_TUN_PI))) {
154 setPi(setting.value(QLatin1String(NM_SETTING_TUN_PI)).toBool());
155 }
156
157 if (setting.contains(QLatin1String(NM_SETTING_TUN_VNET_HDR))) {
158 setVnetHdr(setting.value(QLatin1String(NM_SETTING_TUN_VNET_HDR)).toBool());
159 }
160}
161
163{
164 QVariantMap setting;
165
166 if (!group().isEmpty()) {
167 setting.insert(QLatin1String(NM_SETTING_TUN_GROUP), group());
168 }
169
170 setting.insert(QLatin1String(NM_SETTING_TUN_MODE), (int)mode());
171 setting.insert(QLatin1String(NM_SETTING_TUN_MULTI_QUEUE), multiQueue());
172
173 if (!owner().isEmpty()) {
174 setting.insert(QLatin1String(NM_SETTING_TUN_OWNER), owner());
175 }
176
177 setting.insert(QLatin1String(NM_SETTING_TUN_PI), pi());
178 setting.insert(QLatin1String(NM_SETTING_TUN_VNET_HDR), vnetHdr());
179
180 return setting;
181}
182
183QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::TunSetting &setting)
184{
185 dbg.nospace() << "type: " << setting.typeAsString(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}
Represents generic setting.
Definition tunsetting.h:23
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.
QDebug & maybeSpace()
QDebug & nospace()
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 27 2024 11:55:21 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.