Browse Source

Use QElapsedTimer

adaptive-webui-19844
Thomas Piccirello 6 years ago
parent
commit
f2957c721d
  1. 8
      src/webui/api/synccontroller.cpp
  2. 4
      src/webui/api/synccontroller.h

8
src/webui/api/synccontroller.cpp

@ -329,6 +329,8 @@ SyncController::SyncController(ISessionManager *sessionManager, QObject *parent) @@ -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() @@ -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;
}

4
src/webui/api/synccontroller.h

@ -28,6 +28,8 @@ @@ -28,6 +28,8 @@
#pragma once
#include <QElapsedTimer>
#include "apicontroller.h"
struct ISessionManager;
@ -56,7 +58,7 @@ private: @@ -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;
};

Loading…
Cancel
Save