mirror of https://github.com/KDE/kasts.git
Save filters on episode list and episode detail pages
FEATURE: 466792
This commit is contained in:
parent
7bfaf5654c
commit
9c6c77db7a
|
@ -74,6 +74,8 @@ bool Database::migrate()
|
||||||
TRUE_OR_RETURN(migrateTo8());
|
TRUE_OR_RETURN(migrateTo8());
|
||||||
if (dbversion < 9)
|
if (dbversion < 9)
|
||||||
TRUE_OR_RETURN(migrateTo9());
|
TRUE_OR_RETURN(migrateTo9());
|
||||||
|
if (dbversion < 10)
|
||||||
|
TRUE_OR_RETURN(migrateTo10());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,6 +265,16 @@ bool Database::migrateTo9()
|
||||||
return true;
|
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)
|
bool Database::execute(const QString &query, const QString &connectionName)
|
||||||
{
|
{
|
||||||
QSqlQuery q(connectionName);
|
QSqlQuery q(connectionName);
|
||||||
|
|
|
@ -53,6 +53,7 @@ private:
|
||||||
bool migrateTo7();
|
bool migrateTo7();
|
||||||
bool migrateTo8();
|
bool migrateTo8();
|
||||||
bool migrateTo9();
|
bool migrateTo9();
|
||||||
|
bool migrateTo10();
|
||||||
void cleanup();
|
void cleanup();
|
||||||
void setWalMode();
|
void setWalMode();
|
||||||
|
|
||||||
|
|
|
@ -371,7 +371,7 @@ void DataManager::addFeeds(const QStringList &urls, const bool fetch)
|
||||||
QSqlQuery query;
|
QSqlQuery query;
|
||||||
query.prepare(
|
query.prepare(
|
||||||
QStringLiteral("INSERT INTO Feeds VALUES (:name, :url, :image, :link, :description, :deleteAfterCount, :deleteAfterType, :subscribed, "
|
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(":name"), urlFromInput);
|
||||||
query.bindValue(QStringLiteral(":url"), urlFromInput);
|
query.bindValue(QStringLiteral(":url"), urlFromInput);
|
||||||
query.bindValue(QStringLiteral(":image"), QLatin1String(""));
|
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(":notify"), false);
|
||||||
query.bindValue(QStringLiteral(":dirname"), QLatin1String(""));
|
query.bindValue(QStringLiteral(":dirname"), QLatin1String(""));
|
||||||
query.bindValue(QStringLiteral(":lastHash"), QLatin1String(""));
|
query.bindValue(QStringLiteral(":lastHash"), QLatin1String(""));
|
||||||
|
query.bindValue(QStringLiteral(":filterType"), 0);
|
||||||
Database::instance().execute(query);
|
Database::instance().execute(query);
|
||||||
|
|
||||||
// TODO: check whether the entry in the database happened correctly?
|
// TODO: check whether the entry in the database happened correctly?
|
||||||
|
|
19
src/feed.cpp
19
src/feed.cpp
|
@ -15,6 +15,7 @@
|
||||||
#include "feed.h"
|
#include "feed.h"
|
||||||
#include "feedlogging.h"
|
#include "feedlogging.h"
|
||||||
#include "fetcher.h"
|
#include "fetcher.h"
|
||||||
|
#include "models/abstractepisodeproxymodel.h"
|
||||||
|
|
||||||
Feed::Feed(const QString &feedurl)
|
Feed::Feed(const QString &feedurl)
|
||||||
: QObject(&DataManager::instance())
|
: QObject(&DataManager::instance())
|
||||||
|
@ -38,6 +39,7 @@ Feed::Feed(const QString &feedurl)
|
||||||
m_deleteAfterCount = query.value(QStringLiteral("deleteAfterCount")).toInt();
|
m_deleteAfterCount = query.value(QStringLiteral("deleteAfterCount")).toInt();
|
||||||
m_deleteAfterType = query.value(QStringLiteral("deleteAfterType")).toInt();
|
m_deleteAfterType = query.value(QStringLiteral("deleteAfterType")).toInt();
|
||||||
m_notify = query.value(QStringLiteral("notify")).toBool();
|
m_notify = query.value(QStringLiteral("notify")).toBool();
|
||||||
|
int filterTypeValue = query.value(QStringLiteral("filterType")).toInt();
|
||||||
m_dirname = query.value(QStringLiteral("dirname")).toString();
|
m_dirname = query.value(QStringLiteral("dirname")).toString();
|
||||||
|
|
||||||
m_errorId = 0;
|
m_errorId = 0;
|
||||||
|
@ -97,6 +99,23 @@ Feed::Feed(const QString &feedurl)
|
||||||
});
|
});
|
||||||
|
|
||||||
m_entries = new EntriesProxyModel(this);
|
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<int>(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()
|
void Feed::updateAuthors()
|
||||||
|
|
|
@ -23,7 +23,7 @@ class AbstractEpisodeProxyModel : public QSortFilterProxyModel
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum FilterType {
|
enum FilterType {
|
||||||
NoFilter,
|
NoFilter = 0,
|
||||||
ReadFilter,
|
ReadFilter,
|
||||||
NotReadFilter,
|
NotReadFilter,
|
||||||
NewFilter,
|
NewFilter,
|
||||||
|
|
|
@ -47,7 +47,6 @@ Kirigami.ScrollablePage {
|
||||||
icon.name: "view-refresh"
|
icon.name: "view-refresh"
|
||||||
text: i18n("Refresh All Podcasts")
|
text: i18n("Refresh All Podcasts")
|
||||||
onTriggered: refreshing = true
|
onTriggered: refreshing = true
|
||||||
visible: episodeProxyModel.filterType == AbstractEpisodeProxyModel.NoFilter
|
|
||||||
},
|
},
|
||||||
Kirigami.Action {
|
Kirigami.Action {
|
||||||
id: searchActionButton
|
id: searchActionButton
|
||||||
|
@ -93,6 +92,12 @@ Kirigami.ScrollablePage {
|
||||||
|
|
||||||
model: EpisodeProxyModel {
|
model: EpisodeProxyModel {
|
||||||
id: episodeProxyModel
|
id: episodeProxyModel
|
||||||
|
|
||||||
|
// save and restore filter settings
|
||||||
|
filterType: settings.episodeListFilterType
|
||||||
|
onFilterTypeChanged: {
|
||||||
|
settings.episodeListFilterType = filterType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delegate: GenericEntryDelegate {
|
delegate: GenericEntryDelegate {
|
||||||
|
|
|
@ -93,6 +93,7 @@ Kirigami.ApplicationWindow {
|
||||||
property int headerSize: Kirigami.Units.gridUnit * 5
|
property int headerSize: Kirigami.Units.gridUnit * 5
|
||||||
property alias lastOpenedPage: kastsMainWindow.currentPage
|
property alias lastOpenedPage: kastsMainWindow.currentPage
|
||||||
property alias feedSorting: kastsMainWindow.feedSorting
|
property alias feedSorting: kastsMainWindow.feedSorting
|
||||||
|
property int episodeListFilterType: AbstractEpisodeProxyModel.NoFilter
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveWindowLayout() {
|
function saveWindowLayout() {
|
||||||
|
|
Loading…
Reference in New Issue