mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-22 11:37:56 -04:00
Remember language and category values
Language and category values are now a setting
This commit is contained in:
parent
fd371d2a47
commit
ccf1e505a1
@ -56,7 +56,6 @@ ContentManager::ContentManager(Library* library, kiwix::Downloader* downloader,
|
|||||||
treeView->setColumnWidth(5, 120);
|
treeView->setColumnWidth(5, 120);
|
||||||
// TODO: set width for all columns based on viewport
|
// TODO: set width for all columns based on viewport
|
||||||
|
|
||||||
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::filterParamsChanged, this, &ContentManager::updateLibrary);
|
connect(this, &ContentManager::filterParamsChanged, this, &ContentManager::updateLibrary);
|
||||||
connect(this, &ContentManager::booksChanged, this, [=]() {
|
connect(this, &ContentManager::booksChanged, this, [=]() {
|
||||||
@ -72,6 +71,8 @@ ContentManager::ContentManager(Library* library, kiwix::Downloader* downloader,
|
|||||||
connect(&m_remoteLibraryManager, &OpdsRequestManager::categoriesReceived, this, &ContentManager::updateCategories);
|
connect(&m_remoteLibraryManager, &OpdsRequestManager::categoriesReceived, this, &ContentManager::updateCategories);
|
||||||
setCategories();
|
setCategories();
|
||||||
setLanguages();
|
setLanguages();
|
||||||
|
setCurrentLanguage(KiwixApp::instance()->getSettingsManager()->getLanguageList());
|
||||||
|
setCurrentCategoryFilter(KiwixApp::instance()->getSettingsManager()->getCategoryList());
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QMap<QString, QVariant>> ContentManager::getBooksList()
|
QList<QMap<QString, QVariant>> ContentManager::getBooksList()
|
||||||
@ -617,26 +618,35 @@ QStringList ContentManager::getDownloadIds()
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentManager::setCurrentLanguage(QString language)
|
void ContentManager::setCurrentLanguage(QStringList languageList)
|
||||||
{
|
{
|
||||||
if (language.length() == 2) {
|
languageList.sort();
|
||||||
try {
|
for (auto &language : languageList) {
|
||||||
language = QString::fromStdString(
|
if (language.length() == 2) {
|
||||||
kiwix::converta2toa3(language.toStdString()));
|
try {
|
||||||
} catch (std::out_of_range&) {}
|
language = QString::fromStdString(
|
||||||
|
kiwix::converta2toa3(language.toStdString()));
|
||||||
|
} catch (std::out_of_range&) {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (m_currentLanguage == language)
|
if (languageList.empty())
|
||||||
|
languageList.append("*");
|
||||||
|
auto newLanguage = languageList.join(",");
|
||||||
|
if (m_currentLanguage == newLanguage)
|
||||||
return;
|
return;
|
||||||
m_currentLanguage = language;
|
m_currentLanguage = newLanguage;
|
||||||
|
KiwixApp::instance()->getSettingsManager()->setLanguage(languageList);
|
||||||
emit(currentLangChanged());
|
emit(currentLangChanged());
|
||||||
emit(filterParamsChanged());
|
emit(filterParamsChanged());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentManager::setCurrentCategoryFilter(QString category)
|
void ContentManager::setCurrentCategoryFilter(QStringList categoryList)
|
||||||
{
|
{
|
||||||
if (m_categoryFilter == category)
|
categoryList.sort();
|
||||||
|
if (m_categoryFilter == categoryList.join(","))
|
||||||
return;
|
return;
|
||||||
m_categoryFilter = category.toLower();
|
m_categoryFilter = categoryList.join(",");
|
||||||
|
KiwixApp::instance()->getSettingsManager()->setCategory(categoryList);
|
||||||
emit(filterParamsChanged());
|
emit(filterParamsChanged());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,6 @@ class ContentManager : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QStringList bookIds READ getBookIds NOTIFY booksChanged)
|
Q_PROPERTY(QStringList bookIds READ getBookIds NOTIFY booksChanged)
|
||||||
Q_PROPERTY(QStringList downloadIds READ getDownloadIds NOTIFY downloadsChanged)
|
Q_PROPERTY(QStringList downloadIds READ getDownloadIds NOTIFY downloadsChanged)
|
||||||
Q_PROPERTY(QString currentLanguage MEMBER m_currentLanguage WRITE setCurrentLanguage NOTIFY currentLangChanged)
|
|
||||||
Q_PROPERTY(bool isLocal MEMBER m_local READ isLocal WRITE setLocal NOTIFY localChanged)
|
Q_PROPERTY(bool isLocal MEMBER m_local READ isLocal WRITE setLocal NOTIFY localChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -26,8 +25,8 @@ public:
|
|||||||
ContentManagerView* getView() { return mp_view; }
|
ContentManagerView* getView() { return mp_view; }
|
||||||
void setLocal(bool local);
|
void setLocal(bool local);
|
||||||
QStringList getDownloadIds();
|
QStringList getDownloadIds();
|
||||||
void setCurrentLanguage(QString language);
|
void setCurrentLanguage(QStringList languageList);
|
||||||
void setCurrentCategoryFilter(QString category);
|
void setCurrentCategoryFilter(QStringList category);
|
||||||
void setCurrentContentTypeFilter(QList<ContentTypeFilter*>& contentTypeFilter);
|
void setCurrentContentTypeFilter(QList<ContentTypeFilter*>& contentTypeFilter);
|
||||||
bool isLocal() const { return m_local; }
|
bool isLocal() const { return m_local; }
|
||||||
QStringList getCategories() const { return m_categories; }
|
QStringList getCategories() const { return m_categories; }
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
#include "ui_contentmanagerside.h"
|
#include "ui_contentmanagerside.h"
|
||||||
#include "kiwixapp.h"
|
#include "kiwixapp.h"
|
||||||
#include "kiwixchoicebox.h"
|
#include "kiwixchoicebox.h"
|
||||||
|
|
||||||
#include <QLocale>
|
#include <QLocale>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
@ -118,13 +117,12 @@ void ContentManagerSide::setContentManager(ContentManager *contentManager)
|
|||||||
connect(mp_languages, &KiwixChoiceBox::choiceUpdated,
|
connect(mp_languages, &KiwixChoiceBox::choiceUpdated,
|
||||||
this, [=](QStringList values) {
|
this, [=](QStringList values) {
|
||||||
if (values[0] == "all") {
|
if (values[0] == "all") {
|
||||||
mp_contentManager->setCurrentLanguage("*");
|
values = QStringList();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
mp_contentManager->setCurrentLanguage(values.join(","));
|
mp_contentManager->setCurrentLanguage(values);
|
||||||
});
|
});
|
||||||
connect(mp_categories, &KiwixChoiceBox::choiceUpdated, this, [=](QStringList values) {
|
connect(mp_categories, &KiwixChoiceBox::choiceUpdated, this, [=](QStringList values) {
|
||||||
mp_contentManager->setCurrentCategoryFilter(values.join(","));
|
mp_contentManager->setCurrentCategoryFilter(values);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,10 +135,10 @@ QString beautify(QString word)
|
|||||||
|
|
||||||
void ContentManagerSide::setCategories(QStringList categories)
|
void ContentManagerSide::setCategories(QStringList categories)
|
||||||
{
|
{
|
||||||
mp_categories->setSelections(categories, gt("all"));
|
mp_categories->setSelections(categories, KiwixApp::instance()->getSettingsManager()->getCategoryList());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentManagerSide::setLanguages(ContentManager::LanguageList langList)
|
void ContentManagerSide::setLanguages(ContentManager::LanguageList langList)
|
||||||
{
|
{
|
||||||
mp_languages->setSelections(langList, QLocale::languageToString(QLocale().language()));
|
mp_languages->setSelections(langList, KiwixApp::instance()->getSettingsManager()->getLanguageList());
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,6 @@ KiwixChoiceBox::KiwixChoiceBox(QWidget *parent) :
|
|||||||
QWidget(parent),
|
QWidget(parent),
|
||||||
ui(new Ui::kiwixchoicebox)
|
ui(new Ui::kiwixchoicebox)
|
||||||
{
|
{
|
||||||
m_defaultItem = nullptr;
|
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
QFile file(QString::fromUtf8(":/css/choiceBox.css"));
|
QFile file(QString::fromUtf8(":/css/choiceBox.css"));
|
||||||
@ -153,7 +152,7 @@ QString beautifyString(QString word)
|
|||||||
return word;
|
return word;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KiwixChoiceBox::setSelections(QStringList selections, QString defaultSelection)
|
void KiwixChoiceBox::setSelections(QStringList selections, QStringList defaultSelection)
|
||||||
{
|
{
|
||||||
SelectionList sList;
|
SelectionList sList;
|
||||||
for (const auto &sel : selections) {
|
for (const auto &sel : selections) {
|
||||||
@ -162,7 +161,7 @@ void KiwixChoiceBox::setSelections(QStringList selections, QString defaultSelect
|
|||||||
setSelections(sList, defaultSelection);
|
setSelections(sList, defaultSelection);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KiwixChoiceBox::setSelections(SelectionList selections, QString defaultSelection)
|
void KiwixChoiceBox::setSelections(SelectionList selections, QStringList defaultSelection)
|
||||||
{
|
{
|
||||||
choiceSelector->clear();
|
choiceSelector->clear();
|
||||||
for (const auto &selection: selections)
|
for (const auto &selection: selections)
|
||||||
@ -170,15 +169,11 @@ void KiwixChoiceBox::setSelections(SelectionList selections, QString defaultSele
|
|||||||
auto item = new KListWidgetItem(beautifyString(selection.second));
|
auto item = new KListWidgetItem(beautifyString(selection.second));
|
||||||
item->setData(Qt::UserRole, selection.first);
|
item->setData(Qt::UserRole, selection.first);
|
||||||
choiceSelector->addItem(item);
|
choiceSelector->addItem(item);
|
||||||
if (selection.second == defaultSelection)
|
if (defaultSelection.contains(selection.first)) {
|
||||||
{
|
item->setSelected(true);
|
||||||
m_defaultItem = item;
|
addSelection(item->text(), item->data(Qt::UserRole).toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (choiceSelector->selectedItems().isEmpty() && m_defaultItem) {
|
|
||||||
m_defaultItem->setSelected(true);
|
|
||||||
addSelection(m_defaultItem->text(), m_defaultItem->data(Qt::UserRole).toString());
|
|
||||||
}
|
|
||||||
adjustSize();
|
adjustSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,8 +28,8 @@ class KiwixChoiceBox : public QWidget
|
|||||||
public:
|
public:
|
||||||
explicit KiwixChoiceBox(QWidget *parent = nullptr);
|
explicit KiwixChoiceBox(QWidget *parent = nullptr);
|
||||||
void setType(QString type);
|
void setType(QString type);
|
||||||
void setSelections(SelectionList selections, QString defaultSelection);
|
void setSelections(SelectionList selections, QStringList defaultSelection);
|
||||||
void setSelections(QStringList selections, QString defaultSelection);
|
void setSelections(QStringList selections, QStringList defaultSelection);
|
||||||
~KiwixChoiceBox();
|
~KiwixChoiceBox();
|
||||||
void adjustSize();
|
void adjustSize();
|
||||||
|
|
||||||
@ -44,7 +44,6 @@ private:
|
|||||||
QLabel *choiceLabel;
|
QLabel *choiceLabel;
|
||||||
QLineEdit *choiceSearch;
|
QLineEdit *choiceSearch;
|
||||||
QListWidget *choiceSelector;
|
QListWidget *choiceSelector;
|
||||||
QListWidgetItem *m_defaultItem;
|
|
||||||
FlowLayout *currentChoicesLayout;
|
FlowLayout *currentChoicesLayout;
|
||||||
KiwixLineEdit *searcher;
|
KiwixLineEdit *searcher;
|
||||||
QStringList getCurrentSelected();
|
QStringList getCurrentSelected();
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <kiwix/tools.h>
|
#include <kiwix/tools.h>
|
||||||
|
#include <QLocale>
|
||||||
|
|
||||||
SettingsManager::SettingsManager(QObject *parent)
|
SettingsManager::SettingsManager(QObject *parent)
|
||||||
: QObject(parent),
|
: QObject(parent),
|
||||||
m_settings("Kiwix", "Kiwix-desktop"),
|
m_settings("Kiwix", "Kiwix-desktop"),
|
||||||
@ -96,6 +98,20 @@ void SettingsManager::setMoveToTrash(bool moveToTrash)
|
|||||||
emit(moveToTrashChanged(m_moveToTrash));
|
emit(moveToTrashChanged(m_moveToTrash));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SettingsManager::setLanguage(QStringList langList)
|
||||||
|
{
|
||||||
|
m_langList = langList;
|
||||||
|
setSettings("language", m_langList);
|
||||||
|
emit(languageChanged(m_langList));
|
||||||
|
}
|
||||||
|
|
||||||
|
void SettingsManager::setCategory(QStringList categoryList)
|
||||||
|
{
|
||||||
|
m_categoryList = categoryList;
|
||||||
|
setSettings("category", m_categoryList);
|
||||||
|
emit(categoryChanged(m_categoryList));
|
||||||
|
}
|
||||||
|
|
||||||
void SettingsManager::initSettings()
|
void SettingsManager::initSettings()
|
||||||
{
|
{
|
||||||
m_kiwixServerPort = m_settings.value("localKiwixServer/port", 8080).toInt();
|
m_kiwixServerPort = m_settings.value("localKiwixServer/port", 8080).toInt();
|
||||||
@ -104,4 +120,6 @@ void SettingsManager::initSettings()
|
|||||||
m_kiwixServerIpAddress = m_settings.value("localKiwixServer/ipAddress", QString("0.0.0.0")).toString();
|
m_kiwixServerIpAddress = m_settings.value("localKiwixServer/ipAddress", QString("0.0.0.0")).toString();
|
||||||
m_monitorDir = m_settings.value("monitor/dir", QString("")).toString();
|
m_monitorDir = m_settings.value("monitor/dir", QString("")).toString();
|
||||||
m_moveToTrash = m_settings.value("moveToTrash", true).toBool();
|
m_moveToTrash = m_settings.value("moveToTrash", true).toBool();
|
||||||
|
m_langList = m_settings.value("language", QLocale::languageToString(QLocale().language())).toStringList();
|
||||||
|
m_categoryList = m_settings.value("category", {"all"}).toStringList();
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,8 @@ public:
|
|||||||
QString getDownloadDir() const { return m_downloadDir; }
|
QString getDownloadDir() const { return m_downloadDir; }
|
||||||
QString getMonitorDir() const { return m_monitorDir; }
|
QString getMonitorDir() const { return m_monitorDir; }
|
||||||
bool getMoveToTrash() const { return m_moveToTrash; }
|
bool getMoveToTrash() const { return m_moveToTrash; }
|
||||||
|
QStringList getLanguageList() const { return m_langList; }
|
||||||
|
QStringList getCategoryList() const { return m_categoryList; }
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setKiwixServerPort(int port);
|
void setKiwixServerPort(int port);
|
||||||
@ -36,6 +38,8 @@ public slots:
|
|||||||
void setDownloadDir(QString downloadDir);
|
void setDownloadDir(QString downloadDir);
|
||||||
void setMonitorDir(QString monitorDir);
|
void setMonitorDir(QString monitorDir);
|
||||||
void setMoveToTrash(bool moveToTrash);
|
void setMoveToTrash(bool moveToTrash);
|
||||||
|
void setLanguage(QStringList langList);
|
||||||
|
void setCategory(QStringList categoryList);
|
||||||
private:
|
private:
|
||||||
void initSettings();
|
void initSettings();
|
||||||
|
|
||||||
@ -45,6 +49,8 @@ signals:
|
|||||||
void downloadDirChanged(QString downloadDir);
|
void downloadDirChanged(QString downloadDir);
|
||||||
void monitorDirChanged(QString monitorDir);
|
void monitorDirChanged(QString monitorDir);
|
||||||
void moveToTrashChanged(bool moveToTrash);
|
void moveToTrashChanged(bool moveToTrash);
|
||||||
|
void languageChanged(QStringList langList);
|
||||||
|
void categoryChanged(QStringList categoryList);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QSettings m_settings;
|
QSettings m_settings;
|
||||||
@ -55,6 +61,8 @@ private:
|
|||||||
QString m_downloadDir;
|
QString m_downloadDir;
|
||||||
QString m_monitorDir;
|
QString m_monitorDir;
|
||||||
bool m_moveToTrash;
|
bool m_moveToTrash;
|
||||||
|
QStringList m_langList;
|
||||||
|
QStringList m_categoryList;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SETTINGSMANAGER_H
|
#endif // SETTINGSMANAGER_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user