From f2957c721d3d946df1302b6d83bcfc0ded753827 Mon Sep 17 00:00:00 2001 From: Thomas Piccirello Date: Mon, 22 Oct 2018 23:17:46 -0400 Subject: [PATCH] Use QElapsedTimer --- src/webui/api/synccontroller.cpp | 8 +++++--- src/webui/api/synccontroller.h | 4 +++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/webui/api/synccontroller.cpp b/src/webui/api/synccontroller.cpp index 25ed90302..86f4ccec8 100644 --- a/src/webui/api/synccontroller.cpp +++ b/src/webui/api/synccontroller.cpp @@ -329,6 +329,8 @@ SyncController::SyncController(ISessionManager *sessionManager, QObject *parent) connect(m_freeDiskSpaceChecker, &FreeDiskSpaceChecker::checked, this, &SyncController::freeDiskSpaceSizeUpdated); m_freeDiskSpaceThread->start(); + QTimer::singleShot(0, m_freeDiskSpaceChecker, &FreeDiskSpaceChecker::check); + m_freeDiskSpaceElapsedTimer.start(); } SyncController::~SyncController() @@ -512,11 +514,11 @@ void SyncController::torrentPeersAction() qint64 SyncController::getFreeDiskSpace() { - const qint64 now = QDateTime::currentMSecsSinceEpoch(); - if ((now - m_freeDiskSpaceLastUpdate) >= FREEDISKSPACE_CHECK_TIMEOUT) { + if (m_freeDiskSpaceElapsedTimer.hasExpired(FREEDISKSPACE_CHECK_TIMEOUT)) { QTimer::singleShot(0, m_freeDiskSpaceChecker, &FreeDiskSpaceChecker::check); - m_freeDiskSpaceLastUpdate = now; + m_freeDiskSpaceElapsedTimer.restart(); } + return m_freeDiskSpace; } diff --git a/src/webui/api/synccontroller.h b/src/webui/api/synccontroller.h index e839acc64..e6c48c669 100644 --- a/src/webui/api/synccontroller.h +++ b/src/webui/api/synccontroller.h @@ -28,6 +28,8 @@ #pragma once +#include + #include "apicontroller.h" struct ISessionManager; @@ -56,7 +58,7 @@ private: qint64 getFreeDiskSpace(); qint64 m_freeDiskSpace = 0; - qint64 m_freeDiskSpaceLastUpdate = 0; FreeDiskSpaceChecker *m_freeDiskSpaceChecker = nullptr; QThread *m_freeDiskSpaceThread = nullptr; + QElapsedTimer m_freeDiskSpaceElapsedTimer; };