From f58fd20201bf7f5bef3ec2a35db3325d8d1a7c12 Mon Sep 17 00:00:00 2001 From: Bart De Vries Date: Mon, 22 Apr 2024 16:22:46 +0200 Subject: [PATCH] Save filters on episode list and episode detail pages FEATURE: 466792 --- src/database.cpp | 12 ++++++++++++ src/database.h | 1 + src/datamanager.cpp | 3 ++- src/feed.cpp | 19 +++++++++++++++++++ src/models/abstractepisodeproxymodel.h | 2 +- src/qml/EpisodeListPage.qml | 7 ++++++- src/qml/Main.qml | 1 + 7 files changed, 42 insertions(+), 3 deletions(-) diff --git a/src/database.cpp b/src/database.cpp index 180692b4..318fbadf 100644 --- a/src/database.cpp +++ b/src/database.cpp @@ -74,6 +74,8 @@ bool Database::migrate() TRUE_OR_RETURN(migrateTo8()); if (dbversion < 9) TRUE_OR_RETURN(migrateTo9()); + if (dbversion < 10) + TRUE_OR_RETURN(migrateTo10()); return true; } @@ -263,6 +265,16 @@ bool Database::migrateTo9() return true; } +bool Database::migrateTo10() +{ + qDebug() << "Migrating database to version 10"; + TRUE_OR_RETURN(transaction()); + TRUE_OR_RETURN(execute(QStringLiteral("ALTER TABLE Feeds ADD COLUMN filterType INTEGER DEFAULT 0;"))); + TRUE_OR_RETURN(execute(QStringLiteral("PRAGMA user_version = 10;"))); + TRUE_OR_RETURN(commit()); + return true; +} + bool Database::execute(const QString &query, const QString &connectionName) { QSqlQuery q(connectionName); diff --git a/src/database.h b/src/database.h index d6096414..34ca8a71 100644 --- a/src/database.h +++ b/src/database.h @@ -53,6 +53,7 @@ private: bool migrateTo7(); bool migrateTo8(); bool migrateTo9(); + bool migrateTo10(); void cleanup(); void setWalMode(); diff --git a/src/datamanager.cpp b/src/datamanager.cpp index 8a7f214c..92f0f094 100644 --- a/src/datamanager.cpp +++ b/src/datamanager.cpp @@ -371,7 +371,7 @@ void DataManager::addFeeds(const QStringList &urls, const bool fetch) QSqlQuery query; query.prepare( QStringLiteral("INSERT INTO Feeds VALUES (:name, :url, :image, :link, :description, :deleteAfterCount, :deleteAfterType, :subscribed, " - ":lastUpdated, :new, :notify, :dirname, :lastHash);")); + ":lastUpdated, :new, :notify, :dirname, :lastHash, :filterType);")); query.bindValue(QStringLiteral(":name"), urlFromInput); query.bindValue(QStringLiteral(":url"), urlFromInput); query.bindValue(QStringLiteral(":image"), QLatin1String("")); @@ -385,6 +385,7 @@ void DataManager::addFeeds(const QStringList &urls, const bool fetch) query.bindValue(QStringLiteral(":notify"), false); query.bindValue(QStringLiteral(":dirname"), QLatin1String("")); query.bindValue(QStringLiteral(":lastHash"), QLatin1String("")); + query.bindValue(QStringLiteral(":filterType"), 0); Database::instance().execute(query); // TODO: check whether the entry in the database happened correctly? diff --git a/src/feed.cpp b/src/feed.cpp index 0a580b46..bffac027 100644 --- a/src/feed.cpp +++ b/src/feed.cpp @@ -15,6 +15,7 @@ #include "feed.h" #include "feedlogging.h" #include "fetcher.h" +#include "models/abstractepisodeproxymodel.h" Feed::Feed(const QString &feedurl) : QObject(&DataManager::instance()) @@ -38,6 +39,7 @@ Feed::Feed(const QString &feedurl) m_deleteAfterCount = query.value(QStringLiteral("deleteAfterCount")).toInt(); m_deleteAfterType = query.value(QStringLiteral("deleteAfterType")).toInt(); m_notify = query.value(QStringLiteral("notify")).toBool(); + int filterTypeValue = query.value(QStringLiteral("filterType")).toInt(); m_dirname = query.value(QStringLiteral("dirname")).toString(); m_errorId = 0; @@ -97,6 +99,23 @@ Feed::Feed(const QString &feedurl) }); m_entries = new EntriesProxyModel(this); + + // restore saved filter + AbstractEpisodeProxyModel::FilterType filterType = AbstractEpisodeProxyModel::FilterType(filterTypeValue); + if (filterType != m_entries->filterType()) { + m_entries->setFilterType(filterType); + } + + // save filter to db when changed + connect(m_entries, &EntriesProxyModel::filterTypeChanged, this, [this]() { + int filterTypeValue = static_cast(m_entries->filterType()); + + QSqlQuery writeQuery; + writeQuery.prepare(QStringLiteral("UPDATE Feeds SET filterType=:filterType WHERE url=:feedurl;")); + writeQuery.bindValue(QStringLiteral(":feedurl"), m_url); + writeQuery.bindValue(QStringLiteral(":filterType"), filterTypeValue); + Database::instance().execute(writeQuery); + }); } void Feed::updateAuthors() diff --git a/src/models/abstractepisodeproxymodel.h b/src/models/abstractepisodeproxymodel.h index f123c5d9..92d8ab68 100644 --- a/src/models/abstractepisodeproxymodel.h +++ b/src/models/abstractepisodeproxymodel.h @@ -23,7 +23,7 @@ class AbstractEpisodeProxyModel : public QSortFilterProxyModel public: enum FilterType { - NoFilter, + NoFilter = 0, ReadFilter, NotReadFilter, NewFilter, diff --git a/src/qml/EpisodeListPage.qml b/src/qml/EpisodeListPage.qml index e147ae65..2840267d 100644 --- a/src/qml/EpisodeListPage.qml +++ b/src/qml/EpisodeListPage.qml @@ -47,7 +47,6 @@ Kirigami.ScrollablePage { icon.name: "view-refresh" text: i18n("Refresh All Podcasts") onTriggered: refreshing = true - visible: episodeProxyModel.filterType == AbstractEpisodeProxyModel.NoFilter }, Kirigami.Action { id: searchActionButton @@ -93,6 +92,12 @@ Kirigami.ScrollablePage { model: EpisodeProxyModel { id: episodeProxyModel + + // save and restore filter settings + filterType: settings.episodeListFilterType + onFilterTypeChanged: { + settings.episodeListFilterType = filterType; + } } delegate: GenericEntryDelegate { diff --git a/src/qml/Main.qml b/src/qml/Main.qml index 9ce13d8e..a7cb2854 100644 --- a/src/qml/Main.qml +++ b/src/qml/Main.qml @@ -93,6 +93,7 @@ Kirigami.ApplicationWindow { property int headerSize: Kirigami.Units.gridUnit * 5 property alias lastOpenedPage: kastsMainWindow.currentPage property alias feedSorting: kastsMainWindow.feedSorting + property int episodeListFilterType: AbstractEpisodeProxyModel.NoFilter } function saveWindowLayout() {