Commit 8de6ba60 authored by Arjen Hiemstra's avatar Arjen Hiemstra

Make NetworkManager network backend run at a fixed update of 1000ms

Since we want to report speed per second and the daemon is now running
faster than this.
parent a3660ea8
......@@ -33,29 +33,31 @@ NetworkManagerDevice::NetworkManagerDevice(const QString &id, QSharedPointer<Net
m_statistics = m_device->deviceStatistics();
// We want to display speed in bytes per second, so use a fixed one-second
// update interval here so we are independant of the actual update rate of
// the daemon.
// Unfortunately, the statistics interface does not emit change signals if
// no change happened. This makes the change signals rather useless for our
// case because we also need to know when no change happened, so that we
// can update rate sensors to show 0. So instead use a timer and query the
// statistics every 2 seconds, updating the sensors as needed.
// statistics every second, updating the sensors as needed.
m_statisticsTimer = std::make_unique<QTimer>();
connect(m_statisticsTimer.get(), &QTimer::timeout, this, [this]() {
auto newDownload = m_statistics->rxBytes();
auto previousDownload = m_totalDownloadSensor->value().toULongLong();
if (previousDownload > 0) {
// Our update interval is 2s, so to get bytes/sec we need to divide
// by 2.
m_downloadSensor->setValue((newDownload - previousDownload) / 2.0);
m_downloadSensor->setValue(newDownload - previousDownload);
auto newUpload = m_statistics->txBytes();
auto previousUpload = m_totalUploadSensor->value().toULongLong();
if (previousUpload > 0) {
m_uploadSensor->setValue((newUpload - previousUpload) / 2.0);
m_uploadSensor->setValue(newUpload - previousUpload);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment