41 |
41 |
42 #ifndef MODESTENGINE_MAEMO_H |
42 #ifndef MODESTENGINE_MAEMO_H |
43 #define MODESTENGINE_MAEMO_H |
43 #define MODESTENGINE_MAEMO_H |
44 |
44 |
45 #include "qmessagemanager.h" |
45 #include "qmessagemanager.h" |
|
46 #include "qmessagefilter_p.h" |
|
47 #include "qmessageservice.h" |
|
48 |
46 #include "gconf/gconf-client.h" |
49 #include "gconf/gconf-client.h" |
47 #include "libosso.h" |
50 #include "libosso.h" |
48 |
51 |
|
52 #include <QMap> |
|
53 #include <QString> |
|
54 #include <QDBusArgument> |
|
55 #include <QDBusPendingCallWatcher> |
|
56 #include <QFileInfoList> |
|
57 #include <QThread> |
|
58 #include <QMutex> |
|
59 #include <QEventLoop> |
|
60 |
|
61 class QDBusInterface; |
|
62 class QFileSystemWatcher; |
|
63 class QEventLoop; |
|
64 |
49 QTM_BEGIN_NAMESPACE |
65 QTM_BEGIN_NAMESPACE |
50 |
66 |
|
67 typedef QMap< QString, QString > ModestStringMap; |
|
68 typedef QList< ModestStringMap > ModestStringMapList; |
|
69 |
|
70 static const int maxCacheSize = 1000; |
|
71 |
51 class QMessageService; |
72 class QMessageService; |
52 |
73 class QMessageServicePrivate; |
53 class ModestEngine |
74 class QMessageStorePrivate; |
54 { |
75 |
|
76 struct MessageQueryInfo |
|
77 { |
|
78 int queryId; |
|
79 QString body; |
|
80 QMessageDataComparator::MatchFlags matchFlags; |
|
81 QMessageFilter filter; |
|
82 QMessageSortOrder sortOrder; |
|
83 int limit; |
|
84 int offset; |
|
85 QMessageServicePrivate* privateService; |
|
86 QDBusPendingCallWatcher* pendingCallWatcher; |
|
87 int currentFilterListIndex; |
|
88 int handledFiltersCount; |
|
89 QMessageIdList ids; |
|
90 QString realAccountId; |
|
91 bool isQuery; |
|
92 bool returnWithSingleShot; |
|
93 }; |
|
94 |
|
95 struct ModestUnreadMessageDBusStruct |
|
96 { |
|
97 qlonglong timeStamp; |
|
98 QString subject; |
|
99 }; |
|
100 |
|
101 struct ModestAccountsUnreadMessagesDBusStruct |
|
102 { |
|
103 QString accountId; |
|
104 QString accountName; |
|
105 QString accountProtocol; |
|
106 qlonglong unreadCount; |
|
107 QList<ModestUnreadMessageDBusStruct> unreadMessages; |
|
108 }; |
|
109 |
|
110 struct ModestMessage |
|
111 { |
|
112 QString id; |
|
113 QString subject; |
|
114 QString folder; |
|
115 QString sender; |
|
116 long long size; |
|
117 bool hasAttachment; |
|
118 bool isUnread; |
|
119 long long timeStamp; |
|
120 }; |
|
121 |
|
122 typedef enum { |
|
123 MessagingModestMessageNotDefined = 0, |
|
124 MessagingModestMessageAnswered = 1<<0, |
|
125 MessagingModestMessageDeleted = 1<<1, |
|
126 MessagingModestMessageDraft = 1<<2, |
|
127 MessagingModestMessageFlagged = 1<<3, |
|
128 MessagingModestMessageSeen = 1<<4, |
|
129 MessagingModestMessageAttachments = 1<<5, |
|
130 MessagingModestMessageCached = 1<<6, |
|
131 MessagingModestMessagePartial = 1<<7, |
|
132 MessagingModestMessageExpunged = 1<<8, |
|
133 MessagingModestMessageHasPriority = 1<<9|1<<10 |
|
134 } MessagingModestMessageFlags; |
|
135 |
|
136 typedef enum { |
|
137 MessagingModestMessagePriorityDefined = 0, |
|
138 MessagingModestMessageHighPriority = 1<<9|1<<10, |
|
139 MessagingModestMessageNormalPriority = 0<<9|0<<10, |
|
140 MessagingModestMessageLowPriority = 0<<9|1<<10, |
|
141 MessagingModestMessageSuspendedPriority = 1<<9|0<<10 |
|
142 } MessagingModestMessagePriority; |
|
143 |
|
144 struct MessagingModestMimePart |
|
145 { |
|
146 QString mimeType; |
|
147 bool isAttachment; |
|
148 QString fileName; |
|
149 QString contentId; |
|
150 }; |
|
151 |
|
152 struct MessagingModestMessage |
|
153 { |
|
154 QString id; |
|
155 QString url; |
|
156 QString accountId; |
|
157 QString folderId; |
|
158 QString mimeType; |
|
159 QString from; |
|
160 QString to; |
|
161 QString cc; |
|
162 QString bcc; |
|
163 QString replyTo; |
|
164 QString subject; |
|
165 qlonglong dateReceived; |
|
166 qlonglong dateSent; |
|
167 qlonglong size; |
|
168 MessagingModestMessageFlags flags; |
|
169 MessagingModestMessagePriority priority; |
|
170 QList<MessagingModestMimePart> mimeParts; |
|
171 }; |
|
172 |
|
173 struct INotifyEvent |
|
174 { |
|
175 int watchDescriptor; |
|
176 uint32_t mask; |
|
177 QString fileName; |
|
178 }; |
|
179 |
|
180 class INotifyWatcher : public QThread |
|
181 { |
|
182 Q_OBJECT |
|
183 |
55 public: |
184 public: |
|
185 enum FileNotification |
|
186 { |
|
187 FileNotificationAdded, |
|
188 FileNotificationUpdated, |
|
189 FileNotificationRemoved |
|
190 }; |
|
191 |
|
192 INotifyWatcher(); |
|
193 ~INotifyWatcher(); |
|
194 |
|
195 void run(); |
|
196 int addFile(const QString& path, uint eventsToWatch = 0); |
|
197 QStringList files() const; |
|
198 int addDirectory(const QString& path, uint eventsToWatch = 0); |
|
199 QStringList directories() const; |
|
200 void clear(); |
|
201 |
|
202 private slots: |
|
203 void notifySlot(); |
|
204 |
|
205 signals: |
|
206 void fileChanged(int watchDescriptor, QString filePath, uint events); |
|
207 |
|
208 private: //Data |
|
209 int m_inotifyFileDescriptor; |
|
210 QMutex m_mutex; |
|
211 QMap<int, QString> m_files; |
|
212 QMap<int, QString> m_dirs; |
|
213 }; |
|
214 |
|
215 class ModestEngine : public QObject |
|
216 { |
|
217 Q_OBJECT |
|
218 |
|
219 public: |
|
220 enum EmailProtocol |
|
221 { |
|
222 EmailProtocolUnknown = -1, |
|
223 EmailProtocolPop3 = 1, |
|
224 EmailProtocolIMAP, |
|
225 }; |
|
226 |
|
227 enum NotificationType |
|
228 { |
|
229 None = 0, |
|
230 Added, |
|
231 Updated, |
|
232 Removed |
|
233 }; |
|
234 |
56 static ModestEngine* instance(); |
235 static ModestEngine* instance(); |
57 |
236 |
58 ModestEngine(); |
237 ModestEngine(); |
59 ~ModestEngine(); |
238 ~ModestEngine(); |
|
239 |
|
240 bool exportUpdates(const QMessageAccountId &id); |
60 |
241 |
61 QMessageAccountIdList queryAccounts(const QMessageAccountFilter &filter, const QMessageAccountSortOrder &sortOrder, |
242 QMessageAccountIdList queryAccounts(const QMessageAccountFilter &filter, const QMessageAccountSortOrder &sortOrder, |
62 uint limit, uint offset, bool &isFiltered, bool &isSorted) const; |
243 uint limit, uint offset, bool &isFiltered, bool &isSorted) const; |
63 int countAccounts(const QMessageAccountFilter &filter) const; |
244 int countAccounts(const QMessageAccountFilter &filter) const; |
64 QMessageAccount account(const QMessageAccountId &id) const; |
245 QMessageAccount account(const QMessageAccountId &id) const; |
65 QMessageAccountId defaultAccount(QMessage::Type type) const; |
246 QMessageAccountId defaultAccount() const; |
66 |
247 |
67 bool queryMessages(QMessageService& messageService, const QMessageFilter &filter, const QMessageSortOrder &sortOrder, uint limit, uint offset) const; |
248 QMessageFolderIdList queryFolders(const QMessageFolderFilter &filter, const QMessageFolderSortOrder &sortOrder, |
68 bool queryMessages(QMessageService& messageService, const QMessageFilter &filter, const QString &body, QMessageDataComparator::MatchFlags matchFlags, const QMessageSortOrder &sortOrder, uint limit, uint offset) const; |
249 uint limit, uint offset, bool &isFiltered, bool &isSorted) const; |
|
250 int countFolders(const QMessageFolderFilter &filter) const; |
|
251 QMessageFolder folder(const QMessageFolderId &id) const; |
|
252 |
|
253 QMessage message(const QMessageId &id, bool useCache = true) const; |
|
254 bool addMessage(QMessage &message); |
|
255 bool updateMessage(QMessage &message); |
|
256 bool removeMessage(const QMessageId &id, QMessageManager::RemovalOption option); |
|
257 |
|
258 bool queryMessages(QMessageService& messageService, const QMessageFilter &filter, |
|
259 const QMessageSortOrder &sortOrder, uint limit, uint offset) const; |
|
260 bool queryMessages(QMessageService& messageService, const QMessageFilter &filter, |
|
261 const QString &body, QMessageDataComparator::MatchFlags matchFlags, |
|
262 const QMessageSortOrder &sortOrder, uint limit, uint offset) const; |
69 bool countMessages(QMessageService& messageService, const QMessageFilter &filter); |
263 bool countMessages(QMessageService& messageService, const QMessageFilter &filter); |
|
264 |
|
265 QMessageIdList queryMessagesSync(const QMessageFilter &filter, const QMessageSortOrder &sortOrder, |
|
266 uint limit, uint offset, bool &isFiltered, bool &isSorted) const; |
|
267 QMessageIdList queryMessagesSync(const QMessageFilter &filter, const QString &body, |
|
268 QMessageDataComparator::MatchFlags matchFlags, |
|
269 const QMessageSortOrder &sortOrder, uint limit, uint offset, |
|
270 bool &isFiltered, bool &isSorted) const; |
|
271 int countMessagesSync(const QMessageFilter &filter) const; |
70 |
272 |
71 bool sendEmail(QMessage &message); |
273 bool sendEmail(QMessage &message); |
72 bool composeEmail(const QMessage &message); |
274 bool composeEmail(const QMessage &message); |
|
275 bool showMessage(const QMessageId &id); |
|
276 |
|
277 QMessageManager::NotificationFilterId registerNotificationFilter(QMessageStorePrivate& messageStore, |
|
278 const QMessageFilter& filter, |
|
279 QMessageManager::NotificationFilterId id = 0); |
|
280 void unregisterNotificationFilter(QMessageManager::NotificationFilterId notificationFilterId); |
|
281 QByteArray getMimePart (const QMessageId &id, const QString &attachmentId); |
73 |
282 |
74 private: |
283 private: |
|
284 QFileInfoList localFolders() const; |
|
285 void appendLocalSubFolders(QFileInfoList& fileInfoList, int startIndex) const; |
|
286 void appendIMAPSubFolders(QFileInfoList& fileInfoList, int startIndex) const; |
|
287 QFileInfoList accountFolders(QMessageAccountId& accountId) const; |
|
288 QString localRootFolder() const; |
|
289 QString accountRootFolder(QMessageAccountId& accountId) const; |
|
290 EmailProtocol accountEmailProtocol(QMessageAccountId& accountId) const; |
|
291 QString accountEmailProtocolAsString(const QMessageAccountId& accountId) const; |
|
292 QString accountUsername(QMessageAccountId& accountId) const; |
|
293 QString accountHostname(QMessageAccountId& accountId) const; |
|
294 |
75 void updateEmailAccounts() const; |
295 void updateEmailAccounts() const; |
76 |
296 |
|
297 bool filterMessage(const QMessage& message, QMessageFilterPrivate::SortedMessageFilterList filterList, int start) const; |
|
298 bool queryAndFilterMessages(MessageQueryInfo &msgQueryInfo) const; |
|
299 bool startQueryingAndFilteringMessages(MessageQueryInfo &msgQueryInfo) const; |
|
300 bool searchMessages(MessageQueryInfo &msgQueryInfo, const QStringList& accountIds, |
|
301 const QStringList& folderUris, const QString& body, |
|
302 const QDateTime& startTimeStamp, const QDateTime& endTimeStamp, |
|
303 const QDateTime& startReceptionTimeStamp, const QDateTime& endReceptionTimeStamp) const; |
|
304 void searchNewMessages(const QString& searchString, const QString& folderToSearch, |
|
305 const QDateTime& startDate, const QDateTime& endDate, |
|
306 int searchflags, uint minimumMessageSize) const; |
|
307 void handleQueryFinished(int queryIndex) const; |
|
308 |
|
309 void watchAllKnownEmailFolders(); |
|
310 void notification(const QMessageId& messageId, NotificationType notificationType) const; |
|
311 |
|
312 QMessageAccountId accountIdFromModestMessageId(const QString& modestMessageId) const; |
|
313 QMessageFolderId folderIdFromModestMessageId(const QString& modestMessageId, |
|
314 const QMessageAccountId accountId = QMessageAccountId()) const; |
|
315 |
|
316 MessagingModestMessage messageFromModest(const QString& accountId, |
|
317 const QString &folderId, |
|
318 const QString& messageId) const; |
|
319 |
|
320 QString modestAccountIdFromAccountId(const QMessageAccountId& accountId) const; |
|
321 QString modestFolderIdFromFolderId(const QMessageFolderId& folderId) const; |
|
322 QString modestFolderUriFromFolderId(const QMessageFolderId& folderId) const; |
|
323 QString modestAccountIdFromMessageId(const QMessageId& messageId, bool checkProtocol = true) const; |
|
324 QString modestAccountIdFromFolderId(const QMessageFolderId& folderId, bool checkProtocol = true) const; |
|
325 QString modestFolderIdFromMessageId(const QMessageId& messageId) const; |
|
326 QString modestMessageIdFromMessageId(const QMessageId& messageId) const; |
|
327 void replaceProtocol(QString& id, const QString& newProtocol) const; |
|
328 QMessageAccountId realAccountId(const MessagingModestMessage& modestMessage) const; |
|
329 QMessageAccountId accountIdFromMessageId(const QMessageId& messageId) const; |
|
330 QMessageAccountId accountIdFromFolderId(const QMessageFolderId& folderId) const; |
|
331 QMessageAccountId accountIdFromModestAccountId(const QString& accountId) const; |
|
332 QMessageFolderId folderIdFromModestFolderId(const QMessageAccountId& accountId, |
|
333 bool isLocalFolder, |
|
334 const QString& folderId) const; |
|
335 QMessageId messageIdFromModestMessageId(const QString& messageId) const; |
|
336 QMessageId messageIdFromModestMessageFilePath(const QString& messageFilePath) const; |
|
337 |
|
338 QMessage messageFromModestMessage(const MessagingModestMessage& modestMessage, |
|
339 QMessageAccountId accountId = QMessageAccountId()) const; |
|
340 void appendAttachmentToMessage(QMessage& message, QMessageContentContainer& attachment) const; |
|
341 |
|
342 static QString unescapeString(const QString& string); |
|
343 static QString escapeString(const QString& string); |
|
344 |
|
345 QMessage::StandardFolder standardFolderFromModestFolderId(const QString& modestFolderId) const; |
|
346 QString modestFolderIdFromStandardFolder(QMessage::StandardFolder standardFolder) const; |
|
347 |
|
348 ModestStringMap getModestSenderInfo(QMessage &message); |
|
349 ModestStringMap getModestRecipients(QMessage &message); |
|
350 ModestStringMap getModestMessageData(QMessage &message); |
|
351 ModestStringMapList getModestAttachments(QMessage &message); |
|
352 ModestStringMapList getModestImages(QMessage &message); |
|
353 uint getModestPriority(QMessage &message); |
|
354 ModestStringMap getModestHeaders(QMessage &message); |
|
355 |
|
356 private slots: |
|
357 void searchMessagesHeadersReceivedSlot(QDBusMessage msg); |
|
358 void searchMessagesHeadersFetchedSlot(QDBusMessage msg); |
|
359 void folderUpdatedSlot(QDBusMessage msg); |
|
360 void messageReadChangedSlot(QDBusMessage msg); |
|
361 void pendingGetUnreadMessagesFinishedSlot(QDBusPendingCallWatcher* pendingCallWatcher); |
|
362 void pendingSearchFinishedSlot(QDBusPendingCallWatcher* pendingCallWatcher); |
|
363 void fileChangedSlot(int watchDescriptor, QString filePath, uint events); |
|
364 void sendEmailCallEnded(QDBusPendingCallWatcher *watcher); |
|
365 void addMessageCallEnded(QDBusPendingCallWatcher *watcher); |
|
366 void stateChanged(QMessageService::State newState); |
|
367 void returnQueryResultsSlot(); |
|
368 |
77 private: //Data |
369 private: //Data |
78 GConfClient* m_gconfclient; |
370 GConfClient *m_gconfclient; |
|
371 |
|
372 QDBusInterface *m_ModestDBusInterface; |
|
373 QDBusInterface *m_QtmPluginDBusInterface; |
|
374 |
|
375 INotifyWatcher m_MailFoldersWatcher; |
79 |
376 |
80 mutable QHash<QString, QMessageAccount> iAccounts; |
377 mutable QHash<QString, QMessageAccount> iAccounts; |
81 mutable QMessageAccountId iDefaultEmailAccountId; |
378 mutable QMessageAccountId iDefaultEmailAccountId; |
|
379 |
|
380 mutable int m_queryIds; |
|
381 mutable QList<MessageQueryInfo> m_pendingMessageQueries; |
|
382 |
|
383 QMap<QMessageManager::NotificationFilterId, QMessageFilter> m_filters; |
|
384 QMessageManager::NotificationFilterId m_filterId; |
|
385 QMessageStorePrivate* m_messageStore; |
|
386 |
|
387 QMap<QString, QDateTime> accountsLatestTimestamp; |
|
388 |
|
389 mutable QStringList m_latestRemoveNotifications; |
|
390 |
|
391 mutable QMap<QString, QMessage> m_messageCache; |
|
392 |
|
393 // Following variables are used for sync queries |
|
394 mutable QMessageService m_service; |
|
395 mutable QEventLoop m_eventLoop; |
|
396 mutable QMessageIdList m_ids; |
|
397 mutable int m_count; |
|
398 mutable bool m_isSorted; |
|
399 mutable bool m_isFiltered; |
82 }; |
400 }; |
83 |
401 |
84 QTM_END_NAMESPACE |
402 QTM_END_NAMESPACE |
85 |
403 |
|
404 // Marshall the MyStructure data into a D-Bus argument |
|
405 QDBusArgument &operator<<(QDBusArgument &argument, const QtMobility::ModestStringMap &map); |
|
406 |
|
407 // Retrieve the MyStructure data from the D-Bus argument |
|
408 const QDBusArgument &operator>>(const QDBusArgument &argument, QtMobility::ModestStringMap &map); |
|
409 |
|
410 Q_DECLARE_METATYPE(QtMobility::ModestStringMap); |
|
411 Q_DECLARE_METATYPE(QtMobility::ModestStringMapList); |
|
412 Q_DECLARE_METATYPE(QtMobility::INotifyWatcher::FileNotification); |
|
413 Q_DECLARE_METATYPE(QtMobility::ModestUnreadMessageDBusStruct); |
|
414 Q_DECLARE_METATYPE(QtMobility::ModestAccountsUnreadMessagesDBusStruct); |
|
415 Q_DECLARE_METATYPE(QtMobility::ModestMessage); |
|
416 Q_DECLARE_METATYPE(QtMobility::MessagingModestMimePart); |
|
417 |
86 #endif // MODESTENGINE_MAEMO_H |
418 #endif // MODESTENGINE_MAEMO_H |
87 |
419 |