mirror of
https://github.com/KDE/kasts.git
synced 2025-01-13 09:02:55 +01:00
implement autodeleting entries after <time>
This commit is contained in:
parent
399892d474
commit
bd8ef20ecc
@ -25,6 +25,7 @@ Kirigami.ScrollablePage {
|
||||
settings.deleteAfterCount = deleteAfterCount.text
|
||||
settings.deleteAfterType = deleteAfterType.currentIndex
|
||||
settings.save()
|
||||
pageStack.pop()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,8 +22,10 @@
|
||||
#include <QStandardPaths>
|
||||
#include <QSqlError>
|
||||
#include <QSqlDatabase>
|
||||
#include <QDateTime>
|
||||
|
||||
#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 <count> 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);
|
||||
}
|
||||
}
|
||||
|
@ -39,4 +39,5 @@ private:
|
||||
|
||||
bool migrate();
|
||||
bool migrateTo1();
|
||||
void cleanup();
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user