|
|
@ -32,7 +32,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
#include <QJsonObject> |
|
|
|
#include <QJsonObject> |
|
|
|
#include <QMetaObject> |
|
|
|
#include <QMetaObject> |
|
|
|
#include <QThread> |
|
|
|
#include <QThreadPool> |
|
|
|
|
|
|
|
|
|
|
|
#include "base/bittorrent/cachestatus.h" |
|
|
|
#include "base/bittorrent/cachestatus.h" |
|
|
|
#include "base/bittorrent/infohash.h" |
|
|
|
#include "base/bittorrent/infohash.h" |
|
|
@ -49,7 +49,6 @@ |
|
|
|
#include "base/utils/string.h" |
|
|
|
#include "base/utils/string.h" |
|
|
|
#include "apierror.h" |
|
|
|
#include "apierror.h" |
|
|
|
#include "freediskspacechecker.h" |
|
|
|
#include "freediskspacechecker.h" |
|
|
|
#include "isessionmanager.h" |
|
|
|
|
|
|
|
#include "serialize/serialize_torrent.h" |
|
|
|
#include "serialize/serialize_torrent.h" |
|
|
|
|
|
|
|
|
|
|
|
namespace |
|
|
|
namespace |
|
|
@ -372,15 +371,7 @@ namespace |
|
|
|
|
|
|
|
|
|
|
|
SyncController::SyncController(IApplication *app, QObject *parent) |
|
|
|
SyncController::SyncController(IApplication *app, QObject *parent) |
|
|
|
: APIController(app, parent) |
|
|
|
: APIController(app, parent) |
|
|
|
, m_freeDiskSpaceChecker {new FreeDiskSpaceChecker} |
|
|
|
|
|
|
|
, m_freeDiskSpaceThread {new QThread} |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
m_freeDiskSpaceChecker->moveToThread(m_freeDiskSpaceThread.get()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connect(m_freeDiskSpaceThread.get(), &QThread::finished, m_freeDiskSpaceChecker, &QObject::deleteLater); |
|
|
|
|
|
|
|
connect(m_freeDiskSpaceChecker, &FreeDiskSpaceChecker::checked, this, &SyncController::freeDiskSpaceSizeUpdated); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_freeDiskSpaceThread->start(); |
|
|
|
|
|
|
|
invokeChecker(); |
|
|
|
invokeChecker(); |
|
|
|
m_freeDiskSpaceElapsedTimer.start(); |
|
|
|
m_freeDiskSpaceElapsedTimer.start(); |
|
|
|
} |
|
|
|
} |
|
|
@ -595,20 +586,27 @@ void SyncController::torrentPeersAction() |
|
|
|
qint64 SyncController::getFreeDiskSpace() |
|
|
|
qint64 SyncController::getFreeDiskSpace() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (m_freeDiskSpaceElapsedTimer.hasExpired(FREEDISKSPACE_CHECK_TIMEOUT)) |
|
|
|
if (m_freeDiskSpaceElapsedTimer.hasExpired(FREEDISKSPACE_CHECK_TIMEOUT)) |
|
|
|
{ |
|
|
|
|
|
|
|
invokeChecker(); |
|
|
|
invokeChecker(); |
|
|
|
m_freeDiskSpaceElapsedTimer.restart(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return m_freeDiskSpace; |
|
|
|
return m_freeDiskSpace; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void SyncController::freeDiskSpaceSizeUpdated(qint64 freeSpaceSize) |
|
|
|
void SyncController::invokeChecker() |
|
|
|
{ |
|
|
|
{ |
|
|
|
m_freeDiskSpace = freeSpaceSize; |
|
|
|
if (m_isFreeDiskSpaceCheckerRunning) |
|
|
|
} |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
void SyncController::invokeChecker() const |
|
|
|
auto *freeDiskSpaceChecker = new FreeDiskSpaceChecker; |
|
|
|
{ |
|
|
|
connect(freeDiskSpaceChecker, &FreeDiskSpaceChecker::checked, this, [this](const qint64 freeSpaceSize) |
|
|
|
QMetaObject::invokeMethod(m_freeDiskSpaceChecker, &FreeDiskSpaceChecker::check, Qt::QueuedConnection); |
|
|
|
{ |
|
|
|
|
|
|
|
m_freeDiskSpace = freeSpaceSize; |
|
|
|
|
|
|
|
m_isFreeDiskSpaceCheckerRunning = false; |
|
|
|
|
|
|
|
m_freeDiskSpaceElapsedTimer.restart(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
connect(freeDiskSpaceChecker, &FreeDiskSpaceChecker::checked, freeDiskSpaceChecker, &QObject::deleteLater); |
|
|
|
|
|
|
|
m_isFreeDiskSpaceCheckerRunning = true; |
|
|
|
|
|
|
|
QThreadPool::globalInstance()->start([freeDiskSpaceChecker] |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
freeDiskSpaceChecker->check(); |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|