From f70d0b3ccdcdddc066a0765a1cb38bf0bf78a82e Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Wed, 1 May 2024 18:44:18 +0200 Subject: [PATCH] Download id is accessed directly via kiwix::Book ... whereupon `ContentManager::getBookInfos()` no longer needs to support the `downloadId` key. --- src/contentmanager.cpp | 7 +++---- src/contentmanagerdelegate.cpp | 3 +-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/contentmanager.cpp b/src/contentmanager.cpp index 313f873..d905002 100644 --- a/src/contentmanager.cpp +++ b/src/contentmanager.cpp @@ -385,7 +385,6 @@ QVariant getBookAttribute(const kiwix::Book& b, const QString& a) if ( a == "date" ) return QString::fromStdString(b.getDate()); if ( a == "url" ) return QString::fromStdString(b.getUrl()); if ( a == "name" ) return QString::fromStdString(b.getName()); - if ( a == "downloadId" ) return QString::fromStdString(b.getDownloadId()); if ( a == "favicon") return getFaviconDataOrUrl(b); if ( a == "size" ) return QString::number(b.getSize()); if ( a == "tags" ) return getBookTags(b); @@ -422,9 +421,9 @@ void ContentManager::openBookWithIndex(const QModelIndex &index) QString bookId; auto bookNode = static_cast(index.internalPointer()); bookId = bookNode->getBookId(); - // check if the book is available in local library, will throw std::out_of_range if it isn't. - mp_library->getBookById(bookId); - if (getBookInfos(bookId, {"downloadId"})["downloadId"] != "") + // throws std::out_of_range if the book isn't available in local library + const kiwix::Book& book = mp_library->getBookById(bookId); + if ( !book.getDownloadId().empty() ) return; openBook(bookId); } catch (std::out_of_range &e) {} diff --git a/src/contentmanagerdelegate.cpp b/src/contentmanagerdelegate.cpp index 1f284c5..72fc437 100644 --- a/src/contentmanagerdelegate.cpp +++ b/src/contentmanagerdelegate.cpp @@ -169,8 +169,7 @@ void ContentManagerDelegate::paint(QPainter *painter, const QStyleOptionViewItem try { const auto id = node->getBookId(); const auto book = KiwixApp::instance()->getLibrary()->getBookById(id); - if(KiwixApp::instance()->getContentManager()->getBookInfos(id, {"downloadId"})["downloadId"] != "") { - } else { + if ( book.getDownloadId().empty() ) { button.text = gt("open"); } } catch (std::out_of_range& e) {