Work on #246.
This commit is contained in:
parent
ac778109f5
commit
3e8702fbd1
5 changed files with 127 additions and 52 deletions
|
@ -100,42 +100,47 @@ void FeedDownloader::updateOneFeed(Feed* feed) {
|
||||||
.remove(QRegularExpression(QSL("([\\n\\r])|(^\\s)")));
|
.remove(QRegularExpression(QSL("([\\n\\r])|(^\\s)")));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
#if defined (DEBUG)
|
||||||
///// Initial PoC for JS-based msgs filtering engine.
|
///// Initial PoC for JS-based msgs filtering engine.
|
||||||
|
|
||||||
// Perform per-message filtering.
|
// Perform per-message filtering.
|
||||||
QJSEngine filter_engine;
|
QJSEngine filter_engine;
|
||||||
|
|
||||||
// Create JavaScript communication wrapper for the message.
|
// Create JavaScript communication wrapper for the message.
|
||||||
MessageObject msg_obj;
|
MessageObject msg_obj;
|
||||||
|
|
||||||
// Register the wrapper.
|
// Register the wrapper.
|
||||||
auto js_object = filter_engine.newQObject(&msg_obj);
|
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++) {
|
for (int i = 0; i < msgs.size(); i++) {
|
||||||
// Attach live message object to wrapper.
|
// Attach live message object to wrapper.
|
||||||
msg_obj.setMessage(&msgs[i]);
|
msg_obj.setMessage(&msgs[i]);
|
||||||
|
|
||||||
// Call the filtering logic, given function must return integer value from
|
// Call the filtering logic, given function must return integer value from
|
||||||
// FilteringAction enumeration.
|
// 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.
|
// 1. All Qt properties of MessageObject class are accessible.
|
||||||
QJSValue filter_func = filter_engine.evaluate("(function() { "
|
// For example msg.title.includes("A") returns true if message's title includes "A" etc.
|
||||||
"msg.duplicationAttributeCheck = 3;"
|
// 2. Some Qt properties of MessageObject are writable, so you can alter your message!
|
||||||
"return msg.isDuplicate ? 2 : 8; "
|
// 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();
|
auto filter_output = filter_func.call().toInt();
|
||||||
FilteringAction decision = FilteringAction(filter_output);
|
FilteringAction decision = FilteringAction(filter_output);
|
||||||
|
|
||||||
// Do something according to decision.
|
// Do something according to decision.
|
||||||
//bool should_skip = PerformFilteringAction(&msgs[i]);
|
//bool should_skip = PerformFilteringAction(&msgs[i]);
|
||||||
//if (should_skip) {
|
//if (should_skip) {
|
||||||
// msgs.removeAt(i--);
|
// msgs.removeAt(i--);
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
*/
|
#endif
|
||||||
|
|
||||||
m_feedsUpdated++;
|
m_feedsUpdated++;
|
||||||
|
|
||||||
|
|
|
@ -131,23 +131,67 @@ uint qHash(const Message& key) {
|
||||||
|
|
||||||
MessageObject::MessageObject(QObject* parent) : QObject(parent), m_message(nullptr) {}
|
MessageObject::MessageObject(QObject* parent) : QObject(parent), m_message(nullptr) {}
|
||||||
|
|
||||||
void MessageObject::setMessage(const Message* message) {
|
void MessageObject::setMessage(Message* message) {
|
||||||
m_message = message;
|
m_message = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MessageObject::isDuplicate() const {
|
bool MessageObject::isDuplicate(int attribute_check) const {
|
||||||
// TODO: Check database according to duplication attribute_check.
|
// TODO: Check database according to duplication attribute_check.
|
||||||
return m_duplicationAttributeCheck == 3;
|
return int(attribute_check) == 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString MessageObject::title() const {
|
QString MessageObject::title() const {
|
||||||
return m_message->m_title;
|
return m_message->m_title;
|
||||||
}
|
}
|
||||||
|
|
||||||
int MessageObject::duplicationAttributeCheck() const {
|
void MessageObject::setTitle(const QString& title) {
|
||||||
return m_duplicationAttributeCheck;
|
m_message->m_title = title;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageObject::setDuplicationAttributeCheck(int duplicationAttributeCheck) {
|
QString MessageObject::url() const {
|
||||||
m_duplicationAttributeCheck = duplicationAttributeCheck;
|
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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,12 +71,11 @@ uint qHash(const Message& key, uint seed);
|
||||||
uint qHash(const Message& key);
|
uint qHash(const Message& key);
|
||||||
|
|
||||||
enum class FilteringAction {
|
enum class FilteringAction {
|
||||||
|
// Message is normally accepted and stored in DB.
|
||||||
Accept = 1,
|
Accept = 1,
|
||||||
Ignore = 2,
|
|
||||||
MarkRead = 4,
|
// Message is ignored and now stored in DB.
|
||||||
MarkUnread = 8,
|
Ignore = 2
|
||||||
MarkImportant = 16,
|
|
||||||
MarkUnimportant = 32
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class DuplicationAttributeCheck {
|
enum class DuplicationAttributeCheck {
|
||||||
|
@ -89,26 +88,48 @@ enum class DuplicationAttributeCheck {
|
||||||
|
|
||||||
class MessageObject : public QObject {
|
class MessageObject : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QString title READ title)
|
Q_PROPERTY(QString title READ title WRITE setTitle)
|
||||||
Q_PROPERTY(bool isDuplicate READ isDuplicate)
|
Q_PROPERTY(QString url READ url WRITE setUrl)
|
||||||
Q_PROPERTY(int duplicationAttributeCheck READ duplicationAttributeCheck WRITE setDuplicationAttributeCheck)
|
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:
|
public:
|
||||||
explicit MessageObject(QObject* parent = nullptr);
|
explicit MessageObject(QObject* parent = nullptr);
|
||||||
|
|
||||||
void setMessage(const Message* message);
|
void setMessage(Message* message);
|
||||||
|
|
||||||
int duplicationAttributeCheck() const;
|
// Check if message is duplicate with another messages in DB.
|
||||||
void setDuplicationAttributeCheck(int duplicationAttributeCheck);
|
// Parameter "attribute_check" is DuplicationAttributeCheck enum
|
||||||
|
// value casted to int.
|
||||||
bool isDuplicate() const;
|
Q_INVOKABLE bool isDuplicate(int attribute_check) const;
|
||||||
|
|
||||||
// Generic Message's properties bindings.
|
// Generic Message's properties bindings.
|
||||||
QString title() const;
|
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:
|
private:
|
||||||
const Message* m_message;
|
Message* m_message;
|
||||||
int m_duplicationAttributeCheck;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MESSAGE_H
|
#endif // MESSAGE_H
|
||||||
|
|
|
@ -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) {
|
void MessagesView::selectionChanged(const QItemSelection& selected, const QItemSelection& deselected) {
|
||||||
const QModelIndexList selected_rows = selectionModel()->selectedRows();
|
const QModelIndexList selected_rows = selectionModel()->selectedRows();
|
||||||
const QModelIndex current_index = currentIndex();
|
const QModelIndex current_index = currentIndex();
|
||||||
|
@ -305,11 +309,11 @@ void MessagesView::selectionChanged(const QItemSelection& selected, const QItemS
|
||||||
emit currentMessageRemoved();
|
emit currentMessageRemoved();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QTreeView::selectionChanged(selected, deselected);
|
||||||
|
|
||||||
if (qApp->settings()->value(GROUP(Messages), SETTING(Messages::KeepCursorInCenter)).toBool()) {
|
if (qApp->settings()->value(GROUP(Messages), SETTING(Messages::KeepCursorInCenter)).toBool()) {
|
||||||
scrollTo(currentIndex(), QAbstractItemView::PositionAtCenter);
|
scrollTo(currentIndex(), QAbstractItemView::PositionAtCenter);
|
||||||
}
|
}
|
||||||
|
|
||||||
QTreeView::selectionChanged(selected, deselected);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessagesView::loadItem(RootItem* item) {
|
void MessagesView::loadItem(RootItem* item) {
|
||||||
|
|
|
@ -100,6 +100,7 @@ class MessagesView : public QTreeView {
|
||||||
void focusInEvent(QFocusEvent* event);
|
void focusInEvent(QFocusEvent* event);
|
||||||
void contextMenuEvent(QContextMenuEvent* event);
|
void contextMenuEvent(QContextMenuEvent* event);
|
||||||
void mousePressEvent(QMouseEvent* event);
|
void mousePressEvent(QMouseEvent* event);
|
||||||
|
void mouseMoveEvent(QMouseEvent* event);
|
||||||
void keyPressEvent(QKeyEvent* event);
|
void keyPressEvent(QKeyEvent* event);
|
||||||
void selectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
|
void selectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue