Class Library¶
Defined in File library.h
Inheritance Relationships¶
Base Type¶
private kiwix::LibraryBase
(Class LibraryBase)
Class Documentation¶
-
class
kiwix
::
Library
: private kiwix::LibraryBase¶ A Library store several books.
Public Types
-
typedef LibraryRevision
Revision
¶
-
typedef std::vector<std::string>
BookIdCollection
¶
-
typedef std::map<std::string, int>
AttributeCounts
¶
Public Functions
-
Library
()¶
-
~Library
()¶
-
bool
addBook
(const Book &book)¶ Add a book to the library.
If a book already exist in the library with the same id, update the existing book instead of adding a new one.
- Parameters
book – The book to add.
- Returns
True if the book has been added. False if a book has been updated.
-
void
addBookmark
(const Bookmark &bookmark)¶ Add a bookmark to the library.
- Parameters
bookmark – the book to add.
-
bool
removeBookmark
(const std::string &zimId, const std::string &url)¶ Remove a bookmarkk
- Parameters
zimId – The zimId of the bookmark.
url – The url of the bookmark.
- Returns
True if the bookmark has been removed.
-
std::shared_ptr<zim::Archive>
getArchiveById
(const std::string &id)¶
-
bool
removeBookById
(const std::string &id)¶ Remove a book from the library.
- Parameters
id – the id of the book to remove.
- Returns
True if the book were in the lirbrary and has been removed.
-
bool
writeToFile
(const std::string &path) const¶ Write the library to a file.
- Parameters
path – the path of the file to write to.
- Returns
True if the library has been correctly saved.
-
bool
writeBookmarksToFile
(const std::string &path) const¶ Write the library bookmarks to a file.
- Parameters
path – the path of the file to write to.
- Returns
True if the library has been correctly saved.
-
unsigned int
getBookCount
(const bool localBooks, const bool remoteBooks) const¶ Get the number of book in the library.
- Parameters
localBooks – If we must count local books (books with a path).
remoteBooks – If we must count remote books (books with an url)
- Returns
The number of books.
-
std::vector<std::string>
getBooksLanguages
() const¶ Get all languagues of the books in the library.
- Returns
A list of languages.
-
AttributeCounts
getBooksLanguagesWithCounts
() const¶ Get all languagues of the books in the library with counts.
- Returns
A list of languages with the count of books in each language.
-
std::vector<std::string>
getBooksCategories
() const¶ Get all categories of the books in the library.
- Returns
A list of categories.
-
std::vector<std::string>
getBooksCreators
() const¶ Get all book creators of the books in the library.
- Returns
A list of book creators.
-
std::vector<std::string>
getBooksPublishers
() const¶ Get all book publishers of the books in the library.
- Returns
A list of book publishers.
-
const std::vector<kiwix::Bookmark>
getBookmarks
(bool onlyValidBookmarks = true) const¶ Get all bookmarks.
- Returns
A list of bookmarks
-
BookIdCollection
getBooksIds
() const¶ Get all book ids of the books in the library.
- Returns
A list of book ids.
-
BookIdCollection
filter
(const std::string &search) const¶ Filter the library and generate a new one with the keep elements.
This is equivalent to
listBookIds(ALL, UNSORTED, search)
.- Parameters
search – List only books with search in the title or description.
- Returns
The list of bookIds corresponding to the query.
-
BookIdCollection
filter
(const Filter &filter) const¶ Filter the library and return the id of the keep elements.
- Parameters
filter – The filter to use.
- Returns
The list of bookIds corresponding to the filter.
-
void
sort
(BookIdCollection &bookIds, supportedListSortBy sortBy, bool ascending) const¶ Sort (in place) bookIds using the given comparator.
- Parameters
bookIds – the list of book Ids to sort
comparator – how to sort the books
- Returns
The sorted list of books
-
BookIdCollection
listBooksIds
(int supportedListMode = ALL, supportedListSortBy sortBy = UNSORTED, const std::string &search = "", const std::string &language = "", const std::string &creator = "", const std::string &publisher = "", const std::vector<std::string> &tags = {}, size_t maxSize = 0) const¶ List books in the library.
- Parameters
mode – The mode of listing :
LOCAL : list only local books (with a path).
REMOTE : list only remote books (with an url).
VALID : list only valid books (without a path or with a path pointing to a valid zim file).
NOLOCAL : list only books without valid path.
NOREMOTE : list only books without url.
NOVALID : list only books not valid.
ALL : Do not do any filter (LOCAL or REMOTE)
Flags can be combined.
sortBy – Attribute to sort by the book list.
search – List only books with search in the title, description.
language – List only books in this language.
creator – List only books of this creator.
publisher – List only books of this publisher.
maxSize – Do not list book bigger than maxSize. Set to 0 to cancel this filter.
- Returns
The list of bookIds corresponding to the query.
-
LibraryRevision
getRevision
() const¶ Return the current revision of the library.
The revision of the library is updated (incremented by one) only by the addBook() operation.
- Returns
Current revision of the library.
-
uint32_t
removeBooksNotUpdatedSince
(LibraryRevision rev)¶ Remove books that have not been updated since the specified revision.
- Parameters
rev – the library revision to use
- Returns
Count of books that were removed by this operation.
Friends
- friend class OPDSDumper
- friend class libXMLDumper
-
typedef LibraryRevision