Extracted ContentManager::startDownload()

Extracted from ContentManager::downloadBook() the part that should be
executed asynchronously into a new function
`ContentManager::startDownload()`.
This commit is contained in:
Veloman Yunkan 2024-06-26 11:35:38 +04:00 committed by Kelson
parent e00f023599
commit 426f13a915
2 changed files with 16 additions and 1 deletions

View File

@ -511,9 +511,23 @@ void ContentManager::downloadBook(const QString &id)
kiwix::Book book = getRemoteOrLocalBook(id); kiwix::Book book = getRemoteOrLocalBook(id);
const auto downloadPath = getSettingsManager()->getDownloadDir(); const auto downloadPath = getSettingsManager()->getDownloadDir();
std::string downloadId;
try { try {
DownloadManager::checkThatBookCanBeDownloaded(book, downloadPath); DownloadManager::checkThatBookCanBeDownloaded(book, downloadPath);
} catch ( const KiwixAppError& err ) {
showErrorBox(err, mp_view);
return;
}
startDownload(id);
}
void ContentManager::startDownload(QString id)
{
kiwix::Book book = getRemoteOrLocalBook(id);
const auto downloadPath = getSettingsManager()->getDownloadDir();
std::string downloadId;
try {
downloadId = DownloadManager::startDownload(book, downloadPath); downloadId = DownloadManager::startDownload(book, downloadPath);
} catch ( const KiwixAppError& err ) { } catch ( const KiwixAppError& err ) {
showErrorBox(err, mp_view); showErrorBox(err, mp_view);

View File

@ -118,6 +118,7 @@ private: // functions
const kiwix::Book& getRemoteOrLocalBook(const QString &id); const kiwix::Book& getRemoteOrLocalBook(const QString &id);
QString getRemoteLibraryUrl() const; QString getRemoteLibraryUrl() const;
void startDownload(QString bookId);
void removeDownload(QString bookId); void removeDownload(QString bookId);
void downloadDisappeared(QString bookId); void downloadDisappeared(QString bookId);
void downloadCompleted(QString bookId, QString path); void downloadCompleted(QString bookId, QString path);