From fffe7586b4673d6a192c159124eefc61c378472c Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Thu, 30 May 2024 11:50:30 +0400 Subject: [PATCH] Moved DownloadManager code across .cpp files --- src/contentmanager.cpp | 24 ------------------------ src/downloadmanagement.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/contentmanager.cpp b/src/contentmanager.cpp index b9cd56a..1068656 100644 --- a/src/contentmanager.cpp +++ b/src/contentmanager.cpp @@ -154,30 +154,6 @@ ContentManager::ContentManager(Library* library, kiwix::Downloader* downloader) } } -void DownloadManager::startDownloadUpdaterThread() -{ - // so that DownloadInfo can be copied across threads - qRegisterMetaType("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(); diff --git a/src/downloadmanagement.cpp b/src/downloadmanagement.cpp index a11a7df..32112c9 100644 --- a/src/downloadmanagement.cpp +++ b/src/downloadmanagement.cpp @@ -1,5 +1,7 @@ #include "downloadmanagement.h" +#include + //////////////////////////////////////////////////////////////////////////////// // 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"); + + 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() ) {