Commit 16c5713d authored by David Redondo's avatar David Redondo 🏎
Browse files

Force device statistics refresh rate to be always one second

Unfortunately the statistics refresh rate of a device is a global property. So
when it is changed from the outside we just force it back to one second. The
initial rate is saved and updated when something tries to change it in order
to restore it upon destruction.
Because NetworkmanagerQt just forwards the DBus signal we have to guard the
slot with a boolean to we do not trigger it ourselves.
BUG:433063
FIXED-IN:5.21.1


(cherry picked from commit 4b5251ad)
parent cf6195e9
......@@ -34,6 +34,21 @@ NetworkManagerDevice::NetworkManagerDevice(const QString &id, QSharedPointer<Net
m_statistics = m_device->deviceStatistics();
// We always want to have the refresh rate to be 1000ms but it's a global property. So we store
// the oustide rate. override any changes and restore it when we are destroyed.
m_initialStatisticsRate = m_statistics->refreshRateMs();
connect(m_statistics.get(), &NetworkManager::DeviceStatistics::refreshRateMsChanged, this, [this] (uint rate) {
// Unfortunately we always get a change signal even when disconnecting before the setter and
// connecting afterwards, so we have to do this and assume the first signal after a call is
// caused by it. Iniitally true because of the call below
static bool updatingRefreshRate = true;
if (!updatingRefreshRate) {
m_initialStatisticsRate = rate;
m_statistics->setRefreshRateMs(1000);
}
updatingRefreshRate = !updatingRefreshRate;
});
// 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.
......@@ -88,6 +103,8 @@ NetworkManagerDevice::NetworkManagerDevice(const QString &id, QSharedPointer<Net
NetworkManagerDevice::~NetworkManagerDevice()
{
disconnect(m_statistics.get(), nullptr, this, nullptr);
m_statistics->setRefreshRateMs(m_initialStatisticsRate);
}
void NetworkManagerDevice::update()
......
......@@ -45,6 +45,7 @@ private:
std::unique_ptr<QTimer> m_statisticsTimer;
bool m_connected = false;
bool m_restoreTimer = false;
uint m_initialStatisticsRate;
};
class NetworkManagerBackend : public NetworkBackend
......
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