diff --git a/src/contents/ui/SettingsPage.qml b/src/contents/ui/SettingsPage.qml index a654c00d..99542c36 100644 --- a/src/contents/ui/SettingsPage.qml +++ b/src/contents/ui/SettingsPage.qml @@ -25,6 +25,7 @@ Kirigami.ScrollablePage { settings.deleteAfterCount = deleteAfterCount.text settings.deleteAfterType = deleteAfterType.currentIndex settings.save() + pageStack.pop() } } } diff --git a/src/database.cpp b/src/database.cpp index 351400e4..d013e50a 100644 --- a/src/database.cpp +++ b/src/database.cpp @@ -22,8 +22,10 @@ #include #include #include +#include #include "database.h" +#include "alligatorsettings.h" #include "alligator-debug.h" #define TRUE_OR_RETURN(x) if(!x) return false; @@ -40,6 +42,8 @@ Database::Database() if(!migrate()) { qCCritical(ALLIGATOR) << "Failed to migrate the database"; } + + cleanup(); } bool Database::migrate() { @@ -87,3 +91,24 @@ int Database::version() { } return -1; } + +void Database::cleanup() { + AlligatorSettings settings; + int count = settings.deleteAfterCount(); + int type = settings.deleteAfterType(); + + if(type == 0) { // Delete after posts per feed + //TODO + } else { + QDateTime dateTime = QDateTime::currentDateTime(); + if(type == 1) dateTime.addDays(-count); + else if(type == 2) dateTime.addDays(-7*count); + else if(type == 3) dateTime.addMonths(-count); + qint64 sinceEpoch = dateTime.toSecsSinceEpoch(); + + QSqlQuery query; + query.prepare("DELETE FROM Entries WHERE updated < :sinceEpoch;"); + query.bindValue(":sinceEpoch", sinceEpoch); + execute(query); + } +} diff --git a/src/database.h b/src/database.h index 0804b1ae..54693533 100644 --- a/src/database.h +++ b/src/database.h @@ -39,4 +39,5 @@ private: bool migrate(); bool migrateTo1(); + void cleanup(); };