From 8ae97d5219cf19ea245aa3852fecb99b4ddfa28c Mon Sep 17 00:00:00 2001 From: Ioannis Christoforidis Date: Wed, 27 Nov 2019 16:39:14 +0100 Subject: generate network interfaces; only selecting one which are up and no loopback --- src/datasource/networkspeed.cpp | 4 ++-- src/speedcheck.cpp | 10 +++++++++- 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 #include +#include #include #include #include @@ -17,6 +18,13 @@ SpeedCheck::SpeedCheck(QString fileName) _fileName(fileName) { _ui->setupUi(this); + QList 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); -- cgit v1.2.3-55-g7522