Something went wrong. Try again.
A fork of https://github.com/crosspoint-reader/crosspoint-reader
Something went wrong. Try again.
1.6 kB · 56 lines
C
at master
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657#pragma once#include <string>#include <vector>
struct RecentBook { std::string path; std::string title; std::string author; std::string coverBmpPath;
bool operator==(const RecentBook& other) const { return path == other.path; }};
class RecentBooksStore;namespace JsonSettingsIO {bool loadRecentBooks(RecentBooksStore& store, const char* json);} // namespace JsonSettingsIO
class RecentBooksStore { // Static instance static RecentBooksStore instance;
std::vector<RecentBook> recentBooks;
friend bool JsonSettingsIO::loadRecentBooks(RecentBooksStore&, const char*);
public: ~RecentBooksStore() = default;
// Get singleton instance static RecentBooksStore& getInstance() { return instance; }
// Add a book to the recent list (moves to front if already exists) void addBook(const std::string& path, const std::string& title, const std::string& author, const std::string& coverBmpPath);
void updateBook(const std::string& path, const std::string& title, const std::string& author, const std::string& coverBmpPath);
// Get the list of recent books (most recent first) const std::vector<RecentBook>& getBooks() const { return recentBooks; }
// Get the count of recent books int getCount() const { return static_cast<int>(recentBooks.size()); }
bool saveToFile() const;
bool loadFromFile(); RecentBook getDataFromBook(std::string path) const;
private: bool loadFromBinaryFile();};
// Helper macro to access recent books store#define RECENT_BOOKS RecentBooksStore::getInstance()