-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
83 lines (63 loc) · 1.93 KB
/
mainwindow.cpp
File metadata and controls
83 lines (63 loc) · 1.93 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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "routehandler.h"
#include <QtNetwork/QHostAddress>
#include <QSystemTrayIcon>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
// Load Icons for system tray icon
slowIcon = QIcon("./slowicon.png");
fastIcon = QIcon("./fasticon.png");
metricDisabled = 200;
metricEnabled = 2;
// Add tray icon to system tray
trayIcon = new QSystemTrayIcon(slowIcon, this);
trayIcon->show();
isSlowNet = true;
// Instantate route handler
routeHander = RouteHandler();
firstRoute = QHostAddress("192.168.1.1");
secondRoute = QHostAddress("192.168.1.2");
routeHander.deleteGateways();
routeHander.addRoute(firstRoute, metricEnabled);
routeHander.addRoute(secondRoute, metricDisabled);
}
MainWindow::~MainWindow()
{
delete ui;
delete trayIcon;
}
void MainWindow::on_pushButton_clicked()
{
on_trayicon_activated(QSystemTrayIcon::DoubleClick);
}
void MainWindow::on_trayicon_activated(QSystemTrayIcon::ActivationReason reason) {
// Toggle gateways on double click and change icon
if (reason == QSystemTrayIcon::DoubleClick) {
routeHander.deleteGateways();
if (isSlowNet) {
routeHander.addRoute(secondRoute, metricEnabled);
routeHander.addRoute(firstRoute, metricDisabled);
trayIcon->setIcon(fastIcon);
isSlowNet = false;
} else {
routeHander.addRoute(firstRoute, metricEnabled);
routeHander.addRoute(secondRoute, metricDisabled);
trayIcon->setIcon(slowIcon);
isSlowNet = true;
}
} else if (reason == QSystemTrayIcon::MiddleClick) {
show();
}
}
void MainWindow::on_menu_settings_triggered() {
// SettingsWindow settings;
}
void MainWindow::on_actionSettings_triggered()
{
settings.setModal(true);
settings.exec();
}