diff --git a/src/contentmanager.cpp b/src/contentmanager.cpp index 328eac5..d79d4b7 100644 --- a/src/contentmanager.cpp +++ b/src/contentmanager.cpp @@ -313,12 +313,32 @@ void ContentManager::setSearch(const QString &search) emit(booksChanged()); } -QStringList ContentManager::getBookIds() { +QStringList ContentManager::getBookIds() +{ + kiwix::Filter filter; + std::vector tags; + if (m_categoryFilter != "all" && m_categoryFilter != "other") { + tags.push_back(m_categoryFilter.toStdString()); + filter.acceptTags(tags); + } + if (m_categoryFilter == "other") { + auto categoryList = KiwixApp::instance()->getMainWindow()->getSideContentManager()->getCategoryList(); + for (auto& category: categoryList) { + if (category != "Other") { + tags.push_back(category.toLower().toStdString()); + } + } + filter.rejectTags(tags); + } + filter.query(m_searchQuery.toStdString()); + if (m_local) { - return mp_library->listBookIds(m_searchQuery, m_categoryFilter); + filter.local(true); + filter.valid(true); + return mp_library->listBookIds(filter); } else { - auto bookIds = m_remoteLibrary.listBooksIds(kiwix::REMOTE, kiwix::UNSORTED, - m_searchQuery.toStdString()); + filter.remote(true); + auto bookIds = m_remoteLibrary.filter(filter); QStringList list; for(auto& bookId:bookIds) { list.append(QString::fromStdString(bookId)); diff --git a/src/contentmanagerside.cpp b/src/contentmanagerside.cpp index 1d0d015..cf92dff 100644 --- a/src/contentmanagerside.cpp +++ b/src/contentmanagerside.cpp @@ -224,6 +224,7 @@ ContentManagerSide::ContentManagerSide(QWidget *parent) : }) { auto c = QString(category); + m_categoryList.append(c); auto item = new KListWidgetItem(c); mp_categorySelector->addItem(item); if (c == "All") diff --git a/src/contentmanagerside.h b/src/contentmanagerside.h index 9cfd911..5ffa2f0 100644 --- a/src/contentmanagerside.h +++ b/src/contentmanagerside.h @@ -19,6 +19,7 @@ public: ~ContentManagerSide(); void setContentManager(ContentManager* contentManager); + QStringList getCategoryList() { return m_categoryList;}; private: Ui::contentmanagerside *mp_ui; @@ -27,6 +28,7 @@ private: QListWidget* mp_languageSelector; QCheckBox* mp_categoryButton; QListWidget* mp_categorySelector; + QStringList m_categoryList; }; #endif // CONTENTMANAGERSIDE_H diff --git a/src/library.cpp b/src/library.cpp index f583c35..5ac4fe5 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -2,6 +2,7 @@ #include "kiwixapp.h" #include +#include "kiwixapp.h" #include @@ -90,20 +91,11 @@ QStringList Library::getBookIds() return list; } -QStringList Library::listBookIds(const QString &query, const QString &categoryFilter) +QStringList Library::listBookIds(const kiwix::Filter& filter) { QStringList list; - std::vector tags; - if (categoryFilter != "all") { - tags.push_back(categoryFilter.toStdString()); - } - for(auto& id: m_library.listBooksIds(kiwix::VALID|kiwix::LOCAL, - kiwix::UNSORTED, - query.toStdString(), - "", - "", - "", - tags)) { + auto bookIds = m_library.filter(filter); + for(auto& id: bookIds) { list.append(QString::fromStdString(id)); } return list; diff --git a/src/library.h b/src/library.h index 1fbc911..4910240 100644 --- a/src/library.h +++ b/src/library.h @@ -29,7 +29,7 @@ public: QString openBookFromPath(const QString& zimPath); std::shared_ptr getReader(const QString& zimId); QStringList getBookIds(); - QStringList listBookIds(const QString& query, const QString &categoryFilter); + QStringList listBookIds(const kiwix::Filter& filter); const std::vector& getBookmarks() { return m_library.getBookmarks(); } void addBookToLibrary(kiwix::Book& book); void removeBookFromLibraryById(const QString& id);