44 NmApiEngine::~NmApiEngine() |
43 NmApiEngine::~NmApiEngine() |
45 { |
44 { |
46 NM_FUNCTION; |
45 NM_FUNCTION; |
47 |
46 |
48 NmApiDataPluginFactory::releaseInstance(mFactory); |
47 NmApiDataPluginFactory::releaseInstance(mFactory); |
|
48 |
|
49 if (mMailPlugins.Count() > 0) { |
|
50 CFSMailPlugin* plugin = NULL; |
|
51 for (int i = 0; i < mMailPlugins.Count(); ++i) { |
|
52 plugin = mMailPlugins[i]; |
|
53 |
|
54 if (plugin) { |
|
55 delete plugin; |
|
56 plugin = NULL; |
|
57 } |
|
58 |
|
59 CFSMailPlugin::Close(); |
|
60 } |
|
61 } |
49 } |
62 } |
50 |
63 |
51 /*! |
64 /*! |
52 Creates instance of NmApiEngine and provide pointer to it. |
65 Creates instance of NmApiEngine and provide pointer to it. |
53 |
66 |
92 */ |
105 */ |
93 void NmApiEngine::mailboxChangedArrived(NmMailboxEvent mailboxEvent, const QList<NmId> &mailboxIds) |
106 void NmApiEngine::mailboxChangedArrived(NmMailboxEvent mailboxEvent, const QList<NmId> &mailboxIds) |
94 { |
107 { |
95 NM_FUNCTION; |
108 NM_FUNCTION; |
96 |
109 |
97 NmApiMessage message; |
110 NmApiEvent event; |
98 message.objectType = EMailbox; |
111 event.objectType = EMailbox; |
99 switch (mailboxEvent) { |
112 switch (mailboxEvent) { |
100 case NmMailboxCreated: { |
113 case NmMailboxCreated: { |
101 message.action = ENew; |
114 event.action = ENew; |
102 // subscribe all events also for these new mailboxes |
115 // subscribe all events also for these new mailboxes |
103 for(int i=0; i<mailboxIds.count(); i++) { |
116 for(int i=0; i<mailboxIds.count(); i++) { |
104 mFactory->interfaceInstance()->subscribeMailboxEvents(mailboxIds[i]); |
117 mFactory->interfaceInstance()->subscribeMailboxEvents(mailboxIds[i]); |
105 } |
118 } |
106 } |
119 } |
107 break; |
120 break; |
108 case NmMailboxDeleted: { |
121 case NmMailboxDeleted: { |
109 message.action = EDeleted; |
122 event.action = EDeleted; |
110 // unsubscribe all events from deleted mailboxes |
123 // unsubscribe all events from deleted mailboxes |
111 for(int i=0; i<mailboxIds.count(); i++) { |
124 for(int i=0; i<mailboxIds.count(); i++) { |
112 mFactory->interfaceInstance()->unsubscribeMailboxEvents(mailboxIds[i]); |
125 mFactory->interfaceInstance()->unsubscribeMailboxEvents(mailboxIds[i]); |
113 } |
126 } |
114 } |
127 } |
115 break; |
128 break; |
116 case NmMailboxChanged: { |
129 case NmMailboxChanged: { |
117 message.action = EChange; |
130 event.action = EChange; |
118 } |
131 } |
119 break; |
132 break; |
120 default: |
133 default: |
121 break; |
134 break; |
122 } |
135 } |
123 |
136 |
124 message.folderId = 0; |
137 event.folderId = 0; |
125 message.mailboxId = 0; |
138 event.mailboxId = 0; |
126 |
139 |
127 for (int i = 0; i < mailboxIds.count(); i++) { |
140 for (int i = 0; i < mailboxIds.count(); i++) { |
128 message.objectIds.append(mailboxIds.at(i).id()); |
141 event.objectIds.append(mailboxIds.at(i).id()); |
129 } |
142 } |
130 |
143 |
131 emit emailStoreEvent(message); |
144 emit emailStoreEvent(event); |
132 } |
145 } |
133 |
146 |
134 /*! |
147 /*! |
135 It process message ids from email store for given event. |
148 It process message ids from email store for given event. |
136 On end it emit \sa emailStoreEvent |
149 On end it emit \sa emailStoreEvent |
146 const QList<NmId> &messageIds, |
159 const QList<NmId> &messageIds, |
147 const NmId &mailboxId) |
160 const NmId &mailboxId) |
148 { |
161 { |
149 NM_FUNCTION; |
162 NM_FUNCTION; |
150 |
163 |
151 NmApiMessage message; |
164 NmApiEvent event; |
152 message.objectType = EMessage; |
165 event.objectType = EMessage; |
153 switch (messageEvent) { |
166 switch (messageEvent) { |
154 case NmMessageCreated: { |
167 case NmMessageCreated: { |
155 message.action = ENew; |
168 event.action = ENew; |
156 } |
169 } |
157 break; |
170 break; |
158 case NmMessageDeleted: { |
171 case NmMessageDeleted: { |
159 message.action = EDeleted; |
172 event.action = EDeleted; |
160 } |
173 } |
161 break; |
174 break; |
162 case NmMessageChanged: { |
175 case NmMessageChanged: { |
163 message.action = EChange; |
176 event.action = EChange; |
164 } |
177 } |
165 break; |
178 break; |
166 default: |
179 default: |
167 break; |
180 break; |
168 } |
181 } |
169 |
182 |
170 message.folderId = folderId.id(); |
183 event.folderId = folderId.id(); |
171 message.mailboxId = mailboxId.id(); |
184 event.mailboxId = mailboxId.id(); |
172 |
185 |
173 for (int i = 0; i < messageIds.count(); i++) { |
186 for (int i = 0; i < messageIds.count(); i++) { |
174 message.objectIds.append(messageIds.at(i).id()); |
187 event.objectIds.append(messageIds.at(i).id()); |
175 } |
188 } |
176 |
189 |
177 emit emailStoreEvent(message); |
190 emit emailStoreEvent(event); |
178 } |
191 } |
179 |
192 |
180 /*! |
193 /*! |
181 Release instance of engine if there are not referenced objects. |
194 Release instance of engine if there are not referenced objects. |
182 If there are refenced objects it only decrease refenced count. |
195 If there are refenced objects it only decrease refenced count. |
341 } |
354 } |
342 return found; |
355 return found; |
343 } |
356 } |
344 |
357 |
345 /*! |
358 /*! |
|
359 Return message given by mailbox, folder and message id. |
|
360 |
|
361 \param mailboxId Mailbox id from where message should come |
|
362 \param folderId Folder id from where message should come |
|
363 \param messageId Id of message which should be returned |
|
364 \param message Envelope to fill. |
|
365 |
|
366 \return Return true if it will find any envelope |
|
367 */ |
|
368 bool NmApiEngine::getMessageById( |
|
369 const quint64 mailboxId, |
|
370 const quint64 folderId, |
|
371 const quint64 messageId, |
|
372 EmailClientApi::NmApiMessage &message) |
|
373 { |
|
374 NM_FUNCTION; |
|
375 |
|
376 bool found = false; |
|
377 |
|
378 listMailPlugins(); |
|
379 |
|
380 CFSMailPlugin *plugin = NULL; |
|
381 CFSMailMessage* fsMessage = NULL; |
|
382 TFSMailMsgId fsMailBoxId = TFSMailMsgId(mailboxId); |
|
383 TFSMailMsgId fsFolderId = TFSMailMsgId(folderId); |
|
384 TFSMailMsgId fsMessageId = TFSMailMsgId(messageId); |
|
385 |
|
386 for (int i = 0; i < mMailPlugins.Count() && !fsMessage; i++){ |
|
387 plugin = mMailPlugins[i]; |
|
388 if (plugin) { |
|
389 QT_TRY { |
|
390 fsMessage = plugin->GetMessageByUidL(fsMailBoxId, |
|
391 fsFolderId, |
|
392 fsMessageId, |
|
393 EFSMsgDataStructure); |
|
394 } |
|
395 QT_CATCH(...){} |
|
396 } |
|
397 } |
|
398 if (fsMessage) { |
|
399 NmMessage *nmMessage = fsMessage->GetNmMessage(); |
|
400 EmailClientApi::NmApiMessage apiMessage = NmToApiConverter::NmMessage2NmApiMessage(*nmMessage); |
|
401 message = apiMessage; |
|
402 found = true; |
|
403 delete fsMessage; |
|
404 } |
|
405 return found; |
|
406 } |
|
407 |
|
408 |
|
409 /*! |
346 Return mailbox given by mailbox id. |
410 Return mailbox given by mailbox id. |
347 |
411 |
348 \param mailboxId Id of Mailbox which should be returned |
412 \param mailboxId Id of Mailbox which should be returned |
349 \param mailbox Mailbox to fill. |
413 \param mailbox Mailbox to fill. |
350 |
414 |
369 } |
433 } |
370 } |
434 } |
371 |
435 |
372 return found; |
436 return found; |
373 } |
437 } |
|
438 |
|
439 /*! |
|
440 \fn listMailPlugins |
|
441 \param mailPlugins List of mail plugins to be listed. |
|
442 \return True if operation completed succesfully, otherwise false. |
|
443 |
|
444 Lists all mail plugins. |
|
445 */ |
|
446 bool NmApiEngine::listMailPlugins(RPointerArray<CFSMailPlugin> &mailPlugins) |
|
447 { |
|
448 NM_FUNCTION; |
|
449 bool ret = false; |
|
450 if (mMailPlugins.Count() == 0) { |
|
451 TRAPD(err, listMailPluginsL()); |
|
452 if (err == KErrNone){ |
|
453 ret = true; |
|
454 } |
|
455 } else { |
|
456 ret = true; |
|
457 } |
|
458 mailPlugins = mMailPlugins; |
|
459 |
|
460 return ret; |
|
461 } |
|
462 |
|
463 /*! |
|
464 \fn listMailPlugins |
|
465 |
|
466 Lists all mail plugins. |
|
467 */ |
|
468 void NmApiEngine::listMailPlugins() |
|
469 { |
|
470 NM_FUNCTION; |
|
471 if (mMailPlugins.Count() == 0) { |
|
472 TRAP_IGNORE(listMailPluginsL()); |
|
473 } |
|
474 } |
|
475 |
|
476 /*! |
|
477 \fn ListMailPluginsL |
|
478 |
|
479 Leaving version of listMailPlugins. |
|
480 */ |
|
481 void NmApiEngine::listMailPluginsL() |
|
482 { |
|
483 NM_FUNCTION; |
|
484 |
|
485 RPointerArray<CImplementationInformation> implInfo; |
|
486 CFSMailPlugin::ListImplementationsL(implInfo); |
|
487 CleanupClosePushL(implInfo); |
|
488 CFSMailPlugin* plugin = NULL; |
|
489 for (int i = 0; i < implInfo.Count(); ++i) { |
|
490 TUid id = implInfo[i]->ImplementationUid(); |
|
491 plugin = CFSMailPlugin::NewL(id); |
|
492 |
|
493 if (plugin) { |
|
494 mMailPlugins.AppendL(plugin); |
|
495 } |
|
496 } |
|
497 CleanupStack::Pop(&implInfo); |
|
498 } |
|
499 |