Add setting to automatically delete episodes when they're marked as played

The 3 possibilities are:
0 = Disabled      = Do not delete episodes
1 = Immediately   = Delete immediately
2 = OnNextStartup = Delete on next startup (default)

Fixes #14
This commit is contained in:
Bart De Vries 2021-07-03 22:17:56 +02:00
parent 143ff3a2ed
commit fe2a977a6b
7 changed files with 67 additions and 8 deletions

View File

@ -6,6 +6,7 @@
*/
#include <QDateTime>
#include <QDebug>
#include <QDir>
#include <QSqlDatabase>
#include <QSqlError>
@ -15,8 +16,6 @@
#include <QXmlStreamWriter>
#include "database.h"
#include "fetcher.h"
#include "settingsmanager.h"
#define TRUE_OR_RETURN(x) \
if (!x) \

View File

@ -526,6 +526,24 @@ void DataManager::setLastPlayingEntry(const QString &id)
Database::instance().execute(query);
}
void DataManager::deletePlayedEnclosures()
{
QSqlQuery query;
query.prepare(QStringLiteral("SELECT * FROM Enclosures INNER JOIN Entries ON Enclosures.id = Entries.id WHERE downloaded=:downloaded AND read=:read;"));
query.bindValue(QStringLiteral(":downloaded"), Enclosure::statusToDb(Enclosure::Downloaded));
query.bindValue(QStringLiteral(":read"), true);
Database::instance().execute(query);
while (query.next()) {
QString feed = query.value(QStringLiteral("feed")).toString();
QString id = query.value(QStringLiteral("id")).toString();
qCDebug(kastsDataManager) << "Found entry which has been downloaded and is marked as played; deleting now:" << id;
Entry *entry = getEntry(id);
if (entry->hasEnclosure()) {
entry->enclosure()->deleteFile();
}
}
}
void DataManager::importFeeds(const QString &path)
{
QUrl url(path);

View File

@ -40,10 +40,6 @@ public:
Q_INVOKABLE void removeFeed(Feed *feed);
void removeFeed(const int index);
// Q_INVOKABLE void addEntry(const QString &url); // TODO: implement these methods
// Q_INVOKABLE void removeEntry(const QString &url);
// Q_INVOKABLE void removeEntry(const Feed* feed, const int &index);
Entry *getQueueEntry(int index) const;
int queueCount() const;
QStringList queue() const;
@ -59,6 +55,8 @@ public:
Q_INVOKABLE QString lastPlayingEntry();
Q_INVOKABLE void setLastPlayingEntry(const QString &id);
Q_INVOKABLE void deletePlayedEnclosures();
Q_INVOKABLE void importFeeds(const QString &path);
Q_INVOKABLE void exportFeeds(const QString &path);

View File

@ -15,6 +15,7 @@
#include "datamanager.h"
#include "feed.h"
#include "fetcher.h"
#include "settingsmanager.h"
Entry::Entry(Feed *feed, const QString &id)
: QObject(nullptr)
@ -144,6 +145,14 @@ void Entry::setRead(bool read)
Q_EMIT m_feed->unreadEntryCountChanged();
Q_EMIT DataManager::instance().unreadEntryCountChanged(m_feed->url());
// TODO: can one of the two slots be removed??
// Follow up actions
if (read && hasEnclosure()) {
// 1) Delete episode if that setting is set
if (SettingsManager::self()->autoDelete() == 1) {
m_enclosure->deleteFile();
}
}
}
void Entry::setNew(bool state)

View File

@ -56,8 +56,9 @@ Kirigami.ScrollablePage {
Controls.CheckBox {
id: autoQueue
Kirigami.FormData.label: i18n("New Episodes:")
checked: SettingsManager.autoQueue
text: i18n("Automatically queue new episodes")
text: i18n("Automatically Queue")
onToggled: {
SettingsManager.autoQueue = checked
@ -71,12 +72,26 @@ Kirigami.ScrollablePage {
Controls.CheckBox {
id: autoDownload
checked: SettingsManager.autoDownload
text: i18n("Automatically download new episodes")
text: i18n("Automatically Download")
enabled: autoQueue.checked
onToggled: SettingsManager.autoDownload = checked
}
Controls.ComboBox {
Kirigami.FormData.label: i18n("Played Episodes:")
Layout.alignment: Qt.AlignHCenter
textRole: "text"
valueRole: "value"
model: [{"text": i18n("Do Not Delete"), "value": 0},
{"text": i18n("Delete Immediately"), "value": 1},
{"text": i18n("Delete at Next Startup"), "value": 2}]
Component.onCompleted: currentIndex = indexOfValue(SettingsManager.autoDelete)
onActivated: {
SettingsManager.autoDelete = currentValue;
}
}
Kirigami.Heading {
Kirigami.FormData.isSection: true
text: i18n("Network")

View File

@ -60,6 +60,11 @@ Kirigami.ApplicationWindow {
currentPage = SettingsManager.lastOpenedPage
pageStack.initialPage = getPage(SettingsManager.lastOpenedPage)
// Delete played enclosures if set in settings
if (SettingsManager.autoDelete == 2) {
DataManager.deletePlayedEnclosures();
}
// Refresh feeds on startup if allowed
if (SettingsManager.refreshOnStartup) {
if (SettingsManager.allowMeteredFeedUpdates || !Fetcher.isMeteredConnection()) {

View File

@ -25,6 +25,21 @@
<label>Automatically download new episodes</label>
<default>false</default>
</entry>
<entry name="autoDelete" type="Enum">
<label>Setting to select if or when to delete played episode</label>
<choices>
<choice name="Disabled">
<label>Disabled</label>
</choice>
<choice name="Immediately">
<label>Immediately</label>
</choice>
<choice name="OnNextStartup">
<label>On Next Startup</label>
</choice>
</choices>
<default>OnNextStartup</default>
</entry>
<entry name="toggleRemainingTime" type="Bool">
<label>Whether the player shows remaining track time instead of total track time</label>
<default>false</default>