mirror of https://github.com/kiwix/libkiwix.git
Encapsulated access to Book::m_illustration
This commit is contained in:
parent
ec5a423924
commit
7d8a83cc97
|
@ -107,10 +107,12 @@ class Book
|
||||||
void setSize(uint64_t size) { m_size = size; }
|
void setSize(uint64_t size) { m_size = size; }
|
||||||
void setDownloadId(const std::string& downloadId) { m_downloadId = downloadId; }
|
void setDownloadId(const std::string& downloadId) { m_downloadId = downloadId; }
|
||||||
|
|
||||||
private:
|
private: // functions
|
||||||
std::string getCategoryFromTags() const;
|
std::string getCategoryFromTags() const;
|
||||||
|
const Illustration& getDefaultIllustration() const;
|
||||||
|
Illustration& getMutableDefaultIllustration();
|
||||||
|
|
||||||
protected:
|
protected: // data
|
||||||
std::string m_id;
|
std::string m_id;
|
||||||
std::string m_downloadId;
|
std::string m_downloadId;
|
||||||
std::string m_path;
|
std::string m_path;
|
||||||
|
|
38
src/book.cpp
38
src/book.cpp
|
@ -102,7 +102,8 @@ void Book::update(const zim::Archive& archive) {
|
||||||
m_mediaCount = getArchiveMediaCount(archive);
|
m_mediaCount = getArchiveMediaCount(archive);
|
||||||
m_size = static_cast<uint64_t>(getArchiveFileSize(archive)) << 10;
|
m_size = static_cast<uint64_t>(getArchiveFileSize(archive)) << 10;
|
||||||
|
|
||||||
getArchiveFavicon(archive, 48, m_illustration.data, m_illustration.mimeType);
|
Illustration& favicon = getMutableDefaultIllustration();
|
||||||
|
getArchiveFavicon(archive, 48, favicon.data, favicon.mimeType);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ATTR(name) node.attribute(name).value()
|
#define ATTR(name) node.attribute(name).value()
|
||||||
|
@ -129,9 +130,10 @@ void Book::updateFromXml(const pugi::xml_node& node, const std::string& baseDir)
|
||||||
m_articleCount = strtoull(ATTR("articleCount"), 0, 0);
|
m_articleCount = strtoull(ATTR("articleCount"), 0, 0);
|
||||||
m_mediaCount = strtoull(ATTR("mediaCount"), 0, 0);
|
m_mediaCount = strtoull(ATTR("mediaCount"), 0, 0);
|
||||||
m_size = strtoull(ATTR("size"), 0, 0) << 10;
|
m_size = strtoull(ATTR("size"), 0, 0) << 10;
|
||||||
m_illustration.data = base64_decode(ATTR("favicon"));
|
Illustration& favicon = getMutableDefaultIllustration();
|
||||||
m_illustration.mimeType = ATTR("faviconMimeType");
|
favicon.data = base64_decode(ATTR("favicon"));
|
||||||
m_illustration.url = ATTR("faviconUrl");
|
favicon.mimeType = ATTR("faviconMimeType");
|
||||||
|
favicon.url = ATTR("faviconUrl");
|
||||||
try {
|
try {
|
||||||
m_downloadId = ATTR("downloadId");
|
m_downloadId = ATTR("downloadId");
|
||||||
} catch(...) {}
|
} catch(...) {}
|
||||||
|
@ -179,8 +181,9 @@ void Book::updateFromOpds(const pugi::xml_node& node, const std::string& urlHost
|
||||||
m_size = strtoull(linkNode.attribute("length").value(), 0, 0);
|
m_size = strtoull(linkNode.attribute("length").value(), 0, 0);
|
||||||
}
|
}
|
||||||
if (rel == "http://opds-spec.org/image/thumbnail") {
|
if (rel == "http://opds-spec.org/image/thumbnail") {
|
||||||
m_illustration.url = urlHost + linkNode.attribute("href").value();
|
Illustration& favicon = getMutableDefaultIllustration();
|
||||||
m_illustration.mimeType = linkNode.attribute("type").value();
|
favicon.url = urlHost + linkNode.attribute("href").value();
|
||||||
|
favicon.mimeType = linkNode.attribute("type").value();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,25 +216,36 @@ void Book::setPath(const std::string& path)
|
||||||
: path;
|
: path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Book::Illustration& Book::getDefaultIllustration() const
|
||||||
|
{
|
||||||
|
return m_illustration;
|
||||||
|
}
|
||||||
|
|
||||||
|
Book::Illustration& Book::getMutableDefaultIllustration()
|
||||||
|
{
|
||||||
|
return m_illustration;
|
||||||
|
}
|
||||||
|
|
||||||
const std::string& Book::getFavicon() const {
|
const std::string& Book::getFavicon() const {
|
||||||
if (m_illustration.data.empty() && !m_illustration.url.empty()) {
|
const Illustration& favicon = getDefaultIllustration();
|
||||||
|
if (favicon.data.empty() && !favicon.url.empty()) {
|
||||||
try {
|
try {
|
||||||
m_illustration.data = download(m_illustration.url);
|
favicon.data = download(favicon.url);
|
||||||
} catch(...) {
|
} catch(...) {
|
||||||
std::cerr << "Cannot download favicon from " << m_illustration.url;
|
std::cerr << "Cannot download favicon from " << favicon.url;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return m_illustration.data;
|
return favicon.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& Book::getFaviconUrl() const
|
const std::string& Book::getFaviconUrl() const
|
||||||
{
|
{
|
||||||
return m_illustration.url;
|
return getDefaultIllustration().url;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& Book::getFaviconMimeType() const
|
const std::string& Book::getFaviconMimeType() const
|
||||||
{
|
{
|
||||||
return m_illustration.mimeType;
|
return getDefaultIllustration().mimeType;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Book::getTagStr(const std::string& tagName) const {
|
std::string Book::getTagStr(const std::string& tagName) const {
|
||||||
|
|
Loading…
Reference in New Issue