diff options
author | Max Christian Pohle | 2015-11-30 02:35:31 +0100 |
---|---|---|
committer | Max Christian Pohle | 2015-11-30 02:35:31 +0100 |
commit | 950bf7952bd31c64fb0e5536daec4c6881276d74 (patch) | |
tree | e5fdd27953cc02574be56723df3ad575091d9f55 /mainwindow.cpp | |
parent | 89fada0440c1e3b72afc01cb3052995446a2857d (diff) | |
download | qspacestatus-950bf7952bd31c64fb0e5536daec4c6881276d74.tar.bz2 qspacestatus-950bf7952bd31c64fb0e5536daec4c6881276d74.zip |
added network monitoring
shows network errors and updates status on reconnect
Diffstat (limited to 'mainwindow.cpp')
-rw-r--r-- | mainwindow.cpp | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/mainwindow.cpp b/mainwindow.cpp index 6149e0c..b27876c 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp | |||
@@ -2,6 +2,21 @@ | |||
2 | #include "ui_mainwindow.h" | 2 | #include "ui_mainwindow.h" |
3 | #include <QDebug> | 3 | #include <QDebug> |
4 | 4 | ||
5 | void MainWindow::onNetworkConfigurationChanged() | ||
6 | { | ||
7 | qDebug() << "configuration changed\n"; | ||
8 | if(this->mgr->isOnline()) | ||
9 | { | ||
10 | if(this->ui->comboBox->count() == 0) | ||
11 | { | ||
12 | this->updateSpaceList(); | ||
13 | this->updateStatus(); | ||
14 | } | ||
15 | else | ||
16 | this->updateStatus(); | ||
17 | } | ||
18 | } | ||
19 | |||
5 | MainWindow::MainWindow(QWidget *parent) : | 20 | MainWindow::MainWindow(QWidget *parent) : |
6 | QMainWindow(parent), | 21 | QMainWindow(parent), |
7 | ui(new Ui::MainWindow) | 22 | ui(new Ui::MainWindow) |
@@ -21,12 +36,30 @@ MainWindow::MainWindow(QWidget *parent) : | |||
21 | 36 | ||
22 | 37 | ||
23 | this->timer = new QTimer(); | 38 | this->timer = new QTimer(); |
24 | this->connect(this->timer, SIGNAL(timeout()), this, SLOT(updateStatus())); | 39 | this->connect(this->timer, SIGNAL(timeout()), this, SLOT(updateSpaceList())); |
25 | // update every five minutes... | 40 | // update every five minutes... |
26 | this->timer->start(60000 * 5); | 41 | this->timer->start(60000 * 5); |
27 | 42 | ||
28 | //this->pixmap = new QPixmap(120, 120); | 43 | //this->pixmap = new QPixmap(120, 120); |
29 | //this->currentIcon = new QIcon(this->pixmap); | 44 | //this->currentIcon = new QIcon(this->pixmap); |
45 | |||
46 | this->mgr = new QNetworkConfigurationManager(); | ||
47 | connect(this->mgr, | ||
48 | SIGNAL(configurationChanged(const QNetworkConfiguration &)), | ||
49 | this, | ||
50 | SLOT(onNetworkConfigurationChanged())); | ||
51 | |||
52 | connect(this->mgr, &QNetworkConfigurationManager::onlineStateChanged, | ||
53 | [=] (bool b) | ||
54 | { | ||
55 | if(!b) | ||
56 | { | ||
57 | this->qsystemtrayicon->setIcon(QIcon::fromTheme("network-error")); | ||
58 | this->qsystemtrayicon->showMessage("Offline", "The network connection was lost :("); | ||
59 | } | ||
60 | |||
61 | }); | ||
62 | |||
30 | } | 63 | } |
31 | 64 | ||
32 | MainWindow::~MainWindow() | 65 | MainWindow::~MainWindow() |
@@ -56,10 +89,6 @@ void MainWindow::updateSpaceList() | |||
56 | } | 89 | } |
57 | ui->comboBox->setDisabled(false); | 90 | ui->comboBox->setDisabled(false); |
58 | 91 | ||
59 | // in case of a bad network connection the combobox might show an element | ||
60 | // but does not download data. clicking refresh does not solve that, because | ||
61 | // setCurrentIndex does not trigger a refresh in that (rare) case... | ||
62 | this->updateStatus(); // fixes case where setCurrentIndex does not call on_comboBox_currentIndexChanged | ||
63 | } | 92 | } |
64 | 93 | ||
65 | QJsonObject json_find(QJsonObject json, QStringList list) | 94 | QJsonObject json_find(QJsonObject json, QStringList list) |