From e0f79bf9f211705622499167fe28bb4181a6c93a Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Sun, 11 Feb 2024 20:11:51 +0400 Subject: [PATCH] More elegant ContentManager::updateDownload() --- src/contentmanager.cpp | 8 +++----- src/rownode.cpp | 5 ----- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/contentmanager.cpp b/src/contentmanager.cpp index d63e172..bee053a 100644 --- a/src/contentmanager.cpp +++ b/src/contentmanager.cpp @@ -418,6 +418,7 @@ void ContentManager::removeDownload(QString bookId) void ContentManager::downloadCancelled(QString bookId) { + removeDownload(bookId); kiwix::Book bCopy(mp_library->getBookById(bookId)); bCopy.setDownloadId(""); mp_library->getKiwixLibrary()->addOrUpdateBook(bCopy); @@ -427,6 +428,7 @@ void ContentManager::downloadCancelled(QString bookId) void ContentManager::downloadCompleted(QString bookId, QString path) { + removeDownload(bookId); kiwix::Book bCopy(mp_library->getBookById(bookId)); bCopy.setPath(QDir::toNativeSeparators(path).toStdString()); bCopy.setDownloadId(""); @@ -480,12 +482,8 @@ void ContentManager::updateDownload(QString bookId) downloadCancelled(bookId); } else if ( downloadInfo["status"] == "completed" ) { downloadCompleted(bookId, downloadInfo["path"].toString()); - } - - const bool downloadStillValid = downloadState->update(downloadInfo); - if ( ! downloadStillValid ) { - removeDownload(bookId); } else { + downloadState->update(downloadInfo); managerModel->updateDownload(bookId); } } diff --git a/src/rownode.cpp b/src/rownode.cpp index 2c98968..e4d0cd7 100644 --- a/src/rownode.cpp +++ b/src/rownode.cpp @@ -28,11 +28,6 @@ QString convertToUnits(QString size) bool DownloadState::update(const DownloadInfo& downloadInfos) { - if (!downloadInfos["status"].isValid()) { - *this = {0, "", "", false}; - return false; - } - double percent = downloadInfos["completedLength"].toDouble() / downloadInfos["totalLength"].toDouble(); percent *= 100; percent = QString::number(percent, 'g', 3).toDouble();