diff --git a/include/book.h b/include/book.h index b5ff34052..d53de75d4 100644 --- a/include/book.h +++ b/include/book.h @@ -42,10 +42,16 @@ class Reader; class Book { public: // types - struct Illustration + class Illustration { + friend class Book; + public: std::string mimeType; std::string url; + + const std::string& getData() const; + + private: mutable std::string data; }; diff --git a/src/book.cpp b/src/book.cpp index ed219ce79..8c992deac 100644 --- a/src/book.cpp +++ b/src/book.cpp @@ -226,16 +226,20 @@ Book::Illustration& Book::getMutableDefaultIllustration() return m_illustration; } -const std::string& Book::getFavicon() const { - const Illustration& favicon = getDefaultIllustration(); - if (favicon.data.empty() && !favicon.url.empty()) { +const std::string& Book::Illustration::getData() const +{ + if (data.empty() && !url.empty()) { try { - favicon.data = download(favicon.url); + data = download(url); } 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