Merge pull request #366 from kiwix/new_tag

New tag system
This commit is contained in:
Matthieu Gautier 2020-04-08 12:28:52 +02:00 committed by GitHub
commit c38e43de87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 251 additions and 195 deletions

View File

@ -72,7 +72,8 @@ SOURCES += \
src/localkiwixserver.cpp \
src/fullscreenwindow.cpp \
src/fullscreennotification.cpp \
src/zimview.cpp
src/zimview.cpp \
src/static_content.cpp
HEADERS += \
src/findinpagebar.h \
@ -103,7 +104,8 @@ HEADERS += \
src/fullscreenwindow.h \
src/fullscreennotification.h \
src/menuproxystyle.h \
src/zimview.h
src/zimview.h \
src/static_content.h
FORMS += \
src/findinpagebar.ui \

View File

@ -86,5 +86,22 @@
"hide":"Hide",
"open-in-browser":"Open in browser",
"start-kiwix-server":"Start Kiwix Server",
"stop-kiwix-server":"Stop Kiwix Server"
}
"stop-kiwix-server":"Stop Kiwix Server",
"all":"All",
"other":"Other",
"gutemberg":"Gutenberg",
"phet":"Phet",
"psiram":"Psiram",
"stack_exchange":"Stack Exchange",
"ted":"Ted",
"vikidia":"Vikidia",
"wikibooks":"Wikibooks",
"wikinews":"Wikinews",
"wikipedia":"Wikipedia",
"wikiquote":"Wikiquote",
"wikisource":"Wikisource",
"wikispecies":"Wikispecies",
"wikiversity":"Wikiversity",
"wikivoyage":"Wikivoyage",
"wiktionary":"Wiktionary"
}

View File

@ -1,6 +1,7 @@
#include "contentmanager.h"
#include "kiwixapp.h"
#include "static_content.h"
#include <kiwix/tools/networkTools.h>
#include <kiwix/tools/otherTools.h>
#include <kiwix/manager.h>
@ -97,8 +98,19 @@ QStringList ContentManager::getBookInfos(QString id, const QStringList &keys)
}
if (key == "tags") {
QStringList tagList = QString::fromStdString(b->getTags()).split(';');
tagList = tagList.filter(QRegExp("^(?!_).*"));
QString s = tagList.join(" ");
QMap<QString, bool> displayTagMap;
for(auto tag: tagList) {
if (tag[0] == "_") {
auto splitTag = tag.split(":");
displayTagMap[splitTag[0]] = splitTag[1] == "yes" ? true:false;
}
}
QStringList displayTagList;
if (displayTagMap["_videos"]) displayTagList << tr("Videos");
if (displayTagMap["_pictures"]) displayTagList << tr("Pictures");
if (!displayTagMap["_details"]) displayTagList << tr("Introduction only");
if (displayTagMap["_ftindex"]) displayTagList << tr("Fulltext index");
QString s = displayTagList.join(", ");
values.append(s);
}
}
@ -365,14 +377,13 @@ QStringList ContentManager::getBookIds()
kiwix::Filter filter;
std::vector<std::string> tags;
if (m_categoryFilter != "all" && m_categoryFilter != "other") {
tags.push_back(m_categoryFilter.toStdString());
tags.push_back("_category:"+m_categoryFilter.toStdString());
filter.acceptTags(tags);
}
if (m_categoryFilter == "other") {
auto categoryList = KiwixApp::instance()->getMainWindow()->getSideContentManager()->getCategoryList();
for (auto& category: categoryList) {
if (category != "Other") {
tags.push_back(category.toLower().toStdString());
for (auto& category: S_CATEGORIES) {
if (category.first != "other" && category.first != "all") {
tags.push_back("_category:"+category.first.toStdString());
}
}
filter.rejectTags(tags);
@ -408,4 +419,4 @@ void ContentManager::setSortBy(const QString& sortBy, const bool sortOrderAsc)
}
m_sortOrderAsc = sortOrderAsc;
emit(booksChanged());
}
}

View File

