mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-24 04:32:15 -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;
|
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)
|
QString ContentManager::downloadBook(const QString &id)
|
||||||
{
|
{
|
||||||
if (!mp_downloader)
|
if (!mp_downloader)
|
||||||
return "";
|
return "";
|
||||||
const auto& book = [&]()->const kiwix::Book& {
|
|
||||||
try {
|
const auto& book = getRemoteOrLocalBook(id);
|
||||||
QMutexLocker locker(&remoteLibraryLocker);
|
|
||||||
return mp_remoteLibrary->getBookById(id.toStdString());
|
|
||||||
} catch (...) {
|
|
||||||
return mp_library->getBookById(id);
|
|
||||||
}
|
|
||||||
}();
|
|
||||||
auto downloadPath = KiwixApp::instance()->getSettingsManager()->getDownloadDir();
|
auto downloadPath = KiwixApp::instance()->getSettingsManager()->getDownloadDir();
|
||||||
QStorageInfo storage(downloadPath);
|
QStorageInfo storage(downloadPath);
|
||||||
auto bytesAvailable = storage.bytesAvailable();
|
auto bytesAvailable = storage.bytesAvailable();
|
||||||
if (bytesAvailable == -1 || book.getSize() > (unsigned long long) bytesAvailable) {
|
if (bytesAvailable == -1 || book.getSize() > (unsigned long long) bytesAvailable) {
|
||||||
return "storage_error";
|
return "storage_error";
|
||||||
}
|
}
|
||||||
|
|
||||||
auto booksList = mp_library->getBookIds();
|
auto booksList = mp_library->getBookIds();
|
||||||
for (auto b : booksList)
|
for (auto b : booksList) {
|
||||||
if (b.toStdString() == book.getId())
|
if (b.toStdString() == book.getId())
|
||||||
return "";
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
std::shared_ptr<kiwix::Download> download;
|
std::shared_ptr<kiwix::Download> download;
|
||||||
try {
|
try {
|
||||||
std::pair<std::string, std::string> downloadDir("dir", downloadPath.toStdString());
|
std::pair<std::string, std::string> downloadDir("dir", downloadPath.toStdString());
|
||||||
|
@ -81,6 +81,10 @@ private: // functions
|
|||||||
void setCategories();
|
void setCategories();
|
||||||
void setLanguages();
|
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 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