QNI NetworkManager: Small refactorings and correctness fix
Extract and reuse a lambda for initialization and slot object. Pass a QDBusObjectPath parameter by const-ref. Avoid implicit ascii-to-utf16 string conversion. Change-Id: I591ae6e58e010ccabcf9012db866949492e0191d Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Marc Mutz <marc.mutz@qt.io>bb10
parent
33df48f957
commit
4a3996e98b
|
|
@ -204,32 +204,26 @@ private:
|
|||
|
||||
QNetworkManagerNetworkInformationBackend::QNetworkManagerNetworkInformationBackend()
|
||||
{
|
||||
using NMState = QNetworkManagerInterface::NMState;
|
||||
setReachability(reachabilityFromNMState(iface.state()));
|
||||
connect(&iface, &QNetworkManagerInterface::stateChanged, this,
|
||||
[this](NMState newState) {
|
||||
setReachability(reachabilityFromNMState(newState));
|
||||
});
|
||||
|
||||
using ConnectivityState = QNetworkManagerInterface::NMConnectivityState;
|
||||
|
||||
const auto connectivityState = iface.connectivityState();
|
||||
const bool behindPortal = (connectivityState == ConnectivityState::NM_CONNECTIVITY_PORTAL);
|
||||
setBehindCaptivePortal(behindPortal);
|
||||
auto updateReachability = [this](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);
|
||||
setBehindCaptivePortal(behindPortal);
|
||||
};
|
||||
updateBehindCaptivePortal(iface.connectivityState());
|
||||
connect(&iface, &QNetworkManagerInterface::connectivityChanged, this,
|
||||
[this](ConnectivityState state) {
|
||||
const bool behindPortal = (state == ConnectivityState::NM_CONNECTIVITY_PORTAL);
|
||||
setBehindCaptivePortal(behindPortal);
|
||||
});
|
||||
|
||||
using NMDeviceType = QNetworkManagerInterface::NMDeviceType;
|
||||
setTransportMedium(transportMediumFromDeviceType(iface.deviceType()));
|
||||
std::move(updateBehindCaptivePortal));
|
||||
|
||||
auto updateTransportMedium = [this](QNetworkManagerInterface::NMDeviceType newDevice) {
|
||||
setTransportMedium(transportMediumFromDeviceType(newDevice));
|
||||
};
|
||||
updateTransportMedium(iface.deviceType());
|
||||
connect(&iface, &QNetworkManagerInterface::deviceTypeChanged, this,
|
||||
[this](NMDeviceType newDevice) {
|
||||
setTransportMedium(transportMediumFromDeviceType(newDevice));
|
||||
});
|
||||
std::move(updateTransportMedium));
|
||||
|
||||
auto updateMetered = [this](QNetworkManagerInterface::NMMetered metered) {
|
||||
setMetered(isMeteredFromNMMetered(metered));
|
||||
|
|
|
|||
|
|
@ -137,7 +137,7 @@ static QDBusInterface getPrimaryDevice(const QDBusObjectPath &devicePath)
|
|||
|
||||
auto QNetworkManagerInterface::deviceType() const -> NMDeviceType
|
||||
{
|
||||
auto it = propertyMap.constFind("PrimaryConnection");
|
||||
auto it = propertyMap.constFind(u"PrimaryConnection"_qs);
|
||||
if (it != propertyMap.cend())
|
||||
return extractDeviceType(it->value<QDBusObjectPath>());
|
||||
return NM_DEVICE_TYPE_UNKNOWN;
|
||||
|
|
@ -151,7 +151,8 @@ auto QNetworkManagerInterface::meteredState() const -> NMMetered
|
|||
return NM_METERED_UNKNOWN;
|
||||
}
|
||||
|
||||
auto QNetworkManagerInterface::extractDeviceType(QDBusObjectPath devicePath) const -> NMDeviceType
|
||||
auto QNetworkManagerInterface::extractDeviceType(const QDBusObjectPath &devicePath) const
|
||||
-> NMDeviceType
|
||||
{
|
||||
QDBusInterface primaryDevice = getPrimaryDevice(devicePath);
|
||||
if (!primaryDevice.isValid())
|
||||
|
|
|
|||
|
|
@ -181,7 +181,7 @@ private Q_SLOTS:
|
|||
private:
|
||||
Q_DISABLE_COPY_MOVE(QNetworkManagerInterface)
|
||||
|
||||
NMDeviceType extractDeviceType(QDBusObjectPath devicePath) const;
|
||||
NMDeviceType extractDeviceType(const QDBusObjectPath &devicePath) const;
|
||||
NMMetered extractDeviceMetered(const QDBusObjectPath &devicePath) const;
|
||||
|
||||
QVariantMap propertyMap;
|
||||
|
|
|
|||
Loading…
Reference in New Issue