Fix qWarnings Could not connect "org.freedesktop.NetworkManager" [...]

Could not connect "org.freedesktop.NetworkManager" to "stateChanged" : Type not registered with QtDBus in parameter list: QNetworkManagerInterface::NMState
Could not connect "org.freedesktop.NetworkManager" to "connectivityChanged" : Type not registered with QtDBus in parameter list: QNetworkManagerInterface::NMConnectivityState
Could not connect "org.freedesktop.NetworkManager" to "deviceTypeChanged" : Type not registered with QtDBus in parameter list: QNetworkManagerInterface::NMDeviceType
Could not connect "org.freedesktop.NetworkManager" to "meteredChanged" : Type not registered with QtDBus in parameter list: QNetworkManagerInterface::NMMetered

These came from the fact that QDBus reimplements connectNotify() to
detect connections to a dbus interface's signals. It was triggered
also when connecting to "normal" signals from the dbus interface
subclass QNetworkManagerInterface, leading to those (new) warnings.

The fix in this commit replaces signals with direct method calls,
given that the two classes are internal and that QNetworkManagerInterface
is only used by QNetworkManagerNetworkInformationBackend (and now
vice-versa too).

Change-Id: Ifef3f65ab8e4e21a2f7fdba7fa5f0fc566153649
Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
(cherry picked from commit cb9b46ef70f06c51aea01e83dd07d21a56627a50)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
David Faure 2023-12-27 22:50:35 +01:00 committed by Qt Cherry-pick Bot
parent f5cdefb3ab
commit 1ba994bb0a
4 changed files with 51 additions and 37 deletions

View File

@ -142,33 +142,38 @@ QNetworkManagerNetworkInformationBackend::QNetworkManagerNetworkInformationBacke
{ {
if (!iface.isValid()) if (!iface.isValid())
return; return;
auto updateReachability = [this](QNetworkManagerInterface::NMState newState) { iface.setBackend(this);
onStateChanged(iface.state());
onConnectivityChanged(iface.connectivityState());
onDeviceTypeChanged(iface.deviceType());
onMeteredChanged(iface.meteredState());
}
void QNetworkManagerNetworkInformationBackend::onStateChanged(
QNetworkManagerInterface::NMState newState)
{
setReachability(reachabilityFromNMState(newState)); setReachability(reachabilityFromNMState(newState));
}; }
updateReachability(iface.state());
connect(&iface, &QNetworkManagerInterface::stateChanged, this, std::move(updateReachability));
auto updateBehindCaptivePortal = [this](QNetworkManagerInterface::NMConnectivityState state) { void QNetworkManagerNetworkInformationBackend::onConnectivityChanged(
const bool behindPortal = (state == QNetworkManagerInterface::NM_CONNECTIVITY_PORTAL); QNetworkManagerInterface::NMConnectivityState connectivityState)
{
const bool behindPortal =
(connectivityState == QNetworkManagerInterface::NM_CONNECTIVITY_PORTAL);
setBehindCaptivePortal(behindPortal); setBehindCaptivePortal(behindPortal);
}; }
updateBehindCaptivePortal(iface.connectivityState());
connect(&iface, &QNetworkManagerInterface::connectivityChanged, this,
std::move(updateBehindCaptivePortal));
auto updateTransportMedium = [this](QNetworkManagerInterface::NMDeviceType newDevice) { void QNetworkManagerNetworkInformationBackend::onDeviceTypeChanged(
QNetworkManagerInterface::NMDeviceType newDevice)
{
setTransportMedium(transportMediumFromDeviceType(newDevice)); setTransportMedium(transportMediumFromDeviceType(newDevice));
}; }
updateTransportMedium(iface.deviceType());
connect(&iface, &QNetworkManagerInterface::deviceTypeChanged, this,
std::move(updateTransportMedium));
auto updateMetered = [this](QNetworkManagerInterface::NMMetered metered) { void QNetworkManagerNetworkInformationBackend::onMeteredChanged(
QNetworkManagerInterface::NMMetered metered)
{
setMetered(isMeteredFromNMMetered(metered)); setMetered(isMeteredFromNMMetered(metered));
}; };
updateMetered(iface.meteredState());
connect(&iface, &QNetworkManagerInterface::meteredChanged, this, std::move(updateMetered));
}
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -44,6 +44,11 @@ public:
bool isValid() const { return iface.isValid(); } bool isValid() const { return iface.isValid(); }
void onStateChanged(QNetworkManagerInterface::NMState state);
void onConnectivityChanged(QNetworkManagerInterface::NMConnectivityState connectivityState);
void onDeviceTypeChanged(QNetworkManagerInterface::NMDeviceType deviceType);
void onMeteredChanged(QNetworkManagerInterface::NMMetered metered);
private: private:
Q_DISABLE_COPY_MOVE(QNetworkManagerNetworkInformationBackend) Q_DISABLE_COPY_MOVE(QNetworkManagerNetworkInformationBackend)

