From b112c1b34cf34cfada88879879abf0a5339c42d2 Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Sun, 11 Feb 2024 15:46:48 +0400 Subject: [PATCH] Bugfix: completed downloads are removed The commit "Moved download deregistration to ContentManager" introduced a bug - completed downloads were not properly deregistered. Note that a simpler fix by adding a single `m_downloads.remove(bookId);` line in `ContentManager::downloadCompleted()` didn't work (which means that that function is not always called upon download completion). I am not going to investigate that issue now, hoping that it will be automatically resolved once the redesign of download management is finished. --- src/contentmanager.cpp | 4 +++- src/contentmanagermodel.cpp | 6 ++++-- src/contentmanagermodel.h | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/contentmanager.cpp b/src/contentmanager.cpp index 622a6ff..c31d2e6 100644 --- a/src/contentmanager.cpp +++ b/src/contentmanager.cpp @@ -486,7 +486,9 @@ void ContentManager::updateDownload(QString bookId) if ( downloadState && !downloadState->paused ) { // This calls ContentManager::updateDownloadInfos() in a convoluted way // and also has some other side-effects - managerModel->updateDownload(bookId); + if ( ! managerModel->updateDownload(bookId) ) { + m_downloads.remove(bookId); + } } } diff --git a/src/contentmanagermodel.cpp b/src/contentmanagermodel.cpp index e39c547..4dfc6de 100644 --- a/src/contentmanagermodel.cpp +++ b/src/contentmanagermodel.cpp @@ -245,12 +245,12 @@ void ContentManagerModel::updateImage(QString bookId, QString url, QByteArray im emit dataChanged(index, index); } -void ContentManagerModel::updateDownload(QString bookId) +bool ContentManagerModel::updateDownload(QString bookId) { const auto download = m_downloads.value(bookId); if ( ! download ) - return; + return true; const auto downloadInfos = KiwixApp::instance()->getContentManager()->updateDownloadInfos(bookId, {"status", "completedLength", "totalLength", "downloadSpeed"}); const bool downloadStillValid = download->update(downloadInfos); @@ -269,8 +269,10 @@ void ContentManagerModel::updateDownload(QString bookId) const QModelIndex newIndex = this->index(row, 5); emit dataChanged(newIndex, newIndex); } + return downloadStillValid; } + void ContentManagerModel::pauseDownload(QModelIndex index) { emit dataChanged(index, index); diff --git a/src/contentmanagermodel.h b/src/contentmanagermodel.h index bfc0e52..f7f67f9 100644 --- a/src/contentmanagermodel.h +++ b/src/contentmanagermodel.h @@ -50,7 +50,7 @@ public slots: void pauseDownload(QModelIndex index); void resumeDownload(QModelIndex index); void removeDownload(QString bookId); - void updateDownload(QString bookId); + bool updateDownload(QString bookId); protected: // functions bool canFetchMore(const QModelIndex &parent) const override;