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:
parent
f5cdefb3ab
commit
1ba994bb0a
@ -142,33 +142,38 @@ QNetworkManagerNetworkInformationBackend::QNetworkManagerNetworkInformationBacke
|
||||
{
|
||||
if (!iface.isValid())
|
||||
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));
|
||||
};
|
||||
updateReachability(iface.state());
|
||||
connect(&iface, &QNetworkManagerInterface::stateChanged, this, std::move(updateReachability));
|
||||
}
|
||||
|
||||
auto updateBehindCaptivePortal = [this](QNetworkManagerInterface::NMConnectivityState state) {
|
||||
const bool behindPortal = (state == QNetworkManagerInterface::NM_CONNECTIVITY_PORTAL);
|
||||
void QNetworkManagerNetworkInformationBackend::onConnectivityChanged(
|
||||
QNetworkManagerInterface::NMConnectivityState connectivityState)
|
||||
{
|
||||
const bool behindPortal =
|
||||
(connectivityState == QNetworkManagerInterface::NM_CONNECTIVITY_PORTAL);
|
||||
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));
|
||||
};
|
||||
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));
|
||||
};
|
||||
updateMetered(iface.meteredState());
|
||||
connect(&iface, &QNetworkManagerInterface::meteredChanged, this, std::move(updateMetered));
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
|
@ -44,6 +44,11 @@ public:
|
||||
|
||||
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:
|
||||
Q_DISABLE_COPY_MOVE(QNetworkManagerNetworkInformationBackend)
|
||||
|
||||
|
@ -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
|
||||
|
||||
#include "qnetworkmanagerservice.h"
|
||||
#include "qnetworkmanagernetworkinformationbackend.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QList>
|
||||
@ -173,6 +174,11 @@ auto QNetworkManagerInterface::extractDeviceMetered(const QDBusObjectPath &devic
|
||||
return static_cast<NMMetered>(metered.toUInt());
|
||||
}
|
||||
|
||||
void QNetworkManagerInterface::setBackend(QNetworkManagerNetworkInformationBackend *ourBackend)
|
||||
{
|
||||
backend = ourBackend;
|
||||
}
|
||||
|
||||
void QNetworkManagerInterface::setProperties(const QString &interfaceName,
|
||||
const QMap<QString, QVariant> &map,
|
||||
const QStringList &invalidatedProperties)
|
||||
@ -194,16 +200,16 @@ void QNetworkManagerInterface::setProperties(const QString &interfaceName,
|
||||
if (valueChanged) {
|
||||
if (i.key() == stateKey()) {
|
||||
quint32 state = i.value().toUInt();
|
||||
Q_EMIT stateChanged(static_cast<NMState>(state));
|
||||
backend->onStateChanged(static_cast<NMState>(state));
|
||||
} else if (i.key() == connectivityKey()) {
|
||||
quint32 state = i.value().toUInt();
|
||||
Q_EMIT connectivityChanged(static_cast<NMConnectivityState>(state));
|
||||
backend->onConnectivityChanged(static_cast<NMConnectivityState>(state));
|
||||
} else if (i.key() == primaryConnectionKey()) {
|
||||
const QDBusObjectPath devicePath = i->value<QDBusObjectPath>();
|
||||
Q_EMIT deviceTypeChanged(extractDeviceType(devicePath));
|
||||
Q_EMIT meteredChanged(extractDeviceMetered(devicePath));
|
||||
backend->onDeviceTypeChanged(extractDeviceType(devicePath));
|
||||
backend->onMeteredChanged(extractDeviceMetered(devicePath));
|
||||
} else if (i.key() == "Metered"_L1) {
|
||||
Q_EMIT meteredChanged(static_cast<NMMetered>(i->toUInt()));
|
||||
backend->onMeteredChanged(static_cast<NMMetered>(i->toUInt()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -39,6 +39,7 @@ enum NMDeviceState {
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QDBusObjectPath;
|
||||
class QNetworkManagerNetworkInformationBackend;
|
||||
|
||||
// This tiny class exists for the purpose of seeing if NetworkManager is available without
|
||||
// initializing everything the derived/full class needs.
|
||||
@ -131,6 +132,8 @@ public:
|
||||
explicit QNetworkManagerInterface(QObject *parent = nullptr);
|
||||
~QNetworkManagerInterface();
|
||||
|
||||
void setBackend(QNetworkManagerNetworkInformationBackend *ourBackend);
|
||||
|
||||
NMState state() const;
|
||||
NMConnectivityState connectivityState() const;
|
||||
NMDeviceType deviceType() const;
|
||||
@ -138,12 +141,6 @@ public:
|
||||
|
||||
bool isValid() const { return QDBusAbstractInterface::isValid() && validDBusConnection; }
|
||||
|
||||
Q_SIGNALS:
|
||||
void stateChanged(NMState);
|
||||
void connectivityChanged(NMConnectivityState);
|
||||
void deviceTypeChanged(NMDeviceType);
|
||||
void meteredChanged(NMMetered);
|
||||
|
||||
private Q_SLOTS:
|
||||
void setProperties(const QString &interfaceName, const QMap<QString, QVariant> &map,
|
||||
const QStringList &invalidatedProperties);
|
||||
@ -157,6 +154,7 @@ private:
|
||||
std::optional<QDBusObjectPath> primaryConnectionDevicePath() const;
|
||||
|
||||
QVariantMap propertyMap;
|
||||
QNetworkManagerNetworkInformationBackend *backend = nullptr;
|
||||
bool validDBusConnection = true;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user