Moved DownloadManager code across .cpp files

This commit is contained in:
Veloman Yunkan 2024-05-30 11:50:30 +04:00 committed by Kelson
parent 8fbb867270
commit fffe7586b4
2 changed files with 26 additions and 24 deletions

View File

@ -154,30 +154,6 @@ ContentManager::ContentManager(Library* library, kiwix::Downloader* downloader)
}
}
void DownloadManager::startDownloadUpdaterThread()
{
// so that DownloadInfo can be copied across threads
qRegisterMetaType<DownloadInfo>("DownloadInfo");
mp_downloadUpdaterThread = QThread::create([=]() {
while ( mp_downloadUpdaterThread != nullptr ) {
updateDownloads();
QThread::msleep(1000);
}
});
mp_downloadUpdaterThread->start();
}
DownloadManager::~DownloadManager()
{
if ( mp_downloadUpdaterThread )
{
QThread* t = mp_downloadUpdaterThread;
mp_downloadUpdaterThread = nullptr; // tell the thread to terminate
t->wait();
}
}
void ContentManager::updateModel()
{
const auto bookIds = getBookIds();

View File

@ -1,5 +1,7 @@
#include "downloadmanagement.h"
#include <QThread>
////////////////////////////////////////////////////////////////////////////////
// DowloadState
////////////////////////////////////////////////////////////////////////////////
@ -44,6 +46,30 @@ DownloadManager::DownloadManager(const Library* lib, kiwix::Downloader *download
restoreDownloads();
}
DownloadManager::~DownloadManager()
{
if ( mp_downloadUpdaterThread )
{
QThread* t = mp_downloadUpdaterThread;
mp_downloadUpdaterThread = nullptr; // tell the thread to terminate
t->wait();
}
}
void DownloadManager::startDownloadUpdaterThread()
{
// so that DownloadInfo can be copied across threads
qRegisterMetaType<DownloadInfo>("DownloadInfo");
mp_downloadUpdaterThread = QThread::create([=]() {
while ( mp_downloadUpdaterThread != nullptr ) {
updateDownloads();
QThread::msleep(1000);
}
});
mp_downloadUpdaterThread->start();
}
void DownloadManager::restoreDownloads()
{
for ( const auto& bookId : mp_library->getBookIds() ) {