-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNetworkMonitor.h
More file actions
88 lines (67 loc) · 2.2 KB
/
NetworkMonitor.h
File metadata and controls
88 lines (67 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#ifndef NETWORKMONITOR_H
#define NETWORKMONITOR_H
#include <QObject>
#include <QNetworkConfigurationManager>
#include <QNetworkConfiguration>
#include <QList>
#include <QNetworkSession>
#include <QPointer>
#include <QTimer>
#ifdef Q_OS_IOS
#include "ios/src/ReachabilityListener.h"
#endif
class NetworkMonitor : public QObject
#ifdef Q_OS_IOS
, private utility::ReachabilityDelegate
#endif
{
Q_OBJECT
Q_PROPERTY(bool connected READ isConnected NOTIFY connectionStateChanged)
Q_PROPERTY(QString ssid READ getSsid NOTIFY ssidChanged)
Q_PROPERTY(QString bssid READ bssid NOTIFY bssidChanged)
Q_PROPERTY(QString wlanIp READ getWlanIp NOTIFY wlanIpChanged)
Q_PROPERTY(bool onWlan READ isOnWlan NOTIFY connectionStateChanged)
Q_PROPERTY(QString description READ description NOTIFY descriptionChanged)
signals:
void currentStateChanged(const QString &state);
void connectedChanged();
void ssidChanged();
void bssidChanged();
void wlanIpChanged();
void connectionStateChanged();
void descriptionChanged();
public slots:
void netChanged(const QNetworkConfiguration &conf);
void onApplicationStateChanged(const Qt::ApplicationState state);
private slots:
void setIsOnline(bool online);
void checkBssid();
public:
static NetworkMonitor& instance();
enum ConnectionState { Disconnected, Wifi, NotWifi };
Q_ENUMS(ConnectionState)
bool isConnected() const { return mConnectionState != Disconnected; }
QString getSsid() const;
QString bssid() const;
QString getWlanIp() const;
bool isOnWlan() const { return mConnectionState == Wifi; }
private:
QNetworkConfigurationManager mgr;
QString m_state;
QPointer<QNetworkSession> session;
ConnectionState mConnectionState;
QString mLastBssid;
QTimer mTimer;
NetworkMonitor(QObject *parent = 0);
#ifdef Q_OS_IOS
void statusChanged(utility::NetworkStatus n) override;
#endif
#ifdef Q_OS_ANDROID
int getConnectionType() const;
#endif
QString getBssid() const;
QString description() const;
ConnectionState connectionState() const { return mConnectionState; }
void setConnectionState(ConnectionState connectionState);
};
#endif // NETWORKMONITOR_H