mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-25 05:48:54 -04:00
Merge pull request #404 from kiwix/content-type-filter
This commit is contained in:
commit
2c988568c3
@ -41,6 +41,7 @@ DEFINES += QT_DEPRECATED_WARNINGS
|
||||
|
||||
|
||||
SOURCES += \
|
||||
src/contenttypefilter.cpp \
|
||||
src/findinpagebar.cpp \
|
||||
src/translation.cpp \
|
||||
src/main.cpp \
|
||||
@ -72,6 +73,7 @@ SOURCES += \
|
||||
src/static_content.cpp
|
||||
|
||||
HEADERS += \
|
||||
src/contenttypefilter.h \
|
||||
src/findinpagebar.h \
|
||||
src/translation.h \
|
||||
src/mainwindow.h \
|
||||
|
@ -237,6 +237,10 @@ QTabBar::tab:last QToolButton::hover {
|
||||
show-decoration-selected: 0;
|
||||
}
|
||||
|
||||
#contentTypeSelector QCheckBox {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
#categorySelector QScrollBar,
|
||||
#languageSelector QScrollBar,
|
||||
#readinglistbar QScrollBar {
|
||||
@ -258,6 +262,11 @@ QTabBar::tab:last QToolButton::hover {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
#contentTypeAllButton,
|
||||
ContentTypeFilter {
|
||||
spacing: 10;
|
||||
}
|
||||
|
||||
#readinglistbar QLabel {
|
||||
font-size: 24px;
|
||||
font: bold;
|
||||
|
@ -104,5 +104,12 @@
|
||||
"wikiversity":"Wikiversity",
|
||||
"wikivoyage":"Wikivoyage",
|
||||
"wiktionary":"Wiktionary",
|
||||
"fulltext-search":"Fulltext search"
|
||||
"fulltext-search":"Fulltext search",
|
||||
"pictures":"Pictures",
|
||||
"videos":"Videos",
|
||||
"ftindex":"Fulltext index",
|
||||
"details":"Full article",
|
||||
"yes":"yes",
|
||||
"no":"no",
|
||||
"no-filter":"no filter"
|
||||
}
|
||||
|
@ -345,6 +345,12 @@ void ContentManager::setCurrentCategoryFilter(QString category)
|
||||
emit(filterParamsChanged());
|
||||
}
|
||||
|
||||
void ContentManager::setCurrentContentTypeFilter(QList<ContentTypeFilter*>& contentTypeFilters)
|
||||
{
|
||||
m_contentTypeFilters = contentTypeFilters;
|
||||
emit(filterParamsChanged());
|
||||
}
|
||||
|
||||
void ContentManager::updateLibrary() {
|
||||
if (m_local) {
|
||||
emit(pendingRequest(false));
|
||||
@ -378,7 +384,6 @@ QStringList ContentManager::getBookIds()
|
||||
std::vector<std::string> tags;
|
||||
if (m_categoryFilter != "all" && m_categoryFilter != "other") {
|
||||
tags.push_back("_category:"+m_categoryFilter.toStdString());
|
||||
filter.acceptTags(tags);
|
||||
}
|
||||
if (m_categoryFilter == "other") {
|
||||
for (auto& category: S_CATEGORIES) {
|
||||
@ -388,6 +393,18 @@ QStringList ContentManager::getBookIds()
|
||||
}
|
||||
filter.rejectTags(tags);
|
||||
}
|
||||
|
||||
for (auto &contentTypeFilter : m_contentTypeFilters) {
|
||||
auto state = contentTypeFilter->checkState();
|
||||
auto filter = contentTypeFilter->getName();
|
||||
if (state == Qt::PartiallyChecked) {
|
||||
tags.push_back("_" + filter.toStdString() +":yes");
|
||||
} else if (state == Qt::Checked) {
|
||||
tags.push_back("_" + filter.toStdString() +":no");
|
||||
}
|
||||
}
|
||||
|
||||
filter.acceptTags(tags);
|
||||
filter.query(m_searchQuery.toStdString());
|
||||
|
||||
if (m_local) {
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "contentmanagerview.h"
|
||||
#include <kiwix/downloader.h>
|
||||
#include "opdsrequestmanager.h"
|
||||
#include "contenttypefilter.h"
|
||||
|
||||
class ContentManager : public QObject
|
||||
{
|
||||
@ -25,6 +26,7 @@ public:
|
||||
QStringList getDownloadIds();
|
||||
void setCurrentLanguage(QString language);
|
||||
void setCurrentCategoryFilter(QString category);
|
||||
void setCurrentContentTypeFilter(QList<ContentTypeFilter*>& contentTypeFilter);
|
||||
|
||||
private:
|
||||
Library* mp_library;
|
||||
@ -36,6 +38,7 @@ private:
|
||||
QString m_currentLanguage;
|
||||
QString m_searchQuery;
|
||||
QString m_categoryFilter = "all";
|
||||
QList<ContentTypeFilter*> m_contentTypeFilters;
|
||||
kiwix::supportedListSortBy m_sortBy = kiwix::UNSORTED;
|
||||
bool m_sortOrderAsc = true;
|
||||
|
||||
|
@ -28,15 +28,58 @@ ContentManagerSide::ContentManagerSide(QWidget *parent) :
|
||||
mp_ui->localFileButton ->setText(gt("local-files"));
|
||||
mp_ui->languageButton->setText(gt("browse-by-language"));
|
||||
mp_ui->categoryButton->setText(gt("browse-by-category"));
|
||||
mp_ui->contentTypeButton->setText(gt("content-type"));
|
||||
|
||||
mp_languageButton = mp_ui->languageButton;
|
||||
mp_languageSelector = mp_ui->languageSelector;
|
||||
connect(mp_languageButton, &QCheckBox::toggled, this, [=](bool checked) { mp_languageSelector->setHidden(!checked); });
|
||||
mp_languageSelector->setHidden(true);
|
||||
|
||||
mp_categoryButton = mp_ui->categoryButton;
|
||||
mp_categorySelector = mp_ui->categorySelector;
|
||||
connect(mp_categoryButton, &QCheckBox::toggled, this, [=](bool checked) { mp_categorySelector->setHidden(!checked); });
|
||||
mp_categorySelector->setHidden(true);
|
||||
mp_ui->contentTypeButton->hide();
|
||||
|
||||
mp_contentTypeButton = mp_ui->contentTypeButton;
|
||||
connect(mp_contentTypeButton, &QCheckBox::toggled, this, [=](bool checked) { mp_ui->contentTypeSelector->setHidden(!checked); });
|
||||
mp_ui->contentTypeSelector->setHidden(true);
|
||||
|
||||
mp_ui->contentTypeAllButton->setText(gt("all"));
|
||||
mp_ui->contentTypeAllButton->setStyleSheet("*{font-weight: bold}");
|
||||
connect(mp_ui->contentTypeAllButton, &QCheckBox::clicked, this, [=](bool checked) {
|
||||
Q_UNUSED(checked);
|
||||
mp_ui->contentTypeAllButton->setStyleSheet("*{font-weight: bold}");
|
||||
for (auto &contentTypeFilter : m_contentTypeFilters) {
|
||||
contentTypeFilter->setCheckState(Qt::Unchecked);
|
||||
}
|
||||
mp_contentManager->setCurrentContentTypeFilter(m_contentTypeFilters);
|
||||
});
|
||||
|
||||
ContentTypeFilter* videosFilter = new ContentTypeFilter("pictures", this);
|
||||
ContentTypeFilter* picturesFilter = new ContentTypeFilter("videos", this);
|
||||
ContentTypeFilter* detailsFilter = new ContentTypeFilter("details", this);
|
||||
ContentTypeFilter* ftindexFilter = new ContentTypeFilter("ftindex", this);
|
||||
m_contentTypeFilters.push_back(videosFilter);
|
||||
m_contentTypeFilters.push_back(picturesFilter);
|
||||
m_contentTypeFilters.push_back(detailsFilter);
|
||||
m_contentTypeFilters.push_back(ftindexFilter);
|
||||
|
||||
auto layout = static_cast<QVBoxLayout*>(mp_ui->contentTypeSelector->layout());
|
||||
for (auto &contentTypeFilter : m_contentTypeFilters) {
|
||||
layout->addWidget(contentTypeFilter, 0, Qt::AlignTop);
|
||||
connect(contentTypeFilter, &QCheckBox::clicked, this, [=](bool checked) {
|
||||
Q_UNUSED(checked);
|
||||
bool activeFilter = false;
|
||||
for (auto &contentTypeFilter : m_contentTypeFilters) {
|
||||
if (contentTypeFilter->checkState() != Qt::Unchecked) {
|
||||
activeFilter = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
mp_ui->contentTypeAllButton->setStyleSheet(activeFilter ? "" : "*{font-weight: bold}");
|
||||
mp_contentManager->setCurrentContentTypeFilter(m_contentTypeFilters);
|
||||
});
|
||||
}
|
||||
|
||||
for(auto lang: S_LANGUAGES)
|
||||
{
|
||||
@ -71,7 +114,6 @@ ContentManagerSide::ContentManagerSide(QWidget *parent) :
|
||||
item->setSelected(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ContentManagerSide::~ContentManagerSide()
|
||||
@ -79,7 +121,6 @@ ContentManagerSide::~ContentManagerSide()
|
||||
delete mp_ui;
|
||||
}
|
||||
|
||||
|
||||
void ContentManagerSide::setContentManager(ContentManager *contentManager)
|
||||
{
|
||||
mp_contentManager = contentManager;
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <QListWidget>
|
||||
#include <QCheckBox>
|
||||
#include "contentmanager.h"
|
||||
#include "contenttypefilter.h"
|
||||
|
||||
namespace Ui {
|
||||
class contentmanagerside;
|
||||
@ -27,6 +28,8 @@ private:
|
||||
QListWidget* mp_languageSelector;
|
||||
QCheckBox* mp_categoryButton;
|
||||
QListWidget* mp_categorySelector;
|
||||
QCheckBox* mp_contentTypeButton;
|
||||
QList<ContentTypeFilter*> m_contentTypeFilters;
|
||||
};
|
||||
|
||||
#endif // CONTENTMANAGERSIDE_H
|
||||
|
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>197</width>
|
||||
<height>366</height>
|
||||
<height>368</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
@ -23,6 +23,9 @@
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetMaximumSize</enum>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
@ -43,7 +46,7 @@
|
||||
<property name="flat">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="0,0,0,0,0,0,0,1">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="0,0,0,0,0,0,0,0,0">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
@ -64,6 +67,12 @@
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="allFileButton">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>All Files</string>
|
||||
</property>
|
||||
@ -71,6 +80,12 @@
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="localFileButton">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Local Files</string>
|
||||
</property>
|
||||
@ -81,6 +96,12 @@
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="languageButton">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Browse By Language</string>
|
||||
</property>
|
||||
@ -91,7 +112,7 @@
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>1</verstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
@ -119,6 +140,12 @@
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Browse By Category</string>
|
||||
</property>
|
||||
@ -129,7 +156,7 @@
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>1</verstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
@ -151,14 +178,63 @@
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="contentTypeButton">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Content Type</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="contentTypeSelector">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Sunken</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="contentTypeAllButton">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>All</string>
|
||||
</property>
|
||||
<property name="tristate">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
|
21
src/contenttypefilter.cpp
Normal file
21
src/contenttypefilter.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
#include "contenttypefilter.h"
|
||||
#include "kiwixapp.h"
|
||||
|
||||
ContentTypeFilter::ContentTypeFilter(QString name, QWidget *parent)
|
||||
: QCheckBox(parent),
|
||||
m_name(name)
|
||||
{
|
||||
setTristate(true);
|
||||
|
||||
m_states[Qt::Unchecked] = gt("no-filter");
|
||||
m_states[Qt::PartiallyChecked] = gt("yes");
|
||||
m_states[Qt::Checked] = gt("no");
|
||||
setText(gt(m_name) + " : " + m_states[checkState()]);
|
||||
connect(this, &QCheckBox::stateChanged, this, &ContentTypeFilter::onStateChanged);
|
||||
}
|
||||
|
||||
void ContentTypeFilter::onStateChanged(int state)
|
||||
{
|
||||
setText(gt(m_name) + " : " + m_states[static_cast<Qt::CheckState>(state)]);
|
||||
setStyleSheet((state == 0) ? "" : "*{font-weight: bold}");
|
||||
}
|
25
src/contenttypefilter.h
Normal file
25
src/contenttypefilter.h
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef CONTENTTYPEFILTER_H
|
||||
#define CONTENTTYPEFILTER_H
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QMap>
|
||||
|
||||
class ContentTypeFilter : public QCheckBox
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ContentTypeFilter(QString name, QWidget *parent = nullptr);
|
||||
virtual ~ContentTypeFilter() {}
|
||||
|
||||
QString getName() { return m_name; }
|
||||
|
||||
public slots:
|
||||
void onStateChanged(int state);
|
||||
|
||||
private:
|
||||
QString m_name;
|
||||
QMap<Qt::CheckState, QString> m_states;
|
||||
};
|
||||
|
||||
#endif // CONTENTTYPEFILTER_H
|
Loading…
x
Reference in New Issue
Block a user