NetworkManagerQt

dnsconfiguration.cpp
1/*
2 SPDX-FileCopyrightText: 2018 Aleksander Morgado <aleksander@aleksander.es>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#include "ipconfig.h"
8
9#include <arpa/inet.h>
10
11#include "dnsconfiguration.h"
12
13#include <QVariant>
14
15namespace NetworkManager
16{
17class NetworkManager::DnsConfiguration::Private
18{
19public:
20 Private(const QStringList &theSearches, const QStringList &theOptions, const QList<DnsDomain> theDomains)
21 : searches(theSearches)
22 , options(theOptions)
23 , domains(theDomains)
24 {
25 }
26 Private()
27 {
28 }
29 QStringList searches;
30 QStringList options;
31 QList<DnsDomain> domains;
32};
33
34}
35
37 : d(new Private(searches, options, domains))
38{
39}
40
45
47 : d(new Private)
48{
49 *this = other;
50}
51
56
58{
59 return d->searches;
60}
61
63{
64 d->searches = searches;
65}
66
68{
69 return d->options;
70}
71
73{
74 d->options = options;
75}
76
81
83{
84 d->domains = domains;
85}
86
88{
89 QVariantMap map;
90
91 map["searches"] = d->searches;
92 map["options"] = d->options;
93
94 QVariantMap domains;
95 for (const NetworkManager::DnsDomain &domain : std::as_const(d->domains)) {
96 QVariantMap contents;
97 QStringList serversList;
98 const QList<QHostAddress> servers = domain.servers();
99 for (const QHostAddress &address : servers) {
100 serversList.append(address.toString());
101 }
102 contents["servers"] = serversList;
103 contents["options"] = domain.options();
104 domains[domain.name()] = contents;
105 }
106 map["domains"] = domains;
107
108 return map;
109}
110
112{
113 d->searches = map["searches"].toStringList();
114 d->options = map["options"].toStringList();
116
117 QVariantMap domains = map["domains"].toMap();
118 QVariantMap::const_iterator i = domains.constBegin();
119 while (i != domains.constEnd()) {
120 const QVariantMap contents = i.value().toMap();
121 QList<QHostAddress> addressList;
122 const QStringList serversList = contents["servers"].toStringList();
123 for (const QString &server : serversList) {
124 addressList.append(QHostAddress(server));
125 }
126 NetworkManager::DnsDomain domain(i.key(), addressList, contents["options"].toStringList());
127 d->domains.append(domain);
128 ++i;
129 }
130}
131
133{
134 if (this == &other) {
135 return *this;
136 }
137
138 *d = *other.d;
139 return *this;
140}
This class represents IP configuration.
QVariantMap toMap() const
Marshall into a map.
QStringList searches() const
Returns the list of search domains.
void fromMap(const QVariantMap &map)
De-marshall from a map.
DnsConfiguration()
Constructs an empty DnsConfiguration object.
DnsConfiguration & operator=(const DnsConfiguration &other)
Makes a copy of the DnsConfiguration object other.
void setDomains(const QList< DnsDomain > &domains)
Sets the list of domains.
void setOptions(const QStringList &list)
Sets the list of resolver options.
QStringList options() const
Returns the list of resolver options.
~DnsConfiguration()
Destroys this DnsConfiguration object.
QList< DnsDomain > domains() const
Returns the list of domains.
void setSearches(const QStringList &list)
Sets the list of search domains.
This class represents the configuration for a DNS domain.
Definition dnsdomain.h:28
This class allows querying the underlying system to discover the available network interfaces and rea...
Definition accesspoint.h:21
void append(QList< T > &&value)
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.