mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-22 11:37:56 -04:00
Merge pull request #125 from kiwix/filter-by-category
Filter by category on local files
This commit is contained in:
commit
36a5f5c22d
@ -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());
|
||||
|
@ -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);
|
||||
};
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user