@ -5,6 +5,7 @@
#include <QLocale>
#include "klistwidgetitem.h"
#include "static_content.h"
ContentManagerSide::ContentManagerSide(QWidget *parent) :
QWidget(parent),
@ -37,153 +38,7 @@ ContentManagerSide::ContentManagerSide(QWidget *parent) :
mp_categorySelector->setHidden(true);
mp_ui->contentTypeButton->hide();
for (auto lang:
{
QLocale::AnyLanguage,
QLocale::Afar,
QLocale::Afrikaans,
QLocale::Akan,
QLocale::Amharic,
QLocale::Arabic,
QLocale::Assamese,
QLocale::Azerbaijani,
QLocale::Bashkir,
QLocale::Belarusian,
QLocale::Bulgarian,
QLocale::Bambara,
QLocale::Bengali,
QLocale::Tibetan,
QLocale::Breton,
QLocale::Bosnian,
QLocale::Catalan,
QLocale::Chechen,
QLocale::Corsican,
QLocale::Czech,
QLocale::Church,
QLocale::Chuvash,
QLocale::Welsh,
QLocale::Danish,
QLocale::German,
QLocale::Divehi,
QLocale::Dzongkha,
QLocale::Ewe,
QLocale::Greek,
QLocale::English,
QLocale::Spanish,
QLocale::Estonian,
QLocale::Basque,
QLocale::Persian,
QLocale::Fulah,
QLocale::Finnish,
QLocale::Faroese,
QLocale::French,
QLocale::WesternFrisian,
QLocale::Irish,
QLocale::Gaelic,
QLocale::Galician,
QLocale::Guarani,
QLocale::Gujarati,
QLocale::Manx,
QLocale::Hausa,
QLocale::Hebrew,
QLocale::Hindi,
QLocale::Croatian,
QLocale::Hungarian,
QLocale::Armenian,
QLocale::Interlingua,
QLocale::Indonesian,
QLocale::Igbo,
QLocale::Icelandic,
QLocale::Italian,
QLocale::Inuktitut,
QLocale::Japanese,
QLocale::Javanese,
QLocale::Georgian,
QLocale::Kikuyu,
QLocale::Kazakh,
QLocale::Greenlandic,
QLocale::Khmer,
QLocale::Kannada,
QLocale::Korean,
QLocale::Kashmiri,
QLocale::Kurdish,
QLocale::Cornish,
QLocale::Kirghiz,
QLocale::Luxembourgish,
QLocale::Ganda,
QLocale::Lingala,
QLocale::Lao,
QLocale::Lithuanian,
QLocale::Latvian,
QLocale::Malagasy,
QLocale::Maori,
QLocale::Maori,
QLocale::Macedonian,
QLocale::Malayalam,
QLocale::Mongolian,
QLocale::Marathi,
QLocale::Malay,
QLocale::Maltese,
QLocale::Burmese,
QLocale::Nepali,
QLocale::Dutch,
QLocale::NorwegianNynorsk,
QLocale::NorwegianBokmal,
QLocale::Nyanja,
QLocale::Occitan,
QLocale::Oromo,
QLocale::Oriya,
QLocale::Ossetic,
QLocale::Punjabi,
QLocale::Polish,
QLocale::Pashto,
QLocale::Portuguese,
QLocale::Quechua,
QLocale::Romansh,
QLocale::Rundi,
QLocale::Romanian,
QLocale::Russian,
QLocale::Kinyarwanda,
QLocale::Sanskrit,
QLocale::Sindhi,
QLocale::NorthernSami,
QLocale::Sango,
QLocale::Sinhala,
QLocale::Slovak,
QLocale::Slovenian,
QLocale::Shona,
QLocale::Somali,
QLocale::Albanian,
QLocale::Serbian,
QLocale::Swati,
QLocale::SouthernSotho,
QLocale::Swedish,
QLocale::Swahili,
QLocale::Tamil,
QLocale::Telugu,
QLocale::Tajik,
QLocale::Thai,
QLocale::Tigrinya,
QLocale::Turkmen,
QLocale::Filipino,
QLocale::Tswana,
QLocale::Tongan,
QLocale::Turkish,
QLocale::Tsonga,
QLocale::Tatar,
QLocale::Uighur,
QLocale::Ukrainian,
QLocale::Urdu,
QLocale::Uzbek,
QLocale::Venda,
QLocale::Vietnamese,
QLocale::Walloon,
QLocale::Wolof,
QLocale::Xhosa,
QLocale::Yoruba,
QLocale::Chinese,
QLocale::Zulu,
})
for(auto lang: S_LANGUAGES)
{
auto currentLang = QLocale().language();
if (lang == QLocale::AnyLanguage) {
@ -208,31 +63,12 @@ ContentManagerSide::ContentManagerSide(QWidget *parent) :
}
}
for (auto category: {
"All",
"Gutenberg", // Gutenberg book has wrong tag
"Other",
"Phet", // Phet books have no tags
"Psiram",
"Stack Exchange",
"Ted", // Ted books have wrong tags
"Vikidia",
"Wikibooks", // wikibooks have no tags
"Wikinews",
"Wikipedia",
"Wikiquote",
"Wikisource",
// "Wikispecies", // Wikispecies books have wrong tags
"Wikiversity",
"Wikivoyage",
"Wiktionary"
})
for (auto category: S_CATEGORIES)
{
auto c = QString(category);
m_categoryList.append(c);
auto item = new KListWidgetItem(c);
auto item = new KListWidgetItem(category.second);
item->setData(Qt::UserRole, category.first);
mp_categorySelector->addItem(item);
if (c == "All")
if (category.first == "all")
{
item->setSelected(true);
}
@ -253,22 +89,20 @@ void ContentManagerSide::setContentManager(ContentManager *contentManager)
this, [=]() {
auto item = mp_languageSelector->selectedItems().at(0);
if (!item) return;
auto lang = QLocale::Language(item->data(Qt::UserRole).toInt());
auto langId = item->data(Qt::UserRole).toInt();
auto lang = QLocale::Language(langId);
if (lang == QLocale::AnyLanguage) {
mp_contentManager->setCurrentLanguage("*");
return;
}
auto locale = QLocale(QLocale::Language(item->data(Qt::UserRole).toInt()));
auto locale = QLocale(lang);
mp_contentManager->setCurrentLanguage(locale.name().split("_").at(0));
});
connect(mp_categorySelector, &QListWidget::itemSelectionChanged,
this, [=]() {
auto item = mp_categorySelector->selectedItems().at(0);
if (!item) return;
auto category = item->text();
if (category == "Stack Exchange") {
category = "Stackexchange";
}
auto category = item->data(Qt::UserRole).toString();
mp_contentManager->setCurrentCategoryFilter(category);
});
}

