diff --git a/src/librssguard/core/feeddownloader.cpp b/src/librssguard/core/feeddownloader.cpp index 9e4c78bf6..0530c2754 100644 --- a/src/librssguard/core/feeddownloader.cpp +++ b/src/librssguard/core/feeddownloader.cpp @@ -100,42 +100,47 @@ void FeedDownloader::updateOneFeed(Feed* feed) { .remove(QRegularExpression(QSL("([\\n\\r])|(^\\s)"))); } - /* - ///// Initial PoC for JS-based msgs filtering engine. +#if defined (DEBUG) + ///// Initial PoC for JS-based msgs filtering engine. - // Perform per-message filtering. - QJSEngine filter_engine; + // Perform per-message filtering. + QJSEngine filter_engine; - // Create JavaScript communication wrapper for the message. - MessageObject msg_obj; + // Create JavaScript communication wrapper for the message. + MessageObject msg_obj; - // Register the wrapper. - auto js_object = filter_engine.newQObject(&msg_obj); + // Register the wrapper. + auto js_object = filter_engine.newQObject(&msg_obj); - filter_engine.globalObject().setProperty("msg", js_object); + filter_engine.globalObject().setProperty("msg", js_object); - for (int i = 0; i < msgs.size(); i++) { - // Attach live message object to wrapper. - msg_obj.setMessage(&msgs[i]); + for (int i = 0; i < msgs.size(); i++) { + // Attach live message object to wrapper. + msg_obj.setMessage(&msgs[i]); - // Call the filtering logic, given function must return integer value from - // FilteringAction enumeration. - // All Qt properties of MessageObject class are accessible. - // For example msg.title.includes("A") returns true if message's title includes "A" etc. - QJSValue filter_func = filter_engine.evaluate("(function() { " - "msg.duplicationAttributeCheck = 3;" - "return msg.isDuplicate ? 2 : 8; " + // Call the filtering logic, given function must return integer value from + // FilteringAction enumeration. + // + // 1. All Qt properties of MessageObject class are accessible. + // For example msg.title.includes("A") returns true if message's title includes "A" etc. + // 2. Some Qt properties of MessageObject are writable, so you can alter your message! + // For example msg.isImportant = true. + QJSValue filter_func = filter_engine.evaluate("(function() { " + + //"return msg.isDuplicate(4) ? 1 : 2; " + "msg.isImportant = true;" + "return 1;" "})"); - auto filter_output = filter_func.call().toInt(); - FilteringAction decision = FilteringAction(filter_output); + auto filter_output = filter_func.call().toInt(); + FilteringAction decision = FilteringAction(filter_output); - // Do something according to decision. - //bool should_skip = PerformFilteringAction(&msgs[i]); - //if (should_skip) { - // msgs.removeAt(i--); - //} - } - */ + // Do something according to decision. + //bool should_skip = PerformFilteringAction(&msgs[i]); + //if (should_skip) { + // msgs.removeAt(i--); + //} + } +#endif m_feedsUpdated++; diff --git a/src/librssguard/core/message.cpp b/src/librssguard/core/message.cpp index 814b2f654..b30d491b5 100644 --- a/src/librssguard/core/message.cpp +++ b/src/librssguard/core/message.cpp @@ -131,23 +131,67 @@ uint qHash(const Message& key) { MessageObject::MessageObject(QObject* parent) : QObject(parent), m_message(nullptr) {} -void MessageObject::setMessage(const Message* message) { +void MessageObject::setMessage(Message* message) { m_message = message; } -bool MessageObject::isDuplicate() const { +bool MessageObject::isDuplicate(int attribute_check) const { // TODO: Check database according to duplication attribute_check. - return m_duplicationAttributeCheck == 3; + return int(attribute_check) == 4; } QString MessageObject::title() const { return m_message->m_title; } -int MessageObject::duplicationAttributeCheck() const { - return m_duplicationAttributeCheck; +void MessageObject::setTitle(const QString& title) { + m_message->m_title = title; } -void MessageObject::setDuplicationAttributeCheck(int duplicationAttributeCheck) { - m_duplicationAttributeCheck = duplicationAttributeCheck; +QString MessageObject::url() const { + return m_message->m_url; +} + +void MessageObject::setUrl(const QString& url) { + m_message->m_url = url; +} + +QString MessageObject::author() const { + return m_message->m_author; +} + +void MessageObject::setAuthor(const QString& author) { + m_message->m_author = author; +} + +QString MessageObject::contents() const { + return m_message->m_contents; +} + +void MessageObject::setContents(const QString& contents) { + m_message->m_contents = contents; +} + +QDateTime MessageObject::created() const { + return m_message->m_created; +} + +void MessageObject::setCreated(const QDateTime& created) { + m_message->m_created = created; +} + +bool MessageObject::isRead() const { + return m_message->m_isRead; +} + +void MessageObject::setIsRead(bool is_read) { + m_message->m_isRead = is_read; +} + +bool MessageObject::isImportant() const { + return m_message->m_isImportant; +} + +void MessageObject::setIsImportant(bool is_important) { + m_message->m_isImportant = is_important; } diff --git a/src/librssguard/core/message.h b/src/librssguard/core/message.h index 745168c8a..dba5a2547 100644 --- a/src/librssguard/core/message.h +++ b/src/librssguard/core/message.h @@ -71,12 +71,11 @@ uint qHash(const Message& key, uint seed); uint qHash(const Message& key); enum class FilteringAction { + // Message is normally accepted and stored in DB. Accept = 1, - Ignore = 2, - MarkRead = 4, - MarkUnread = 8, - MarkImportant = 16, - MarkUnimportant = 32 + + // Message is ignored and now stored in DB. + Ignore = 2 }; enum class DuplicationAttributeCheck { @@ -89,26 +88,48 @@ enum class DuplicationAttributeCheck { class MessageObject : public QObject { Q_OBJECT - Q_PROPERTY(QString title READ title) - Q_PROPERTY(bool isDuplicate READ isDuplicate) - Q_PROPERTY(int duplicationAttributeCheck READ duplicationAttributeCheck WRITE setDuplicationAttributeCheck) + Q_PROPERTY(QString title READ title WRITE setTitle) + Q_PROPERTY(QString url READ url WRITE setUrl) + Q_PROPERTY(QString author READ author WRITE setAuthor) + Q_PROPERTY(QString contents READ contents WRITE setContents) + Q_PROPERTY(QDateTime created READ created WRITE setCreated) + Q_PROPERTY(bool isRead READ isRead WRITE setIsRead) + Q_PROPERTY(bool isImportant READ isImportant WRITE setIsImportant) public: explicit MessageObject(QObject* parent = nullptr); - void setMessage(const Message* message); + void setMessage(Message* message); - int duplicationAttributeCheck() const; - void setDuplicationAttributeCheck(int duplicationAttributeCheck); - - bool isDuplicate() const; + // Check if message is duplicate with another messages in DB. + // Parameter "attribute_check" is DuplicationAttributeCheck enum + // value casted to int. + Q_INVOKABLE bool isDuplicate(int attribute_check) const; // Generic Message's properties bindings. QString title() const; + void setTitle(const QString& title); + + QString url() const; + void setUrl(const QString& url); + + QString author() const; + void setAuthor(const QString& author); + + QString contents() const; + void setContents(const QString& contents); + + QDateTime created() const; + void setCreated(const QDateTime& created); + + bool isRead() const; + void setIsRead(bool is_read); + + bool isImportant() const; + void setIsImportant(bool is_important); private: - const Message* m_message; - int m_duplicationAttributeCheck; + Message* m_message; }; #endif // MESSAGE_H diff --git a/src/librssguard/gui/messagesview.cpp b/src/librssguard/gui/messagesview.cpp index 6ec3d3ffc..a4e0b4b21 100644 --- a/src/librssguard/gui/messagesview.cpp +++ b/src/librssguard/gui/messagesview.cpp @@ -280,6 +280,10 @@ void MessagesView::mousePressEvent(QMouseEvent* event) { } } +void MessagesView::mouseMoveEvent(QMouseEvent* event) { + event->accept(); +} + void MessagesView::selectionChanged(const QItemSelection& selected, const QItemSelection& deselected) { const QModelIndexList selected_rows = selectionModel()->selectedRows(); const QModelIndex current_index = currentIndex(); @@ -305,11 +309,11 @@ void MessagesView::selectionChanged(const QItemSelection& selected, const QItemS emit currentMessageRemoved(); } + QTreeView::selectionChanged(selected, deselected); + if (qApp->settings()->value(GROUP(Messages), SETTING(Messages::KeepCursorInCenter)).toBool()) { scrollTo(currentIndex(), QAbstractItemView::PositionAtCenter); } - - QTreeView::selectionChanged(selected, deselected); } void MessagesView::loadItem(RootItem* item) { diff --git a/src/librssguard/gui/messagesview.h b/src/librssguard/gui/messagesview.h index 5ad2765e6..5f948ee22 100644 --- a/src/librssguard/gui/messagesview.h +++ b/src/librssguard/gui/messagesview.h @@ -100,6 +100,7 @@ class MessagesView : public QTreeView { void focusInEvent(QFocusEvent* event); void contextMenuEvent(QContextMenuEvent* event); void mousePressEvent(QMouseEvent* event); + void mouseMoveEvent(QMouseEvent* event); void keyPressEvent(QKeyEvent* event); void selectionChanged(const QItemSelection& selected, const QItemSelection& deselected);