File indexing completed on 2024-04-14 03:57:42

0001 /*
0002     SPDX-FileCopyrightText: 2011 Lamarque V. Souza <lamarque@kde.org>
0003     SPDX-FileCopyrightText: 2014 Jan Grulich <jgrulich@redhat.com>
0004 
0005     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006 */
0007 
0008 #include "dhcp6config_p.h"
0009 #include "manager_p.h"
0010 #include "nmdebug.h"
0011 
0012 NetworkManager::Dhcp6ConfigPrivate::Dhcp6ConfigPrivate(const QString &path, Dhcp6Config *q)
0013 #ifdef NMQT_STATIC
0014     : dhcp6Iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::sessionBus())
0015 #else
0016     : dhcp6Iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::systemBus())
0017 #endif
0018     , path(path)
0019     , q_ptr(q)
0020 {
0021 }
0022 
0023 NetworkManager::Dhcp6ConfigPrivate::~Dhcp6ConfigPrivate()
0024 {
0025 }
0026 
0027 NetworkManager::Dhcp6Config::Dhcp6Config(const QString &path, QObject *owner)
0028     : d_ptr(new Dhcp6ConfigPrivate(path, this))
0029 {
0030     Q_D(Dhcp6Config);
0031     Q_UNUSED(owner);
0032 
0033     QDBusConnection::systemBus().connect(NetworkManagerPrivate::DBUS_SERVICE,
0034                                          d->path,
0035                                          NetworkManagerPrivate::FDO_DBUS_PROPERTIES,
0036                                          QLatin1String("PropertiesChanged"),
0037                                          d,
0038                                          SLOT(dbusPropertiesChanged(QString, QVariantMap, QStringList)));
0039 
0040     d->options = d->dhcp6Iface.options();
0041 }
0042 
0043 NetworkManager::Dhcp6Config::~Dhcp6Config()
0044 {
0045     delete d_ptr;
0046 }
0047 
0048 QString NetworkManager::Dhcp6Config::path() const
0049 {
0050     Q_D(const Dhcp6Config);
0051     return d->path;
0052 }
0053 
0054 QVariantMap NetworkManager::Dhcp6Config::options() const
0055 {
0056     Q_D(const Dhcp6Config);
0057     return d->options;
0058 }
0059 
0060 QString NetworkManager::Dhcp6Config::optionValue(const QString &key) const
0061 {
0062     Q_D(const Dhcp6Config);
0063     QString value;
0064     if (d->options.contains(key)) {
0065         value = d->options.value(key).toString();
0066     }
0067     return value;
0068 }
0069 
0070 void NetworkManager::Dhcp6ConfigPrivate::dbusPropertiesChanged(const QString &interfaceName,
0071                                                                const QVariantMap &properties,
0072                                                                const QStringList &invalidatedProperties)
0073 {
0074     Q_UNUSED(invalidatedProperties);
0075     if (interfaceName == QLatin1String("org.freedesktop.NetworkManager.DHCP6Config")) {
0076         dhcp6PropertiesChanged(properties);
0077     }
0078 }
0079 
0080 void NetworkManager::Dhcp6ConfigPrivate::dhcp6PropertiesChanged(const QVariantMap &properties)
0081 {
0082     Q_Q(Dhcp6Config);
0083 
0084     QVariantMap::const_iterator it = properties.constBegin();
0085     while (it != properties.constEnd()) {
0086         const QString property = it.key();
0087         if (property == QLatin1String("Options")) {
0088             options = it.value().toMap();
0089             Q_EMIT q->optionsChanged(options);
0090         } else {
0091             qCWarning(NMQT) << Q_FUNC_INFO << "Unhandled property" << property;
0092         }
0093         ++it;
0094     }
0095 }
0096 
0097 #include "moc_dhcp6config.cpp"
0098 #include "moc_dhcp6config_p.cpp"