diff --git a/include/book.h b/include/book.h index cdcbf51fe..f0ac10aea 100644 --- a/include/book.h +++ b/include/book.h @@ -100,6 +100,7 @@ class Book const std::string& getFaviconMimeType() const; Illustrations getIllustrations() const; + std::shared_ptr getIllustration(unsigned int size) const; const std::string& getDownloadId() const { return m_downloadId; } diff --git a/src/book.cpp b/src/book.cpp index 5e1952a43..e04b0192e 100644 --- a/src/book.cpp +++ b/src/book.cpp @@ -217,14 +217,23 @@ void Book::setPath(const std::string& path) const Book::Illustration Book::missingDefaultIllustration; -const Book::Illustration& Book::getDefaultIllustration() const +std::shared_ptr Book::getIllustration(unsigned int size) const { for ( const auto& ilPtr : m_illustrations ) { - if (ilPtr->width == 48 && ilPtr->height == 48) { - return *ilPtr; + if (ilPtr->width == size && ilPtr->height == size) { + return ilPtr; } } - return missingDefaultIllustration; + throw std::runtime_error("Cannot find illustration"); +} + +const Book::Illustration& Book::getDefaultIllustration() const +{ + try { + return *getIllustration(48); + } catch (...) { + return missingDefaultIllustration; + } } const std::string& Book::Illustration::getData() const