Add a method to get the a book illustration for a specific size.

This commit is contained in:
Matthieu Gautier 2021-11-17 15:09:15 +01:00
parent 66c40817ee
commit 9482bfb95b
2 changed files with 14 additions and 4 deletions

View File

@ -100,6 +100,7 @@ class Book
const std::string& getFaviconMimeType() const; const std::string& getFaviconMimeType() const;
Illustrations getIllustrations() const; Illustrations getIllustrations() const;
std::shared_ptr<const Illustration> getIllustration(unsigned int size) const;
const std::string& getDownloadId() const { return m_downloadId; } const std::string& getDownloadId() const { return m_downloadId; }

View File

@ -217,14 +217,23 @@ void Book::setPath(const std::string& path)
const Book::Illustration Book::missingDefaultIllustration; const Book::Illustration Book::missingDefaultIllustration;
const Book::Illustration& Book::getDefaultIllustration() const std::shared_ptr<const Book::Illustration> Book::getIllustration(unsigned int size) const
{ {
for ( const auto& ilPtr : m_illustrations ) { for ( const auto& ilPtr : m_illustrations ) {
if (ilPtr->width == 48 && ilPtr->height == 48) { if (ilPtr->width == size && ilPtr->height == size) {
return *ilPtr; 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 const std::string& Book::Illustration::getData() const