| 1 |
m> |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 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 |
|
| 35 |
|
| 36 |
|
| 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 |
|
| 72 |
Q_PROPERTY(QObject *model READ model NOTIFY modelChanged) |
| 73 |
|
| 74 |
Q_PROPERTY(int limit READ limit WRITE setLimit NOTIFY limitChanged) |
| 75 |
|
| 76 |
Q_PROPERTY(QVariant messageKey READ key WRITE setKey NOTIFY messageKeyChanged) |
| 77 |
|
| 78 |
Q_PROPERTY(Qt::SortOrder sortOrder READ sortOrder WRITE setSortOrder NOTIFY sortOrderChanged) |
| 79 |
|
| 80 |
Q_PROPERTY(FilterKey filter READ filterKey WRITE setFilterKey NOTIFY filterKeyChanged) |
| 81 |
|
| 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 |
|
| 86 |
|
| 87 |
Q_PROPERTY(bool isInSelectionMode READ isInSelectionMode NOTIFY isInSelectionModeChanged) |
| 88 |
|
| 89 |
|
| 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 |
|
| 182 |
|
| 183 |
void startSelection(); |
| 184 |
|
| 185 |
void endSelection(); |
| 186 |
|
| 187 |
void selectAll(); |
| 188 |
|
| 189 |
void unselectAll(); |
| 190 |
|
| 191 |
void setChecked(const int &index, const Qt::CheckState &checkState); |
| 192 |
void markSelectedMessagesImportant(); |
| 193 |
void markSelectedMessagesRead(); |
| 194 |
void deleteSelectedMessages(); |
| 195 |
|
| 196 |
|
| 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: |
| 225 |
typedef QMap<QMailMessageId, int> MessageIndexMap; |
| 226 |
|
| 227 |
QMailMessageKey messageListKey(); |
| 228 |
|
| 229 |
QQmlObjectListModel<MinimalMessage> *m_model; |
| 230 |
QMailMessageIdList m_idList; |
| 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 |