From 550604b44270f15930cbea9ae3b241f82bb2f826 Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Thu, 28 Mar 2024 12:24:49 +0400 Subject: [PATCH] Download paused state in UI set by updater thread Now the downloader paused/active state in UI is set by the updater thread. This will make it easier to restore downloads after closing and re-opening kiwix-desktop. --- src/contentmanager.cpp | 8 +------- src/rownode.cpp | 13 ++----------- src/rownode.h | 2 -- 3 files changed, 3 insertions(+), 20 deletions(-) diff --git a/src/contentmanager.cpp b/src/contentmanager.cpp index 9e6a4db..b98abe6 100644 --- a/src/contentmanager.cpp +++ b/src/contentmanager.cpp @@ -501,7 +501,7 @@ DownloadInfo ContentManager::getDownloadInfo(QString bookId) const void ContentManager::updateDownload(QString bookId, const DownloadInfo& downloadInfo) { const auto downloadState = m_downloads.value(bookId); - if ( downloadState && !downloadState->paused ) { + if ( downloadState ) { if ( downloadInfo["status"].toString() == "completed" ) { downloadCompleted(bookId, downloadInfo["path"].toString()); } else { @@ -684,9 +684,6 @@ void ContentManager::pauseBook(const QString& id, QModelIndex index) if (download->getStatus() == kiwix::Download::K_ACTIVE) { try { download->pauseDownload(); - if ( const auto downloadState = m_downloads.value(id) ) { - downloadState->pause(); - } } catch (const kiwix::AriaError&) { // Download has completed before the pause request was handled. // Most likely the download was already complete at the time @@ -704,9 +701,6 @@ void ContentManager::resumeBook(const QString& id, QModelIndex index) auto download = mp_downloader->getDownload(b.getDownloadId()); if (download->getStatus() == kiwix::Download::K_PAUSED) { download->resumeDownload(); - if ( const auto downloadState = m_downloads.value(id) ) { - downloadState->resume(); - } } managerModel->triggerDataUpdateAt(index); } diff --git a/src/rownode.cpp b/src/rownode.cpp index 57ce5ac..0ae6882 100644 --- a/src/rownode.cpp +++ b/src/rownode.cpp @@ -32,17 +32,8 @@ void DownloadState::update(const DownloadInfo& downloadInfos) percent = QString::number(percent, 'g', 3).toDouble(); auto completedLength = convertToUnits(downloadInfos["completedLength"].toDouble()); auto downloadSpeed = convertToUnits(downloadInfos["downloadSpeed"].toDouble()) + "/s"; - *this = {percent, completedLength, downloadSpeed, false}; -} - -void DownloadState::pause() -{ - this->paused = true; -} - -void DownloadState::resume() -{ - this->paused = false; + const bool paused = downloadInfos["status"] == "paused"; + *this = {percent, completedLength, downloadSpeed, paused}; } diff --git a/src/rownode.h b/src/rownode.h index f986806..f169827 100644 --- a/src/rownode.h +++ b/src/rownode.h @@ -17,8 +17,6 @@ public: bool paused = false; public: - void pause(); - void resume(); void update(const DownloadInfo& info); };