mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-21 02:51:26 -04:00
Extracted ContentManager::getRemoteOrLocalBook()
... mainly for readability.
This commit is contained in:
parent
c70ab0ed0d
commit
a31aec56f8
@ -463,29 +463,35 @@ QString ContentManager::downloadBook(const QString &id, QModelIndex index)
|
||||
return downloadStatus;
|
||||
}
|
||||
|
||||
const kiwix::Book& ContentManager::getRemoteOrLocalBook(const QString &id)
|
||||
{
|
||||
try {
|
||||
QMutexLocker locker(&remoteLibraryLocker);
|
||||
return mp_remoteLibrary->getBookById(id.toStdString());
|
||||
} catch (...) {
|
||||
return mp_library->getBookById(id);
|
||||
}
|
||||
}
|
||||
|
||||
QString ContentManager::downloadBook(const QString &id)
|
||||
{
|
||||
if (!mp_downloader)
|
||||
return "";
|
||||
const auto& book = [&]()->const kiwix::Book& {
|
||||
try {
|
||||
QMutexLocker locker(&remoteLibraryLocker);
|
||||
return mp_remoteLibrary->getBookById(id.toStdString());
|
||||
} catch (...) {
|
||||
return mp_library->getBookById(id);
|
||||
}
|
||||
}();
|
||||
|
||||
const auto& book = getRemoteOrLocalBook(id);
|
||||
auto downloadPath = KiwixApp::instance()->getSettingsManager()->getDownloadDir();
|
||||
QStorageInfo storage(downloadPath);
|
||||
auto bytesAvailable = storage.bytesAvailable();
|
||||
if (bytesAvailable == -1 || book.getSize() > (unsigned long long) bytesAvailable) {
|
||||
return "storage_error";
|
||||
}
|
||||
|
||||
auto booksList = mp_library->getBookIds();
|
||||
for (auto b : booksList)
|
||||
for (auto b : booksList) {
|
||||
if (b.toStdString() == book.getId())
|
||||
return "";
|
||||
}
|
||||
|
||||
std::shared_ptr<kiwix::Download> download;
|
||||
try {
|
||||
std::pair<std::string, std::string> downloadDir("dir", downloadPath.toStdString());
|
||||
|
@ -81,6 +81,10 @@ private: // functions
|
||||
void setCategories();
|
||||
void setLanguages();
|
||||
|
||||
// Get the book with the specified id from
|
||||
// the remote or local library (in that order).
|
||||
const kiwix::Book& getRemoteOrLocalBook(const QString &id);
|
||||
|
||||
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