Merge pull request #125 from kiwix/filter-by-category

Filter by category on local files
This commit is contained in:
Matthieu Gautier 2019-04-15 17:09:36 +02:00 committed by GitHub
commit 36a5f5c22d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 14 deletions

View File

@ -22,7 +22,7 @@ ContentManager::ContentManager(Library* library, kiwix::Downloader* downloader,
mp_view->setHtml();
setCurrentLanguage(QLocale().name().split("_").at(0));
connect(mp_library, &Library::booksChanged, this, [=]() {emit(this->booksChanged());});
connect(this, &ContentManager::remoteParamsChanged, this, &ContentManager::updateRemoteLibrary);
connect(this, &ContentManager::filterParamsChanged, this, &ContentManager::updateLibrary);
}
@ -31,8 +31,7 @@ void ContentManager::setLocal(bool local) {
return;
}
m_local = local;
emit(remoteParamsChanged());
emit(booksChanged());
emit(filterParamsChanged());
}
#define ADD_V(KEY, METH) {if(key==KEY) values.append(QString::fromStdString((b->METH())));}
@ -212,21 +211,23 @@ void ContentManager::setCurrentLanguage(QString language)
}
m_currentLanguage = language;
emit(currentLangChanged());
emit(remoteParamsChanged());
emit(filterParamsChanged());
}
void ContentManager::setCurrentCategoryFilter(QString category)
{
m_categoryFilter = category.toLower();
emit(remoteParamsChanged());
emit(filterParamsChanged());
}
#define CATALOG_HOST "library.kiwix.org"
#define CATALOG_PORT 80
#define CATALOG_URL "library.kiwix.org"
void ContentManager::updateRemoteLibrary() {
if (m_local)
return;
void ContentManager::updateLibrary() {
if (m_local) {
emit(booksChanged());
return ();
}
QUrlQuery query;
if (m_currentLanguage != "*") {
query.addQueryItem("lang", m_currentLanguage);
@ -259,7 +260,7 @@ void ContentManager::setSearch(const QString &search)
QStringList ContentManager::getBookIds() {
if (m_local) {
return mp_library->listBookIds(m_searchQuery);
return mp_library->listBookIds(m_searchQuery, m_categoryFilter);
} else {
auto bookIds = m_remoteLibrary.listBooksIds(kiwix::REMOTE, kiwix::UNSORTED,
m_searchQuery.toStdString());

View File

@ -39,7 +39,7 @@ private:
QStringList getBookIds();
signals:
void remoteParamsChanged();
void filterParamsChanged();
void booksChanged();
void downloadsChanged();
void currentLangChanged();
@ -49,7 +49,7 @@ public slots:
void openBook(const QString& id);
QStringList updateDownloadInfos(QString id, const QStringList& keys);
QString downloadBook(const QString& id);
void updateRemoteLibrary();
void updateLibrary();
void setSearch(const QString& search);
};

View File

@ -89,12 +89,20 @@ QStringList Library::getBookIds()
return list;
}
QStringList Library::listBookIds(const QString &query)
QStringList Library::listBookIds(const QString &query, const QString &categoryFilter)
{
QStringList list;
std::vector<std::string> tags;
if (categoryFilter != "all") {
tags.push_back(categoryFilter.toStdString());
}
for(auto& id: m_library.listBooksIds(kiwix::VALID|kiwix::LOCAL,
kiwix::UNSORTED,
query.toStdString())) {
query.toStdString(),
"",
"",
"",
tags)) {
list.append(QString::fromStdString(id));
}
return list;

View File

@ -29,7 +29,7 @@ public:
QString openBookFromPath(const QString& zimPath);
std::shared_ptr<kiwix::Reader> getReader(const QString& zimId);
QStringList getBookIds();
QStringList listBookIds(const QString& query);
QStringList listBookIds(const QString& query, const QString &categoryFilter);
const std::vector<kiwix::Bookmark>& getBookmarks() { return m_library.getBookmarks(); }
void addBookToLibrary(kiwix::Book& book);
void addBookmark(kiwix::Bookmark& bookmark);