Debian Codegraph @

src/librssguard/core/messagesmodel.h

raw symbols SCIP
1 // For license of this file, see <project-root-folder>/LICENSE.md.
2
3 #ifndef MESSAGESMODEL_H
4 #define MESSAGESMODEL_H
5
6 #include "core/message.h"
7 #include "core/messagesmodelsqllayer.h"
8 #include "definitions/definitions.h"
9 #include "services/abstract/rootitem.h"
10
11 #include <QFont>
12 #include <QIcon>
13 #include <QSqlQueryModel>
14
15 class MessagesView;
16 class MessagesModelCache;
17
18 class MessagesModel : public QSqlQueryModel, public MessagesModelSqlLayer {
19 Q_OBJECT
20
21 public:
22 // Enum which describes basic highlighting schemes
23 // for messages.
24 enum class MessageHighlighter {
25 NoHighlighting = 1,
26 HighlightUnread = 2,
27 HighlightImportant = 4
28 };
29
30 enum class MessageUnreadIcon {
31 Dot = 1,
32 Envelope = 2,
33 FeedIcon = 3
34 };
35
36 Q_ENUM(MessageUnreadIcon)
37
38 // Constructors and destructors.
39 explicit MessagesModel(QObject* parent = nullptr);
40 virtual ~MessagesModel();
41
42 // Fetches ALL available data to the model.
43 // NOTE: This activates the SQL query and populates the model with new data.
44 void repopulate(int additional_article_id = 0);
45
46 // Model implementation.
47 bool setData(const QModelIndex& idx, const QVariant& value, int role = Qt::EditRole);
48 QVariant data(const QModelIndex& idx, int role = Qt::DisplayRole) const;
49 QVariant data(int row, int column, int role = Qt::DisplayRole) const;
50 QVariant headerData(int section, Qt::Orientation orientation, int role) const;
51 Qt::ItemFlags flags(const QModelIndex& index) const;
52
53 QList<Message> messagesAt(const QList<int>& row_indices) const;
54 Message messageAt(int row_index) const;
55 int messageId(int row_index) const;
56 RootItem::Importance messageImportance(int row_index) const;
57
58 RootItem* loadedItem() const;
59 MessagesModelCache* cache() const;
60
61 void setupIcons();
62 void setupFonts();
63 void updateDateFormat();
64 void updateFeedIconsDisplay();
65 void reloadWholeLayout();
66
67 // SINGLE message manipulators.
68 bool switchMessageImportance(int row_index);
69 bool switchMessageReadUnread(int row_index);
70 bool setMessageRead(int row_index, RootItem::ReadStatus read);
71
72 // BATCH messages manipulators.
73 bool switchBatchMessageImportance(const QModelIndexList& messages);
74 bool setBatchMessagesDeleted(const QModelIndexList& messages);
75 bool setBatchMessagesRead(const QModelIndexList& messages, RootItem::ReadStatus read);
76 bool setBatchMessagesRestored(const QModelIndexList& messages);
77
78 // Highlights messages.
79 void highlightMessages(MessageHighlighter highlighter);
80
81 // Loads messages of given feeds.
82 void loadMessages(RootItem* item);
83
84 MessagesView* view() const;
85 void setView(MessagesView* new_view);
86
87 static QIcon generateIconForScore(double score);
88 static QIcon generateUnreadIcon();
89 static QString descriptionOfUnreadIcon(MessagesModel::MessageUnreadIcon type);
90
91 public slots:
92
93 // NOTE: These methods DO NOT actually change data in the DB, just in the model.
94 // These are particularly used by msg browser.
95 bool setMessageImportantById(int id, RootItem::Importance important);
96 bool setMessageReadById(int id, RootItem::ReadStatus read);
97 bool setMessageLabelsById(int id, const QStringList& label_ids);
98
99 private:
100 void setupHeaderData();
101
102 private:
103 MessagesView* m_view;
104 MessagesModelCache* m_cache;
105 MessageHighlighter m_messageHighlighter;
106 QString m_customDateFormat;
107 QString m_customTimeFormat;
108 QString m_customFormatForDatesOnly;
109 int m_newerArticlesRelativeTime;
110 RootItem* m_selectedItem;
111 QList<QString> m_headerData;
112 QList<QString> m_tooltipData;
113 QFont m_normalFont;
114 QFont m_boldFont;
115 QFont m_normalStrikedFont;
116 QFont m_boldStrikedFont;
117 QIcon m_favoriteIcon;
118 QIcon m_readIcon;
119 QIcon m_unreadIcon;
120 QIcon m_enclosuresIcon;
121 QList<QIcon> m_scoreIcons;
122 MessageUnreadIcon m_unreadIconType;
123 bool m_multilineListItems;
124 };
125
126 Q_DECLARE_METATYPE(MessagesModel::MessageHighlighter)
127 Q_DECLARE_METATYPE(MessagesModel::MessageUnreadIcon)
128
129 #endif // MESSAGESMODEL_H