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);
|
||||
// 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(this, &ContentManager::filterParamsChanged, this, &ContentManager::updateLibrary);
|
||||
connect(this, &ContentManager::booksChanged, this, [=]() {
|
||||
@ -72,6 +71,8 @@ ContentManager::ContentManager(Library* library, kiwix::Downloader* downloader,
|
||||
connect(&m_remoteLibraryManager, &OpdsRequestManager::categoriesReceived, this, &ContentManager::updateCategories);
|
||||
setCategories();
|
||||
setLanguages();
|
||||
setCurrentLanguage(KiwixApp::instance()->getSettingsManager()->getLanguageList());
|
||||
setCurrentCategoryFilter(KiwixApp::instance()->getSettingsManager()->getCategoryList());
|
||||
}
|
||||
|
||||
QList<QMap<QString, QVariant>> ContentManager::getBooksList()
|
||||
@ -617,26 +618,35 @@ QStringList ContentManager::getDownloadIds()
|
||||
return list;
|
||||
}
|
||||
|
||||
void ContentManager::setCurrentLanguage(QString language)
|
||||
void ContentManager::setCurrentLanguage(QStringList languageList)
|
||||
{
|
||||
if (language.length() == 2) {
|
||||
try {
|
||||
language = QString::fromStdString(
|
||||
kiwix::converta2toa3(language.toStdString()));
|
||||
} catch (std::out_of_range&) {}
|
||||
languageList.sort();
|
||||
for (auto &language : languageList) {
|
||||
if (language.length() == 2) {
|
||||
try {
|
||||
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;
|
||||
m_currentLanguage = language;
|
||||
m_currentLanguage = newLanguage;
|
||||
KiwixApp::instance()->getSettingsManager()->setLanguage(languageList);
|
||||
emit(currentLangChanged());
|
||||
emit(filterParamsChanged());
|
||||
}
|
||||
|
||||
void ContentManager::setCurrentCategoryFilter(QString category)
|
||||
void ContentManager::setCurrentCategoryFilter(QStringList categoryList)
|
||||
{
|
||||
if (m_categoryFilter == category)
|
||||
categoryList.sort();
|
||||
if (m_categoryFilter == categoryList.join(","))
|
||||
return;
|
||||
m_categoryFilter = category.toLower();
|
||||
m_categoryFilter = categoryList.join(",");
|
||||
KiwixApp::instance()->getSettingsManager()->setCategory(categoryList);
|
||||
emit(filterParamsChanged());
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,6 @@ class ContentManager : public QObject
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QStringList bookIds READ getBookIds NOTIFY booksChanged)
|
||||
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)
|
||||
|
||||
public:
|
||||
@ -26,8 +25,8 @@ public:
|
||||
ContentManagerView* getView() { return mp_view; }
|
||||
void setLocal(bool local);
|
||||
QStringList getDownloadIds();
|
||||
void setCurrentLanguage(QString language);
|
||||
void setCurrentCategoryFilter(QString category);
|
||||
void setCurrentLanguage(QStringList languageList);
|
||||
void setCurrentCategoryFilter(QStringList category);
|
||||
void setCurrentContentTypeFilter(QList<ContentTypeFilter*>& contentTypeFilter);
|
||||
bool isLocal() const { return m_local; }
|
||||
QStringList getCategories() const { return m_categories; }
|
||||
|
@ -2,7 +2,6 @@
|
||||
#include "ui_contentmanagerside.h"
|
||||
#include "kiwixapp.h"
|
||||
#include "kiwixchoicebox.h"
|
||||
|
||||
#include <QLocale>
|
||||
#include <QDebug>
|
||||
|
||||
@ -118,13 +117,12 @@ void ContentManagerSide::setContentManager(ContentManager *contentManager)
|
||||
connect(mp_languages, &KiwixChoiceBox::choiceUpdated,
|
||||
this, [=](QStringList values) {
|
||||
if (values[0] == "all") {
|
||||
mp_contentManager->setCurrentLanguage("*");
|
||||
return;
|
||||
values = QStringList();
|
||||
}
|
||||
mp_contentManager->setCurrentLanguage(values.join(","));
|
||||
mp_contentManager->setCurrentLanguage(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)
|
||||
{
|
||||
mp_categories->setSelections(categories, gt("all"));
|
||||
mp_categories->setSelections(categories, KiwixApp::instance()->getSettingsManager()->getCategoryList());
|
||||
}
|
||||
|
||||
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),
|
||||
ui(new Ui::kiwixchoicebox)
|
||||
{
|
||||
m_defaultItem = nullptr;
|
||||
ui->setupUi(this);
|
||||
|
||||
QFile file(QString::fromUtf8(":/css/choiceBox.css"));
|
||||
@ -153,7 +152,7 @@ QString beautifyString(QString word)
|
||||
return word;
|
||||
}
|
||||
|
||||
void KiwixChoiceBox::setSelections(QStringList selections, QString defaultSelection)
|
||||
void KiwixChoiceBox::setSelections(QStringList selections, QStringList defaultSelection)
|
||||
{
|
||||
SelectionList sList;
|
||||
for (const auto &sel : selections) {
|
||||
@ -162,7 +161,7 @@ void KiwixChoiceBox::setSelections(QStringList selections, QString defaultSelect
|
||||
setSelections(sList, defaultSelection);
|
||||
}
|
||||
|
||||
void KiwixChoiceBox::setSelections(SelectionList selections, QString defaultSelection)
|
||||
void KiwixChoiceBox::setSelections(SelectionList selections, QStringList defaultSelection)
|
||||
{
|
||||
choiceSelector->clear();
|
||||
for (const auto &selection: selections)
|
||||
@ -170,15 +169,11 @@ void KiwixChoiceBox::setSelections(SelectionList selections, QString defaultSele
|
||||
auto item = new KListWidgetItem(beautifyString(selection.second));
|
||||
item->setData(Qt::UserRole, selection.first);
|
||||
choiceSelector->addItem(item);
|
||||
if (selection.second == defaultSelection)
|
||||
{
|
||||
m_defaultItem = item;
|
||||
if (defaultSelection.contains(selection.first)) {
|
||||
item->setSelected(true);
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -28,8 +28,8 @@ class KiwixChoiceBox : public QWidget
|
||||
public:
|
||||
explicit KiwixChoiceBox(QWidget *parent = nullptr);
|
||||
void setType(QString type);
|
||||
void setSelections(SelectionList selections, QString defaultSelection);
|
||||
void setSelections(QStringList selections, QString defaultSelection);
|
||||
void setSelections(SelectionList selections, QStringList defaultSelection);
|
||||
void setSelections(QStringList selections, QStringList defaultSelection);
|
||||
~KiwixChoiceBox();
|
||||
void adjustSize();
|
||||
|
||||
@ -44,7 +44,6 @@ private:
|
||||
QLabel *choiceLabel;
|
||||
QLineEdit *choiceSearch;
|
||||
QListWidget *choiceSelector;
|
||||
QListWidgetItem *m_defaultItem;
|
||||
FlowLayout *currentChoicesLayout;
|
||||
KiwixLineEdit *searcher;
|
||||
QStringList getCurrentSelected();
|
||||
|
@ -4,6 +4,8 @@
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
#include <kiwix/tools.h>
|
||||
#include <QLocale>
|
||||
|
||||
SettingsManager::SettingsManager(QObject *parent)
|
||||
: QObject(parent),
|
||||
m_settings("Kiwix", "Kiwix-desktop"),
|
||||
@ -96,6 +98,20 @@ void SettingsManager::setMoveToTrash(bool 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()
|
||||
{
|
||||
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_monitorDir = m_settings.value("monitor/dir", QString("")).toString();
|
||||
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 getMonitorDir() const { return m_monitorDir; }
|
||||
bool getMoveToTrash() const { return m_moveToTrash; }
|
||||
QStringList getLanguageList() const { return m_langList; }
|
||||
QStringList getCategoryList() const { return m_categoryList; }
|
||||
|
||||
public slots:
|
||||
void setKiwixServerPort(int port);
|
||||
@ -36,6 +38,8 @@ public slots:
|
||||
void setDownloadDir(QString downloadDir);
|
||||
void setMonitorDir(QString monitorDir);
|
||||
void setMoveToTrash(bool moveToTrash);
|
||||
void setLanguage(QStringList langList);
|
||||
void setCategory(QStringList categoryList);
|
||||
private:
|
||||
void initSettings();
|
||||
|
||||
@ -45,6 +49,8 @@ signals:
|
||||
void downloadDirChanged(QString downloadDir);
|
||||
void monitorDirChanged(QString monitorDir);
|
||||
void moveToTrashChanged(bool moveToTrash);
|
||||
void languageChanged(QStringList langList);
|
||||
void categoryChanged(QStringList categoryList);
|
||||
|
||||
private:
|
||||
QSettings m_settings;
|
||||
@ -55,6 +61,8 @@ private:
|
||||
QString m_downloadDir;
|
||||
QString m_monitorDir;
|
||||
bool m_moveToTrash;
|
||||
QStringList m_langList;
|
||||
QStringList m_categoryList;
|
||||
};
|
||||
|
||||
#endif // SETTINGSMANAGER_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user