30 const QString syncIndicatorName = "com.nokia.nmail.indicatorplugin.sync/1.0"; |
30 const QString syncIndicatorName = "com.nokia.nmail.indicatorplugin.sync/1.0"; |
31 |
31 |
32 /*! |
32 /*! |
33 Constructor |
33 Constructor |
34 */ |
34 */ |
35 NmUiEngine::NmUiEngine() |
35 NmUiEngine::NmUiEngine() |
36 : mMailboxListModel(NULL), |
36 : mMailboxListModel(NULL), |
37 mInboxListModel(NULL), |
37 mInboxListModel(NULL), |
38 mMessageListModel(NULL), |
38 mMessageListModel(NULL), |
39 mMessageSearchListModel(NULL), |
39 mMessageSearchListModel(NULL), |
40 mSendOperation(NULL), |
40 mSendOperation(NULL), |
41 mRemoveDraftOperation(NULL), |
41 mRemoveDraftOperation(NULL), |
42 mSaveDraftOperation(NULL), |
42 mSaveDraftOperation(NULL), |
43 mDraftMessage(NULL) |
43 mDraftMessage(NULL) |
44 { |
44 { |
45 NM_FUNCTION; |
45 NM_FUNCTION; |
46 |
46 |
47 mPluginFactory = NmDataPluginFactory::instance(); |
47 mPluginFactory = NmDataPluginFactory::instance(); |
48 mDataManager = new NmDataManager(); |
48 mDataManager = new NmDataManager(); |
49 // Connect to the plugins to receive change notifications |
49 // Connect to the plugins to receive change notifications |
50 QList<QObject*> *dataPlugins = mPluginFactory->pluginInstances(); |
50 QList<QObject*> *dataPlugins = mPluginFactory->pluginInstances(); |
51 for (int i(0); i < dataPlugins->count(); i++) { |
51 for (int i(0); i < dataPlugins->count(); i++) { |
54 // connet mailbox events |
54 // connet mailbox events |
55 QObject::connect(plugin, SIGNAL(mailboxEvent(NmMailboxEvent, const QList<NmId> &)), |
55 QObject::connect(plugin, SIGNAL(mailboxEvent(NmMailboxEvent, const QList<NmId> &)), |
56 this, SLOT(handleMailboxEvent(NmMailboxEvent, const QList<NmId> &)), |
56 this, SLOT(handleMailboxEvent(NmMailboxEvent, const QList<NmId> &)), |
57 Qt::UniqueConnection); |
57 Qt::UniqueConnection); |
58 // connect message events |
58 // connect message events |
59 QObject::connect(plugin, |
59 QObject::connect(plugin, |
60 SIGNAL(messageEvent(NmMessageEvent, const NmId &, const QList<NmId> &, const NmId&)), |
60 SIGNAL(messageEvent(NmMessageEvent, const NmId &, const QList<NmId> &, const NmId&)), |
61 this, SLOT(handleMessageEvent(NmMessageEvent, const NmId &, const QList<NmId> &, const NmId &)), |
61 this, SLOT(handleMessageEvent(NmMessageEvent, const NmId &, const QList<NmId> &, const NmId &)), |
62 Qt::UniqueConnection); |
62 Qt::UniqueConnection); |
63 // connect connection events |
63 // connect connection events |
64 QObject::connect(plugin, |
64 QObject::connect(plugin, |
65 SIGNAL(connectionEvent(NmConnectState, const NmId &, const int)), |
65 SIGNAL(connectionEvent(NmConnectState, const NmId &, const int)), |
66 this, |
66 this, |
67 SLOT(handleConnectEvent(NmConnectState, const NmId &, const int)), |
67 SLOT(handleConnectEvent(NmConnectState, const NmId &, const int)), |
68 Qt::UniqueConnection); |
68 Qt::UniqueConnection); |
69 // do the subscriptions also |
69 // do the subscriptions also |
70 NmDataPluginInterface *pluginInterface = mPluginFactory->interfaceInstance(plugin); |
70 NmDataPluginInterface *pluginInterface = mPluginFactory->interfaceInstance(plugin); |
71 if (pluginInterface) { |
71 if (pluginInterface) { |
72 QList<NmId> mailboxIdList; |
72 QList<NmId> mailboxIdList; |
73 pluginInterface->listMailboxIds(mailboxIdList); |
73 pluginInterface->listMailboxIds(mailboxIdList); |
194 updated dynamically. The ownership of the model object is not moved to the caller. |
193 updated dynamically. The ownership of the model object is not moved to the caller. |
195 */ |
194 */ |
196 NmMailboxListModel &NmUiEngine::mailboxListModel() |
195 NmMailboxListModel &NmUiEngine::mailboxListModel() |
197 { |
196 { |
198 NM_FUNCTION; |
197 NM_FUNCTION; |
199 |
198 |
200 if (!mMailboxListModel) { |
199 if (!mMailboxListModel) { |
201 refreshMailboxListModel(); // creates the model too |
200 refreshMailboxListModel(); // creates the model too |
202 } |
201 } |
203 |
202 |
204 return *mMailboxListModel; |
203 return *mMailboxListModel; |
205 } |
204 } |
206 |
205 |
207 /*! |
206 /*! |
208 Populate the list model with the mailbox and top level folder objects. The model is |
207 Populate the list model with the mailbox and top level folder objects. The model is |
209 updated dynamically. Creates the model if needed. |
208 updated dynamically. Creates the model if needed. |
210 */ |
209 */ |
211 void NmUiEngine::refreshMailboxListModel() |
210 void NmUiEngine::refreshMailboxListModel() |
212 { |
211 { |
213 NM_FUNCTION; |
212 NM_FUNCTION; |
214 |
213 |
215 if (!mMailboxListModel) { |
214 if (!mMailboxListModel) { |
216 mMailboxListModel = new NmMailboxListModel(*mDataManager); |
215 mMailboxListModel = new NmMailboxListModel(*mDataManager); |
217 |
216 |
218 // Connect the model to the plugins to receive change notifications |
217 // Connect the model to the plugins to receive change notifications |
219 QList<QObject*> *dataPlugins = mPluginFactory->pluginInstances(); |
218 QList<QObject*> *dataPlugins = mPluginFactory->pluginInstances(); |
220 for (int i = 0; i < dataPlugins->count(); i++) { |
219 for (int i = 0; i < dataPlugins->count(); i++) { |
221 QObject *plugin = (*dataPlugins)[i]; |
220 QObject *plugin = (*dataPlugins)[i]; |
222 if (plugin) { |
221 if (plugin) { |
225 } |
224 } |
226 } |
225 } |
227 } else { |
226 } else { |
228 mMailboxListModel->clear(); |
227 mMailboxListModel->clear(); |
229 } |
228 } |
230 |
229 |
231 QList<NmMailbox*> mailboxList; |
230 QList<NmMailbox*> mailboxList; |
232 mDataManager->listMailboxes(mailboxList); |
231 mDataManager->listMailboxes(mailboxList); |
233 mMailboxListModel->refresh(mailboxList); |
232 mMailboxListModel->refresh(mailboxList); |
234 while (!mailboxList.isEmpty()) { |
233 while (!mailboxList.isEmpty()) { |
235 delete mailboxList.takeFirst(); |
234 delete mailboxList.takeFirst(); |
236 } |
235 } |
237 } |
236 } |
238 |
237 |
239 |
238 |
240 /*! |
239 /*! |
241 Returns a message list model for a folder identified by \a mailboxId and |
240 Returns a message list model for a folder identified by \a mailboxId and |
242 \a folderId. The model is updated dynamically. The ownership of the model |
241 \a folderId. The model is updated dynamically. The ownership of the model |
243 object is not moved to the caller. |
242 object is not moved to the caller. |
244 */ |
243 */ |
245 NmMessageListModel &NmUiEngine::messageListModel(const NmId &mailboxId, |
244 NmMessageListModel &NmUiEngine::messageListModel(const NmId &mailboxId, |
246 const NmId &folderId) |
245 const NmId &folderId) |
250 QObject *plugin = mPluginFactory->pluginInstance(mailboxId); |
249 QObject *plugin = mPluginFactory->pluginInstance(mailboxId); |
251 bool isInbox(false); |
250 bool isInbox(false); |
252 if (standardFolderId(mailboxId,NmFolderInbox)==folderId){ |
251 if (standardFolderId(mailboxId,NmFolderInbox)==folderId){ |
253 isInbox=true; |
252 isInbox=true; |
254 } |
253 } |
255 if (plugin) { |
254 if (plugin) { |
256 // Connect plugin message events to handler slot messageEventForListModel |
255 // Connect plugin message events to handler slot messageEventForListModel |
257 QObject::connect(plugin, SIGNAL(messageEvent(NmMessageEvent, const NmId &, |
256 QObject::connect(plugin, SIGNAL(messageEvent(NmMessageEvent, const NmId &, |
258 const QList<NmId> &, const NmId&)), |
257 const QList<NmId> &, const NmId&)), |
259 this, SLOT(messageEventForListModel(NmMessageEvent, |
258 this, SLOT(messageEventForListModel(NmMessageEvent, |
260 const NmId &, const QList<NmId> &, const NmId&)), Qt::UniqueConnection ); |
259 const NmId &, const QList<NmId> &, const NmId&)), Qt::UniqueConnection ); |
261 // Create inbox list model only once when entering to inbox for the first time |
260 // Create inbox list model only once when entering to inbox for the first time |
262 // or re-create inbox list model when mailbox has changed |
261 // or re-create inbox list model when mailbox has changed |
263 if ((!mInboxListModel&&isInbox)|| |
262 if ((!mInboxListModel&&isInbox)|| |
264 (mInboxListModel&&isInbox&&mailboxId!=mInboxListModel->currentMailboxId())){ |
263 (mInboxListModel&&isInbox&&mailboxId!=mInboxListModel->currentMailboxId())){ |
265 // Delete previous model and set to NULL. Deleting model will also |
264 // Delete previous model and set to NULL. Deleting model will also |
266 // delete all items in model. |
265 // delete all items in model. |
267 if (mInboxListModel){ |
266 if (mInboxListModel){ |
268 delete mInboxListModel; |
267 delete mInboxListModel; |
269 mInboxListModel=NULL; |
268 mInboxListModel=NULL; |
270 } |
269 } |
271 // Create new inbox model |
270 // Create new inbox model |
272 mInboxListModel = new NmMessageListModel(*mDataManager); |
271 mInboxListModel = new NmMessageListModel(*mDataManager); |
273 // Initial fill up of inbox list model, otherwise updated in the background |
272 // Initial fill up of inbox list model, otherwise updated in the background |
274 QList<NmMessageEnvelope*> messageEnvelopeList; |
273 QList<NmMessageEnvelope*> messageEnvelopeList; |
275 mDataManager->listMessages(mailboxId, folderId, messageEnvelopeList); |
274 mDataManager->listMessages(mailboxId, folderId, messageEnvelopeList); |
276 mInboxListModel->refresh(mailboxId, folderId, messageEnvelopeList); |
275 mInboxListModel->refresh(mailboxId, folderId, messageEnvelopeList); |
286 if (mMessageListModel){ |
285 if (mMessageListModel){ |
287 delete mMessageListModel; |
286 delete mMessageListModel; |
288 mMessageListModel=NULL; |
287 mMessageListModel=NULL; |
289 } |
288 } |
290 mMessageListModel = new NmMessageListModel(*mDataManager); |
289 mMessageListModel = new NmMessageListModel(*mDataManager); |
291 |
290 |
292 // Fill up other model |
291 // Fill up other model |
293 QList<NmMessageEnvelope*> messageEnvelopeList; |
292 QList<NmMessageEnvelope*> messageEnvelopeList; |
294 mDataManager->listMessages(mailboxId, folderId, messageEnvelopeList); |
293 mDataManager->listMessages(mailboxId, folderId, messageEnvelopeList); |
295 mMessageListModel->refresh(mailboxId, folderId, messageEnvelopeList); |
294 mMessageListModel->refresh(mailboxId, folderId, messageEnvelopeList); |
296 |
295 |
297 while (!messageEnvelopeList.isEmpty()) { |
296 while (!messageEnvelopeList.isEmpty()) { |
298 delete messageEnvelopeList.takeFirst(); |
297 delete messageEnvelopeList.takeFirst(); |
299 } |
298 } |
300 } |
299 } |
301 } |
300 } |
302 |
301 |
303 // Connect sync state changed |
302 // Connect sync state changed |
304 if (plugin){ |
303 if (plugin){ |
305 QObject::connect( |
304 QObject::connect( |
306 plugin, SIGNAL(syncStateEvent(NmSyncState, const NmOperationCompletionEvent &)), |
305 plugin, SIGNAL(syncStateEvent(NmSyncState, const NmOperationCompletionEvent &)), |
307 this, SLOT(handleSyncStateEvent(NmSyncState, const NmOperationCompletionEvent &)), |
306 this, SLOT(handleSyncStateEvent(NmSyncState, const NmOperationCompletionEvent &)), |
308 Qt::UniqueConnection); |
307 Qt::UniqueConnection); |
309 } |
308 } |
310 NmMessageListModel* ret(NULL); |
309 NmMessageListModel* ret(NULL); |
311 if (isInbox){ |
310 if (isInbox){ |
312 ret = mInboxListModel; |
311 ret = mInboxListModel; |
313 // Inbox list model is queried, other model is not |
312 // Inbox list model is queried, other model is not |
314 // needed anymore and memory should be freeded |
313 // needed anymore and memory should be freeded |
315 if (mMessageListModel){ |
314 if (mMessageListModel){ |
316 delete mMessageListModel; |
315 delete mMessageListModel; |
317 mMessageListModel=NULL; |
316 mMessageListModel=NULL; |
318 } |
317 } |
319 } |
318 } |
320 else { |
319 else { |
321 ret = mMessageListModel; |
320 ret = mMessageListModel; |
322 } |
321 } |
323 return *ret; |
322 return *ret; |
324 } |
323 } |
325 |
324 |
326 |
325 |
362 return *mMessageSearchListModel; |
361 return *mMessageSearchListModel; |
363 } |
362 } |
364 |
363 |
365 |
364 |
366 /*! |
365 /*! |
367 Get the identifier of the standard folder of a type \a folderType |
366 Get the identifier of the standard folder of a type \a folderType |
368 from the mailbox \a mailboxId. |
367 from the mailbox \a mailboxId. |
369 */ |
368 */ |
370 NmId NmUiEngine::standardFolderId( |
369 NmId NmUiEngine::standardFolderId( |
371 const NmId &mailboxId, |
370 const NmId &mailboxId, |
372 NmFolderType folderType) |
371 NmFolderType folderType) |
373 { |
372 { |
374 NM_FUNCTION; |
373 NM_FUNCTION; |
375 |
374 |
376 NmId value; |
375 NmId value; |
377 if (folderType != NmFolderOther) { |
376 if (folderType != NmFolderOther) { |
378 NmDataPluginInterface *plugin = |
377 NmDataPluginInterface *plugin = |
379 mPluginFactory->interfaceInstance(mailboxId); |
378 mPluginFactory->interfaceInstance(mailboxId); |
380 if(plugin) { |
379 if(plugin) { |
405 QPointer<NmOperation> NmUiEngine::fetchMessage( const NmId &mailboxId, |
404 QPointer<NmOperation> NmUiEngine::fetchMessage( const NmId &mailboxId, |
406 const NmId &folderId, |
405 const NmId &folderId, |
407 const NmId &messageId ) |
406 const NmId &messageId ) |
408 { |
407 { |
409 NM_FUNCTION; |
408 NM_FUNCTION; |
410 |
409 |
411 QPointer<NmOperation> value(NULL); |
410 QPointer<NmOperation> value(NULL); |
412 NmDataPluginInterface *plugin = |
411 NmDataPluginInterface *plugin = |
413 mPluginFactory->interfaceInstance(mailboxId); |
412 mPluginFactory->interfaceInstance(mailboxId); |
414 if (plugin) { |
413 if (plugin) { |
415 value = plugin->fetchMessage(mailboxId, folderId, messageId); |
414 value = plugin->fetchMessage(mailboxId, folderId, messageId); |
425 const NmId &folderId, |
424 const NmId &folderId, |
426 const NmId &messageId, |
425 const NmId &messageId, |
427 const NmId &messagePartId) |
426 const NmId &messagePartId) |
428 { |
427 { |
429 NM_FUNCTION; |
428 NM_FUNCTION; |
430 |
429 |
431 QPointer<NmOperation> value(NULL); |
430 QPointer<NmOperation> value(NULL); |
432 NmDataPluginInterface *plugin = |
431 NmDataPluginInterface *plugin = |
433 mPluginFactory->interfaceInstance(mailboxId); |
432 mPluginFactory->interfaceInstance(mailboxId); |
434 if (plugin) { |
433 if (plugin) { |
435 value = plugin->fetchMessagePart(mailboxId, folderId, messageId, messagePartId); |
434 value = plugin->fetchMessagePart(mailboxId, folderId, messageId, messagePartId); |
445 const NmId &folderId, |
444 const NmId &folderId, |
446 const NmId &messageId, |
445 const NmId &messageId, |
447 const QList<NmId> &messagePartIds) |
446 const QList<NmId> &messagePartIds) |
448 { |
447 { |
449 NM_FUNCTION; |
448 NM_FUNCTION; |
450 |
449 |
451 QPointer<NmOperation> value(NULL); |
450 QPointer<NmOperation> value(NULL); |
452 NmDataPluginInterface *plugin = |
451 NmDataPluginInterface *plugin = |
453 mPluginFactory->interfaceInstance(mailboxId); |
452 mPluginFactory->interfaceInstance(mailboxId); |
454 if (plugin) { |
453 if (plugin) { |
455 value = plugin->fetchMessageParts(mailboxId, folderId, messageId, messagePartIds); |
454 value = plugin->fetchMessageParts(mailboxId, folderId, messageId, messagePartIds); |
505 int NmUiEngine::deleteMessages(const NmId &mailboxId, |
504 int NmUiEngine::deleteMessages(const NmId &mailboxId, |
506 const NmId &folderId, |
505 const NmId &folderId, |
507 const QList<NmId> &messageIdList) |
506 const QList<NmId> &messageIdList) |
508 { |
507 { |
509 NM_FUNCTION; |
508 NM_FUNCTION; |
510 |
509 |
511 int result(NmNotFoundError); |
510 int result(NmNotFoundError); |
512 |
511 |
513 bool isInbox(false); |
512 bool isInbox(false); |
514 if (standardFolderId(mailboxId,NmFolderInbox)==folderId){ |
513 if (standardFolderId(mailboxId,NmFolderInbox)==folderId){ |
515 isInbox=true; |
514 isInbox=true; |
516 } |
515 } |
517 if (isInbox&&mInboxListModel){ |
516 if (isInbox&&mInboxListModel){ |
518 mInboxListModel->handleMessageEvent(NmMessageDeleted, folderId, |
517 mInboxListModel->handleMessageEvent(NmMessageDeleted, folderId, |
519 messageIdList, mailboxId); |
518 messageIdList, mailboxId); |
520 } |
519 } |
521 else if (mMessageListModel) { |
520 else if (mMessageListModel) { |
522 mMessageListModel->handleMessageEvent(NmMessageDeleted, folderId, |
521 mMessageListModel->handleMessageEvent(NmMessageDeleted, folderId, |
523 messageIdList, mailboxId); |
522 messageIdList, mailboxId); |
524 } |
523 } |
525 |
524 |
557 const NmId &folderId, |
556 const NmId &folderId, |
558 NmEnvelopeProperties property, |
557 NmEnvelopeProperties property, |
559 const QList<const NmMessageEnvelope*> &envelopeList) |
558 const QList<const NmMessageEnvelope*> &envelopeList) |
560 { |
559 { |
561 NM_FUNCTION; |
560 NM_FUNCTION; |
562 |
561 |
563 QPointer<NmStoreEnvelopesOperation> operation(NULL); |
562 QPointer<NmStoreEnvelopesOperation> operation(NULL); |
564 NmMessageListModel *theMessageListModel = mMessageListModel; |
563 NmMessageListModel *theMessageListModel = mMessageListModel; |
565 |
564 |
566 if (!theMessageListModel) { |
565 if (!theMessageListModel) { |
567 theMessageListModel = &messageListModel(mailboxId, folderId); |
566 theMessageListModel = &messageListModel(mailboxId, folderId); |
568 } |
567 } |
569 |
568 |
570 if (theMessageListModel && envelopeList.count()) { |
569 if (theMessageListModel && envelopeList.count()) { |
571 QList<NmId> messageIdList; |
570 QList<NmId> messageIdList; |
572 |
571 |
573 for (int i(0); i < envelopeList.count(); i++){ |
572 for (int i(0); i < envelopeList.count(); i++){ |
574 messageIdList.append(envelopeList[i]->messageId()); |
573 messageIdList.append(envelopeList[i]->messageId()); |
575 } |
574 } |
576 |
575 |
577 theMessageListModel->setEnvelopeProperties(property, messageIdList); |
576 theMessageListModel->setEnvelopeProperties(property, messageIdList); |
754 const NmId &mailboxId, |
752 const NmId &mailboxId, |
755 const NmId &folderId, |
753 const NmId &folderId, |
756 const NmId &messageId) |
754 const NmId &messageId) |
757 { |
755 { |
758 NM_FUNCTION; |
756 NM_FUNCTION; |
759 |
757 |
760 int result(NmNotFoundError); |
758 int result(NmNotFoundError); |
761 NmDataPluginInterface *plugin = |
759 NmDataPluginInterface *plugin = |
762 mPluginFactory->interfaceInstance(mailboxId); |
760 mPluginFactory->interfaceInstance(mailboxId); |
763 if (plugin) { |
761 if (plugin) { |
764 result = plugin->removeMessage(mailboxId, folderId, messageId); |
762 result = plugin->removeMessage(mailboxId, folderId, messageId); |
766 return result; |
764 return result; |
767 } |
765 } |
768 |
766 |
769 |
767 |
770 /*! |
768 /*! |
771 Handles draft message deletion after editor has closed, takes ownership of message. |
769 Handles draft message deletion after editor has closed, takes ownership of message. |
772 */ |
770 */ |
773 void NmUiEngine::removeDraftMessage(NmMessage *message) |
771 void NmUiEngine::removeDraftMessage(NmMessage *message) |
774 { |
772 { |
775 NM_FUNCTION; |
773 NM_FUNCTION; |
776 |
774 |
777 if (message) { |
775 if (message) { |
778 NmDataPluginInterface *plugin = |
776 NmDataPluginInterface *plugin = |
779 mPluginFactory->interfaceInstance(message->envelope().mailboxId()); |
777 mPluginFactory->interfaceInstance(message->envelope().mailboxId()); |
780 |
778 |
781 if (plugin) { |
779 if (plugin) { |
782 // to be on the safer side: |
780 // to be on the safer side: |
783 // we shouldn't even be here if mRemoveDraftOperation != NULL |
781 // we shouldn't even be here if mRemoveDraftOperation != NULL |
784 if (mRemoveDraftOperation && mRemoveDraftOperation->isRunning()) { |
782 if (mRemoveDraftOperation && mRemoveDraftOperation->isRunning()) { |
785 mRemoveDraftOperation->cancelOperation(); |
783 mRemoveDraftOperation->cancelOperation(); |
786 } |
784 } |
787 // ownership of message changes |
785 // ownership of message changes |
788 mRemoveDraftOperation = plugin->removeDraftMessage(message); |
786 mRemoveDraftOperation = plugin->removeDraftMessage(message); |
789 |
787 |
790 if (mRemoveDraftOperation) { |
788 if (mRemoveDraftOperation) { |
791 connect(mRemoveDraftOperation, |
789 connect(mRemoveDraftOperation, |
792 SIGNAL(operationCompleted(int)), |
790 SIGNAL(operationCompleted(int)), |
793 this, |
791 this, |
794 SLOT(handleCompletedRemoveDraftOperation())); |
792 SLOT(handleCompletedRemoveDraftOperation())); |
795 } |
793 } |
796 } |
794 } |
797 } |
795 } |
798 } |
796 } |
799 |
797 |
800 /*! |
798 /*! |
801 Handles draft message saving after editor has closed, takes ownership of message. |
799 Handles draft message saving after editor has closed, takes ownership of message. |
802 */ |
800 */ |
803 void NmUiEngine::saveDraftMessage(NmMessage *message, |
801 void NmUiEngine::saveDraftMessage(NmMessage *message, |
804 const QList<NmOperation*> &preliminaryOperations) |
802 const QList<NmOperation*> &preliminaryOperations) |
805 { |
803 { |
806 NM_FUNCTION; |
804 NM_FUNCTION; |
807 |
805 |
808 if (message) { |
806 if (message) { |
809 NmDataPluginInterface *plugin = |
807 NmDataPluginInterface *plugin = |
810 mPluginFactory->interfaceInstance(message->envelope().mailboxId()); |
808 mPluginFactory->interfaceInstance(message->envelope().mailboxId()); |
811 |
809 |
812 if (plugin) { |
810 if (plugin) { |
813 // to be on the safer side: |
811 // to be on the safer side: |
814 // we shouldn't even be here if mSaveDraftOperation != NULL |
812 // we shouldn't even be here if mSaveDraftOperation != NULL |
815 if (mSaveDraftOperation && mSaveDraftOperation->isRunning()) { |
813 if (mSaveDraftOperation && mSaveDraftOperation->isRunning()) { |
816 mSaveDraftOperation->cancelOperation(); |
814 mSaveDraftOperation->cancelOperation(); |
817 } |
815 } |
818 |
816 |
819 mSaveDraftOperation = plugin->saveMessageWithSubparts(*message); |
817 mSaveDraftOperation = plugin->saveMessageWithSubparts(*message); |
820 |
818 |
821 if (mSaveDraftOperation) { |
819 if (mSaveDraftOperation) { |
822 // Ownership of message changes but saveMessageWithSubparts operation only makes a |
820 // Ownership of message changes but saveMessageWithSubparts operation only makes a |
823 // copy so we handle the msg object deletion in engine. mDraftMessage is deleted |
821 // copy so we handle the msg object deletion in engine. mDraftMessage is deleted |
824 // in handleCompletedSaveDraftOperation once operation finishes. |
822 // in handleCompletedSaveDraftOperation once operation finishes. |
825 if(mDraftMessage) { |
823 if(mDraftMessage) { |
826 delete mDraftMessage; |
824 delete mDraftMessage; |
827 mDraftMessage = NULL; |
825 mDraftMessage = NULL; |
828 } |
826 } |
829 mDraftMessage = message; |
827 mDraftMessage = message; |
830 message = NULL; |
828 message = NULL; |
831 |
829 |
832 for (int i(0); i < preliminaryOperations.count(); i++ ) { |
830 for (int i(0); i < preliminaryOperations.count(); i++ ) { |
833 QPointer<NmOperation> op = preliminaryOperations[i]; |
831 QPointer<NmOperation> op = preliminaryOperations[i]; |
834 mSaveDraftOperation->addPreliminaryOperation(op); |
832 mSaveDraftOperation->addPreliminaryOperation(op); |
835 } |
833 } |
836 |
834 |
837 connect(mSaveDraftOperation, |
835 connect(mSaveDraftOperation, |
838 SIGNAL(operationCompleted(int)), |
836 SIGNAL(operationCompleted(int)), |
839 this, |
837 this, |
840 SLOT(handleCompletedSaveDraftOperation())); |
838 SLOT(handleCompletedSaveDraftOperation())); |
841 |
839 |
842 } |
840 } |
843 } |
841 } |
844 } |
842 } |
845 } |
843 } |
846 |
844 |
848 Sends the given message. |
846 Sends the given message. |
849 */ |
847 */ |
850 void NmUiEngine::sendMessage(NmMessage *message, const QList<NmOperation *> &preliminaryOperations) |
848 void NmUiEngine::sendMessage(NmMessage *message, const QList<NmOperation *> &preliminaryOperations) |
851 { |
849 { |
852 NM_FUNCTION; |
850 NM_FUNCTION; |
853 |
851 |
854 //First trigger message storing |
852 //First trigger message storing |
855 if (message) { |
853 if (message) { |
856 NmDataPluginInterface *plugin = |
854 NmDataPluginInterface *plugin = |
857 mPluginFactory->interfaceInstance(message->envelope().mailboxId()); |
855 mPluginFactory->interfaceInstance(message->envelope().mailboxId()); |
858 |
856 |
859 if (plugin) { |
857 if (plugin) { |
860 // to be on the safer side: |
858 // to be on the safer side: |
861 // we shouldn't even be here if mSendOperation != NULL |
859 // we shouldn't even be here if mSendOperation != NULL |
862 if (mSendOperation && mSendOperation->isRunning()) { |
860 if (mSendOperation && mSendOperation->isRunning()) { |
863 mSendOperation->cancelOperation(); |
861 mSendOperation->cancelOperation(); |
1008 this, SIGNAL(matchFound(const NmId &, const NmId &)), |
1006 this, SIGNAL(matchFound(const NmId &, const NmId &)), |
1009 Qt::UniqueConnection); |
1007 Qt::UniqueConnection); |
1010 |
1008 |
1011 connect(pluginInstance, SIGNAL(matchFound(const NmId &, const NmId &)), |
1009 connect(pluginInstance, SIGNAL(matchFound(const NmId &, const NmId &)), |
1012 this, SLOT(handleMatchFound(const NmId &, const NmId &)), |
1010 this, SLOT(handleMatchFound(const NmId &, const NmId &)), |
1013 Qt::UniqueConnection); |
1011 Qt::UniqueConnection); |
1014 |
1012 |
1015 connect(pluginInstance, SIGNAL(searchComplete()), |
1013 connect(pluginInstance, SIGNAL(searchComplete()), |
1016 this, SIGNAL(searchComplete()), |
1014 this, SIGNAL(searchComplete()), |
1017 Qt::UniqueConnection); |
1015 Qt::UniqueConnection); |
1018 } |
1016 } |
1019 |
1017 |
1020 int retVal(NmNoError); |
1018 int retVal(NmNoError); |
1021 |
1019 |
1022 // Get the plugin interface. |
1020 // Get the plugin interface. |
1040 \return A possible error code. |
1038 \return A possible error code. |
1041 */ |
1039 */ |
1042 int NmUiEngine::cancelSearch(const NmId &mailboxId) |
1040 int NmUiEngine::cancelSearch(const NmId &mailboxId) |
1043 { |
1041 { |
1044 NM_FUNCTION; |
1042 NM_FUNCTION; |
1045 |
1043 |
1046 int retVal(NmNoError); |
1044 int retVal(NmNoError); |
1047 |
1045 |
1048 // Get the plugin interface. |
1046 // Get the plugin interface. |
1049 NmDataPluginInterface *pluginInterface = |
1047 NmDataPluginInterface *pluginInterface = |
1050 mPluginFactory->interfaceInstance(mailboxId); |
1048 mPluginFactory->interfaceInstance(mailboxId); |
1051 |
1049 |
1052 if (pluginInterface) { |
1050 if (pluginInterface) { |
1053 // Cancel the search. |
1051 // Cancel the search. |
1054 retVal = pluginInterface->cancelSearch(mailboxId); |
1052 retVal = pluginInterface->cancelSearch(mailboxId); |
1055 } |
1053 } |
1056 return retVal; |
1054 return retVal; |
1057 } |
1055 } |
1058 |
1056 |
1059 /*! |
1057 /*! |
|
1058 Get mailbox folder type by folder id |
|
1059 \param mailboxId id of the mailbox |
|
1060 \param folderId id of the folder |
1060 \return Folder type |
1061 \return Folder type |
1061 */ |
1062 */ |
1062 NmFolderType NmUiEngine::folderTypeById(NmId mailboxId, NmId folderId) |
1063 NmFolderType NmUiEngine::folderTypeById(NmId mailboxId, NmId folderId) |
1063 { |
1064 { |
1064 NM_FUNCTION; |
1065 NM_FUNCTION; |
1065 |
1066 |
1066 NmFolderType ret(NmFolderInbox); |
1067 NmFolderType ret(NmFolderInbox); |
1067 if (mDataManager){ |
1068 if (mDataManager){ |
1068 ret = mDataManager->folderTypeById(mailboxId,folderId); |
1069 ret = mDataManager->folderTypeById(mailboxId,folderId); |
1069 } |
1070 } |
1070 return ret; |
1071 return ret; |
1071 } |
1072 } |
1072 |
1073 |
1073 /*! |
1074 /*! |
1090 Handle completed send operation. |
1091 Handle completed send operation. |
1091 */ |
1092 */ |
1092 void NmUiEngine::handleCompletedSendOperation() |
1093 void NmUiEngine::handleCompletedSendOperation() |
1093 { |
1094 { |
1094 NM_FUNCTION; |
1095 NM_FUNCTION; |
1095 |
1096 |
1096 emit sendOperationCompleted(); |
1097 emit sendOperationCompleted(); |
1097 } |
1098 } |
1098 |
1099 |
1099 /*! |
1100 /*! |
1100 Handle completed remove draft operation. |
1101 Handle completed remove draft operation. |
1101 */ |
1102 */ |
1102 void NmUiEngine::handleCompletedRemoveDraftOperation() |
1103 void NmUiEngine::handleCompletedRemoveDraftOperation() |
1103 { |
1104 { |
1104 NM_FUNCTION; |
1105 NM_FUNCTION; |
1105 |
1106 |
1106 // draft message deletion observing not yet implemented... |
1107 // draft message deletion observing not yet implemented... |
1107 } |
1108 } |
1108 |
1109 |
1109 /*! |
1110 /*! |
1110 Handle completed save draft operation. |
1111 Handle completed save draft operation. |
1111 */ |
1112 */ |
1112 void NmUiEngine::handleCompletedSaveDraftOperation() |
1113 void NmUiEngine::handleCompletedSaveDraftOperation() |
1113 { |
1114 { |
1114 NM_FUNCTION; |
1115 NM_FUNCTION; |
1115 |
1116 |
1116 // delete message object since it's not needed anymore |
1117 // delete message object since it's not needed anymore |
1117 if(mDraftMessage) { |
1118 if(mDraftMessage) { |
1118 delete mDraftMessage; |
1119 delete mDraftMessage; |
1119 mDraftMessage = NULL; |
1120 mDraftMessage = NULL; |
1120 } |
1121 } |
1124 Handles synch operation related events |
1125 Handles synch operation related events |
1125 */ |
1126 */ |
1126 void NmUiEngine::handleSyncStateEvent(NmSyncState syncState, const NmOperationCompletionEvent &event) |
1127 void NmUiEngine::handleSyncStateEvent(NmSyncState syncState, const NmOperationCompletionEvent &event) |
1127 { |
1128 { |
1128 NM_FUNCTION; |
1129 NM_FUNCTION; |
1129 |
1130 |
1130 if ( syncState == SyncComplete ) { |
1131 if ( syncState == SyncComplete ) { |
1131 // signal for reporting about (sync) operation completion status |
1132 // signal for reporting about (sync) operation completion status |
1132 emit operationCompleted(event); |
1133 emit operationCompleted(event); |
1133 HbIndicator indicator; |
1134 |
1134 indicator.deactivate(syncIndicatorName, QVariant()); |
1135 enableSyncIndicator(false); |
1135 } |
1136 } |
1136 |
1137 |
1137 // signal for handling sync state icons |
1138 // signal for handling sync state icons |
1138 emit syncStateEvent(syncState, event.mMailboxId); |
1139 emit syncStateEvent(syncState, event.mMailboxId); |
1139 } |
1140 } |
1140 |
1141 |
1141 /*! |
1142 /*! |
1142 Emits signals based on message events coming from plugins. |
1143 Enable or disable sync indicator |
|
1144 |
|
1145 \param enabled true if indicator is enabled, false if disabled |
|
1146 */ |
|
1147 void NmUiEngine::enableSyncIndicator(bool enabled) |
|
1148 { |
|
1149 NM_FUNCTION; |
|
1150 |
|
1151 HbIndicator indicator; |
|
1152 if (enabled) { |
|
1153 indicator.activate(syncIndicatorName, QVariant()); |
|
1154 } |
|
1155 else { |
|
1156 indicator.deactivate(syncIndicatorName, QVariant()); |
|
1157 } |
|
1158 } |
|
1159 |
|
1160 |
|
1161 /*! |
|
1162 Emits signals based on message events coming from plugins. |
1143 Currently only NmMessageDeleted is handled. |
1163 Currently only NmMessageDeleted is handled. |
1144 */ |
1164 */ |
1145 void NmUiEngine::handleMessageEvent(NmMessageEvent event, |
1165 void NmUiEngine::handleMessageEvent(NmMessageEvent event, |
1146 const NmId &folderId, |
1166 const NmId &folderId, |
1147 const QList<NmId> &messageIds, |
1167 const QList<NmId> &messageIds, |
1148 const NmId& mailboxId) |
1168 const NmId& mailboxId) |
1149 { |
1169 { |
1150 NM_FUNCTION; |
1170 NM_FUNCTION; |
1151 |
1171 |
1152 switch (event) { |
1172 switch (event) { |
1153 case NmMessageDeleted: |
1173 case NmMessageDeleted: |
1154 { |
1174 { |
1155 for (int i(0); i < messageIds.count(); i++) { |
1175 for (int i(0); i < messageIds.count(); i++) { |
1156 emit messageDeleted(mailboxId, folderId, messageIds[i]); |
1176 emit messageDeleted(mailboxId, folderId, messageIds[i]); |
1157 } |
1177 } |
1158 break; |
1178 break; |
1159 } |
1179 } |
1160 default: |
1180 default: |
1161 break; |
1181 break; |
1162 } |
1182 } |
1163 } |
1183 } |
1164 |
1184 |
1165 /*! |
1185 /*! |
1166 Emits signals based on mailbox events coming from plugins. |
1186 Emits signals based on mailbox events coming from plugins. |
1167 Currently only NmMailboxDeleted is handled. |
1187 Currently only NmMailboxDeleted is handled. |
1168 */ |
1188 */ |
1169 void NmUiEngine::handleMailboxEvent(NmMailboxEvent event, |
1189 void NmUiEngine::handleMailboxEvent(NmMailboxEvent event, |
1170 const QList<NmId> &mailboxIds) |
1190 const QList<NmId> &mailboxIds) |
1171 { |
1191 { |
1172 NM_FUNCTION; |
1192 NM_FUNCTION; |
1173 |
1193 |
1174 switch (event) { |
1194 switch (event) { |
1175 case NmMailboxDeleted: |
1195 case NmMailboxDeleted: |
1176 { |
1196 { |
1177 for (int i(0); i < mailboxIds.count(); i++) { |
1197 for (int i(0); i < mailboxIds.count(); i++) { |
1178 emit mailboxDeleted(mailboxIds[i]); |
1198 emit mailboxDeleted(mailboxIds[i]); |
1179 } |
1199 } |
1180 break; |
1200 break; |
1181 } |
1201 } |
1182 default: |
1202 default: |
1183 break; |
1203 break; |
1184 } |
1204 } |
1185 } |
1205 } |
1220 active mailbox is always alove whereas mMessageListModel can represent |
1240 active mailbox is always alove whereas mMessageListModel can represent |
1221 other folder in the device (sent, outbox, drafts, etc.) |
1241 other folder in the device (sent, outbox, drafts, etc.) |
1222 */ |
1242 */ |
1223 void NmUiEngine::messageEventForListModel(NmMessageEvent event, |
1243 void NmUiEngine::messageEventForListModel(NmMessageEvent event, |
1224 const NmId &folderId, |
1244 const NmId &folderId, |
1225 const QList<NmId> &messageIds, |
1245 const QList<NmId> &messageIds, |
1226 const NmId& mailboxId) |
1246 const NmId& mailboxId) |
1227 { |
1247 { |
1228 NM_FUNCTION; |
1248 NM_FUNCTION; |
1229 |
1249 |
1230 // Forward event to both list models. Models will take care of checking |
1250 // Forward event to both list models. Models will take care of checking |
1231 // whether event really belongs to current mailbox & folder |
1251 // whether event really belongs to current mailbox & folder |
1232 if (mInboxListModel){ |
1252 if (mInboxListModel){ |
1233 mInboxListModel->handleMessageEvent(event, folderId, |
1253 mInboxListModel->handleMessageEvent(event, folderId, |
1234 messageIds, mailboxId); |
1254 messageIds, mailboxId); |
1235 } |
1255 } |
1236 if (mMessageListModel){ |
1256 if (mMessageListModel){ |
1237 mMessageListModel->handleMessageEvent(event, folderId, |
1257 mMessageListModel->handleMessageEvent(event, folderId, |
1238 messageIds, mailboxId); |
1258 messageIds, mailboxId); |
1239 } |
1259 } |
1240 } |
1260 } |
1241 |
1261 |
1242 /*! |
1262 /*! |
1243 receives events when going online, and offline. |
1263 receives events when going online, and offline. |
1244 */ |
1264 */ |
1245 void NmUiEngine::handleConnectEvent(NmConnectState connectState, const NmId &mailboxId, const int errorCode) |
1265 void NmUiEngine::handleConnectEvent(NmConnectState connectState, const NmId &mailboxId, const int errorCode) |
1246 { |
1266 { |
1247 NM_FUNCTION; |
1267 NM_FUNCTION; |
1248 |
1268 |
1249 // signal for connection state icon handling |
1269 // signal for connection state icon handling |
1250 emit connectionEvent(connectState, mailboxId); |
1270 emit connectionEvent(connectState, mailboxId); |
1251 |
1271 |
1252 // in case going offline w/ error, emit signal to UI |
1272 // in case going offline w/ error, emit signal to UI |
1253 if ( connectState == Disconnected && errorCode!= NmNoError ) { |
1273 if ( connectState == Disconnected && errorCode!= NmNoError ) { |
1254 NmOperationCompletionEvent event={NoOp, errorCode, mailboxId, 0, 0}; |
1274 NmOperationCompletionEvent event={NoOp, errorCode, mailboxId, 0, 0}; |
1255 emit operationCompleted(event); |
1275 emit operationCompleted(event); |
1256 } |
1276 } |
1257 } |
1277 } |
1258 |
1278 |
1259 /*! |
1279 /*! |
1260 returns full mailbox id from plain account id |
1280 returns full mailbox id from plain account id |
1261 */ |
1281 */ |
1262 NmId NmUiEngine::getPluginIdByMailboxId(quint32 accountId) |
1282 NmId NmUiEngine::getPluginIdByMailboxId(quint32 accountId) |
1263 { |
1283 { |
1264 NM_FUNCTION; |
1284 NM_FUNCTION; |
1265 |
1285 |
1266 NmId fullId = NULL; |
1286 NmId fullId = NULL; |
1267 fullId.setId32(accountId); |
1287 fullId.setId32(accountId); |
1268 QList<NmId> mailboxList; |
1288 QList<NmId> mailboxList; |
1269 if(mDataManager){ |
1289 if(mDataManager){ |
1270 mDataManager->listMailboxIds(mailboxList); |
1290 mDataManager->listMailboxIds(mailboxList); |