NetworkManagerQt

bondsetting.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 "bondsetting.h"
8#include "bondsetting_p.h"
9
10#define NM_SETTING_BOND_INTERFACE_NAME "interface-name"
11
12#include <QDebug>
13
14NetworkManager::BondSettingPrivate::BondSettingPrivate()
15 : name(NM_SETTING_BOND_SETTING_NAME)
16{
17}
18
19NetworkManager::BondSetting::BondSetting()
20 : Setting(Setting::Bond)
21 , d_ptr(new BondSettingPrivate())
22{
23}
24
25NetworkManager::BondSetting::BondSetting(const Ptr &other)
26 : Setting(other)
27 , d_ptr(new BondSettingPrivate())
28{
29 setInterfaceName(other->interfaceName());
30 setOptions(other->options());
31}
32
33NetworkManager::BondSetting::~BondSetting()
34{
35 delete d_ptr;
36}
37
39{
40 Q_D(const BondSetting);
41
42 return d->name;
43}
44
46{
48
49 d->interfaceName = name;
50}
51
52QString NetworkManager::BondSetting::interfaceName() const
53{
54 Q_D(const BondSetting);
55
56 return d->interfaceName;
57}
58
59void NetworkManager::BondSetting::addOption(const QString &option, const QString &value)
60{
61 Q_D(BondSetting);
62
63 d->options.insert(option, value);
64}
65
66void NetworkManager::BondSetting::setOptions(const NMStringMap &options)
67{
68 Q_D(BondSetting);
69
70 d->options = options;
71}
72
73NMStringMap NetworkManager::BondSetting::options() const
74{
75 Q_D(const BondSetting);
76
77 return d->options;
78}
79
80void NetworkManager::BondSetting::fromMap(const QVariantMap &setting)
81{
82 if (setting.contains(QLatin1String(NM_SETTING_BOND_INTERFACE_NAME))) {
83 setInterfaceName(setting.value(QLatin1String(NM_SETTING_BOND_INTERFACE_NAME)).toString());
84 }
85
86 if (setting.contains(QLatin1String(NM_SETTING_BOND_OPTIONS))) {
87 setOptions(qdbus_cast<NMStringMap>(setting.value(QLatin1String(NM_SETTING_BOND_OPTIONS))));
88 }
89}
90
92{
93 QVariantMap setting;
94 if (!interfaceName().isEmpty()) {
95 setting.insert(QLatin1String(NM_SETTING_BOND_INTERFACE_NAME), interfaceName());
96 }
97 if (!options().isEmpty()) {
98 setting.insert(QLatin1String(NM_SETTING_BOND_OPTIONS), QVariant::fromValue<NMStringMap>(options()));
99 }
100
101 return setting;
102}
103
104QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::BondSetting &setting)
105{
106 dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n';
107 dbg.nospace() << "initialized: " << !setting.isNull() << '\n';
108
109 dbg.nospace() << NM_SETTING_BOND_INTERFACE_NAME << ": " << setting.interfaceName() << '\n';
110 dbg.nospace() << NM_SETTING_BOND_OPTIONS << ": " << setting.options() << '\n';
111
112 return dbg.maybeSpace();
113}
Represents bond setting.
Definition bondsetting.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.
void setInterfaceName(const QString &name)
QDebug & maybeSpace()
QDebug & nospace()
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.