Book::Illustration::getData()

This commit is contained in:
Veloman Yunkan 2021-10-31 17:18:45 +04:00
parent 7d8a83cc97
commit 9f0db6b7fa
2 changed files with 17 additions and 7 deletions

View File

@ -42,10 +42,16 @@ class Reader;
class Book class Book
{ {
public: // types public: // types
struct Illustration class Illustration
{ {
friend class Book;
public:
std::string mimeType; std::string mimeType;
std::string url; std::string url;
const std::string& getData() const;
private:
mutable std::string data; mutable std::string data;
}; };

View File

@ -226,16 +226,20 @@ Book::Illustration& Book::getMutableDefaultIllustration()
return m_illustration; return m_illustration;
} }
const std::string& Book::getFavicon() const { const std::string& Book::Illustration::getData() const
const Illustration& favicon = getDefaultIllustration(); {
if (favicon.data.empty() && !favicon.url.empty()) { if (data.empty() && !url.empty()) {
try { try {
favicon.data = download(favicon.url); data = download(url);
} catch(...) { } catch(...) {
std::cerr << "Cannot download favicon from " << favicon.url; std::cerr << "Cannot download favicon from " << url;
} }
} }
return favicon.data; return data;
}
const std::string& Book::getFavicon() const {
return getDefaultIllustration().getData();
} }
const std::string& Book::getFaviconUrl() const const std::string& Book::getFaviconUrl() const