mirror of https://github.com/kiwix/libkiwix.git
Be able to filter a library.
This generate a new library only with the corresponding books.
This commit is contained in:
parent
ee51c470b4
commit
ad92af928b
|
@ -254,6 +254,16 @@ class Manager
|
||||||
const string creator,
|
const string creator,
|
||||||
const string publisher,
|
const string publisher,
|
||||||
const string search);
|
const string search);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter the library and generate a new one with the keep elements.
|
||||||
|
*
|
||||||
|
* @param search List only books with search in the title or description.
|
||||||
|
* @return A `Library`.
|
||||||
|
*/
|
||||||
|
Library filter(const string& search);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all langagues of the books in the library.
|
* Get all langagues of the books in the library.
|
||||||
*
|
*
|
||||||
|
|
|
@ -626,6 +626,24 @@ bool Manager::listBooks(const supportedListMode mode,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Library Manager::filter(const std::string& search) {
|
||||||
|
Library library;
|
||||||
|
|
||||||
|
if (search.empty()) {
|
||||||
|
return library;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(auto book:this->library.books) {
|
||||||
|
if (matchRegex(book.title, "\\Q" + search + "\\E")
|
||||||
|
|| matchRegex(book.description, "\\Q" + search + "\\E")) {
|
||||||
|
library.addBook(book);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return library;
|
||||||
|
}
|
||||||
|
|
||||||
void Manager::checkAndCleanBookPaths(Book& book, const string& libraryPath)
|
void Manager::checkAndCleanBookPaths(Book& book, const string& libraryPath)
|
||||||
{
|
{
|
||||||
if (!book.path.empty()) {
|
if (!book.path.empty()) {
|
||||||
|
|
Loading…
Reference in New Issue