From ac88418638fc18144d9024702c62a6e4936ad81f Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 20 Jun 2022 16:02:07 +0200 Subject: Was not working anymore since eth0 was renamed boot0 -.- --- src/datasource/networkspeed.cpp | 24 ++++++++++++++++++------ src/datasource/networkspeed.h | 2 +- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/datasource/networkspeed.cpp b/src/datasource/networkspeed.cpp index 8888fd4..451c97e 100644 --- a/src/datasource/networkspeed.cpp +++ b/src/datasource/networkspeed.cpp @@ -3,26 +3,38 @@ NetworkSpeed::NetworkSpeed() : _lastBytes(0), _lastMs(0), - _file("/sys/class/net/eth0/statistics/rx_bytes") + _file(nullptr) { - _timer.start(); + for (QString s : QStringList() + << "/sys/class/net/boot0/statistics/rx_bytes" + << "/sys/class/net/eth0/statistics/rx_bytes" + << "/sys/class/net/br0/statistics/rx_bytes") { + if (!QFile::exists(s)) + continue; + _file = new QFile(s); + } + if (_file != nullptr) { + _timer.start(); + } } NetworkSpeed::~NetworkSpeed() { - // TODO Auto-generated destructor stub + if (_file != nullptr) { + _file->deleteLater(); + } } qint64 NetworkSpeed::read() { char buffer[500]; qint64 ret, now; - if (!_file.open(QIODevice::ReadOnly)) { + if (_file == nullptr || !_file->open(QIODevice::ReadOnly)) { return -1; } now = _timer.elapsed(); - _file.readLine(buffer, sizeof(buffer)); - _file.close(); + _file->readLine(buffer, sizeof(buffer)); + _file->close(); QString line(buffer); const qint64 counter = (qint64)line.toLongLong(); if (_lastBytes == 0) { diff --git a/src/datasource/networkspeed.h b/src/datasource/networkspeed.h index 482f4cd..7b9d3ae 100644 --- a/src/datasource/networkspeed.h +++ b/src/datasource/networkspeed.h @@ -18,7 +18,7 @@ private: qint64 _lastBytes; qint64 _lastMs; QElapsedTimer _timer; - QFile _file; + QFile* _file; }; #endif /* NETWORKSPEED_H_ */ -- cgit v1.2.3-55-g7522