File indexing completed on 2025-03-23 12:49:50
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 "dhcp4config.h" 0009 #include "dhcp4config_p.h" 0010 #include "manager_p.h" 0011 #include "nmdebug.h" 0012 0013 NetworkManager::Dhcp4ConfigPrivate::Dhcp4ConfigPrivate(const QString &path, Dhcp4Config *q) 0014 #ifdef NMQT_STATIC 0015 : dhcp4Iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::sessionBus()) 0016 #else 0017 : dhcp4Iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::systemBus()) 0018 #endif 0019 , myPath(path) 0020 , q_ptr(q) 0021 { 0022 } 0023 0024 NetworkManager::Dhcp4ConfigPrivate::~Dhcp4ConfigPrivate() 0025 { 0026 } 0027 0028 NetworkManager::Dhcp4Config::Dhcp4Config(const QString &path, QObject *owner) 0029 : d_ptr(new Dhcp4ConfigPrivate(path, this)) 0030 { 0031 Q_D(Dhcp4Config); 0032 Q_UNUSED(owner); 0033 0034 QDBusConnection::systemBus().connect(NetworkManagerPrivate::DBUS_SERVICE, 0035 d->myPath, 0036 NetworkManagerPrivate::FDO_DBUS_PROPERTIES, 0037 QLatin1String("PropertiesChanged"), 0038 d, 0039 SLOT(dbusPropertiesChanged(QString, QVariantMap, QStringList))); 0040 d->options = d->dhcp4Iface.options(); 0041 } 0042 0043 NetworkManager::Dhcp4Config::~Dhcp4Config() 0044 { 0045 delete d_ptr; 0046 } 0047 0048 QString NetworkManager::Dhcp4Config::path() const 0049 { 0050 Q_D(const Dhcp4Config); 0051 return d->myPath; 0052 } 0053 0054 QVariantMap NetworkManager::Dhcp4Config::options() const 0055 { 0056 Q_D(const Dhcp4Config); 0057 return d->options; 0058 } 0059 0060 QString NetworkManager::Dhcp4Config::optionValue(const QString &key) const 0061 { 0062 Q_D(const Dhcp4Config); 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::Dhcp4ConfigPrivate::dbusPropertiesChanged(const QString &interfaceName, 0071 const QVariantMap &properties, 0072 const QStringList &invalidatedProperties) 0073 { 0074 Q_UNUSED(invalidatedProperties); 0075 if (interfaceName == QLatin1String("org.freedesktop.NetworkManager.DHCP4Config")) { 0076 dhcp4PropertiesChanged(properties); 0077 } 0078 } 0079 0080 void NetworkManager::Dhcp4ConfigPrivate::dhcp4PropertiesChanged(const QVariantMap &properties) 0081 { 0082 Q_Q(Dhcp4Config); 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_dhcp4config.cpp" 0098 #include "moc_dhcp4config_p.cpp"