mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-22 19:46:12 -04:00
Dynamic category values
The category values are not static after this change. If local library is displayed, we get the categories from local library If remote library is displayed, we send a request to /catalog/v2/categories
This commit is contained in:
parent
ce140d2aa5
commit
574d1e2a29
@ -70,7 +70,7 @@ ContentManager::ContentManager(Library* library, kiwix::Downloader* downloader,
|
||||
connect(treeView, &QTreeView::doubleClicked, this, &ContentManager::openBookWithIndex);
|
||||
connect(&m_remoteLibraryManager, &OpdsRequestManager::languagesReceived, this, &ContentManager::updateLanguages);
|
||||
connect(&m_remoteLibraryManager, &OpdsRequestManager::categoriesReceived, this, &ContentManager::updateCategories);
|
||||
setLanguages();
|
||||
setCategories();
|
||||
}
|
||||
|
||||
QList<QMap<QString, QVariant>> ContentManager::getBooksList()
|
||||
@ -146,6 +146,7 @@ void ContentManager::setLocal(bool local) {
|
||||
}
|
||||
m_local = local;
|
||||
emit(filterParamsChanged());
|
||||
setCategories();
|
||||
}
|
||||
|
||||
QStringList ContentManager::getTranslations(const QStringList &keys)
|
||||
@ -163,11 +164,13 @@ void ContentManager::setCategories()
|
||||
QStringList categories;
|
||||
if (m_local) {
|
||||
auto categoryData = mp_library->getKiwixLibrary().getBooksCategories();
|
||||
categories.push_back("all");
|
||||
for (auto category : categoryData) {
|
||||
auto categoryName = QString::fromStdString(category);
|
||||
categories.push_back(categoryName);
|
||||
}
|
||||
m_categories = categories;
|
||||
emit(categoriesLoaded(m_categories));
|
||||
return;
|
||||
}
|
||||
m_remoteLibraryManager.getCategoriesFromOpds();
|
||||
@ -633,10 +636,12 @@ void ContentManager::updateLanguages(const QString& content) {
|
||||
void ContentManager::updateCategories(const QString& content) {;
|
||||
auto categories = kiwix::readCategoriesFromFeed(content.toStdString());
|
||||
QStringList tempCategories;
|
||||
tempCategories.push_back("all");
|
||||
for (auto catg : categories) {
|
||||
tempCategories.push_back(QString::fromStdString(catg));
|
||||
}
|
||||
m_categories = tempCategories;
|
||||
emit(categoriesLoaded(m_categories));
|
||||
}
|
||||
|
||||
void ContentManager::setSearch(const QString &search)
|
||||
@ -653,9 +658,9 @@ QStringList ContentManager::getBookIds()
|
||||
acceptTags.push_back("_category:"+m_categoryFilter.toStdString());
|
||||
}
|
||||
if (m_categoryFilter == "other") {
|
||||
for (auto& category: S_CATEGORIES) {
|
||||
if (category.first != "other" && category.first != "all") {
|
||||
rejectTags.push_back("_category:"+category.first.toStdString());
|
||||
for (auto& category: m_categories) {
|
||||
if (category != "other" && category != "all") {
|
||||
rejectTags.push_back("_category:"+category.toStdString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -64,6 +64,7 @@ signals:
|
||||
void downloadsChanged();
|
||||
void currentLangChanged();
|
||||
void pendingRequest(const bool);
|
||||
void categoriesLoaded(QStringList);
|
||||
|
||||
public slots:
|
||||
QStringList getTranslations(const QStringList &keys);
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "kiwixapp.h"
|
||||
|
||||
#include <QLocale>
|
||||
#include <QDebug>
|
||||
|
||||
#include "klistwidgetitem.h"
|
||||
#include "static_content.h"
|
||||
@ -91,6 +92,9 @@ ContentManagerSide::ContentManagerSide(QWidget *parent) :
|
||||
});
|
||||
}
|
||||
|
||||
setCategories(KiwixApp::instance()->getContentManager()->getCategories());
|
||||
connect(KiwixApp::instance()->getContentManager(), &ContentManager::categoriesLoaded, this, &ContentManagerSide::setCategories);
|
||||
|
||||
for(auto lang: S_LANGUAGES)
|
||||
{
|
||||
auto currentLang = QLocale().language();
|
||||
@ -113,17 +117,6 @@ ContentManagerSide::ContentManagerSide(QWidget *parent) :
|
||||
auto item = new KListWidgetItem("All");
|
||||
item->setData(Qt::UserRole, QLocale::AnyLanguage);
|
||||
mp_languageSelector->insertItem(0, item);
|
||||
|
||||
for (auto category: S_CATEGORIES)
|
||||
{
|
||||
auto item = new KListWidgetItem(category.second);
|
||||
item->setData(Qt::UserRole, category.first);
|
||||
mp_categorySelector->addItem(item);
|
||||
if (category.first == "all")
|
||||
{
|
||||
item->setSelected(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ContentManagerSide::~ContentManagerSide()
|
||||
@ -155,3 +148,28 @@ void ContentManagerSide::setContentManager(ContentManager *contentManager)
|
||||
mp_contentManager->setCurrentCategoryFilter(category);
|
||||
});
|
||||
}
|
||||
|
||||
QString beautify(QString word)
|
||||
{
|
||||
word = word.replace("_", " ");
|
||||
word[0] = word[0].toUpper();
|
||||
return word;
|
||||
}
|
||||
|
||||
void ContentManagerSide::setCategories(QStringList categories)
|
||||
{
|
||||
mp_categorySelector->blockSignals(true);
|
||||
mp_categorySelector->setHidden(true);
|
||||
mp_categorySelector->clear();
|
||||
mp_categorySelector->blockSignals(false);
|
||||
for (auto category: categories)
|
||||
{
|
||||
auto item = new KListWidgetItem(beautify(category));
|
||||
item->setData(Qt::UserRole, category);
|
||||
mp_categorySelector->addItem(item);
|
||||
if (category == "all")
|
||||
{
|
||||
item->setSelected(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +30,9 @@ private:
|
||||
QListWidget* mp_categorySelector;
|
||||
QCheckBox* mp_contentTypeButton;
|
||||
QList<ContentTypeFilter*> m_contentTypeFilters;
|
||||
|
||||
public slots:
|
||||
void setCategories(QStringList);
|
||||
};
|
||||
|
||||
#endif // CONTENTMANAGERSIDE_H
|
||||
|
@ -30,9 +30,9 @@ void OpdsRequestManager::doUpdate(const QString& currentLanguage, const QString&
|
||||
|
||||
// Add "special negative" filter for "other" category (if necessary)
|
||||
if (categoryFilter == "other") {
|
||||
for (auto& category: S_CATEGORIES) {
|
||||
if (category.first != "other" && category.first != "all") {
|
||||
excludeTags += "_category:"+category.first;
|
||||
for (auto& category: KiwixApp::instance()->getContentManager()->getCategories()) {
|
||||
if (category != "other" && category != "all") {
|
||||
excludeTags += "_category:"+category;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user