mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-23 03:58:56 -04:00
DownloadManager::pauseDownload()
This commit is contained in:
parent
1354363bfc
commit
24cce79c1e
@ -727,28 +727,7 @@ void ContentManager::eraseBook(const QString& id)
|
|||||||
|
|
||||||
void ContentManager::pauseBook(const QString& id, QModelIndex index)
|
void ContentManager::pauseBook(const QString& id, QModelIndex index)
|
||||||
{
|
{
|
||||||
const auto downloadId = mp_library->getBookById(id).getDownloadId();
|
DownloadManager::pauseDownload(id);
|
||||||
if ( downloadId.empty() ) {
|
|
||||||
// Completion of the download has been detected (and its id was reset)
|
|
||||||
// before the pause-download action was triggered (most likely through
|
|
||||||
// the context menu which can stay open for an arbitrarily long time,
|
|
||||||
// or, unlikely, through the ⏸ button during the last milliseconds of
|
|
||||||
// the download progress).
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto download = mp_downloader->getDownload(downloadId);
|
|
||||||
if (download->getStatus() == kiwix::Download::K_ACTIVE) {
|
|
||||||
try {
|
|
||||||
download->pauseDownload();
|
|
||||||
} catch (const kiwix::AriaError&) {
|
|
||||||
// Download has completed before the pause request was handled.
|
|
||||||
// Most likely the download was already complete at the time
|
|
||||||
// when ContentManager::pauseBook() started executing, but its
|
|
||||||
// completion was not yet detected (and/or handled) by the download
|
|
||||||
// updater thread.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
managerModel->triggerDataUpdateAt(index);
|
managerModel->triggerDataUpdateAt(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,3 +103,30 @@ DownloadInfo DownloadManager::getDownloadInfo(QString bookId) const
|
|||||||
{ "path" , QString::fromStdString(d->getPath()) }
|
{ "path" , QString::fromStdString(d->getPath()) }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DownloadManager::pauseDownload(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 pause-download action was triggered (most likely through
|
||||||
|
// the context menu which can stay open for an arbitrarily long time,
|
||||||
|
// or, unlikely, through the ⏸ button during the last milliseconds of
|
||||||
|
// the download progress).
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto download = mp_downloader->getDownload(downloadId);
|
||||||
|
if (download->getStatus() == kiwix::Download::K_ACTIVE) {
|
||||||
|
try {
|
||||||
|
download->pauseDownload();
|
||||||
|
} catch (const kiwix::AriaError&) {
|
||||||
|
// Download has completed before the pause request was handled.
|
||||||
|
// Most likely the download was already complete at the time
|
||||||
|
// when ContentManager::pauseBook() started executing, but its
|
||||||
|
// completion was not yet detected (and/or handled) by the download
|
||||||
|
// updater thread.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -73,6 +73,7 @@ public: // functions
|
|||||||
DownloadInfo getDownloadInfo(QString bookId) const;
|
DownloadInfo getDownloadInfo(QString bookId) const;
|
||||||
void restoreDownloads();
|
void restoreDownloads();
|
||||||
void updateDownloads();
|
void updateDownloads();
|
||||||
|
void pauseDownload(const QString& bookId);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void downloadUpdated(QString bookId, const DownloadInfo& );
|
void downloadUpdated(QString bookId, const DownloadInfo& );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user