From e00f02359980ea91cd760fbf3a462f7b7efa6bb8 Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Wed, 26 Jun 2024 11:17:41 +0400 Subject: [PATCH] DownloadManager::checkThatBookCanBeDownloaded() Separated checks that can be performed early (independent of aria2c services). When the download initiation is converted to a 2-stage procedure (similar to how it was done for pausing/resuming/cancelling a download) those checks better be performed synchronously in the main thread. --- src/contentmanager.cpp | 1 + src/downloadmanagement.cpp | 5 ++++- src/downloadmanagement.h | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/contentmanager.cpp b/src/contentmanager.cpp index 4178b47..065a8b1 100644 --- a/src/contentmanager.cpp +++ b/src/contentmanager.cpp @@ -513,6 +513,7 @@ void ContentManager::downloadBook(const QString &id) std::string downloadId; try { + DownloadManager::checkThatBookCanBeDownloaded(book, downloadPath); downloadId = DownloadManager::startDownload(book, downloadPath); } catch ( const KiwixAppError& err ) { showErrorBox(err, mp_view); diff --git a/src/downloadmanagement.cpp b/src/downloadmanagement.cpp index 2be8c8b..20fbab0 100644 --- a/src/downloadmanagement.cpp +++ b/src/downloadmanagement.cpp @@ -257,13 +257,16 @@ void checkThatBookCanBeSaved(const kiwix::Book& book, QString targetDir) } // unnamed namespace -std::string DownloadManager::startDownload(const kiwix::Book& book, const QString& downloadDirPath) +void DownloadManager::checkThatBookCanBeDownloaded(const kiwix::Book& book, const QString& downloadDirPath) { if ( ! DownloadManager::downloadingFunctionalityAvailable() ) throwDownloadUnavailableError(); checkThatBookCanBeSaved(book, downloadDirPath); +} +std::string DownloadManager::startDownload(const kiwix::Book& book, const QString& downloadDirPath) +{ typedef std::vector> DownloadOptions; const std::string& url = book.getUrl(); diff --git a/src/downloadmanagement.h b/src/downloadmanagement.h index 0509b78..07d0e73 100644 --- a/src/downloadmanagement.h +++ b/src/downloadmanagement.h @@ -156,6 +156,10 @@ public: // functions void addRequest(Action action, QString bookId); + // Throws a KiwixAppError in case of any foreseeable problem preventing a + // successful download + void checkThatBookCanBeDownloaded(const kiwix::Book& book, const QString& downloadDirPath); + // returns the download id std::string startDownload(const kiwix::Book& book, const QString& downloadDirPath); void removeDownload(QString bookId);