diff --git a/include/library.h b/include/library.h index bf919ccc0..e24bf9d7e 100644 --- a/include/library.h +++ b/include/library.h @@ -33,7 +33,15 @@ class Book; class OPDSDumper; enum supportedListSortBy { UNSORTED, TITLE, SIZE, DATE, CREATOR, PUBLISHER }; -enum supportedListMode { ALL, REMOTE, LOCAL }; +enum supportedListMode { + ALL = 0, + LOCAL = 1, + REMOTE = 1 << 1, + NOLOCAL = 1 << 2, + NOREMOTE = 1 << 3, + VALID = 1 << 4, + NOVALID = 1 << 5 +}; /** * A Library store several books. */ @@ -127,10 +135,15 @@ class Library * List books in the library. * * @param mode The mode of listing : - * - ALL list all books. - * (LOCAL and REMOTE. Other filters are applied). - * - LOCAL list only local books. - * - REMOTE list only remote books. + * - 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. * @param sortBy Attribute to sort by the book list. * @param search List only books with search in the title, description. * @param language List only books in this language. @@ -141,7 +154,7 @@ class Library * @return The list of bookIds corresponding to the query. */ std::vector listBooksIds( - supportedListMode = ALL, + int supportedListMode = ALL, supportedListSortBy sortBy = UNSORTED, const std::string& search = "", const std::string& language = "", diff --git a/src/library.cpp b/src/library.cpp index 9a4ec60d6..bd37e4127 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -303,7 +303,7 @@ std::string Comparator::get_keys(const std::string& id) std::vector Library::listBooksIds( - supportedListMode mode, + int mode, supportedListSortBy sortBy, const std::string& search, const std::string& language, @@ -314,9 +314,20 @@ std::vector Library::listBooksIds( std::vector bookIds; for(auto& pair:books) { auto& book = pair.second; - if (mode == LOCAL && book.getPath().empty()) + auto local = !book.getPath().empty(); + if (mode & LOCAL && !local) continue; - if (mode == REMOTE && (!book.getPath().empty() || book.getUrl().empty())) + if (mode & NOLOCAL && local) + continue; + auto valid = book.isPathValid(); + if (mode & VALID && !valid) + continue; + if (mode & NOVALID && valid) + continue; + auto remote = !book.getUrl().empty(); + if (mode & REMOTE && !remote) + continue; + if (mode & NOREMOTE && remote) continue; if (maxSize != 0 && book.getSize() > maxSize) continue;