| 1 | // Copyright (C) 2021 The Qt Company Ltd. |
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | // Qt-Security score:significant reason:default |
| 4 | |
| 5 | #ifndef QNETWORKMANAGERINFORMATIONBACKEND_H |
| 6 | #define QNETWORKMANAGERINFORMATIONBACKEND_H |
| 7 | |
| 8 | // |
| 9 | // W A R N I N G |
| 10 | // ------------- |
| 11 | // |
| 12 | // This file is not part of the Qt API. It exists purely as an |
| 13 | // implementation detail. This header file may change from version to |
| 14 | // version without notice, or even be removed. |
| 15 | // |
| 16 | // We mean it. |
| 17 | // |
| 18 | |
| 19 | #include <QtNetwork/private/qnetworkinformation_p.h> |
| 20 | #include "qnetworkmanagerservice.h" |
| 21 | |
| 22 | QT_BEGIN_NAMESPACE |
| 23 | |
| 24 | class QNetworkManagerNetworkInformationBackend : public QNetworkInformationBackend |
| 25 | { |
| 26 | Q_OBJECT |
| 27 | public: |
| 28 | QNetworkManagerNetworkInformationBackend(); |
| 29 | ~QNetworkManagerNetworkInformationBackend() = default; |
| 30 | |
| 31 | QString name() const override; |
| 32 | QNetworkInformation::Features featuresSupported() const override |
| 33 | { |
| 34 | if (!isValid()) |
| 35 | return {}; |
| 36 | return featuresSupportedStatic(); |
| 37 | } |
| 38 | |
| 39 | static QNetworkInformation::Features featuresSupportedStatic() |
| 40 | { |
| 41 | using Feature = QNetworkInformation::Feature; |
| 42 | return QNetworkInformation::Features(Feature::Reachability | Feature::CaptivePortal |
| 43 | | Feature::TransportMedium | Feature::Metered); |
| 44 | } |
| 45 | |
| 46 | bool isValid() const { return iface.isValid(); } |
| 47 | |
| 48 | void onStateChanged(QNetworkManagerInterface::NMState state); |
| 49 | void onConnectivityChanged(QNetworkManagerInterface::NMConnectivityState connectivityState); |
| 50 | void onDeviceTypeChanged(QNetworkManagerInterface::NMDeviceType deviceType); |
| 51 | void onMeteredChanged(QNetworkManagerInterface::NMMetered metered); |
| 52 | |
| 53 | private: |
| 54 | Q_DISABLE_COPY_MOVE(QNetworkManagerNetworkInformationBackend) |
| 55 | |
| 56 | QNetworkManagerInterface iface; |
| 57 | }; |
| 58 | |
| 59 | QT_END_NAMESPACE |
| 60 | |
| 61 | #endif |
| 62 |
