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 "olpcmeshsetting.h"
8#include "olpcmeshsetting_p.h"
9
10#include <QDebug>
11
12NetworkManager::OlpcMeshSettingPrivate::OlpcMeshSettingPrivate()
13 : name(NM_SETTING_OLPC_MESH_SETTING_NAME)
14 , channel(0)
15{
16}
17
18NetworkManager::OlpcMeshSetting::OlpcMeshSetting()
19 : Setting(Setting::Bond)
20 , d_ptr(new OlpcMeshSettingPrivate())
21{
22}
23
24NetworkManager::OlpcMeshSetting::OlpcMeshSetting(const Ptr &other)
25 : Setting(other)
26 , d_ptr(new OlpcMeshSettingPrivate())
27{
28 setSsid(other->ssid());
29 setChannel(other->channel());
30 setDhcpAnycastAddress(other->dhcpAnycastAddress());
31}
32
33NetworkManager::OlpcMeshSetting::~OlpcMeshSetting()
34{
35 delete d_ptr;
36}
37
38QString NetworkManager::OlpcMeshSetting::name() const
39{
40 Q_D(const OlpcMeshSetting);
41
42 return d->name;
43}
44
45void NetworkManager::OlpcMeshSetting::setSsid(const QByteArray &ssid)
46{
47 Q_D(OlpcMeshSetting);
48
49 d->ssid = ssid;
50}
51
52QByteArray NetworkManager::OlpcMeshSetting::ssid() const
53{
54 Q_D(const OlpcMeshSetting);
55
56 return d->ssid;
57}
58
59void NetworkManager::OlpcMeshSetting::setChannel(quint32 channel)
60{
61 Q_D(OlpcMeshSetting);
62
63 d->channel = channel;
64}
65
66quint32 NetworkManager::OlpcMeshSetting::channel() const
67{
68 Q_D(const OlpcMeshSetting);
69
70 return d->channel;
71}
72
73void NetworkManager::OlpcMeshSetting::setDhcpAnycastAddress(const QByteArray &address)
74{
75 Q_D(OlpcMeshSetting);
76
77 d->dhcpAnycastAddress = address;
78}
79
80QByteArray NetworkManager::OlpcMeshSetting::dhcpAnycastAddress() const
81{
82 Q_D(const OlpcMeshSetting);
83
84 return d->dhcpAnycastAddress;
85}
86
87void NetworkManager::OlpcMeshSetting::fromMap(const QVariantMap &setting)
88{
89 if (setting.contains(key: QLatin1String(NM_SETTING_OLPC_MESH_SSID))) {
90 setSsid(setting.value(key: QLatin1String(NM_SETTING_OLPC_MESH_SSID)).toByteArray());
91 }
92
93 if (setting.contains(key: QLatin1String(NM_SETTING_OLPC_MESH_CHANNEL))) {
94 setChannel(setting.value(key: QLatin1String(NM_SETTING_OLPC_MESH_CHANNEL)).toUInt());
95 }
96
97 if (setting.contains(key: QLatin1String(NM_SETTING_OLPC_MESH_DHCP_ANYCAST_ADDRESS))) {
98 setDhcpAnycastAddress(setting.value(key: QLatin1String(NM_SETTING_OLPC_MESH_DHCP_ANYCAST_ADDRESS)).toByteArray());
99 }
100}
101
102QVariantMap NetworkManager::OlpcMeshSetting::toMap() const
103{
104 QVariantMap setting;
105
106 if (!ssid().isEmpty()) {
107 setting.insert(key: QLatin1String(NM_SETTING_OLPC_MESH_SSID), value: ssid());
108 }
109
110 if (channel()) {
111 setting.insert(key: QLatin1String(NM_SETTING_OLPC_MESH_CHANNEL), value: channel());
112 }
113
114 if (!dhcpAnycastAddress().isEmpty()) {
115 setting.insert(key: QLatin1String(NM_SETTING_OLPC_MESH_DHCP_ANYCAST_ADDRESS), value: dhcpAnycastAddress());
116 }
117
118 return setting;
119}
120
121QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::OlpcMeshSetting &setting)
122{
123 dbg.nospace() << "type: " << setting.typeAsString(type: setting.type()) << '\n';
124 dbg.nospace() << "initialized: " << !setting.isNull() << '\n';
125
126 dbg.nospace() << NM_SETTING_OLPC_MESH_SSID << ": " << setting.ssid() << '\n';
127 dbg.nospace() << NM_SETTING_OLPC_MESH_CHANNEL << ": " << setting.channel() << '\n';
128 dbg.nospace() << NM_SETTING_OLPC_MESH_DHCP_ANYCAST_ADDRESS << ": " << setting.dhcpAnycastAddress() << '\n';
129
130 return dbg.maybeSpace();
131}
132

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