/* * Copyright (C) 2009-2012 Geometer Plus * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA. */ #ifndef __BOOKSDB_H__ #define __BOOKSDB_H__ #include #include #include #include "../sqldb/implsqlite/SQLiteDataBase.h" #include "DBRunnables.h" #include "../../reader/ReadingState.h" class Book; class BooksDB : public SQLiteDataBase { public: static const std::string DATABASE_NAME; static const std::string STATE_DATABASE_NAME; static const std::string NET_DATABASE_NAME; static BooksDB &Instance(); private: static shared_ptr ourInstance; BooksDB(const std::string &path); public: virtual ~BooksDB(); public: bool initDatabase(); bool isInitialized() const; bool clearDatabase(); shared_ptr loadBook(const std::string &fileName); bool saveBook(const shared_ptr book); bool saveAuthors(const shared_ptr book); bool saveSeries(const shared_ptr book); bool saveTags(const shared_ptr book); int getFileSize(const std::string fileName); bool setFileSize(const std::string fileName, int size); bool setEncoding(const Book &book, const std::string &encoding); bool loadFileEntries(const std::string &fileName, std::vector &entries); bool saveFileEntries(const std::string &fileName, const std::vector &entries); bool loadRecentBooks(std::vector &fileNames); bool saveRecentBooks(const BookList &books); bool loadBooks(BookList &books); bool loadBookStateStack(const Book &book, std::deque &stack); bool saveBookStateStack(const Book &book, const std::deque &stack); bool removeBook(const Book &book); std::string getPalmType(const std::string &fileName); bool setPalmType(const std::string &fileName, const std::string &type); bool loadBookState(const Book &book, ReadingState &state); bool setBookState(const Book &book, const ReadingState &state); int loadStackPos(const Book &book); bool setStackPos(const Book &book, int stackPos); bool insertIntoBookList(const Book &book); bool deleteFromBookList(const Book &book); bool checkBookList(const Book &book); private: public: shared_ptr getTagById(int id) const; void loadAllTagsById() const; private: void loadSeries(Book &book); void loadSeries(const std::map > &books); void loadAuthors(Book &book); void loadAuthors(const std::map > &books); void loadTags(Book &book); void loadTags(const std::map > &books); std::string getFileName(int fileId); private: void initCommands(); private: bool myInitialized; shared_ptr mySaveTableBook; shared_ptr mySaveAuthors; shared_ptr mySaveSeries; shared_ptr mySaveTags; shared_ptr mySaveBook; shared_ptr mySaveFileEntries; shared_ptr myFindFileId; shared_ptr myLoadFileEntries; shared_ptr myLoadRecentBooks; shared_ptr mySaveRecentBooks; shared_ptr mySaveBookStateStack; shared_ptr myDeleteBook; shared_ptr myLoadNetworkLinks; shared_ptr myFindNetworkLinkId; shared_ptr myDeleteNetworkLink; shared_ptr myDeleteNetworkLinkUrls; shared_ptr myLoadNetworkLinkUrls; shared_ptr myLoadBook; shared_ptr myGetFileSize; shared_ptr mySetFileSize; shared_ptr myFindFileName; shared_ptr myFindAuthorId; shared_ptr myLoadBooks; shared_ptr myLoadBookStateStack; shared_ptr myGetPalmType; shared_ptr mySetPalmType; shared_ptr myGetNetFile; shared_ptr mySetNetFile; shared_ptr myLoadStackPos; shared_ptr mySetStackPos; shared_ptr myLoadBookState; shared_ptr mySetBookState; shared_ptr myInsertBookList; shared_ptr myDeleteBookList; shared_ptr myCheckBookList; private: // disable copying BooksDB(const BooksDB &); const BooksDB &operator = (const BooksDB &); }; inline bool BooksDB::isInitialized() const { return myInitialized; } #endif /* __BOOKSDB_H__ */