1 // For license of this file, see <project-root-folder>/LICENSE.md.
2
3 #ifndef MESSAGESVIEW_H
4 #define MESSAGESVIEW_H
5
6 #include "gui/reusable/basetreeview.h"
7
8 #include "core/messagesmodel.h"
9 #include "services/abstract/rootitem.h"
10
11 #include <QHeaderView>
12
13 class MessagesProxyModel;
14
15 class MessagesView : public BaseTreeView {
16 Q_OBJECT
17
18 public:
19 explicit MessagesView(QWidget* parent = nullptr);
20 virtual ~MessagesView();
21
22 MessagesProxyModel* model() const;
23 MessagesModel* sourceModel() const;
24
25 void reloadFontSettings();
26
27 QByteArray saveHeaderState() const;
28 void restoreHeaderState(const QByteArray& dta);
29
30 public slots:
31 void keyboardSearch(const QString& search);
32
33 // Called after data got changed externally
34 // and it needs to be reloaded to the view.
35 void reloadSelections();
36
37 // Loads un-deleted messages from selected feeds.
38 void loadItem(RootItem* item);
39
40 // Message manipulators.
41 void openSelectedSourceMessagesExternally();
42 void openSelectedMessagesInternally();
43 void sendSelectedMessageViaEmail();
44
45 // Works with SELECTED messages only.
46 void setSelectedMessagesReadStatus(RootItem::ReadStatus read);
47 void markSelectedMessagesRead();
48 void markSelectedMessagesUnread();
49 void switchSelectedMessagesImportance();
50 void deleteSelectedMessages();
51 void restoreSelectedMessages();
52
53 void selectNextItem();
54 void selectPreviousItem();
55 void selectNextUnreadItem();
56
57 // Searchs the visible message according to given pattern.
58 void searchMessages(const QString& pattern);
59 void filterMessages(MessagesModel::MessageHighlighter filter);
60
61 void switchShowUnreadOnly(bool set_new_value = false, bool show_unread_only = false);
62
63 private slots:
64 void openSelectedMessagesWithExternalTool();
65
66 // Marks given indexes as selected.
67 void reselectIndexes(const QModelIndexList& indexes);
68
69 // Changes resize mode for all columns.
70 void adjustColumns();
71
72 // Saves current sort state.
73 void onSortIndicatorChanged(int column, Qt::SortOrder order);
74
75 signals:
76 void openLinkNewTab(const QString& link);
77 void openLinkMiniBrowser(const QString& link);
78 void openMessagesInNewspaperView(RootItem* root, const QList<Message>& messages);
79
80 // Notify others about message selections.
81 void currentMessageChanged(const Message& message, RootItem* root);
82 void currentMessageRemoved();
83 void willReselectSameMessage();
84
85 private:
86 void sort(int column, Qt::SortOrder order, bool repopulate_data,
87 bool change_header, bool emit_changed_from_header, bool ignore_multicolumn_sorting);
88
89 // Creates needed connections.
90 void createConnections();
91
92 // Initializes context menu.
93 void initializeContextMenu();
94
95 // Sets up appearance.
96 void setupAppearance();
97
98 // Event reimplementations.
99 void focusInEvent(QFocusEvent* event);
100 void contextMenuEvent(QContextMenuEvent* event);
101 void mousePressEvent(QMouseEvent* event);
102 void mouseMoveEvent(QMouseEvent* event);
103 void keyPressEvent(QKeyEvent* event);
104 void selectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
105
106 QMenu* m_contextMenu;
107 MessagesProxyModel* m_proxyModel;
108 MessagesModel* m_sourceModel;
109 bool m_columnsAdjusted;
110 bool m_processingMouse;
111 };
112
model()113 inline MessagesProxyModel* MessagesView::model() const {
114 return m_proxyModel;
115 }
116
sourceModel()117 inline MessagesModel* MessagesView::sourceModel() const {
118 return m_sourceModel;
119 }
120
121 #endif // MESSAGESVIEW_H
122