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 "vlansetting.h"
8#include "vlansetting_p.h"
9
10// define the deprecated&dropped values
11#define NM_SETTING_VLAN_INTERFACE_NAME "interface-name"
12
13#include <QDebug>
14
15NetworkManager::VlanSettingPrivate::VlanSettingPrivate()
16 : name(NM_SETTING_VLAN_SETTING_NAME)
17 , id(0)
18 , flags(VlanSetting::None)
19{
20}
21
22NetworkManager::VlanSetting::VlanSetting()
23 : Setting(Setting::Vlan)
24 , d_ptr(new VlanSettingPrivate())
25{
26}
27
28NetworkManager::VlanSetting::VlanSetting(const Ptr &other)
29 : Setting(other)
30 , d_ptr(new VlanSettingPrivate())
31{
32 setInterfaceName(other->interfaceName());
33 setParent(other->parent());
34 setId(other->id());
35 setFlags(other->flags());
36 setIngressPriorityMap(other->ingressPriorityMap());
37 setEgressPriorityMap(other->egressPriorityMap());
38}
39
40NetworkManager::VlanSetting::~VlanSetting()
41{
42 delete d_ptr;
43}
44
45QString NetworkManager::VlanSetting::name() const
46{
47 Q_D(const VlanSetting);
48
49 return d->name;
50}
51
52void NetworkManager::VlanSetting::setInterfaceName(const QString &name)
53{
54 Q_D(VlanSetting);
55
56 d->interfaceName = name;
57}
58
59QString NetworkManager::VlanSetting::interfaceName() const
60{
61 Q_D(const VlanSetting);
62
63 return d->interfaceName;
64}
65
66void NetworkManager::VlanSetting::setParent(const QString &parent)
67{
68 Q_D(VlanSetting);
69
70 d->parent = parent;
71}
72
73QString NetworkManager::VlanSetting::parent() const
74{
75 Q_D(const VlanSetting);
76
77 return d->parent;
78}
79
80void NetworkManager::VlanSetting::setId(quint32 id)
81{
82 Q_D(VlanSetting);
83
84 d->id = id;
85}
86
87quint32 NetworkManager::VlanSetting::id() const
88{
89 Q_D(const VlanSetting);
90
91 return d->id;
92}
93
94void NetworkManager::VlanSetting::setFlags(NetworkManager::VlanSetting::Flags flags)
95{
96 Q_D(VlanSetting);
97
98 d->flags = flags;
99}
100
101NetworkManager::VlanSetting::Flags NetworkManager::VlanSetting::flags() const
102{
103 Q_D(const VlanSetting);
104
105 return d->flags;
106}
107
108void NetworkManager::VlanSetting::setIngressPriorityMap(const QStringList &map)
109{
110 Q_D(VlanSetting);
111
112 d->ingressPriorityMap = map;
113}
114
115QStringList NetworkManager::VlanSetting::ingressPriorityMap() const
116{
117 Q_D(const VlanSetting);
118
119 return d->ingressPriorityMap;
120}
121
122void NetworkManager::VlanSetting::setEgressPriorityMap(const QStringList &map)
123{
124 Q_D(VlanSetting);
125
126 d->egressPriorityMap = map;
127}
128
129QStringList NetworkManager::VlanSetting::egressPriorityMap() const
130{
131 Q_D(const VlanSetting);
132
133 return d->egressPriorityMap;
134}
135
136void NetworkManager::VlanSetting::fromMap(const QVariantMap &setting)
137{
138 if (setting.contains(key: QLatin1String(NM_SETTING_VLAN_INTERFACE_NAME))) {
139 setInterfaceName(setting.value(key: QLatin1String(NM_SETTING_VLAN_INTERFACE_NAME)).toString());
140 }
141
142 if (setting.contains(key: QLatin1String(NM_SETTING_VLAN_PARENT))) {
143 setParent(setting.value(key: QLatin1String(NM_SETTING_VLAN_PARENT)).toString());
144 }
145
146 if (setting.contains(key: QLatin1String(NM_SETTING_VLAN_ID))) {
147 setId(setting.value(key: QLatin1String(NM_SETTING_VLAN_ID)).toUInt());
148 }
149
150 if (setting.contains(key: QLatin1String(NM_SETTING_VLAN_FLAGS))) {
151 setFlags((Flag)setting.value(key: QLatin1String(NM_SETTING_VLAN_FLAGS)).toUInt());
152 }
153
154 if (setting.contains(key: QLatin1String(NM_SETTING_VLAN_INGRESS_PRIORITY_MAP))) {
155 setIngressPriorityMap(setting.value(key: QLatin1String(NM_SETTING_VLAN_INGRESS_PRIORITY_MAP)).toStringList());
156 }
157
158 if (setting.contains(key: QLatin1String(NM_SETTING_VLAN_EGRESS_PRIORITY_MAP))) {
159 setEgressPriorityMap(setting.value(key: QLatin1String(NM_SETTING_VLAN_EGRESS_PRIORITY_MAP)).toStringList());
160 }
161}
162
163QVariantMap NetworkManager::VlanSetting::toMap() const
164{
165 QVariantMap setting;
166
167 if (!interfaceName().isEmpty()) {
168 setting.insert(key: QLatin1String(NM_SETTING_VLAN_INTERFACE_NAME), value: interfaceName());
169 }
170
171 if (!parent().isEmpty()) {
172 setting.insert(key: QLatin1String(NM_SETTING_VLAN_PARENT), value: parent());
173 }
174
175 if (id()) {
176 setting.insert(key: QLatin1String(NM_SETTING_VLAN_ID), value: id());
177 }
178
179 if (flags() != None) {
180 setting.insert(key: QLatin1String(NM_SETTING_VLAN_FLAGS), value: (int)flags());
181 }
182
183 if (!ingressPriorityMap().isEmpty()) {
184 setting.insert(key: QLatin1String(NM_SETTING_VLAN_INGRESS_PRIORITY_MAP), value: ingressPriorityMap());
185 }
186
187 if (!egressPriorityMap().isEmpty()) {
188 setting.insert(key: QLatin1String(NM_SETTING_VLAN_EGRESS_PRIORITY_MAP), value: egressPriorityMap());
189 }
190
191 return setting;
192}
193
194QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::VlanSetting &setting)
195{
196 dbg.nospace() << "type: " << setting.typeAsString(type: setting.type()) << '\n';
197 dbg.nospace() << "initialized: " << !setting.isNull() << '\n';
198
199 dbg.nospace() << NM_SETTING_VLAN_INTERFACE_NAME << ": " << setting.interfaceName() << '\n';
200 dbg.nospace() << NM_SETTING_VLAN_PARENT << ": " << setting.parent() << '\n';
201 dbg.nospace() << NM_SETTING_VLAN_ID << ": " << setting.id() << '\n';
202 dbg.nospace() << NM_SETTING_VLAN_FLAGS << ": " << setting.flags() << '\n';
203 dbg.nospace() << NM_SETTING_VLAN_INGRESS_PRIORITY_MAP << ": " << setting.ingressPriorityMap() << '\n';
204 dbg.nospace() << NM_SETTING_VLAN_EGRESS_PRIORITY_MAP << ": " << setting.egressPriorityMap() << '\n';
205
206 return dbg.maybeSpace();
207}
208

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