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.
This commit is contained in:
Veloman Yunkan 2024-02-11 15:46:48 +04:00
parent b288f287f2
commit b112c1b34c
3 changed files with 8 additions and 4 deletions

View File

@ -486,7 +486,9 @@ void ContentManager::updateDownload(QString bookId)
if ( downloadState && !downloadState->paused ) { if ( downloadState && !downloadState->paused ) {
// This calls ContentManager::updateDownloadInfos() in a convoluted way // This calls ContentManager::updateDownloadInfos() in a convoluted way
// and also has some other side-effects // and also has some other side-effects
managerModel->updateDownload(bookId); if ( ! managerModel->updateDownload(bookId) ) {
m_downloads.remove(bookId);
}
} }
} }

View File

@ -245,12 +245,12 @@ void ContentManagerModel::updateImage(QString bookId, QString url, QByteArray im
emit dataChanged(index, index); emit dataChanged(index, index);
} }
void ContentManagerModel::updateDownload(QString bookId) bool ContentManagerModel::updateDownload(QString bookId)
{ {
const auto download = m_downloads.value(bookId); const auto download = m_downloads.value(bookId);
if ( ! download ) if ( ! download )
return; return true;
const auto downloadInfos = KiwixApp::instance()->getContentManager()->updateDownloadInfos(bookId, {"status", "completedLength", "totalLength", "downloadSpeed"}); const auto downloadInfos = KiwixApp::instance()->getContentManager()->updateDownloadInfos(bookId, {"status", "completedLength", "totalLength", "downloadSpeed"});
const bool downloadStillValid = download->update(downloadInfos); const bool downloadStillValid = download->update(downloadInfos);
@ -269,8 +269,10 @@ void ContentManagerModel::updateDownload(QString bookId)
const QModelIndex newIndex = this->index(row, 5); const QModelIndex newIndex = this->index(row, 5);
emit dataChanged(newIndex, newIndex); emit dataChanged(newIndex, newIndex);
} }
return downloadStillValid;
} }
void ContentManagerModel::pauseDownload(QModelIndex index) void ContentManagerModel::pauseDownload(QModelIndex index)
{ {
emit dataChanged(index, index); emit dataChanged(index, index);

View File

@ -50,7 +50,7 @@ public slots:
void pauseDownload(QModelIndex index); void pauseDownload(QModelIndex index);
void resumeDownload(QModelIndex index); void resumeDownload(QModelIndex index);
void removeDownload(QString bookId); void removeDownload(QString bookId);
void updateDownload(QString bookId); bool updateDownload(QString bookId);
protected: // functions protected: // functions
bool canFetchMore(const QModelIndex &parent) const override; bool canFetchMore(const QModelIndex &parent) const override;