Skip to content

Commit

Permalink
fixup! Save filter settings with their keys
Browse files Browse the repository at this point in the history
  • Loading branch information
juuz0 committed Oct 4, 2023
1 parent 6a3edc3 commit 0a14818
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 24 deletions.
6 changes: 3 additions & 3 deletions src/contentmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ QStringList ContentManager::getDownloadIds()
return list;
}

void ContentManager::setCurrentLanguage(QList<QPair<QString, QString>> langPairList)
void ContentManager::setCurrentLanguage(FilterList langPairList)
{
QStringList languageList;
for (auto &langPair : langPairList) {
Expand All @@ -643,7 +643,7 @@ void ContentManager::setCurrentLanguage(QList<QPair<QString, QString>> langPairL
emit(filterParamsChanged());
}

void ContentManager::setCurrentCategoryFilter(QList<QPair<QString, QString>> categoryPairList)
void ContentManager::setCurrentCategoryFilter(FilterList categoryPairList)
{
QStringList categoryList;
for (auto &catPair : categoryPairList) {
Expand All @@ -657,7 +657,7 @@ void ContentManager::setCurrentCategoryFilter(QList<QPair<QString, QString>> cat
emit(filterParamsChanged());
}

void ContentManager::setCurrentContentTypeFilter(QList<QPair<QString, QString>> contentTypeFiltersPairList)
void ContentManager::setCurrentContentTypeFilter(FilterList contentTypeFiltersPairList)
{
QStringList contentTypeFilters;
for (auto &ctfPair : contentTypeFiltersPairList) {
Expand Down
7 changes: 4 additions & 3 deletions src/contentmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ class ContentManager : public QObject

public:
typedef QList<QPair<QString, QString>> LanguageList;
typedef QList<QPair<QString, QString>> FilterList;
explicit ContentManager(Library* library, kiwix::Downloader *downloader, QObject *parent = nullptr);
virtual ~ContentManager() {}

ContentManagerView* getView() { return mp_view; }
void setLocal(bool local);
QStringList getDownloadIds();
void setCurrentLanguage(QList<QPair<QString, QString>> languageList);
void setCurrentCategoryFilter(QList<QPair<QString, QString>> category);
void setCurrentContentTypeFilter(QList<QPair<QString, QString>> contentTypeFilter);
void setCurrentLanguage(FilterList languageList);
void setCurrentCategoryFilter(FilterList category);
void setCurrentContentTypeFilter(FilterList contentTypeFilter);
bool isLocal() const { return m_local; }
QStringList getCategories() const { return m_categories; }
LanguageList getLanguages() const { return m_languages; }
Expand Down
8 changes: 4 additions & 4 deletions src/contentmanagerside.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ ContentManagerSide::ContentManagerSide(QWidget *parent) :
KiwixApp::instance()->getContentManager()->setSearch(searcher->text());
});

QList<QPair<QString, QString>> contentTypeList = {
FilterList contentTypeList = {
{"_pictures:yes", gt("pictures")},
{"_pictures:no", gt("no-pictures")},
{"_videos:yes", gt("videos")},
Expand Down Expand Up @@ -79,13 +79,13 @@ void ContentManagerSide::setContentManager(ContentManager *contentManager)
const auto checkedButton = mp_ui->buttonGroup->button(isLocal == CatalogButtonId::LOCAL);
checkedButton->setChecked(true);
checkedButton->setStyleSheet("*{font-weight: bold}");
connect(mp_languages, &KiwixChoiceBox::choiceUpdated, this, [=](QList<QPair<QString, QString>> values) {
connect(mp_languages, &KiwixChoiceBox::choiceUpdated, this, [=](FilterList values) {
mp_contentManager->setCurrentLanguage(values);
});
connect(mp_categories, &KiwixChoiceBox::choiceUpdated, this, [=](QList<QPair<QString, QString>> values) {
connect(mp_categories, &KiwixChoiceBox::choiceUpdated, this, [=](FilterList values) {
mp_contentManager->setCurrentCategoryFilter(values);
});
connect(mp_contentType, &KiwixChoiceBox::choiceUpdated, this, [=](QList<QPair<QString, QString>> values) {
connect(mp_contentType, &KiwixChoiceBox::choiceUpdated, this, [=](FilterList values) {
mp_contentManager->setCurrentContentTypeFilter(values);
});
}
Expand Down
1 change: 1 addition & 0 deletions src/contentmanagerside.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class contentmanagerside;
}

class KiwixChoiceBox;
using FilterList = ContentManager::FilterList;

class ContentManagerSide : public QWidget
{
Expand Down
12 changes: 6 additions & 6 deletions src/settingsmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void SettingsManager::setMoveToTrash(bool moveToTrash)
emit(moveToTrashChanged(m_moveToTrash));
}

QList<QVariant> SettingsManager::flattenPair(QList<QPair<QString, QString>> pairList)
QList<QVariant> SettingsManager::flattenPair(FilterList pairList)
{
QList<QVariant> res;
for (auto &pair : pairList) {
Expand All @@ -107,9 +107,9 @@ QList<QVariant> SettingsManager::flattenPair(QList<QPair<QString, QString>> pair
return res;
}

QList<QPair<QString, QString>> SettingsManager::deducePair(QList<QVariant> variantList)
SettingsManager::FilterList SettingsManager::deducePair(QList<QVariant> variantList)
{
QList<QPair<QString, QString>> pairList;
FilterList pairList;
for (auto &variant : variantList) {
QString str = variant.toString();
auto pairs = str.split('|');
Expand All @@ -118,21 +118,21 @@ QList<QPair<QString, QString>> SettingsManager::deducePair(QList<QVariant> varia
return pairList;
}

void SettingsManager::setLanguage(QList<QPair<QString, QString>> langList)
void SettingsManager::setLanguage(FilterList langList)
{
m_langList = flattenPair(langList);
setSettings("language", m_langList);
emit(languageChanged(m_langList));
}

void SettingsManager::setCategory(QList<QPair<QString, QString>> categoryList)
void SettingsManager::setCategory(FilterList categoryList)
{
m_categoryList = flattenPair(categoryList);
setSettings("category", m_categoryList);
emit(categoryChanged(m_categoryList));
}

void SettingsManager::setContentType(QList<QPair<QString, QString>> contentTypeList)
void SettingsManager::setContentType(FilterList contentTypeList)
{
m_contentTypeList = flattenPair(contentTypeList);
setSettings("contentType", m_contentTypeList);
Expand Down
17 changes: 9 additions & 8 deletions src/settingsmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class SettingsManager : public QObject
Q_PROPERTY(QString downloadDir MEMBER m_downloadDir WRITE setDownloadDir NOTIFY downloadDirChanged)

public:
typedef QList<QPair<QString, QString>> FilterList;
explicit SettingsManager(QObject *parent = nullptr);
virtual ~SettingsManager() {};

Expand All @@ -28,9 +29,9 @@ class SettingsManager : public QObject
QString getDownloadDir() const { return m_downloadDir; }
QString getMonitorDir() const { return m_monitorDir; }
bool getMoveToTrash() const { return m_moveToTrash; }
QList<QPair<QString, QString>> getLanguageList() { return deducePair(m_langList); }
QList<QPair<QString, QString>> getCategoryList() { return deducePair(m_categoryList); }
QList<QPair<QString, QString>> getContentType() { return deducePair(m_contentTypeList); }
FilterList getLanguageList() { return deducePair(m_langList); }
FilterList getCategoryList() { return deducePair(m_categoryList); }
FilterList getContentType() { return deducePair(m_contentTypeList); }

public slots:
void setKiwixServerPort(int port);
Expand All @@ -39,13 +40,13 @@ public slots:
void setDownloadDir(QString downloadDir);
void setMonitorDir(QString monitorDir);
void setMoveToTrash(bool moveToTrash);
void setLanguage(QList<QPair<QString, QString>> langList);
void setCategory(QList<QPair<QString, QString>> categoryList);
void setContentType(QList<QPair<QString, QString>> contentTypeList);
void setLanguage(FilterList langList);
void setCategory(FilterList categoryList);
void setContentType(FilterList contentTypeList);
private:
void initSettings();
QList<QVariant> flattenPair(QList<QPair<QString, QString>> pairList);
QList<QPair<QString, QString>> deducePair(QList<QVariant>);
QList<QVariant> flattenPair(FilterList pairList);
FilterList deducePair(QList<QVariant>);

signals:
void portChanged(int port);
Expand Down

0 comments on commit 0a14818

Please sign in to comment.