|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #ifndef QMTMENGINE_SYMBIAN_H |
|
43 #define QMTMENGINE_SYMBIAN_H |
|
44 |
|
45 #include <QMap> |
|
46 #include <QSet> |
|
47 #include <QList> |
|
48 #include <QHash> |
|
49 |
|
50 #include <e32base.h> |
|
51 #include <msvapi.h> // MMsvSessionObserver |
|
52 #include "qmessagemanager.h" |
|
53 #include "qmessagestore_symbian_p.h" |
|
54 #include "qmessagefilter.h" |
|
55 #include "qmessagefilter_p.h" |
|
56 #include "qmessagefolderfilter.h" |
|
57 #include "qmessageservice.h" |
|
58 |
|
59 |
|
60 class CRichText; |
|
61 class CCharFormatLayer; |
|
62 class CParaFormatLayer; |
|
63 class CMsvSession; |
|
64 class CClientMtmRegistry; |
|
65 class CSmsClientMtm; |
|
66 class CMmsClientMtm; |
|
67 class CSmtpClientMtm; |
|
68 class CImap4ClientMtm; |
|
69 class CPop3ClientMtm; |
|
70 class CMsvFindOperation; |
|
71 |
|
72 |
|
73 QTM_BEGIN_NAMESPACE |
|
74 |
|
75 class CMessagesFindOperation; |
|
76 class QMessageId; |
|
77 class QMessageAccount; |
|
78 class CAsynchronousMTMOperation; |
|
79 |
|
80 struct MessageEvent |
|
81 { |
|
82 QMessageStorePrivate::NotificationType notificationType; |
|
83 TMsvId messageId; |
|
84 QMessageManager::NotificationFilterIdSet matchingFilters; |
|
85 bool unfiltered; |
|
86 }; |
|
87 |
|
88 struct MessageQueryInfo |
|
89 { |
|
90 int operationId; |
|
91 bool isQuery; |
|
92 QString body; |
|
93 QMessageDataComparator::MatchFlags matchFlags; |
|
94 QMessageFilter filter; |
|
95 QMessageSortOrder sortOrder; |
|
96 int offset; |
|
97 int limit; |
|
98 QMessageServicePrivate* privateService; |
|
99 CMessagesFindOperation* findOperation; |
|
100 int currentFilterListIndex; |
|
101 QMessageIdList ids; |
|
102 int count; |
|
103 }; |
|
104 |
|
105 class CMTMEngine : public QObject, public CActive, public MMsvSessionObserver |
|
106 { |
|
107 Q_OBJECT |
|
108 |
|
109 public: |
|
110 enum MTMType |
|
111 { |
|
112 MTMTypeSMS, |
|
113 MTMTypeMMS, |
|
114 MTMTypeSMTP, |
|
115 MTMTypeIMAP, |
|
116 MTMTypePOP3 |
|
117 }; |
|
118 |
|
119 static CMTMEngine* instance(); |
|
120 |
|
121 CMTMEngine(); |
|
122 ~CMTMEngine(); |
|
123 |
|
124 QMessageAccountIdList queryAccounts(const QMessageAccountFilter &filter, const QMessageAccountSortOrder &sortOrder, uint limit, uint offset) const; |
|
125 int countAccounts(const QMessageAccountFilter &filter) const; |
|
126 QMessageAccount account(const QMessageAccountId &id) const; |
|
127 QMessageAccountId defaultAccount(QMessage::Type type) const; |
|
128 |
|
129 QMessageFolderIdList queryFolders(const QMessageFolderFilter &filter, const QMessageFolderSortOrder &sortOrder, uint limit, uint offset) const; |
|
130 int countFolders(const QMessageFolderFilter &filter) const; |
|
131 QMessageFolder folder(const QMessageFolderId &id) const; |
|
132 |
|
133 bool addMessage(QMessage *m); |
|
134 bool updateMessage(QMessage *m); |
|
135 bool removeMessage(const QMessageId &id, QMessageManager::RemovalOption option); |
|
136 bool removeMessages(const QMessageFilter &filter, QMessageManager::RemovalOption option); |
|
137 bool queryMessages(QMessageServicePrivate& privateService, const QMessageFilter &filter, const QMessageSortOrder &sortOrder, uint limit, uint offset) const; |
|
138 bool queryMessages(QMessageServicePrivate& privateService, const QMessageFilter &filter, const QString &body, QMessageDataComparator::MatchFlags matchFlags, const QMessageSortOrder &sortOrder, uint limit, uint offset) const; |
|
139 bool countMessages(QMessageServicePrivate& privateService, const QMessageFilter &filter); |
|
140 bool showMessage(const QMessageId &id); |
|
141 bool composeMessage(const QMessage &message); |
|
142 |
|
143 QMessage message(const QMessageId& id) const; |
|
144 |
|
145 bool storeMMS(QMessage &message); |
|
146 bool sendMMS(QMessage &message); |
|
147 bool storeEmail(QMessage &message); |
|
148 bool sendEmail(QMessage &message); |
|
149 bool storeSMS(QMessage &message); |
|
150 bool sendSMS(QMessage &message); |
|
151 bool retrieve(QMessageServicePrivate& privateService, const QMessageId &messageId, const QMessageContentContainerId& id); |
|
152 bool retrieveBody(QMessageServicePrivate& privateService, const QMessageId& id); |
|
153 bool retrieveHeader(QMessageServicePrivate& privateService, const QMessageId& id); |
|
154 bool exportUpdates(QMessageServicePrivate& privateService, const QMessageAccountId &id); |
|
155 |
|
156 QByteArray attachmentContent(long int messageId, unsigned int attachmentId); |
|
157 QString attachmentTextContent(long int messageId, unsigned int attachmentId, const QByteArray &charset); |
|
158 |
|
159 QMessageManager::NotificationFilterId registerNotificationFilter(QMessageStorePrivate& aPrivateStore, |
|
160 const QMessageFilter& filter); |
|
161 void unregisterNotificationFilter(QMessageManager::NotificationFilterId notificationFilterId); |
|
162 |
|
163 void notification(TMsvSessionEvent aEvent, TUid aMsgType, TMsvId aFolderId, TMsvId aMessageId); |
|
164 void filterAndOrderMessagesReady(bool success, int operationId, QMessageIdList ids, int numberOfHandledFilters, |
|
165 bool resultSetOrdered); |
|
166 |
|
167 inline RFs& FsSession() const { return((RFs&)iFsSession); } |
|
168 |
|
169 public slots: |
|
170 void cleanupMTMBackend(); |
|
171 |
|
172 private: |
|
173 void updateEmailAccountsL() const; |
|
174 bool switchToMTMRootEntry(MTMType aMTMType); |
|
175 TMsvId mtmServiceEntryIdL(MTMType aMTMType) const; |
|
176 CBaseMtm* mtmByType(MTMType aMTMType); |
|
177 CBaseMtm* mtmByUid(TUid aMTMUid); |
|
178 TUid mtmUidByType(MTMType aMTMType); |
|
179 TMsvId standardFolderId(QMessage::StandardFolder standardFolder); |
|
180 |
|
181 QMessageFolderIdList allFolders() const; |
|
182 QMessageFolderIdList folderIdsByAccountId(const QMessageAccountId& accountId) const; |
|
183 QMessageFolderIdList folderIdsByServiceEntryId(const TMsvId& serviceEntryId, const TMsvId& folderServiceEntryId) const; |
|
184 QMessageFolderId createQMessageFolderId(const TMsvId& serviceEntryId, const TMsvId& folderId) const; |
|
185 TMsvId serviceEntryIdFromQMessageFolderId(const QMessageFolderId& folderId) const; |
|
186 TMsvId folderIdFromQMessageFolderId(const QMessageFolderId& folderId) const; |
|
187 |
|
188 QMessageAccountIdList accountsByType(QMessage::Type type) const; |
|
189 QMessageAccountId accountIdByServiceId(TMsvId serviceId) const; |
|
190 |
|
191 QMessageFolder folderL(const QMessageFolderId &id) const; |
|
192 |
|
193 static bool accountLessThan(const QMessageAccountId accountId1, const QMessageAccountId accountId2); |
|
194 void orderAccounts(QMessageAccountIdList& accountIds, const QMessageAccountSortOrder &sortOrder) const; |
|
195 void applyOffsetAndLimitToAccountIds(QMessageAccountIdList& idList, int offset, int limit) const; |
|
196 static bool folderLessThan(const QMessageFolderId folderId1, const QMessageFolderId folderId2); |
|
197 void orderFolders(QMessageFolderIdList& folderIds, const QMessageFolderSortOrder &sortOrder) const; |
|
198 static bool messageLessThan(const QMessage& message1, const QMessage& message2); |
|
199 void orderMessages(QMessageIdList& messageIds, const QMessageSortOrder &sortOrder) const; |
|
200 |
|
201 void handleNestedFiltersFromFolderFilter(QMessageFolderFilter &filter) const; |
|
202 void handleNestedFiltersFromMessageFilter(QMessageFilter &filter) const; |
|
203 |
|
204 void queryMessagesL(QMessageServicePrivate& privateService, const QMessageFilter &filter, const QMessageSortOrder &sortOrder, uint limit, uint offset) const; |
|
205 void queryMessagesL(QMessageServicePrivate& privateService, const QMessageFilter &filter, const QString &body, QMessageDataComparator::MatchFlags matchFlags, const QMessageSortOrder &sortOrder, uint limit, uint offset) const; |
|
206 void countMessagesL(QMessageServicePrivate& privateService, const QMessageFilter &filter); |
|
207 void applyOffsetAndLimitToMsgIds(QMessageIdList& idList, int offset, int limit) const; |
|
208 |
|
209 QMessageFolderIdList filterMessageFolders(const QMessageFolderFilter& filter, bool& filterHandled) const; |
|
210 QMessageFolderIdList filterMessageFoldersL(const QMessageFolderFilter& filter, bool& filterHandled) const; |
|
211 void applyOffsetAndLimitToMsgFolderIds(QMessageFolderIdList& idList, int offset, int limit) const; |
|
212 |
|
213 bool removeMessageL(const QMessageId &id, QMessageManager::RemovalOption option); |
|
214 void copyMessageL(TMsvId aMessageId, TMsvId aFolder); |
|
215 QMessage messageL(const QMessageId& id) const; |
|
216 QMessage smsMessageL(CMsvEntry& receivedEntry, long int messageId) const; |
|
217 QMessage mmsMessageL(CMsvEntry& receivedEntry, long int messageId) const; |
|
218 QMessage emailMessageL(CMsvEntry& receivedEntry, long int messageId) const; |
|
219 QMessage pop3MessageL(CMsvEntry& receivedEntry, long int messageId) const; |
|
220 QMessage imap4MessageL(CMsvEntry& receivedEntry, long int messageId) const; |
|
221 bool composeSMSL(const QMessage &message); |
|
222 bool composeMMSL(const QMessage &message); |
|
223 bool composeEmailL(const QMessage &message); |
|
224 void tryToDeliverMessageNotifications(); |
|
225 void updateMMSL(QMessage &message); |
|
226 void updateSMSL(QMessage &message); |
|
227 void updateEmailL(QMessage &message); |
|
228 void showMessageL(const QMessageId &id); |
|
229 |
|
230 void storeMMSL(QMessage &message); |
|
231 void sendMMSL(QMessage &message); |
|
232 void storeEmailL(QMessage &message); |
|
233 void sendEmailL(QMessage &message); |
|
234 void storeSMSL(QMessage &message); |
|
235 bool validateSMS(); |
|
236 void sendSMSL(QMessage &message); |
|
237 void retrieveL(QMessageServicePrivate& privateService, const QMessageId &messageId, const QMessageContentContainerId& id); |
|
238 void retrieveBodyL(QMessageServicePrivate& privateService, const QMessageId& id); |
|
239 void retrieveHeaderL(QMessageServicePrivate& privateService, const QMessageId& id); |
|
240 void exportUpdatesL(QMessageServicePrivate& privateService, const QMessageAccountId &id); |
|
241 void appendAttachmentToMessage(QMessage& message, QMessageContentContainer& attachment) const; |
|
242 QByteArray attachmentContentL(long int messageId, unsigned int attachmentId); |
|
243 |
|
244 QString privateFolderPath(); |
|
245 |
|
246 QDateTime symbianTTimetoQDateTime(const TTime& time) const; |
|
247 TTime qDateTimeToSymbianTTime(const QDateTime& date) const; |
|
248 |
|
249 static void cmsvEntryCleanup(TAny* aCMsvEntry); |
|
250 CMsvEntry* retrieveCMsvEntryAndPushToCleanupStack(TMsvId id = 0) const; |
|
251 void releaseCMsvEntryAndPopFromCleanupStack(CMsvEntry* pEntry) const; |
|
252 |
|
253 CAsynchronousMTMOperation* createAsynchronousMTMOperation(QMessageServicePrivate& privateService, |
|
254 CBaseMtm* mtm, |
|
255 TMsvId serviceId); |
|
256 void deleteAsynchronousMTMOperation(CAsynchronousMTMOperation *apOperation); |
|
257 bool checkIfWaitingDiscardClearMessage(TMsvId aMessageId); |
|
258 |
|
259 private: // from CActive |
|
260 void RunL(); |
|
261 void DoCancel(); |
|
262 |
|
263 private: //from MMsvSessionObserver: |
|
264 void HandleSessionEventL(TMsvSessionEvent aEvent, TAny* aArg1, |
|
265 TAny* aArg2, TAny* aArg3); |
|
266 |
|
267 private: |
|
268 RFs iFsSession; |
|
269 QMessageStorePrivate* ipMessageStorePrivate; |
|
270 |
|
271 bool iSessionReady; |
|
272 bool iListenForNotifications; |
|
273 |
|
274 mutable CRichText* ipRichText; |
|
275 mutable CCharFormatLayer* ipCharFormatLayer; |
|
276 mutable CParaFormatLayer* ipParaFormatLayer; |
|
277 |
|
278 MTMType iMTMType; |
|
279 |
|
280 CMsvSession* ipMsvSession; |
|
281 CClientMtmRegistry* ipClientMtmReg; |
|
282 CSmsClientMtm* ipSmsMtm; |
|
283 CMmsClientMtm* ipMmsMtm; |
|
284 CSmtpClientMtm* ipSmtpMtm; |
|
285 CImap4ClientMtm* ipImap4Mtm; |
|
286 CPop3ClientMtm* ipPop3Mtm; |
|
287 TBuf<KMaxPath> iPath; |
|
288 |
|
289 QString iSMSAccountidAsString; |
|
290 QString iMMSAccountidAsString; |
|
291 |
|
292 mutable RPointerArray<CMsvEntry> iCmsvEntryPoolFree; |
|
293 mutable RPointerArray<CMsvEntry> iCmsvEntryPoolInUse; |
|
294 |
|
295 CMsvFindOperation* ipFindOperation; |
|
296 |
|
297 QMessageManager::NotificationFilterId _filterId; |
|
298 QMap<QMessageManager::NotificationFilterId, QMessageFilter> _filters; |
|
299 |
|
300 mutable QHash<QString, QMessageAccount> iAccounts; |
|
301 mutable QMessageAccountId idefaultEmailAccountId; |
|
302 |
|
303 int iDeliveryTriesCounter; |
|
304 QList<MessageEvent> iUndeliveredMessageEvents; |
|
305 RTimer iTimer; // Timer used for delaying delivering of received |
|
306 // messages until messages are ready to be read |
|
307 TMsvId iMessageId; |
|
308 bool iNewMessage; |
|
309 |
|
310 mutable int iOperationIds; |
|
311 mutable QList<MessageQueryInfo> iMessageQueries; |
|
312 |
|
313 mutable QMessageAccountSortOrder iCurrentAccountOrdering; |
|
314 mutable QMessageFolderSortOrder iCurrentFolderOrdering; |
|
315 mutable QMessageSortOrder iCurrentMessageOrdering; |
|
316 |
|
317 friend class QMessageService; |
|
318 friend class CMessagesFindOperation; |
|
319 friend class CAsynchronousMTMOperation; |
|
320 }; |
|
321 |
|
322 class CMessagesFindOperation : public CActive |
|
323 { |
|
324 public: |
|
325 CMessagesFindOperation(CMTMEngine& aOwner, CMsvSession* apMsvSession, int aOperationId); |
|
326 ~CMessagesFindOperation(); |
|
327 |
|
328 void filterAndOrderMessages(const QMessageFilter& filter, |
|
329 const QMessageSortOrder& sortOrder, |
|
330 const QString body = QString(), |
|
331 QMessageDataComparator::MatchFlags matchFlags = 0); |
|
332 void filterAndOrderMessages(const QMessageFilterPrivate::SortedMessageFilterList& filters, |
|
333 const QMessageSortOrder& sortOrder, |
|
334 const QString body = QString(), |
|
335 QMessageDataComparator::MatchFlags matchFlags = 0); |
|
336 |
|
337 protected: // From CActive |
|
338 void RunL(); |
|
339 void DoCancel(); |
|
340 |
|
341 private: |
|
342 void getAllMessagesL(const TMsvSelectionOrdering sortOrder = TMsvSelectionOrdering()); |
|
343 void getAccountSpecificMessagesL(QMessageAccount& messageAccount, const TMsvSelectionOrdering sortOrder, QMessageFilterPrivate* privateFolderFilter = NULL); |
|
344 void getServiceSpecificMessagesL(TMsvId serviceId, const TMsvSelectionOrdering sortOrder, QMessageFilterPrivate* privateFolderFilter = NULL); |
|
345 void getServiceSpecificMessagesFromFolderL(TMsvId serviceId, const TMsvSelectionOrdering sortOrder, TMsvId standardFolderId = NULL); |
|
346 |
|
347 private: // Data |
|
348 CMTMEngine& iOwner; |
|
349 CMsvSession* ipMsvSession; |
|
350 |
|
351 int iNumberOfHandledFilters; |
|
352 int iOperationId; |
|
353 TMsvSelectionOrdering iOrdering; |
|
354 bool iResultCorrectlyOrdered; |
|
355 QMessageIdList iIdList; |
|
356 QMessageFilterPrivate::SortedMessageFilterList iFilterList; |
|
357 |
|
358 CMsvEntrySelection* ipEntrySelection; |
|
359 CMsvFindOperation* ipMsvFindOperation; |
|
360 |
|
361 mutable RTimer iTimer; |
|
362 }; |
|
363 |
|
364 class QMTMWait : public CActive |
|
365 { |
|
366 public: |
|
367 QMTMWait(TInt aPriority = EPriorityStandard); |
|
368 ~QMTMWait(); |
|
369 |
|
370 void start(); |
|
371 |
|
372 protected: // From CActive |
|
373 void RunL(); |
|
374 void DoCancel(); |
|
375 |
|
376 private: // Data |
|
377 QEventLoop m_eventLoop; |
|
378 }; |
|
379 |
|
380 class CAsynchronousMTMOperation : public CActive |
|
381 { |
|
382 public: |
|
383 enum MTMOperation |
|
384 { |
|
385 MTMOperationRetrieveMessageHeader, |
|
386 MTMOperationRetrieveMessageBody, |
|
387 MTMOperationRetrieveMessageAttachments, |
|
388 MTMOperationFullSync, |
|
389 }; |
|
390 |
|
391 enum MTMOperationStep |
|
392 { |
|
393 MTMOperationStepConnect, |
|
394 MTMOperationStepDoOperation, |
|
395 MTMOperationStepDisconnect, |
|
396 MTMOperationStepFinished |
|
397 }; |
|
398 |
|
399 CAsynchronousMTMOperation(CMTMEngine& aParent, |
|
400 QMessageServicePrivate& privateService, |
|
401 CBaseMtm* mtm, |
|
402 TMsvId serviceId, |
|
403 TInt aOperationId); |
|
404 ~CAsynchronousMTMOperation(); |
|
405 |
|
406 bool retrieveMessageHeader(TMsvId aMessageId); |
|
407 bool retrieveMessageBody(TMsvId aMessageId); |
|
408 bool retrieveMessageAttachments(TMsvId aMessageId); |
|
409 bool doFullSync(); |
|
410 |
|
411 protected: // From CActive |
|
412 void RunL(); |
|
413 void DoCancel(); |
|
414 |
|
415 private: // Data |
|
416 CMTMEngine* ipParent; |
|
417 |
|
418 TInt iOperationId; |
|
419 TMsvId iServiceId; |
|
420 TMsvId iMessageId; |
|
421 QMessageServicePrivate* ipPrivateService; |
|
422 |
|
423 CBaseMtm* ipMTM; |
|
424 MTMOperation iOperation; |
|
425 MTMOperationStep iOperationStep; |
|
426 |
|
427 CMsvEntrySelection* ipMsvEntrySelection; |
|
428 CMsvOperation* ipMsvOperation; |
|
429 |
|
430 bool isActive; |
|
431 }; |
|
432 |
|
433 QTM_END_NAMESPACE |
|
434 #endif // QMTMENGINE_SYMBIAN_H |