From e12715e6c4460441147b3b92c9c79f2f85860864 Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Thu, 2 May 2024 11:31:23 +0200 Subject: [PATCH] Fixed thumbnail display for books being downloaded --- src/contentmanager.cpp | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/contentmanager.cpp b/src/contentmanager.cpp index 047b6a8..2e44125 100644 --- a/src/contentmanager.cpp +++ b/src/contentmanager.cpp @@ -394,18 +394,25 @@ QVariant getBookAttribute(const kiwix::Book& b, const QString& a) ContentManager::BookInfo ContentManager::getBookInfos(QString id, const QStringList &keys) { - BookInfo values; - const kiwix::Book* b = [=]()->const kiwix::Book* { - try { - return &mp_library->getBookById(id); - } catch (...) { - try { - QMutexLocker locker(&remoteLibraryLocker); - return &mp_remoteLibrary->getBookById(id.toStdString()); - } catch(...) { return nullptr; } + const kiwix::Book* b = nullptr; + try { + b = &mp_library->getBookById(id); + if ( ! b->getDownloadId().empty() ) { + // The book is still being downloaded and has been entered into the + // local library for technical reasons only. Get the book info from + // the remote library. + b = nullptr; } - }(); + } catch (...) {} + if ( !b ) { + try { + QMutexLocker locker(&remoteLibraryLocker); + b = &mp_remoteLibrary->getBookById(id.toStdString()); + } catch(...) {} + } + + BookInfo values; for(auto& key: keys){ values.insert(key, b ? getBookAttribute(*b, key) : ""); }