-
Notifications
You must be signed in to change notification settings - Fork 0
/
widget.h
86 lines (67 loc) · 1.71 KB
/
widget.h
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
#ifndef WIDGET_H
#define WIDGET_H
#include <map>
#include <thread>
#include <atomic>
#include <QSystemTrayIcon>
#include <QActionGroup>
#include <QObject>
#include <QMenu>
#include <QList>
#include "Pinger/Pinger.h"
class QTimer;
class QAction;
class QNetworkAddressEntry;
class Widget : public QObject
{
Q_OBJECT
public:
Widget();
~Widget();
void showIcon();
private slots:
void onTimerEvent();
void onUpdateTrayMenu();
void onSetInterfaceActive(QAction *sender);
signals:
void updateTrayMenu();
private:
bool setupNetworkInterface(std::vector<QNetworkAddressEntry> &interfaces);
void setupPersistentMenu(const std::vector<QNetworkAddressEntry> &interfaces);
std::vector<QNetworkAddressEntry> getFilteredAddressEntries();
class NetworkState
{
public:
enum State
{
Good,
NoInternetAccess,
NoLocalNetAccess,
Invalid
};
NetworkState(QSystemTrayIcon *icon) : currState(Invalid), icon(icon) {}
NetworkState& operator=(const State &state);
private:
State currState;
QSystemTrayIcon *icon;
};
QSystemTrayIcon trayIcon;
QMenu trayContextMenu;
NetworkState currentState;
Pinger pinger;
typedef quint32 NodeAddr;
typedef quint32 ThrustLevel;
typedef std::map< NodeAddr, ThrustLevel > PresentNodes;
PresentNodes presentNodes;
QActionGroup persistentActionGroup;
QList<QAction*> temporaryActionsList;
std::thread pingerThread;
std::atomic_bool threadWorking;
QTimer *timer;
quint32 srcIpv4;
quint32 netStartIpv4;
quint32 netEndIpv4;
static const ThrustLevel maxThrustLevel = 2;
void stopScan();
};
#endif // WIDGET_H