From 950bf7952bd31c64fb0e5536daec4c6881276d74 Mon Sep 17 00:00:00 2001 From: Max Christian Pohle Date: Mon, 30 Nov 2015 02:35:31 +0100 Subject: added network monitoring shows network errors and updates status on reconnect --- mainwindow.cpp | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) (limited to 'mainwindow.cpp') diff --git a/mainwindow.cpp b/mainwindow.cpp index 6149e0c..b27876c 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -2,6 +2,21 @@ #include "ui_mainwindow.h" #include +void MainWindow::onNetworkConfigurationChanged() +{ + qDebug() << "configuration changed\n"; + if(this->mgr->isOnline()) + { + if(this->ui->comboBox->count() == 0) + { + this->updateSpaceList(); + this->updateStatus(); + } + else + this->updateStatus(); + } +} + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) @@ -21,12 +36,30 @@ MainWindow::MainWindow(QWidget *parent) : this->timer = new QTimer(); - this->connect(this->timer, SIGNAL(timeout()), this, SLOT(updateStatus())); + this->connect(this->timer, SIGNAL(timeout()), this, SLOT(updateSpaceList())); // update every five minutes... this->timer->start(60000 * 5); //this->pixmap = new QPixmap(120, 120); //this->currentIcon = new QIcon(this->pixmap); + + this->mgr = new QNetworkConfigurationManager(); + connect(this->mgr, + SIGNAL(configurationChanged(const QNetworkConfiguration &)), + this, + SLOT(onNetworkConfigurationChanged())); + + connect(this->mgr, &QNetworkConfigurationManager::onlineStateChanged, + [=] (bool b) + { + if(!b) + { + this->qsystemtrayicon->setIcon(QIcon::fromTheme("network-error")); + this->qsystemtrayicon->showMessage("Offline", "The network connection was lost :("); + } + + }); + } MainWindow::~MainWindow() @@ -56,10 +89,6 @@ void MainWindow::updateSpaceList() } ui->comboBox->setDisabled(false); - // in case of a bad network connection the combobox might show an element - // but does not download data. clicking refresh does not solve that, because - // setCurrentIndex does not trigger a refresh in that (rare) case... - this->updateStatus(); // fixes case where setCurrentIndex does not call on_comboBox_currentIndexChanged } QJsonObject json_find(QJsonObject json, QStringList list) -- cgit v1.2.3