mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-23 03:58:56 -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)
|
void ContentManager::downloadBook(const QString &id)
|
||||||
{
|
{
|
||||||
if (!mp_downloader)
|
if (!mp_downloader)
|
||||||
@ -506,18 +519,13 @@ void ContentManager::downloadBook(const QString &id)
|
|||||||
|
|
||||||
const auto& book = getRemoteOrLocalBook(id);
|
const auto& book = getRemoteOrLocalBook(id);
|
||||||
|
|
||||||
auto downloadPath = KiwixApp::instance()->getSettingsManager()->getDownloadDir();
|
std::string downloadId;
|
||||||
checkEnoughStorageAvailable(book, downloadPath);
|
|
||||||
|
|
||||||
std::shared_ptr<kiwix::Download> download;
|
|
||||||
try {
|
try {
|
||||||
std::pair<std::string, std::string> downloadDir("dir", downloadPath.toStdString());
|
downloadId = startDownload(book);
|
||||||
const std::vector<std::pair<std::string, std::string>> options = { downloadDir };
|
|
||||||
download = mp_downloader->startDownload(book.getUrl(), options);
|
|
||||||
} catch (std::exception& e) {
|
} catch (std::exception& e) {
|
||||||
throwDownloadUnavailableError();
|
throwDownloadUnavailableError();
|
||||||
}
|
}
|
||||||
downloadStarted(book, download->getDid());
|
downloadStarted(book, downloadId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentManager::eraseBookFilesFromComputer(const QString dirPath, const QString fileName, const bool moveToTrash)
|
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).
|
// the remote or local library (in that order).
|
||||||
const kiwix::Book& getRemoteOrLocalBook(const QString &id);
|
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 downloadStarted(const kiwix::Book& book, const std::string& downloadId);
|
||||||
void downloadCancelled(QString bookId);
|
void downloadCancelled(QString bookId);
|
||||||
void downloadCompleted(QString bookId, QString path);
|
void downloadCompleted(QString bookId, QString path);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user