mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-22 19:46:12 -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();
|
mp_view->setHtml();
|
||||||
setCurrentLanguage(QLocale().name().split("_").at(0));
|
setCurrentLanguage(QLocale().name().split("_").at(0));
|
||||||
connect(mp_library, &Library::booksChanged, this, [=]() {emit(this->booksChanged());});
|
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;
|
return;
|
||||||
}
|
}
|
||||||
m_local = local;
|
m_local = local;
|
||||||
emit(remoteParamsChanged());
|
emit(filterParamsChanged());
|
||||||
emit(booksChanged());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ADD_V(KEY, METH) {if(key==KEY) values.append(QString::fromStdString((b->METH())));}
|
#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;
|
m_currentLanguage = language;
|
||||||
emit(currentLangChanged());
|
emit(currentLangChanged());
|
||||||
emit(remoteParamsChanged());
|
emit(filterParamsChanged());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentManager::setCurrentCategoryFilter(QString category)
|
void ContentManager::setCurrentCategoryFilter(QString category)
|
||||||
{
|
{
|
||||||
m_categoryFilter = category.toLower();
|
m_categoryFilter = category.toLower();
|
||||||
emit(remoteParamsChanged());
|
emit(filterParamsChanged());
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CATALOG_HOST "library.kiwix.org"
|
#define CATALOG_HOST "library.kiwix.org"
|
||||||
#define CATALOG_PORT 80
|
#define CATALOG_PORT 80
|
||||||
#define CATALOG_URL "library.kiwix.org"
|
#define CATALOG_URL "library.kiwix.org"
|
||||||
void ContentManager::updateRemoteLibrary() {
|
void ContentManager::updateLibrary() {
|
||||||
if (m_local)
|
if (m_local) {
|
||||||
return;
|
emit(booksChanged());
|
||||||
|
return ();
|
||||||
|
}
|
||||||
QUrlQuery query;
|
QUrlQuery query;
|
||||||
if (m_currentLanguage != "*") {
|
if (m_currentLanguage != "*") {
|
||||||
query.addQueryItem("lang", m_currentLanguage);
|
query.addQueryItem("lang", m_currentLanguage);
|
||||||
@ -259,7 +260,7 @@ void ContentManager::setSearch(const QString &search)
|
|||||||
|
|
||||||
QStringList ContentManager::getBookIds() {
|
QStringList ContentManager::getBookIds() {
|
||||||
if (m_local) {
|
if (m_local) {
|
||||||
return mp_library->listBookIds(m_searchQuery);
|
return mp_library->listBookIds(m_searchQuery, m_categoryFilter);
|
||||||
} else {
|
} else {
|
||||||
auto bookIds = m_remoteLibrary.listBooksIds(kiwix::REMOTE, kiwix::UNSORTED,
|
auto bookIds = m_remoteLibrary.listBooksIds(kiwix::REMOTE, kiwix::UNSORTED,
|
||||||
m_searchQuery.toStdString());
|
m_searchQuery.toStdString());
|
||||||
|
@ -39,7 +39,7 @@ private:
|
|||||||
QStringList getBookIds();
|
QStringList getBookIds();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void remoteParamsChanged();
|
void filterParamsChanged();
|
||||||
void booksChanged();
|
void booksChanged();
|
||||||
void downloadsChanged();
|
void downloadsChanged();
|
||||||
void currentLangChanged();
|
void currentLangChanged();
|
||||||
@ -49,7 +49,7 @@ public slots:
|
|||||||
void openBook(const QString& id);
|
void openBook(const QString& id);
|
||||||
QStringList updateDownloadInfos(QString id, const QStringList& keys);
|
QStringList updateDownloadInfos(QString id, const QStringList& keys);
|
||||||
QString downloadBook(const QString& id);
|
QString downloadBook(const QString& id);
|
||||||
void updateRemoteLibrary();
|
void updateLibrary();
|
||||||
void setSearch(const QString& search);
|
void setSearch(const QString& search);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -89,12 +89,20 @@ QStringList Library::getBookIds()
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList Library::listBookIds(const QString &query)
|
QStringList Library::listBookIds(const QString &query, const QString &categoryFilter)
|
||||||
{
|
{
|
||||||
QStringList list;
|
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,
|
for(auto& id: m_library.listBooksIds(kiwix::VALID|kiwix::LOCAL,
|
||||||
kiwix::UNSORTED,
|
kiwix::UNSORTED,
|
||||||
query.toStdString())) {
|
query.toStdString(),
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
tags)) {
|
||||||
list.append(QString::fromStdString(id));
|
list.append(QString::fromStdString(id));
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
|
@ -29,7 +29,7 @@ public:
|
|||||||
QString openBookFromPath(const QString& zimPath);
|
QString openBookFromPath(const QString& zimPath);
|
||||||
std::shared_ptr<kiwix::Reader> getReader(const QString& zimId);
|
std::shared_ptr<kiwix::Reader> getReader(const QString& zimId);
|
||||||
QStringList getBookIds();
|
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(); }
|
const std::vector<kiwix::Bookmark>& getBookmarks() { return m_library.getBookmarks(); }
|
||||||
void addBookToLibrary(kiwix::Book& book);
|
void addBookToLibrary(kiwix::Book& book);
|
||||||
void addBookmark(kiwix::Bookmark& bookmark);
|
void addBookmark(kiwix::Bookmark& bookmark);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user