View File

@ -2,6 +2,7 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qnetworkmanagerservice.h" #include "qnetworkmanagerservice.h"
#include "qnetworkmanagernetworkinformationbackend.h"
#include <QObject> #include <QObject>
#include <QList> #include <QList>
@ -173,6 +174,11 @@ auto QNetworkManagerInterface::extractDeviceMetered(const QDBusObjectPath &devic
return static_cast<NMMetered>(metered.toUInt()); return static_cast<NMMetered>(metered.toUInt());
} }
void QNetworkManagerInterface::setBackend(QNetworkManagerNetworkInformationBackend *ourBackend)
{
backend = ourBackend;
}
void QNetworkManagerInterface::setProperties(const QString &interfaceName, void QNetworkManagerInterface::setProperties(const QString &interfaceName,
const QMap<QString, QVariant> &map, const QMap<QString, QVariant> &map,
const QStringList &invalidatedProperties) const QStringList &invalidatedProperties)
@ -194,16 +200,16 @@ void QNetworkManagerInterface::setProperties(const QString &interfaceName,
if (valueChanged) { if (valueChanged) {
if (i.key() == stateKey()) { if (i.key() == stateKey()) {
quint32 state = i.value().toUInt(); quint32 state = i.value().toUInt();
Q_EMIT stateChanged(static_cast<NMState>(state)); backend->onStateChanged(static_cast<NMState>(state));
} else if (i.key() == connectivityKey()) { } else if (i.key() == connectivityKey()) {
quint32 state = i.value().toUInt(); quint32 state = i.value().toUInt();
Q_EMIT connectivityChanged(static_cast<NMConnectivityState>(state)); backend->onConnectivityChanged(static_cast<NMConnectivityState>(state));
} else if (i.key() == primaryConnectionKey()) { } else if (i.key() == primaryConnectionKey()) {
const QDBusObjectPath devicePath = i->value<QDBusObjectPath>(); const QDBusObjectPath devicePath = i->value<QDBusObjectPath>();
Q_EMIT deviceTypeChanged(extractDeviceType(devicePath)); backend->onDeviceTypeChanged(extractDeviceType(devicePath));
Q_EMIT meteredChanged(extractDeviceMetered(devicePath)); backend->onMeteredChanged(extractDeviceMetered(devicePath));
} else if (i.key() == "Metered"_L1) { } else if (i.key() == "Metered"_L1) {
Q_EMIT meteredChanged(static_cast<NMMetered>(i->toUInt())); backend->onMeteredChanged(static_cast<NMMetered>(i->toUInt()));
} }
} }
} }

View File

@ -39,6 +39,7 @@ enum NMDeviceState {
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QDBusObjectPath; class QDBusObjectPath;
class QNetworkManagerNetworkInformationBackend;
// This tiny class exists for the purpose of seeing if NetworkManager is available without // This tiny class exists for the purpose of seeing if NetworkManager is available without
// initializing everything the derived/full class needs. // initializing everything the derived/full class needs.
@ -131,6 +132,8 @@ public:
explicit QNetworkManagerInterface(QObject *parent = nullptr); explicit QNetworkManagerInterface(QObject *parent = nullptr);
~QNetworkManagerInterface(); ~QNetworkManagerInterface();
void setBackend(QNetworkManagerNetworkInformationBackend *ourBackend);
NMState state() const; NMState state() const;
NMConnectivityState connectivityState() const; NMConnectivityState connectivityState() const;
NMDeviceType deviceType() const; NMDeviceType deviceType() const;
@ -138,12 +141,6 @@ public:
bool isValid() const { return QDBusAbstractInterface::isValid() && validDBusConnection; } bool isValid() const { return QDBusAbstractInterface::isValid() && validDBusConnection; }
Q_SIGNALS:
void stateChanged(NMState);
void connectivityChanged(NMConnectivityState);
void deviceTypeChanged(NMDeviceType);
void meteredChanged(NMMetered);
private Q_SLOTS: private Q_SLOTS:
void setProperties(const QString &interfaceName, const QMap<QString, QVariant> &map, void setProperties(const QString &interfaceName, const QMap<QString, QVariant> &map,
const QStringList &invalidatedProperties); const QStringList &invalidatedProperties);
@ -157,6 +154,7 @@ private:
std::optional<QDBusObjectPath> primaryConnectionDevicePath() const; std::optional<QDBusObjectPath> primaryConnectionDevicePath() const;
QVariantMap propertyMap; QVariantMap propertyMap;
QNetworkManagerNetworkInformationBackend *backend = nullptr;
bool validDBusConnection = true; bool validDBusConnection = true;
}; };