QNI NetworkManager: Extract Method primaryConnectionDevicePath()
Avoids duplication of complex code (RB tree lookup). Change-Id: I70ac7095b05ee56cdf7c86dd1d1a7c9c3232c9d4 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
4a3996e98b
commit
5d19219eeb
@ -135,19 +135,25 @@ static QDBusInterface getPrimaryDevice(const QDBusObjectPath &devicePath)
|
||||
QDBusConnection::systemBus());
|
||||
}
|
||||
|
||||
auto QNetworkManagerInterface::deviceType() const -> NMDeviceType
|
||||
std::optional<QDBusObjectPath> QNetworkManagerInterface::primaryConnectionDevicePath() const
|
||||
{
|
||||
auto it = propertyMap.constFind(u"PrimaryConnection"_qs);
|
||||
if (it != propertyMap.cend())
|
||||
return extractDeviceType(it->value<QDBusObjectPath>());
|
||||
return it->value<QDBusObjectPath>();
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
auto QNetworkManagerInterface::deviceType() const -> NMDeviceType
|
||||
{
|
||||
if (const auto path = primaryConnectionDevicePath())
|
||||
return extractDeviceType(*path);
|
||||
return NM_DEVICE_TYPE_UNKNOWN;
|
||||
}
|
||||
|
||||
auto QNetworkManagerInterface::meteredState() const -> NMMetered
|
||||
{
|
||||
auto it = propertyMap.constFind(u"PrimaryConnection"_qs);
|
||||
if (it != propertyMap.cend())
|
||||
return extractDeviceMetered(it->value<QDBusObjectPath>());
|
||||
if (const auto path = primaryConnectionDevicePath())
|
||||
return extractDeviceMetered(*path);
|
||||
return NM_METERED_UNKNOWN;
|
||||
}
|
||||
|
||||
|
@ -55,6 +55,8 @@
|
||||
#include <QtDBus/QDBusPendingCallWatcher>
|
||||
#include <QtDBus/QDBusObjectPath>
|
||||
|
||||
#include <optional>
|
||||
|
||||
// Matches 'NMDeviceState' from https://developer.gnome.org/NetworkManager/stable/nm-dbus-types.html
|
||||
enum NMDeviceState {
|
||||
NM_DEVICE_STATE_UNKNOWN = 0,
|
||||
@ -184,6 +186,8 @@ private:
|
||||
NMDeviceType extractDeviceType(const QDBusObjectPath &devicePath) const;
|
||||
NMMetered extractDeviceMetered(const QDBusObjectPath &devicePath) const;
|
||||
|
||||
std::optional<QDBusObjectPath> primaryConnectionDevicePath() const;
|
||||
|
||||
QVariantMap propertyMap;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user