1/*
2 SPDX-FileCopyrightText: 2011 Lamarque V. Souza <lamarque@kde.org>
3 SPDX-FileCopyrightText: 2014 Jan Grulich <jgrulich@redhat.com>
4
5 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6*/
7
8#include "dhcp4config.h"
9#include "dhcp4config_p.h"
10#include "manager_p.h"
11#include "nmdebug.h"
12
13NetworkManager::Dhcp4ConfigPrivate::Dhcp4ConfigPrivate(const QString &path, Dhcp4Config *q)
14#ifdef NMQT_STATIC
15 : dhcp4Iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::sessionBus())
16#else
17 : dhcp4Iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::systemBus())
18#endif
19 , myPath(path)
20 , q_ptr(q)
21{
22}
23
24NetworkManager::Dhcp4ConfigPrivate::~Dhcp4ConfigPrivate()
25{
26}
27
28NetworkManager::Dhcp4Config::Dhcp4Config(const QString &path, QObject *owner)
29 : d_ptr(new Dhcp4ConfigPrivate(path, this))
30{
31 Q_D(Dhcp4Config);
32 Q_UNUSED(owner);
33
34 QDBusConnection::systemBus().connect(service: NetworkManagerPrivate::DBUS_SERVICE,
35 path: d->myPath,
36 interface: NetworkManagerPrivate::FDO_DBUS_PROPERTIES,
37 name: QLatin1String("PropertiesChanged"),
38 receiver: d,
39 SLOT(dbusPropertiesChanged(QString, QVariantMap, QStringList)));
40 d->options = d->dhcp4Iface.options();
41}
42
43NetworkManager::Dhcp4Config::~Dhcp4Config()
44{
45 delete d_ptr;
46}
47
48QString NetworkManager::Dhcp4Config::path() const
49{
50 Q_D(const Dhcp4Config);
51 return d->myPath;
52}
53
54QVariantMap NetworkManager::Dhcp4Config::options() const
55{
56 Q_D(const Dhcp4Config);
57 return d->options;
58}
59
60QString NetworkManager::Dhcp4Config::optionValue(const QString &key) const
61{
62 Q_D(const Dhcp4Config);
63 QString value;
64 if (d->options.contains(key)) {
65 value = d->options.value(key).toString();
66 }
67 return value;
68}
69
70void NetworkManager::Dhcp4ConfigPrivate::dbusPropertiesChanged(const QString &interfaceName,
71 const QVariantMap &properties,
72 const QStringList &invalidatedProperties)
73{
74 Q_UNUSED(invalidatedProperties);
75 if (interfaceName == QLatin1String("org.freedesktop.NetworkManager.DHCP4Config")) {
76 dhcp4PropertiesChanged(properties);
77 }
78}
79
80void NetworkManager::Dhcp4ConfigPrivate::dhcp4PropertiesChanged(const QVariantMap &properties)
81{
82 Q_Q(Dhcp4Config);
83
84 QVariantMap::const_iterator it = properties.constBegin();
85 while (it != properties.constEnd()) {
86 const QString property = it.key();
87 if (property == QLatin1String("Options")) {
88 options = it.value().toMap();
89 Q_EMIT q->optionsChanged(options);
90 } else {
91 qCWarning(NMQT) << Q_FUNC_INFO << "Unhandled property" << property;
92 }
93 ++it;
94 }
95}
96
97#include "moc_dhcp4config.cpp"
98#include "moc_dhcp4config_p.cpp"
99

source code of networkmanager-qt/src/dhcp4config.cpp