From ec5a4239241c852c814116d49985dbe966fcf993 Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Sun, 31 Oct 2021 16:38:21 +0400 Subject: [PATCH] Enter Book::Illustration `Book::m_favicon` and its 2 friends are replaced with a single `Book::m_illustration` data member. --- include/book.h | 15 +++++++++++---- src/book.cpp | 28 +++++++++++++--------------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/include/book.h b/include/book.h index 6378fac73..e18a8142b 100644 --- a/include/book.h +++ b/include/book.h @@ -41,7 +41,15 @@ class Reader; */ class Book { - public: + public: // types + struct Illustration + { + std::string mimeType; + std::string url; + mutable std::string data; + }; + + public: // functions Book(); ~Book(); @@ -76,6 +84,7 @@ class Book const std::string& getFavicon() const; const std::string& getFaviconUrl() const; const std::string& getFaviconMimeType() const; + const std::string& getDownloadId() const { return m_downloadId; } void setReadOnly(bool readOnly) { m_readOnly = readOnly; } @@ -122,9 +131,7 @@ class Book uint64_t m_mediaCount = 0; bool m_readOnly = false; uint64_t m_size = 0; - mutable std::string m_favicon; - std::string m_faviconUrl; - std::string m_faviconMimeType; + Illustration m_illustration; }; } diff --git a/src/book.cpp b/src/book.cpp index 01e742ca9..0ac5b6a8b 100644 --- a/src/book.cpp +++ b/src/book.cpp @@ -72,9 +72,7 @@ bool Book::update(const kiwix::Book& other) m_articleCount = other.m_articleCount; m_mediaCount = other.m_mediaCount; m_size = other.m_size; - m_favicon = other.m_favicon; - m_faviconMimeType = other.m_faviconMimeType; - m_faviconUrl = other.m_faviconUrl; + m_illustration = other.m_illustration; m_downloadId = other.m_downloadId; @@ -104,7 +102,7 @@ void Book::update(const zim::Archive& archive) { m_mediaCount = getArchiveMediaCount(archive); m_size = static_cast(getArchiveFileSize(archive)) << 10; - getArchiveFavicon(archive, 48, m_favicon, m_faviconMimeType); + getArchiveFavicon(archive, 48, m_illustration.data, m_illustration.mimeType); } #define ATTR(name) node.attribute(name).value() @@ -131,9 +129,9 @@ void Book::updateFromXml(const pugi::xml_node& node, const std::string& baseDir) m_articleCount = strtoull(ATTR("articleCount"), 0, 0); m_mediaCount = strtoull(ATTR("mediaCount"), 0, 0); m_size = strtoull(ATTR("size"), 0, 0) << 10; - m_favicon = base64_decode(ATTR("favicon")); - m_faviconMimeType = ATTR("faviconMimeType"); - m_faviconUrl = ATTR("faviconUrl"); + m_illustration.data = base64_decode(ATTR("favicon")); + m_illustration.mimeType = ATTR("faviconMimeType"); + m_illustration.url = ATTR("faviconUrl"); try { m_downloadId = ATTR("downloadId"); } catch(...) {} @@ -181,8 +179,8 @@ void Book::updateFromOpds(const pugi::xml_node& node, const std::string& urlHost m_size = strtoull(linkNode.attribute("length").value(), 0, 0); } if (rel == "http://opds-spec.org/image/thumbnail") { - m_faviconUrl = urlHost + linkNode.attribute("href").value(); - m_faviconMimeType = linkNode.attribute("type").value(); + m_illustration.url = urlHost + linkNode.attribute("href").value(); + m_illustration.mimeType = linkNode.attribute("type").value(); } } @@ -216,24 +214,24 @@ void Book::setPath(const std::string& path) } const std::string& Book::getFavicon() const { - if (m_favicon.empty() && !m_faviconUrl.empty()) { + if (m_illustration.data.empty() && !m_illustration.url.empty()) { try { - m_favicon = download(m_faviconUrl); + m_illustration.data = download(m_illustration.url); } catch(...) { - std::cerr << "Cannot download favicon from " << m_faviconUrl; + std::cerr << "Cannot download favicon from " << m_illustration.url; } } - return m_favicon; + return m_illustration.data; } const std::string& Book::getFaviconUrl() const { - return m_faviconUrl; + return m_illustration.url; } const std::string& Book::getFaviconMimeType() const { - return m_faviconMimeType; + return m_illustration.mimeType; } std::string Book::getTagStr(const std::string& tagName) const {