QNetworkInformation: Some cleanup in NetworkManager

Change-Id: I7e0fce63883019278ceb9dc757bf10ee9d77097c
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
Mårten Nordheim 2021-05-26 11:55:46 +02:00
parent 0baf172611
commit c34b596119
3 changed files with 10 additions and 14 deletions

View File

@ -101,7 +101,6 @@ private:
Q_DISABLE_COPY_MOVE(QNetworkManagerNetworkInformationBackend)
QNetworkManagerInterface iface;
QNetworkManagerInterface::NMState prevState;
};
class QNetworkManagerNetworkInformationBackendFactory : public QNetworkInformationBackendFactory
@ -137,15 +136,12 @@ private:
QNetworkManagerNetworkInformationBackend::QNetworkManagerNetworkInformationBackend()
{
prevState = iface.state();
setReachability(reachabilityFromNMState(prevState));
connect(&iface, &QNetworkManagerInterface::stateChanged, this, [this]() {
auto newState = iface.state();
if (newState != prevState) {
prevState = newState;
setReachability(reachabilityFromNMState(prevState));
}
});
using NMState = QNetworkManagerInterface::NMState;
setReachability(reachabilityFromNMState(iface.state()));
connect(&iface, &QNetworkManagerInterface::stateChanged, this,
[this](NMState newState) {
setReachability(reachabilityFromNMState(newState));
});
using ConnectivityState = QNetworkManagerInterface::NMConnectivityState;
using TriState = QNetworkInformation::TriState;

View File

@ -98,7 +98,7 @@ QNetworkManagerInterface::~QNetworkManagerInterface()
SLOT(setProperties(QMap<QString, QVariant>)));
}
QNetworkManagerInterface::NMState QNetworkManagerInterface::state()
QNetworkManagerInterface::NMState QNetworkManagerInterface::state() const
{
if (propertyMap.contains("State"))
return static_cast<QNetworkManagerInterface::NMState>(propertyMap.value("State").toUInt());
@ -131,7 +131,7 @@ void QNetworkManagerInterface::setProperties(const QMap<QString, QVariant> &map)
if (stateUpdate) {
quint32 state = i.value().toUInt();
Q_EMIT stateChanged(state);
Q_EMIT stateChanged(static_cast<NMState>(state));
} else if (connectivityUpdate) {
quint32 state = i.value().toUInt();
Q_EMIT connectivityChanged(static_cast<NMConnectivityState>(state));

View File

@ -123,11 +123,11 @@ public:
QNetworkManagerInterface(QObject *parent = nullptr);
~QNetworkManagerInterface();
NMState state();
NMState state() const;
NMConnectivityState connectivityState() const;
Q_SIGNALS:
void stateChanged(quint32);
void stateChanged(NMState);
void connectivityChanged(NMConnectivityState);
private Q_SLOTS: