From d4f10f9fe446da2aff65088e5236d6ffcdd034b5 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 24 Feb 2017 12:33:55 +0100 Subject: initial commit --- src/speedcheck.cpp | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 src/speedcheck.cpp (limited to 'src/speedcheck.cpp') diff --git a/src/speedcheck.cpp b/src/speedcheck.cpp new file mode 100644 index 0000000..8ff8c93 --- /dev/null +++ b/src/speedcheck.cpp @@ -0,0 +1,81 @@ +#include "speedcheck.h" +#include "ui_speedcheck.h" +#include "copythread.h" +#include "datasource/cpuload.h" +#include "datasource/networkspeed.h" + +#include +#include +#include +#include +#include + +SpeedCheck::SpeedCheck(QString fileName) + : _ui(new Ui::MainWindow), + _thread(NULL), + _doQuit(false), + _fileName(fileName) +{ + _ui->setupUi(this); + connect(_ui->btnStart, SIGNAL(clicked(bool)), this, SLOT(startClicked(bool))); + connect(_ui->btnQuit, SIGNAL(clicked(bool)), this, SLOT(quitClicked(bool))); + _timer.setInterval(200); + connect(&_timer, SIGNAL(timeout()), this, SLOT(updateTimer())); +} + +SpeedCheck::~SpeedCheck() +{ + +} + +void SpeedCheck::logMessage(QString message) +{ + qDebug() << message; + _ui->statusBar->showMessage(message); +} + +void SpeedCheck::startClicked(bool) +{ + QFile *file = new QFile(_fileName); + if (!file->open(QIODevice::ReadOnly)) { + QMessageBox::critical(this, trUtf8("Error"), trUtf8("Could not open %1 for reading.").arg(_fileName)); + return; + } + _ui->picCpu->setDataSource(new CpuLoad()); + _ui->picSpeed->setDataSource(new NetworkSpeed()); + _ui->btnStart->setDisabled(true); + delete _thread; + _thread = new CopyThread(file, this); + connect(_thread, SIGNAL(logMessage(QString)), this, SLOT(logMessage(QString)), Qt::QueuedConnection); + connect(_thread, SIGNAL(finished()), this, SLOT(testFinished()), Qt::QueuedConnection); + _timer.start(); + _thread->start(); +} + +void SpeedCheck::quitClicked(bool) +{ + if (_thread != NULL && _thread->isRunning()) { + _doQuit = true; + _thread->stop(); + } + if (_thread == NULL || !_thread->isRunning()) { + QCoreApplication::instance()->quit(); + } +} + +void SpeedCheck::testFinished() +{ + _timer.stop(); + delete _thread; + _thread = NULL; + if (_doQuit) { + QCoreApplication::instance()->quit(); + } + _ui->btnStart->setEnabled(true); +} + +void SpeedCheck::updateTimer() +{ + _ui->picCpu->readNextValue(); + _ui->picSpeed->readNextValue(); +} -- cgit v1.2.3-55-g7522