mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-22 03:26:05 -04:00
ContentManager::startDownload()
This commit is contained in:
parent
4b773f4c1d
commit
6ba6ad0ee8
@ -499,6 +499,19 @@ const kiwix::Book& ContentManager::getRemoteOrLocalBook(const QString &id)
|
||||
}
|
||||
}
|
||||
|
||||
std::string ContentManager::startDownload(const kiwix::Book& book)
|
||||
{
|
||||
auto downloadPath = KiwixApp::instance()->getSettingsManager()->getDownloadDir();
|
||||
checkEnoughStorageAvailable(book, downloadPath);
|
||||
|
||||
typedef std::vector<std::pair<std::string, std::string>> DownloadOptions;
|
||||
|
||||
const DownloadOptions downloadOptions{{"dir", downloadPath.toStdString()}};
|
||||
|
||||
const auto d = mp_downloader->startDownload(book.getUrl(), downloadOptions);
|
||||
return d->getDid();
|
||||
}
|
||||
|
||||
void ContentManager::downloadBook(const QString &id)
|
||||
{
|
||||
if (!mp_downloader)
|
||||
@ -506,18 +519,13 @@ void ContentManager::downloadBook(const QString &id)
|
||||
|
||||
const auto& book = getRemoteOrLocalBook(id);
|
||||
|
||||
auto downloadPath = KiwixApp::instance()->getSettingsManager()->getDownloadDir();
|
||||
checkEnoughStorageAvailable(book, downloadPath);
|
||||
|
||||
std::shared_ptr<kiwix::Download> download;
|
||||
std::string downloadId;
|
||||
try {
|
||||
std::pair<std::string, std::string> downloadDir("dir", downloadPath.toStdString());
|
||||
const std::vector<std::pair<std::string, std::string>> options = { downloadDir };
|
||||
download = mp_downloader->startDownload(book.getUrl(), options);
|
||||
downloadId = startDownload(book);
|
||||
} catch (std::exception& e) {
|
||||
throwDownloadUnavailableError();
|
||||
}
|
||||
downloadStarted(book, download->getDid());
|
||||
downloadStarted(book, downloadId);
|
||||
}
|
||||
|
||||
void ContentManager::eraseBookFilesFromComputer(const QString dirPath, const QString fileName, const bool moveToTrash)
|
||||
|
@ -85,6 +85,7 @@ private: // functions
|
||||
// the remote or local library (in that order).
|
||||
const kiwix::Book& getRemoteOrLocalBook(const QString &id);
|
||||
|
||||
std::string startDownload(const kiwix::Book& book);
|
||||
void downloadStarted(const kiwix::Book& book, const std::string& downloadId);
|
||||
void downloadCancelled(QString bookId);
|
||||
void downloadCompleted(QString bookId, QString path);
|
||||
|
Loading…
x
Reference in New Issue
Block a user