Load saved filters from DB, some cleanups.
This commit is contained in:
parent
5ebad9060d
commit
bf3aaa961a
9 changed files with 58 additions and 12 deletions
|
@ -6,15 +6,17 @@
|
||||||
|
|
||||||
#include <QJSEngine>
|
#include <QJSEngine>
|
||||||
|
|
||||||
MessageFilter::MessageFilter(QObject* parent) : QObject(parent) {}
|
MessageFilter::MessageFilter(int id, QObject* parent) : QObject(parent), m_id(id) {}
|
||||||
|
|
||||||
FilteringAction MessageFilter::filterMessage(QJSEngine* engine) {
|
FilteringAction MessageFilter::filterMessage(QJSEngine* engine) {
|
||||||
QJSValue filter_func = engine->evaluate("(function() { "
|
/*
|
||||||
|
* "(function() { "
|
||||||
|
|
||||||
//"return msg.isDuplicateWithAttribute(4) ? 1 : 2; "
|
//"return msg.isDuplicateWithAttribute(4) ? 1 : 2; "
|
||||||
"msg.isImportant = true;"
|
"msg.isImportant = true;"
|
||||||
"return 1;"
|
"return 1;"
|
||||||
"})");
|
"})"*/
|
||||||
|
QJSValue filter_func = engine->evaluate(m_script);
|
||||||
auto filter_output = filter_func.call().toInt();
|
auto filter_output = filter_func.call().toInt();
|
||||||
FilteringAction decision = FilteringAction(filter_output);
|
FilteringAction decision = FilteringAction(filter_output);
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ class MessageFilter : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MessageFilter(QObject* parent = nullptr);
|
explicit MessageFilter(int id, QObject* parent = nullptr);
|
||||||
|
|
||||||
FilteringAction filterMessage(QJSEngine* engine);
|
FilteringAction filterMessage(QJSEngine* engine);
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
#define ICON_SIZE_SETTINGS 16
|
#define ICON_SIZE_SETTINGS 16
|
||||||
#define NO_PARENT_CATEGORY -1
|
#define NO_PARENT_CATEGORY -1
|
||||||
#define ID_RECYCLE_BIN -2
|
#define ID_RECYCLE_BIN -2
|
||||||
|
#define ID_IMPORTANT -3
|
||||||
#define TRAY_ICON_BUBBLE_TIMEOUT 20000
|
#define TRAY_ICON_BUBBLE_TIMEOUT 20000
|
||||||
#define CLOSE_LOCK_TIMEOUT 500
|
#define CLOSE_LOCK_TIMEOUT 500
|
||||||
#define DOWNLOAD_TIMEOUT 30000
|
#define DOWNLOAD_TIMEOUT 30000
|
||||||
|
|
|
@ -202,6 +202,7 @@ void Application::eliminateFirstRun(const QString& version) {
|
||||||
|
|
||||||
void Application::setFeedReader(FeedReader* feed_reader) {
|
void Application::setFeedReader(FeedReader* feed_reader) {
|
||||||
m_feedReader = feed_reader;
|
m_feedReader = feed_reader;
|
||||||
|
|
||||||
connect(m_feedReader, &FeedReader::feedUpdatesStarted, this, &Application::onFeedUpdatesStarted);
|
connect(m_feedReader, &FeedReader::feedUpdatesStarted, this, &Application::onFeedUpdatesStarted);
|
||||||
connect(m_feedReader, &FeedReader::feedUpdatesProgress, this, &Application::onFeedUpdatesProgress);
|
connect(m_feedReader, &FeedReader::feedUpdatesProgress, this, &Application::onFeedUpdatesProgress);
|
||||||
connect(m_feedReader, &FeedReader::feedUpdatesFinished, this, &Application::onFeedUpdatesFinished);
|
connect(m_feedReader, &FeedReader::feedUpdatesFinished, this, &Application::onFeedUpdatesFinished);
|
||||||
|
|
|
@ -1396,6 +1396,37 @@ bool DatabaseQueries::editBaseFeed(const QSqlDatabase& db, int feed_id, Feed::Au
|
||||||
return q.exec();
|
return q.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<MessageFilter*> DatabaseQueries::getMessageFilters(const QSqlDatabase& db, bool* ok) {
|
||||||
|
QSqlQuery q(db);
|
||||||
|
QList<MessageFilter*> filters;
|
||||||
|
|
||||||
|
q.setForwardOnly(true);
|
||||||
|
q.prepare(QSL("SELECT * FROM MessageFilters;"));
|
||||||
|
|
||||||
|
if (q.exec()) {
|
||||||
|
while (q.next()) {
|
||||||
|
auto rec = q.record();
|
||||||
|
auto* filter = new MessageFilter(rec.value(0).toInt());
|
||||||
|
|
||||||
|
filter->setName(rec.value(1).toString());
|
||||||
|
filter->setScript(rec.value(2).toString());
|
||||||
|
|
||||||
|
filters.append(filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ok != nullptr) {
|
||||||
|
*ok = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (ok != nullptr) {
|
||||||
|
*ok = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return filters;
|
||||||
|
}
|
||||||
|
|
||||||
QList<ServiceRoot*> DatabaseQueries::getStandardAccounts(const QSqlDatabase& db, bool* ok) {
|
QList<ServiceRoot*> DatabaseQueries::getStandardAccounts(const QSqlDatabase& db, bool* ok) {
|
||||||
QSqlQuery q(db);
|
QSqlQuery q(db);
|
||||||
QList<ServiceRoot*> roots;
|
QList<ServiceRoot*> roots;
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
#include "services/abstract/rootitem.h"
|
#include "services/abstract/rootitem.h"
|
||||||
|
|
||||||
|
#include "core/messagefilter.h"
|
||||||
#include "services/abstract/category.h"
|
#include "services/abstract/category.h"
|
||||||
#include "services/abstract/serviceroot.h"
|
#include "services/abstract/serviceroot.h"
|
||||||
#include "services/standard/standardfeed.h"
|
#include "services/standard/standardfeed.h"
|
||||||
|
@ -15,7 +16,7 @@
|
||||||
class DatabaseQueries {
|
class DatabaseQueries {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Mark read/unread/starred/delete messages.
|
// Message operators.
|
||||||
static bool markImportantMessagesReadUnread(const QSqlDatabase& db, int account_id, RootItem::ReadStatus read);
|
static bool markImportantMessagesReadUnread(const QSqlDatabase& db, int account_id, RootItem::ReadStatus read);
|
||||||
static bool markMessagesReadUnread(const QSqlDatabase& db, const QStringList& ids, RootItem::ReadStatus read);
|
static bool markMessagesReadUnread(const QSqlDatabase& db, const QStringList& ids, RootItem::ReadStatus read);
|
||||||
static bool markMessageImportant(const QSqlDatabase& db, int id, RootItem::Importance importance);
|
static bool markMessageImportant(const QSqlDatabase& db, int id, RootItem::Importance importance);
|
||||||
|
@ -35,7 +36,7 @@ class DatabaseQueries {
|
||||||
static bool purgeMessagesFromBin(const QSqlDatabase& db, bool clear_only_read, int account_id);
|
static bool purgeMessagesFromBin(const QSqlDatabase& db, bool clear_only_read, int account_id);
|
||||||
static bool purgeLeftoverMessages(const QSqlDatabase& db, int account_id);
|
static bool purgeLeftoverMessages(const QSqlDatabase& db, int account_id);
|
||||||
|
|
||||||
// Obtain counts of unread/all messages.
|
// Counts of unread/all messages.
|
||||||
static QMap<QString, QPair<int, int>> getMessageCountsForCategory(const QSqlDatabase& db, const QString& custom_id,
|
static QMap<QString, QPair<int, int>> getMessageCountsForCategory(const QSqlDatabase& db, const QString& custom_id,
|
||||||
int account_id, bool only_total_counts,
|
int account_id, bool only_total_counts,
|
||||||
bool* ok = nullptr);
|
bool* ok = nullptr);
|
||||||
|
@ -83,6 +84,9 @@ class DatabaseQueries {
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static Assignment getFeeds(const QSqlDatabase& db, int account_id, bool* ok = nullptr);
|
static Assignment getFeeds(const QSqlDatabase& db, int account_id, bool* ok = nullptr);
|
||||||
|
|
||||||
|
// Message filters operators.
|
||||||
|
static QList<MessageFilter*> getMessageFilters(const QSqlDatabase& db, bool* ok = nullptr);
|
||||||
|
|
||||||
// Standard account.
|
// Standard account.
|
||||||
static bool deleteFeed(const QSqlDatabase& db, int feed_custom_id, int account_id);
|
static bool deleteFeed(const QSqlDatabase& db, int feed_custom_id, int account_id);
|
||||||
static bool deleteStandardCategory(const QSqlDatabase& db, int id);
|
static bool deleteStandardCategory(const QSqlDatabase& db, int id);
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include "core/messagesmodel.h"
|
#include "core/messagesmodel.h"
|
||||||
#include "core/messagesproxymodel.h"
|
#include "core/messagesproxymodel.h"
|
||||||
#include "miscellaneous/application.h"
|
#include "miscellaneous/application.h"
|
||||||
|
#include "miscellaneous/databasequeries.h"
|
||||||
#include "miscellaneous/mutex.h"
|
#include "miscellaneous/mutex.h"
|
||||||
#include "services/abstract/cacheforserviceroot.h"
|
#include "services/abstract/cacheforserviceroot.h"
|
||||||
#include "services/abstract/serviceroot.h"
|
#include "services/abstract/serviceroot.h"
|
||||||
|
@ -129,9 +130,16 @@ int FeedReader::autoUpdateInitialInterval() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void FeedReader::loadSaveMessageFilters() {
|
void FeedReader::loadSaveMessageFilters() {
|
||||||
// TODO: Load all message filters from database.
|
// Load all message filters from database.
|
||||||
// All plugin services will hook active filters to
|
// All plugin services will hook active filters to
|
||||||
// all feeds.
|
// all feeds.
|
||||||
|
QSqlDatabase database = qApp->database()->connection(QSL("FeedReader"));
|
||||||
|
|
||||||
|
m_messageFilters = DatabaseQueries::getMessageFilters(database);
|
||||||
|
|
||||||
|
for (auto* filter : m_messageFilters) {
|
||||||
|
filter->setParent(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FeedReader::updateAllFeeds() {
|
void FeedReader::updateAllFeeds() {
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
ImportantNode::ImportantNode(RootItem* parent_item) : RootItem(parent_item) {
|
ImportantNode::ImportantNode(RootItem* parent_item) : RootItem(parent_item) {
|
||||||
setKind(RootItemKind::Important);
|
setKind(RootItemKind::Important);
|
||||||
setId(ID_RECYCLE_BIN);
|
setId(ID_IMPORTANT);
|
||||||
setIcon(qApp->icons()->fromTheme(QSL("mail-mark-important")));
|
setIcon(qApp->icons()->fromTheme(QSL("mail-mark-important")));
|
||||||
setTitle(tr("Important messages"));
|
setTitle(tr("Important messages"));
|
||||||
setDescription(tr("You can find all important messages here."));
|
setDescription(tr("You can find all important messages here."));
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "miscellaneous/databasequeries.h"
|
#include "miscellaneous/databasequeries.h"
|
||||||
#include "miscellaneous/iconfactory.h"
|
#include "miscellaneous/iconfactory.h"
|
||||||
#include "network-web/oauth2service.h"
|
#include "network-web/oauth2service.h"
|
||||||
|
#include "services/abstract/importantnode.h"
|
||||||
#include "services/abstract/recyclebin.h"
|
#include "services/abstract/recyclebin.h"
|
||||||
#include "services/gmail/definitions.h"
|
#include "services/gmail/definitions.h"
|
||||||
#include "services/gmail/gmailentrypoint.h"
|
#include "services/gmail/gmailentrypoint.h"
|
||||||
|
@ -27,9 +28,6 @@ GmailServiceRoot::GmailServiceRoot(GmailNetworkFactory* network, RootItem* paren
|
||||||
|
|
||||||
m_network->setService(this);
|
m_network->setService(this);
|
||||||
setIcon(GmailEntryPoint().icon());
|
setIcon(GmailEntryPoint().icon());
|
||||||
|
|
||||||
recycleBin()->deleteLater();
|
|
||||||
setRecycleBin(nullptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GmailServiceRoot::~GmailServiceRoot() = default;
|
GmailServiceRoot::~GmailServiceRoot() = default;
|
||||||
|
@ -71,7 +69,8 @@ void GmailServiceRoot::loadFromDatabase() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// As the last item, add recycle bin, which is needed.
|
appendChild(recycleBin());
|
||||||
|
appendChild(importantNode());
|
||||||
updateCounts(true);
|
updateCounts(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue