Make it work with older NetworkManager versions

add-support-for-wired-network-config
Michael Zanetti 2022-10-25 23:06:49 +02:00
parent e1f01118ed
commit 14cb9d9e97
2 changed files with 18 additions and 10 deletions

View File

@ -82,7 +82,10 @@ WirelessNetworkDevice::WirelessNetworkDevice(const QDBusObjectPath &objectPath,
QDBusConnection::systemBus().connect(NetworkManagerUtils::networkManagerServiceString(), this->objectPath().path(), NetworkManagerUtils::wirelessInterfaceString(), "AccessPointAdded", this, SLOT(accessPointAdded(QDBusObjectPath)));
QDBusConnection::systemBus().connect(NetworkManagerUtils::networkManagerServiceString(), this->objectPath().path(), NetworkManagerUtils::wirelessInterfaceString(), "AccessPointRemoved", this, SLOT(accessPointRemoved(QDBusObjectPath)));
// org.freedesktop.NetworkManager.Device.Wireless.PropertiesChanged(QVariantMap) is used in older versions of NetworkManager instead of the standard D-Bus properties changed signal
QDBusConnection::systemBus().connect(NetworkManagerUtils::networkManagerServiceString(), this->objectPath().path(), NetworkManagerUtils::wirelessInterfaceString(), "PropertiesChanged", this, SLOT(propertiesChanged(QVariantMap)));
// Newer versions of NetworkManager dropped the other and switched to the D-Bus standard PropertiesChanged
QDBusConnection::systemBus().connect(NetworkManagerUtils::networkManagerServiceString(), this->objectPath().path(), "org.freedesktop.DBus.Properties", "PropertiesChanged", this, SLOT(propertiesChanged(QString, QVariantMap, QStringList)));
readAccessPoints();
@ -219,36 +222,40 @@ void WirelessNetworkDevice::accessPointRemoved(const QDBusObjectPath &objectPath
accessPoint->deleteLater();
}
void WirelessNetworkDevice::propertiesChanged(const QString &interface_name, const QVariantMap &changed_properties, const QStringList &invalidated_properties)
void WirelessNetworkDevice::propertiesChanged(const QVariantMap &properties)
{
Q_UNUSED(interface_name)
Q_UNUSED(invalidated_properties)
//qCDebug(dcNetworkManager()) << "WirelessNetworkDevice: Property changed" << properties;
if (changed_properties.contains("Bitrate")) {
m_bitRate = changed_properties.value("Bitrate").toInt() / 1000;
if (properties.contains("Bitrate")) {
m_bitRate = properties.value("Bitrate").toInt() / 1000;
emit bitRateChanged(m_bitRate);
}
if (changed_properties.contains("Mode")) {
if (properties.contains("Mode")) {
m_wirelessMode = static_cast<WirelessMode>(m_wirelessInterface->property("Mode").toUInt());
emit wirelessModeChanged(m_wirelessMode);
}
// Note: available since 1.12 (-1 means never scanned)
if (changed_properties.contains("LastScan")) {
if (properties.contains("LastScan")) {
m_lastScan = m_wirelessInterface->property("LastScan").toInt();
emit lastScanChanged(m_lastScan);
}
if (changed_properties.contains("ActiveAccessPoint")) {
setActiveAccessPoint(qdbus_cast<QDBusObjectPath>(changed_properties.value("ActiveAccessPoint")));
if (properties.contains("ActiveAccessPoint")) {
setActiveAccessPoint(qdbus_cast<QDBusObjectPath>(properties.value("ActiveAccessPoint")));
}
emit deviceChanged();
}
void WirelessNetworkDevice::propertiesChanged(const QString &interface_name, const QVariantMap &changed_properties, const QStringList &invalidated_properties)
{
Q_UNUSED(interface_name)
Q_UNUSED(invalidated_properties)
propertiesChanged(changed_properties);
}
/*! Writes the given \a device to the given to \a debug. \sa WirelessNetworkDevice, */
QDebug operator<<(QDebug debug, WirelessNetworkDevice *device)
{

View File

@ -78,6 +78,7 @@ signals:
private slots:
void accessPointAdded(const QDBusObjectPath &objectPath);
void accessPointRemoved(const QDBusObjectPath &objectPath);
void propertiesChanged(const QVariantMap &properties);
void propertiesChanged(const QString &interface_name, const QVariantMap &changed_properties, const QStringList &invalidated_properties);
private: