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.
This commit is contained in:
Veloman Yunkan 2024-06-26 11:17:41 +04:00 committed by Kelson
parent b753a47fbc
commit e00f023599
3 changed files with 9 additions and 1 deletions

View File

@ -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);

View File

@ -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<std::pair<std::string, std::string>> DownloadOptions;
const std::string& url = book.getUrl();

View File

@ -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);