summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIoannis Christoforidis2019-11-27 16:39:14 +0100
committerIoannis Christoforidis2019-11-27 16:39:14 +0100
commit8ae97d5219cf19ea245aa3852fecb99b4ddfa28c (patch)
tree5616adcd4f7bc6dce28409ee9840a3856fa1c532
parentsmall Interface changes; make network interface changeable (diff)
downloadspeedcheck-8ae97d5219cf19ea245aa3852fecb99b4ddfa28c.tar.gz
speedcheck-8ae97d5219cf19ea245aa3852fecb99b4ddfa28c.tar.xz
speedcheck-8ae97d5219cf19ea245aa3852fecb99b4ddfa28c.zip
generate network interfaces; only selecting one which are up and no loopback
-rw-r--r--src/datasource/networkspeed.cpp4
-rw-r--r--src/speedcheck.cpp10
2 files changed, 11 insertions, 3 deletions
diff --git a/src/datasource/networkspeed.cpp b/src/datasource/networkspeed.cpp
index 8888fd4..0ebd26d 100644
--- a/src/datasource/networkspeed.cpp
+++ b/src/datasource/networkspeed.cpp
@@ -1,9 +1,9 @@
#include "networkspeed.h"
-NetworkSpeed::NetworkSpeed() :
+NetworkSpeed::NetworkSpeed(QString iface) :
_lastBytes(0),
_lastMs(0),
- _file("/sys/class/net/eth0/statistics/rx_bytes")
+ _file("/sys/class/net/" + iface + "/statistics/rx_bytes")
{
_timer.start();
}
diff --git a/src/speedcheck.cpp b/src/speedcheck.cpp
index b4dd718..882eeab 100644
--- a/src/speedcheck.cpp
+++ b/src/speedcheck.cpp
@@ -6,6 +6,7 @@
#include <QCoreApplication>
#include <QMessageBox>
+#include <QNetworkInterface>
#include <QFile>
#include <QDebug>
#include <QTimer>
@@ -17,6 +18,13 @@ SpeedCheck::SpeedCheck(QString fileName)
_fileName(fileName)
{
_ui->setupUi(this);
+ QList<QNetworkInterface> interfaces = QNetworkInterface::allInterfaces();
+ foreach (QNetworkInterface iface, interfaces) {
+ if ((iface.flags().testFlag(QNetworkInterface::IsUp)) && !iface.flags().testFlag(QNetworkInterface::IsLoopBack)) {
+ _ui->comboBox->addItem(iface.name());
+ }
+ }
+
connect(_ui->btnStart, SIGNAL(clicked(bool)), this, SLOT(startClicked(bool)));
connect(_ui->btnQuit, SIGNAL(clicked(bool)), this, SLOT(quitClicked(bool)));
_timer.setInterval(200);
@@ -43,7 +51,7 @@ void SpeedCheck::startClicked(bool)
return;
}
_ui->picCpu->setDataSource(new CpuLoad());
- _ui->picSpeed->setDataSource(new NetworkSpeed());
+ _ui->picSpeed->setDataSource(new NetworkSpeed(_ui->comboBox->currentText()));
_ui->btnStart->setDisabled(true);
delete _thread;
_thread = new CopyThread(file, this);