| 22 | RecentBooksStore RecentBooksStore::instance; |
| 23 | |
| 24 | void RecentBooksStore::addBook(const std::string& path, const std::string& title, const std::string& author, |
| 25 | const std::string& coverBmpPath) { |
| 26 | // Drop stale entries first so a new add can't evict a valid book in their stead. |
| 27 | pruneMissing(); |
| 28 | |
| 29 | // Remove existing entry if present |
| 30 | auto it = |
| 31 | std::find_if(recentBooks.begin(), recentBooks.end(), [&](const RecentBook& book) { return book.path == path; }); |
| 32 | if (it != recentBooks.end()) { |
| 33 | recentBooks.erase(it); |
| 34 | } |
| 35 | |
| 36 | // Add to front |
| 37 | recentBooks.insert(recentBooks.begin(), {path, title, author, coverBmpPath}); |
| 38 | |
| 39 | // Trim to max size |
| 40 | if (recentBooks.size() > MAX_RECENT_BOOKS) { |
| 41 | recentBooks.resize(MAX_RECENT_BOOKS); |
| 42 | } |
| 43 | |
| 44 | saveToFile(); |
| 45 | } |
| 46 | |
| 47 | void RecentBooksStore::updateBook(const std::string& path, const std::string& title, const std::string& author, |
| 48 | const std::string& coverBmpPath) { |