mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-21 02:51:26 -04:00
DownloadManager::cancelDownload()
This commit is contained in:
parent
28c52e7884
commit
88eb29f791
@ -744,25 +744,9 @@ void ContentManager::cancelBook(const QString& id)
|
||||
|
||||
void ContentManager::reallyCancelBook(const QString& id)
|
||||
{
|
||||
const auto downloadId = mp_library->getBookById(id).getDownloadId();
|
||||
if ( downloadId.empty() ) {
|
||||
// Completion of the download has been detected (and its id was reset)
|
||||
// before the confirmation to cancel the download was granted.
|
||||
if ( !DownloadManager::cancelDownload(id) )
|
||||
return;
|
||||
}
|
||||
|
||||
auto download = mp_downloader->getDownload(downloadId);
|
||||
try {
|
||||
download->cancelDownload();
|
||||
} catch (const kiwix::AriaError&) {
|
||||
// Download has completed before the cancel request was handled.
|
||||
// Most likely the download was already complete at the time
|
||||
// when ContentManager::reallyCancelBook() started executing, but
|
||||
// its completion was not yet detected (and/or handled) by the
|
||||
// download updater thread (letting the code pass past the empty
|
||||
// downloadId check above).
|
||||
return;
|
||||
}
|
||||
removeDownload(id);
|
||||
|
||||
// incompleted downloaded file should be perma deleted
|
||||
|
@ -148,3 +148,27 @@ void DownloadManager::resumeDownload(const QString& bookId)
|
||||
download->resumeDownload();
|
||||
}
|
||||
}
|
||||
|
||||
bool DownloadManager::cancelDownload(const QString& bookId)
|
||||
{
|
||||
const auto downloadId = mp_library->getBookById(bookId).getDownloadId();
|
||||
if ( downloadId.empty() ) {
|
||||
// Completion of the download has been detected (and its id was reset)
|
||||
// before the confirmation to cancel the download was granted.
|
||||
return false;
|
||||
}
|
||||
|
||||
auto download = mp_downloader->getDownload(downloadId);
|
||||
try {
|
||||
download->cancelDownload();
|
||||
return true;
|
||||
} catch (const kiwix::AriaError&) {
|
||||
// Download has completed before the cancel request was handled.
|
||||
// Most likely the download was already complete at the time
|
||||
// when ContentManager::reallyCancelBook() started executing, but
|
||||
// its completion was not yet detected (and/or handled) by the
|
||||
// download updater thread (letting the code pass past the empty
|
||||
// downloadId check above).
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -78,6 +78,7 @@ public: // functions
|
||||
std::string startDownload(const std::string& url, const std::string& downloadDirPath);
|
||||
void pauseDownload(const QString& bookId);
|
||||
void resumeDownload(const QString& bookId);
|
||||
bool cancelDownload(const QString& bookId);
|
||||
|
||||
signals:
|
||||
void downloadUpdated(QString bookId, const DownloadInfo& );
|
||||
|
Loading…
x
Reference in New Issue
Block a user