diff options
-rw-r--r-- | main.cpp | 1 | ||||
-rw-r--r-- | mainwindow.cpp | 39 | ||||
-rw-r--r-- | mainwindow.h | 8 |
3 files changed, 43 insertions, 5 deletions
@@ -4,6 +4,7 @@ | |||
4 | #include <QMetaObject> | 4 | #include <QMetaObject> |
5 | 5 | ||
6 | 6 | ||
7 | |||
7 | int main(int argc, char *argv[]) | 8 | int main(int argc, char *argv[]) |
8 | { | 9 | { |
9 | QApplication a(argc, argv); | 10 | QApplication a(argc, argv); |
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) |
diff --git a/mainwindow.h b/mainwindow.h index 305b79b..916f95b 100644 --- a/mainwindow.h +++ b/mainwindow.h | |||
@@ -26,6 +26,10 @@ | |||
26 | #include <QTimer> | 26 | #include <QTimer> |
27 | 27 | ||
28 | #include <QApplication> | 28 | #include <QApplication> |
29 | #include <QNetworkSession> | ||
30 | #include <QNetworkConfigurationManager> | ||
31 | |||
32 | |||
29 | 33 | ||
30 | namespace Ui { | 34 | namespace Ui { |
31 | class MainWindow; | 35 | class MainWindow; |
@@ -47,6 +51,7 @@ private: | |||
47 | QTimer* timer; | 51 | QTimer* timer; |
48 | void saveSettings(); | 52 | void saveSettings(); |
49 | QByteArray download(QUrl url); | 53 | QByteArray download(QUrl url); |
54 | QNetworkConfigurationManager* mgr; | ||
50 | 55 | ||
51 | 56 | ||
52 | private slots: | 57 | private slots: |
@@ -55,6 +60,9 @@ private slots: | |||
55 | void updateStatus(); | 60 | void updateStatus(); |
56 | void updateSpaceList(); | 61 | void updateSpaceList(); |
57 | void exitApplication(); | 62 | void exitApplication(); |
63 | //void stateChanged(QNetworkSession::State); | ||
64 | //void onlineStateChanged(bool); | ||
65 | void onNetworkConfigurationChanged(); | ||
58 | }; | 66 | }; |
59 | 67 | ||
60 | #endif // MAINWINDOW_H | 68 | #endif // MAINWINDOW_H |