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