Debian Codegraph @

Dekko/backend/mail/MessageList.h

raw symbols SCIP
1 /* Copyright (C) 2016 - 2017 Dan Chapman <[email protected]m>
2
3 This file is part of Dekko email client for Ubuntu devices
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of
8 the License or (at your option) version 3
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #ifndef MESSAGELIST_H
19 #define MESSAGELIST_H
20
21 #include <QLoggingCategory>
22 #include <QObject>
23 #include <QMap>
24 #include <QCache>
25 #include <QmlObjectListModel.h>
26 #include <QThread>
27 #include <QDBusPendingCallWatcher>
28 #include <qmailmessage.h>
29 #include <qmailmessagekey.h>
30 #include <qmailmessagesortkey.h>
31 #include "Message.h"
32
33 #define INCREMENT_VALUE 50
34 // Remember the selected message for each key using QCache
35 // it works but it's really bogging down qml. Bindings need optimizing.
36 //#define EXPERIMENTAL_REMEMBER_SELECTED_MESSAGE
37
38 Q_DECLARE_LOGGING_CATEGORY(D_MSG_LIST)
39
40 class MessageListWorker : public QObject
41 {
42 Q_OBJECT
43
44 signals:
45 void insertMessageAt(const int &index, const QMailMessageId &id);
46 void removeMessageAt(const int &index);
47 void updateMessageAt(const int &index);
48 void removeMessages(const QMailMessageIdList &msgIds);
49 void canPossiblyLoadMore();
50 public slots:
51
52 void updateMessages(
53 const QMailMessageIdList &idList,
54 const QMailMessageIdList &needsUpdate,
55 const QMailMessageIdList &newIds,
56 const QMap<QMailMessageId, int> &indexMap,
57 const int& limit);
58
59 void sortAndAppend(
60 const QMailMessageIdList &idList,
61 const QMailMessageIdList &idsToAppend,
62 const QMailMessageIdList &newIdsList,
63 const QMap<QMailMessageId, int> &indexMap,
64 const int& limit);
65 };
66
67 class MessageList : public QObject
68 {
69 Q_OBJECT
70 Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged)
71 /** @short model containing messages in this list */
72 Q_PROPERTY(QObject *model READ model NOTIFY modelChanged)
73 /** @short Number of messages to show in the list */
74 Q_PROPERTY(int limit READ limit WRITE setLimit NOTIFY limitChanged)
75 /** @short MessageKey for this message set */
76 Q_PROPERTY(QVariant messageKey READ key WRITE setKey NOTIFY messageKeyChanged)
77 /** @short Sort order on DateTime */
78 Q_PROPERTY(Qt::SortOrder sortOrder READ sortOrder WRITE setSortOrder NOTIFY sortOrderChanged)
79 /** @short Filter applied to mailstore query */
80 Q_PROPERTY(FilterKey filter READ filterKey WRITE setFilterKey NOTIFY filterKeyChanged)
81 /** @short Total count - this is the total available message count and not this models count as we have a limit */
82 Q_PROPERTY(int totalCount READ totalCount NOTIFY totalCountChanged)
83 Q_PROPERTY(bool canLoadMore READ canLoadMore NOTIFY canPossiblyLoadMore)
84 Q_PROPERTY(int currentSelectedIndex READ currentSelectedIndex WRITE setCurrentSelectedIndex NOTIFY currentSelectedIndexChanged)
85 // /** @short unread count for this messagekey */
86 // Q_PROPERTY(int unreadCount READ unreadCount NOTIFY unreadCountChanged)
87 Q_PROPERTY(bool isInSelectionMode READ isInSelectionMode NOTIFY isInSelectionModeChanged)
88
89 // // Selectionmode icon properties
90 Q_PROPERTY(bool canSelectAll READ canSelectAll NOTIFY selectionIndexesChanged)
91 Q_PROPERTY(bool canMarkSelectionRead READ canMarkSelectionAsRead NOTIFY selectionIndexesChanged)
92 Q_PROPERTY(bool canMarkSelectionImportant READ canMarkSelectionImportant NOTIFY selectionIndexesChanged)
93
94 Q_PROPERTY(bool disableUpdates READ disableUpdates WRITE setDisableUpdates NOTIFY disableUpdatesChanged)
95 Q_PROPERTY(bool disableRemovals READ disableRemovals WRITE setDisableRemovals NOTIFY disableRemovalsChanged)
96
97 Q_ENUMS(FilterKey)
98
99 public:
100 explicit MessageList(QObject *parent = 0);
101 ~MessageList();
102
103 enum FilterKey {
104 All,
105 Unread,
106 Important,
107 Replied,
108 Forwarded,
109 Attachments,
110 HighPriority,
111 Calendar,
112 Todo
113 };
114
115 QObject *model() const { return m_model; }
116
117 bool loading() const { return m_loading; }
118 int limit() const;
119 QVariant key() const;
120 Qt::SortOrder sortOrder() const;
121 int totalCount();
122 bool canLoadMore();
123 bool isInSelectionMode() const { return m_selectionMode; }
124 bool canSelectAll();
125 bool canMarkSelectionAsRead();
126 bool canMarkSelectionImportant();
127
128 Q_INVOKABLE int indexOf(const quint64 &id);
129 int indexOf(const QMailMessageId &id);
130 Q_INVOKABLE void loadMore();
131 Q_INVOKABLE void refresh();
132
133 int currentSelectedIndex() const;
134
135 FilterKey filterKey() const;
136
137 bool disableUpdates() const;
138
139 bool disableRemovals() const;
140
141 signals:
142 void loadingChanged();
143 void totalCountChanged();
144 void canPossiblyLoadMore();
145 void modelChanged();
146 void limitChanged(int limit);
147 void messageKeyChanged();
148 void sortOrderChanged();
149 void isInSelectionModeChanged();
150 void selectionStarted();
151 void selectionEnded();
152 void selectionIndexesChanged();
153
154 void currentSelectedIndexChanged();
155
156 void filterKeyChanged(FilterKey filter);
157
158 void disableUpdatesChanged(bool disableUpdates);
159
160 void sortAndAppendNewMessages(
161 const QMailMessageIdList &idList,
162 const QMailMessageIdList &idsToAppend,
163 const QMailMessageIdList &newIdsList,
164 const QMap<QMailMessageId, int> &indexMap,
165 const int& limit);
166
167 void updateMessages(
168 const QMailMessageIdList &idList,
169 const QMailMessageIdList &needsUpdate,
170 const QMailMessageIdList &newIds,
171 const QMap<QMailMessageId, int> &indexMap,
172 const int& limit);
173
174 void disableRemovalsChanged(bool disableRemovals);
175
176 public slots:
177 void setLimit(int limit);
178 void setKey(const QVariant &key);
179 void setSortOrder(const Qt::SortOrder &order);
180
181 // Multiselect options
182 /** @short Enter selection mode */
183 void startSelection();
184 /** @short Exit selection mode */
185 void endSelection();
186 /** @short Select all messages in model */
187 void selectAll();
188 /** @short Unselects all messages in model */
189 void unselectAll();
190 /** @short Set checked value at index */
191 void setChecked(const int &index, const Qt::CheckState &checkState);
192 void markSelectedMessagesImportant();
193 void markSelectedMessagesRead();
194 void deleteSelectedMessages();
195 // void moveSelectedMessages()
196 // void copySelectedMessages()
197
198 void setCurrentSelectedIndex(int currentSelectedIndex);
199
200 void setFilterKey(FilterKey filter);
201
202 void setDisableUpdates(bool disableUpdates);
203
204 void setDisableRemovals(bool disableRemovals);
205
206 private slots:
207 void handleNewMessages(const QMailMessageIdList &newList);
208 void handleMessagesRemoved(const QMailMessageIdList &removedList);
209 void handleUpdatedMessages(const QMailMessageIdList &updatedList);
210
211 void insertMessageAt(const int &index, const QMailMessageId &id);
212 void removeMessageAt(const int &index);
213 void addNewMessages(const QMailMessageIdList &idList);
214 void removeMessages(const QMailMessageIdList &idList);
215 void updateMessageAt(const int &index);
216
217 void refreshResponse(QDBusPendingCallWatcher *call);
218 void queryMessageResponse(QDBusPendingCallWatcher *call);
219 private:
220 QMailMessageIdList checkedIds();
221 void init();
222 void reset();
223
224 private: //members
225 typedef QMap<QMailMessageId, int> MessageIndexMap;
226
227 QMailMessageKey messageListKey();
228
229 QQmlObjectListModel<MinimalMessage> *m_model;
230 QMailMessageIdList m_idList; // List if id's in our model.
231 MessageIndexMap m_indexMap;
232 int m_limit = 50;
233 QMailMessageKey m_msgKey;
234 QMailMessageSortKey m_sortKey;
235 Qt::SortOrder m_sortOrder;
236 bool m_initialized;
237 bool m_selectionMode;
238 int m_currentIndex;
239 FilterKey m_filter;
240 #ifdef EXPERIMENTAL_REMEMBER_SELECTED_MESSAGE
241 QCache<QByteArray, QMailMessageId> m_cache;
242 #endif
243 bool m_disableUpdates;
244 bool m_needsRefresh;
245 QMailMessageIdList m_refreshList;
246 QThread m_workerThread;
247 bool m_loading;
248 bool m_disableRemovals;
249 };
250
251 #endif // MESSAGELIST_H