View File

@ -19,7 +19,6 @@ public:
~ContentManagerSide();
void setContentManager(ContentManager* contentManager);
QStringList getCategoryList() { return m_categoryList;};
private:
Ui::contentmanagerside *mp_ui;
@ -28,7 +27,6 @@ private:
QListWidget* mp_languageSelector;
QCheckBox* mp_categoryButton;
QListWidget* mp_categorySelector;
QStringList m_categoryList;
};
#endif // CONTENTMANAGERSIDE_H

View File

@ -1,4 +1,5 @@
#include "kiwixapp.h"
#include "static_content.h"
#include "zim/error.h"
#include <QLocale>
@ -76,6 +77,8 @@ void KiwixApp::init()
}
mp_manager = new ContentManager(&m_library, mp_downloader);
initStaticContent();
auto icon = QIcon();
icon.addFile(":/icons/kiwix-app-icons-square.svg");
setWindowIcon(icon);

View File

@ -1,4 +1,5 @@
#include "opdsrequestmanager.h"
#include "static_content.h"
#include "kiwixapp.h"
OpdsRequestManager::OpdsRequestManager()
@ -16,15 +17,14 @@ void OpdsRequestManager::doUpdate(const QString& currentLanguage, const QString&
}
query.addQueryItem("count", QString::number(0));
if (categoryFilter != "all" && categoryFilter != "other") {
query.addQueryItem("tag", categoryFilter);
query.addQueryItem("tag", "_category:"+categoryFilter);
}
if (categoryFilter == "other") {
auto allCategories = KiwixApp::instance()->getMainWindow()->getSideContentManager()->getCategoryList();
QStringList excludeTags;
for (auto& category:allCategories) {
if (category != "Other") {
excludeTags += category.toLower();
for (auto& category: S_CATEGORIES) {
if (category.first != "other" && category.first != "all") {
excludeTags += "_category:"+category.first;
}
}
query.addQueryItem("notag", excludeTags.join(";"));

176
src/static_content.cpp Normal file
View File

@ -0,0 +1,176 @@
#include "static_content.h"
#include "kiwixapp.h"
std::vector<QLocale::Language> S_LANGUAGES;
std::vector<std::pair<QString, QString>> S_CATEGORIES;
void initStaticContent() {
#define PUSH(key) S_CATEGORIES.push_back(std::make_pair(QString::fromStdString(key), gt(key)))
PUSH("all");
PUSH("other");
// PUSH("gutenberg"); // Gutenberg book has wrong tag
// PUSH("phet"); // Phet books have no tags
PUSH("psiram");
PUSH("stack_exchange");
// PUSH("ted"); // Ted books have wrong tags
PUSH("vikidia");
// PUSH("wikibooks"); // wikibooks have no tags
PUSH("wikinews");
PUSH("wikipedia");
PUSH("wikiquote");
PUSH("wikisource");
// PUSH("wikispecies"); // Wikispecies books have wrong tags
PUSH("wikiversity");
PUSH("wikivoyage");
PUSH("wiktionary");
#undef PUSH
#define PUSH(value) S_LANGUAGES.push_back(value)
PUSH(QLocale::AnyLanguage);
PUSH(QLocale::Afar);
PUSH(QLocale::Afrikaans);
PUSH(QLocale::Akan);
PUSH(QLocale::Amharic);
PUSH(QLocale::Arabic);
PUSH(QLocale::Assamese);
PUSH(QLocale::Azerbaijani);
PUSH(QLocale::Bashkir);
PUSH(QLocale::Belarusian);
PUSH(QLocale::Bulgarian);
PUSH(QLocale::Bambara);
PUSH(QLocale::Bengali);
PUSH(QLocale::Tibetan);
PUSH(QLocale::Breton);
PUSH(QLocale::Bosnian);
PUSH(QLocale::Catalan);
PUSH(QLocale::Chechen);
PUSH(QLocale::Corsican);
PUSH(QLocale::Czech);
PUSH(QLocale::Church);
PUSH(QLocale::Chuvash);
PUSH(QLocale::Welsh);
PUSH(QLocale::Danish);
PUSH(QLocale::German);
PUSH(QLocale::Divehi);
PUSH(QLocale::Dzongkha);
PUSH(QLocale::Ewe);
PUSH(QLocale::Greek);
PUSH(QLocale::English);
PUSH(QLocale::Spanish);
PUSH(QLocale::Estonian);
PUSH(QLocale::Basque);
PUSH(QLocale::Persian);
PUSH(QLocale::Fulah);
PUSH(QLocale::Finnish);
PUSH(QLocale::Faroese);
PUSH(QLocale::French);
PUSH(QLocale::WesternFrisian);
PUSH(QLocale::Irish);
PUSH(QLocale::Gaelic);
PUSH(QLocale::Galician);
PUSH(QLocale::Guarani);
PUSH(QLocale::Gujarati);
PUSH(QLocale::Manx);
PUSH(QLocale::Hausa);
PUSH(QLocale::Hebrew);
PUSH(QLocale::Hindi);
PUSH(QLocale::Croatian);
PUSH(QLocale::Hungarian);
PUSH(QLocale::Armenian);
PUSH(QLocale::Interlingua);
PUSH(QLocale::Indonesian);
PUSH(QLocale::Igbo);
PUSH(QLocale::Icelandic);
PUSH(QLocale::Italian);
PUSH(QLocale::Inuktitut);
PUSH(QLocale::Japanese);
PUSH(QLocale::Javanese);
PUSH(QLocale::Georgian);
PUSH(QLocale::Kikuyu);
PUSH(QLocale::Kazakh);
PUSH(QLocale::Greenlandic);
PUSH(QLocale::Khmer);
PUSH(QLocale::Kannada);
PUSH(QLocale::Korean);
PUSH(QLocale::Kashmiri);
PUSH(QLocale::Kurdish);
PUSH(QLocale::Cornish);
PUSH(QLocale::Kirghiz);
PUSH(QLocale::Luxembourgish);
PUSH(QLocale::Ganda);
PUSH(QLocale::Lingala);
PUSH(QLocale::Lao);
PUSH(QLocale::Lithuanian);
PUSH(QLocale::Latvian);
PUSH(QLocale::Malagasy);
PUSH(QLocale::Maori);
PUSH(QLocale::Maori);
PUSH(QLocale::Macedonian);
PUSH(QLocale::Malayalam);
PUSH(QLocale::Mongolian);
PUSH(QLocale::Marathi);
PUSH(QLocale::Malay);
PUSH(QLocale::Maltese);
PUSH(QLocale::Burmese);
PUSH(QLocale::Nepali);
PUSH(QLocale::Dutch);
PUSH(QLocale::NorwegianNynorsk);
PUSH(QLocale::NorwegianBokmal);
PUSH(QLocale::Nyanja);
PUSH(QLocale::Occitan);
PUSH(QLocale::Oromo);
PUSH(QLocale::Oriya);
PUSH(QLocale::Ossetic);
PUSH(QLocale::Punjabi);
PUSH(QLocale::Polish);
PUSH(QLocale::Pashto);
PUSH(QLocale::Portuguese);
PUSH(QLocale::Quechua);
PUSH(QLocale::Romansh);
PUSH(QLocale::Rundi);
PUSH(QLocale::Romanian);
PUSH(QLocale::Russian);
PUSH(QLocale::Kinyarwanda);
PUSH(QLocale::Sanskrit);
PUSH(QLocale::Sindhi);
PUSH(QLocale::NorthernSami);
PUSH(QLocale::Sango);
PUSH(QLocale::Sinhala);
PUSH(QLocale::Slovak);
PUSH(QLocale::Slovenian);
PUSH(QLocale::Shona);
PUSH(QLocale::Somali);
PUSH(QLocale::Albanian);
PUSH(QLocale::Serbian);
PUSH(QLocale::Swati);
PUSH(QLocale::SouthernSotho);
PUSH(QLocale::Swedish);
PUSH(QLocale::Swahili);
PUSH(QLocale::Tamil);
PUSH(QLocale::Telugu);
PUSH(QLocale::Tajik);
PUSH(QLocale::Thai);
PUSH(QLocale::Tigrinya);
PUSH(QLocale::Turkmen);
PUSH(QLocale::Filipino);
PUSH(QLocale::Tswana);
PUSH(QLocale::Tongan);
PUSH(QLocale::Turkish);
PUSH(QLocale::Tsonga);
PUSH(QLocale::Tatar);
PUSH(QLocale::Uighur);
PUSH(QLocale::Ukrainian);
PUSH(QLocale::Urdu);
PUSH(QLocale::Uzbek);
PUSH(QLocale::Venda);
PUSH(QLocale::Vietnamese);
PUSH(QLocale::Walloon);
PUSH(QLocale::Wolof);
PUSH(QLocale::Xhosa);
PUSH(QLocale::Yoruba);
PUSH(QLocale::Chinese);
PUSH(QLocale::Zulu);
#undef PUSH
}

15
src/static_content.h Normal file
View File

@ -0,0 +1,15 @@
#ifndef STATICCONTENT_H
#define STATICCONTENT_H
#include <QLocale>
#include <QString>
#include <utility>
#include <vector>
extern std::vector<QLocale::Language> S_LANGUAGES;
extern std::vector<std::pair<QString, QString>> S_CATEGORIES;
void initStaticContent();
#endif //STATICCONTENT_H