|
1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: CS Message Handler, This class caches the conversation server |
|
15 * with the message data and also sends run-time updates to the |
|
16 * server with the message data |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // USER INCLUDES |
|
22 #include "ccsmsghandler.h" |
|
23 #include "msgbiouids.h" |
|
24 |
|
25 // SYSTEM INCLUDES |
|
26 #include <smsclnt.h> |
|
27 #include <mmsclient.h> |
|
28 #include <mtclreg.h> |
|
29 #include <csmsemailfields.h> |
|
30 #include <txtrich.h> |
|
31 #include <msvids.h> |
|
32 #include <e32const.h> |
|
33 #include <SendUiConsts.h> |
|
34 #include <pushentry.h> // For services messages |
|
35 |
|
36 // NOTE:- DRAFTS AND OUTBOX ENTRIES ARE NOT HANDLED IN THE PLUGIN |
|
37 |
|
38 // ============================== MEMBER FUNCTIONS ============================ |
|
39 // ---------------------------------------------------------------------------- |
|
40 // CCsMsgHandler::NewL |
|
41 // Two Phase Construction |
|
42 // ---------------------------------------------------------------------------- |
|
43 // |
|
44 CCsMsgHandler* CCsMsgHandler::NewL(MCsMsgObserver *aMsgObserver) |
|
45 { |
|
46 PRINT ( _L("Enter CCsMsgHandler::NewL") ); |
|
47 |
|
48 CCsMsgHandler* self = new ( ELeave ) CCsMsgHandler(); |
|
49 CleanupStack::PushL( self ); |
|
50 self->ConstructL(aMsgObserver); |
|
51 CleanupStack::Pop( self ); |
|
52 |
|
53 PRINT ( _L("End CCsMsgHandler::NewL") ); |
|
54 |
|
55 return self; |
|
56 } |
|
57 |
|
58 // ---------------------------------------------------------------------------- |
|
59 // CCsMsgHandler::~CCsMsgHandler |
|
60 // Destructor |
|
61 // ---------------------------------------------------------------------------- |
|
62 // |
|
63 CCsMsgHandler::~CCsMsgHandler() |
|
64 { |
|
65 PRINT ( _L("Enter CCsMsgHandler::~CCsMsgHandler") ); |
|
66 |
|
67 if(iMsgPluginUtility) |
|
68 { |
|
69 delete iMsgPluginUtility; |
|
70 iMsgPluginUtility = NULL; |
|
71 } |
|
72 |
|
73 if(iConverstationEntryList) |
|
74 { |
|
75 iConverstationEntryList->ResetAndDestroy(); |
|
76 iConverstationEntryList->Close(); |
|
77 delete iConverstationEntryList; |
|
78 iConverstationEntryList = NULL; |
|
79 } |
|
80 |
|
81 if(iSmsMtm) |
|
82 { |
|
83 delete iSmsMtm; |
|
84 iSmsMtm = NULL; |
|
85 } |
|
86 |
|
87 if(iMmsMtm) |
|
88 { |
|
89 delete iMmsMtm; |
|
90 iMmsMtm = NULL; |
|
91 } |
|
92 |
|
93 if(iMtmRegistry) |
|
94 { |
|
95 delete iMtmRegistry; |
|
96 iMtmRegistry = NULL; |
|
97 } |
|
98 |
|
99 if(iSession) |
|
100 { |
|
101 delete iSession; |
|
102 iSession = NULL; |
|
103 } |
|
104 |
|
105 if ( iRootEntry ) |
|
106 { |
|
107 delete iRootEntry; |
|
108 iRootEntry = NULL; |
|
109 } |
|
110 |
|
111 if ( iMessages ) |
|
112 { |
|
113 iMessages->Reset(); |
|
114 delete iMessages; |
|
115 iMessages = NULL; |
|
116 } |
|
117 |
|
118 PRINT ( _L("End CCsMsgHandler::~CCsMsgHandler") ); |
|
119 } |
|
120 |
|
121 // ---------------------------------------------------------------------------- |
|
122 // CCsMsgHandler::ConstructL |
|
123 // Two Phase Construction |
|
124 // ---------------------------------------------------------------------------- |
|
125 // |
|
126 void CCsMsgHandler::ConstructL(MCsMsgObserver *aMsgObserver) |
|
127 { |
|
128 PRINT ( _L("Enter CCsMsgHandler::ConstructL") ); |
|
129 |
|
130 iMsgObserver = aMsgObserver; |
|
131 |
|
132 iSession = CMsvSession::OpenSyncL(*this); |
|
133 |
|
134 iMsgPluginUtility = CCsMsgPluginUtility::NewL(); |
|
135 |
|
136 iConverstationEntryList = new(ELeave)RPointerArray<CCsConversationEntry>(); |
|
137 |
|
138 iMtmRegistry = CClientMtmRegistry::NewL( *iSession ); |
|
139 |
|
140 iSmsMtm = static_cast<CSmsClientMtm*>( iMtmRegistry-> |
|
141 NewMtmL( KSenduiMtmSmsUid ) ); |
|
142 |
|
143 iMmsMtm = static_cast<CMmsClientMtm*>( iMtmRegistry-> |
|
144 NewMtmL( KSenduiMtmMmsUid ) ); |
|
145 |
|
146 iState = EReadInbox; |
|
147 |
|
148 iMessageCount = 0; |
|
149 |
|
150 PRINT ( _L("End CCsMsgHandler::ConstructL") ); |
|
151 } |
|
152 |
|
153 // ---------------------------------------------------------------------------- |
|
154 // CCsMsgHandler::CCsMsgHandler |
|
155 // Two Phase Construction |
|
156 // ---------------------------------------------------------------------------- |
|
157 // |
|
158 CCsMsgHandler::CCsMsgHandler() |
|
159 { |
|
160 } |
|
161 |
|
162 // ----------------------------------------------------------------------------- |
|
163 // CCsMsgHandler::ProcessResultsL() |
|
164 // ProcessResultsL fetches results for the searchsort query and |
|
165 // updates the CCsServer with the fetched data |
|
166 // ----------------------------------------------------------------------------- |
|
167 // |
|
168 void CCsMsgHandler::ProcessResultsL(TMsvEntry entry) |
|
169 { |
|
170 PRINT ( _L("Enter CCsMsgHandler::ProcessResultsL")); |
|
171 |
|
172 // Cleanup the conversationEntry List initially. |
|
173 // So that the previous entries not cleaned up in |
|
174 // the event of Leave have been clean up. |
|
175 iConverstationEntryList->ResetAndDestroy(); |
|
176 |
|
177 RPointerArray<HBufC> addressList; |
|
178 |
|
179 // Ignore hidden items during upload |
|
180 if ( entry.Visible() == EFalse ) |
|
181 { |
|
182 return; |
|
183 } |
|
184 |
|
185 if ( entry.Parent() == KMsvGlobalInBoxIndexEntryIdValue || |
|
186 entry.Parent() == KMsvSentEntryIdValue || |
|
187 entry.Parent() == KMsvGlobalOutBoxIndexEntryIdValue ) |
|
188 { |
|
189 iMsgPluginUtility->CreateContactL(iSession, entry, addressList); |
|
190 |
|
191 //process entry |
|
192 ExtractAddressesL(entry, ERead, addressList); |
|
193 |
|
194 addressList.ResetAndDestroy(); |
|
195 } |
|
196 |
|
197 PRINT ( _L("Exit CCsMsgHandler::ProcessResultsL") ); |
|
198 } |
|
199 |
|
200 // ---------------------------------------------------------------------------- |
|
201 // CCsMsgHandler::HandleSessionEventL |
|
202 // Implemented for MMsvSessionObserver |
|
203 // ---------------------------------------------------------------------------- |
|
204 // |
|
205 void CCsMsgHandler::HandleSessionEventL( TMsvSessionEvent aEvent, |
|
206 TAny* aArg1, |
|
207 TAny* aArg2, |
|
208 TAny* /*aArg3*/) |
|
209 { |
|
210 PRINT1 ( _L("Enter CCsMsgHandler::HandleSessionEventL aEvent=%d"),aEvent ); |
|
211 |
|
212 CMsvEntrySelection* selection=NULL; |
|
213 TMsvId parent; |
|
214 |
|
215 //args |
|
216 if(aArg1 == NULL || aArg2 == NULL) |
|
217 { |
|
218 PRINT ( _L("Enter CCsMsgHandler::HandleSessionEventL arguments invalid")); |
|
219 return; |
|
220 } |
|
221 |
|
222 //start, processing the event |
|
223 selection= (CMsvEntrySelection*)aArg1; |
|
224 parent = *(TMsvId*)aArg2; |
|
225 |
|
226 // Cleanup the conversationEntry List initially. |
|
227 iConverstationEntryList->ResetAndDestroy(); |
|
228 |
|
229 switch( aEvent ) |
|
230 { |
|
231 case EMsvEntriesChanged: |
|
232 case EMsvEntriesMoved: |
|
233 { |
|
234 HandleEventL(selection,parent); |
|
235 } |
|
236 break; |
|
237 |
|
238 case EMsvEntriesDeleted: |
|
239 { |
|
240 if ( parent == KMsvGlobalInBoxIndexEntryIdValue || |
|
241 parent == KMsvSentEntryIdValue || |
|
242 parent == KMsvGlobalOutBoxIndexEntryIdValue) |
|
243 { |
|
244 for( TInt i=0 ; i < selection->Count() ; i++ ) |
|
245 { |
|
246 TMsvId id = selection->At( i ); |
|
247 |
|
248 //use utility to create conversation entry |
|
249 CCsConversationEntry *conversationEntry = |
|
250 iMsgPluginUtility->CreateConversationEntryL( |
|
251 NULL, |
|
252 id, |
|
253 0, |
|
254 parent, |
|
255 NULL, |
|
256 ECsSendStateUnknown, |
|
257 ECsAttributeNone, |
|
258 0); |
|
259 CleanupStack::PushL(conversationEntry); |
|
260 iConverstationEntryList->AppendL( conversationEntry ); |
|
261 CleanupStack::Pop(conversationEntry); |
|
262 |
|
263 // call observer interface for each entry |
|
264 iMsgObserver->HandleDeleteCompleteL(iConverstationEntryList); |
|
265 |
|
266 //cleanup before next iteration |
|
267 iConverstationEntryList->ResetAndDestroy(); |
|
268 } |
|
269 } |
|
270 } |
|
271 break; |
|
272 |
|
273 case EMsvMediaChanged: |
|
274 iMsgObserver->HandleRefreshCompleteL(); |
|
275 break; |
|
276 } |
|
277 |
|
278 // Cleanup the conversationEntry List before function exits. |
|
279 iConverstationEntryList->ResetAndDestroy(); |
|
280 PRINT ( _L("Exit CCsMsgHandler::HandleSessionEventL") ); |
|
281 } |
|
282 |
|
283 // --------------------------------------------------------------------- |
|
284 // CCsMsgHandler::HandleEvent |
|
285 // Handle events |
|
286 // --------------------------------------------------------------------- |
|
287 // |
|
288 void CCsMsgHandler::HandleEventL(CMsvEntrySelection* aSelection, TMsvId aParent) |
|
289 { |
|
290 PRINT ( _L("Enter CCsMsgHandler::HandleEvent") ); |
|
291 TMsvEntry entry; |
|
292 TMsvId service; |
|
293 TInt error= KErrNone; |
|
294 RPointerArray<HBufC> addressList; |
|
295 |
|
296 for( TInt i=0 ; i < aSelection->Count() ; i++ ) |
|
297 { |
|
298 error = iSession->GetEntry(aSelection->At(i),service,entry); |
|
299 |
|
300 if ( entry.Visible() == EFalse ) |
|
301 { |
|
302 // Do a delete if entry becomes invisible. |
|
303 // e.g) My Nokia registration messages. |
|
304 RPointerArray<CCsConversationEntry>* hiddenEntries = |
|
305 new (ELeave) RPointerArray<CCsConversationEntry>(); |
|
306 |
|
307 CCsConversationEntry *conversationEntry = |
|
308 iMsgPluginUtility->CreateConversationEntryL ( |
|
309 NULL, |
|
310 entry.Id(), |
|
311 0, |
|
312 aParent, |
|
313 NULL, |
|
314 ECsSendStateUnknown, |
|
315 ECsAttributeNone, |
|
316 0 ); |
|
317 CleanupStack::PushL(conversationEntry); |
|
318 hiddenEntries->AppendL( conversationEntry ); |
|
319 CleanupStack::Pop(conversationEntry); |
|
320 |
|
321 // Delete at server |
|
322 iMsgObserver->HandleDeleteCompleteL(hiddenEntries); |
|
323 hiddenEntries->ResetAndDestroy(); |
|
324 hiddenEntries->Close(); |
|
325 delete hiddenEntries; |
|
326 |
|
327 break; |
|
328 } |
|
329 |
|
330 if ( (KErrNone == error) && (IsMtmSupported(entry.iMtm.iUid) ) ) |
|
331 { |
|
332 // sent/inbox/Outbox entry |
|
333 if ( aParent == KMsvSentEntryIdValue || |
|
334 aParent == KMsvGlobalInBoxIndexEntryIdValue ) |
|
335 { |
|
336 // currently server needs number, so getting it from header |
|
337 iMsgPluginUtility->CreateContactL(iSession, entry, |
|
338 addressList); |
|
339 |
|
340 //process entry |
|
341 // entry created in sent already exists, hence an update |
|
342 ExtractAddressesL(entry, EUpdate, addressList); |
|
343 |
|
344 addressList.ResetAndDestroy(); |
|
345 } |
|
346 |
|
347 //for drafts and outbox, the entry changes multiple times, |
|
348 // so making a check if entry has changed |
|
349 else if(aParent == KMsvGlobalOutBoxIndexEntryIdValue) |
|
350 { |
|
351 //outbox |
|
352 if(!(iMsgPluginUtility->CompareEntry(iPrevEntry,entry,aParent))) |
|
353 { |
|
354 TUint sendState = entry.SendingState(); |
|
355 |
|
356 // if the entry state is sent, we dont need to process it |
|
357 // as it is going to appear in sent items |
|
358 if( ECsSendStateSent != iMsgPluginUtility->GetSendState(entry) ) |
|
359 { |
|
360 // currently server needs number, so getting it from header |
|
361 iMsgPluginUtility->CreateContactL(iSession, entry, |
|
362 addressList); |
|
363 |
|
364 //process entry |
|
365 // entry created in sent already exists, hence an update |
|
366 ExtractAddressesL(entry, EUpdate, addressList); |
|
367 |
|
368 iPrevEntry = entry; |
|
369 |
|
370 addressList.ResetAndDestroy(); |
|
371 } |
|
372 }//end check changed entry |
|
373 } |
|
374 } |
|
375 }//end for loop |
|
376 |
|
377 PRINT ( _L("Exit CCsMsgHandler::HandleEvent") ); |
|
378 } |
|
379 |
|
380 // ---------------------------------------------------------------------------- |
|
381 // CCsMsgHandler::CreateAndAddEntryL |
|
382 // Creates CCsConversationEntry and adds to the list |
|
383 // ---------------------------------------------------------------------------- |
|
384 // |
|
385 void CCsMsgHandler::CreateAndAddEntryL(const TDesC& aContact, |
|
386 const TDesC& aDescription, |
|
387 const TMsvEntry& aEntry) |
|
388 { |
|
389 PRINT ( _L("Enter CCsMsgHandler::CreateAndAddEntryL") ); |
|
390 |
|
391 HBufC* contact = NULL; |
|
392 HBufC* sDescription = NULL; |
|
393 |
|
394 if (aContact.Length()>0) |
|
395 { |
|
396 contact = aContact.AllocL(); |
|
397 CleanupStack::PushL(contact); |
|
398 } |
|
399 if (aDescription.Length()>0) |
|
400 { |
|
401 sDescription = aDescription.AllocL(); |
|
402 CleanupStack::PushL(sDescription); |
|
403 } |
|
404 |
|
405 //use utility to create conversation entry |
|
406 CCsConversationEntry *conversationEntry = iMsgPluginUtility->CreateConversationEntryL( |
|
407 contact, |
|
408 aEntry.Id(), |
|
409 aEntry.iDate.Int64(), |
|
410 aEntry.Parent(), |
|
411 sDescription, |
|
412 iMsgPluginUtility->GetSendState(aEntry), |
|
413 iMsgPluginUtility->GetMsgAttributes(aEntry), |
|
414 ExtractCsType(aEntry)); |
|
415 CleanupStack::PushL(conversationEntry); |
|
416 |
|
417 //add to the list |
|
418 iConverstationEntryList->AppendL( conversationEntry ); |
|
419 CleanupStack::Pop(conversationEntry); |
|
420 |
|
421 // cleanup |
|
422 if (sDescription) |
|
423 { |
|
424 CleanupStack::PopAndDestroy(sDescription); |
|
425 } |
|
426 if (contact) |
|
427 { |
|
428 CleanupStack::PopAndDestroy(contact); |
|
429 } |
|
430 |
|
431 PRINT ( _L("Exit CCsMsgHandler::CreateAndAddEntryL") ); |
|
432 } |
|
433 |
|
434 // ---------------------------------------------------------------------------- |
|
435 // CCsMsgHandler::ProcessEntryL |
|
436 // Creates CCsConversationEntry and adds to the list |
|
437 // ---------------------------------------------------------------------------- |
|
438 // |
|
439 void CCsMsgHandler::ProcessEntryL( TEventType aEvent, const TDesC& aContact, |
|
440 const TDesC& aDescription, const TMsvEntry& aEntry) |
|
441 { |
|
442 PRINT ( _L("Enter CCsMsgHandler::ProcessEntryL") ); |
|
443 |
|
444 // create and add entry to the list |
|
445 CreateAndAddEntryL(aContact,aDescription,aEntry); |
|
446 |
|
447 // call cs observer interface for each entry |
|
448 switch(aEvent) |
|
449 { |
|
450 case ERead: |
|
451 { |
|
452 iMsgObserver->HandleReadCompleteL(iConverstationEntryList); |
|
453 } |
|
454 break; |
|
455 case EUpdate: |
|
456 { |
|
457 iMsgObserver->HandleUpdateCompleteL(iConverstationEntryList); |
|
458 } |
|
459 break; |
|
460 } |
|
461 |
|
462 // Cleanup the conversationEntry List, as we are just sending one entry at a time |
|
463 iConverstationEntryList->ResetAndDestroy(); |
|
464 |
|
465 PRINT ( _L("Exit CCsMsgHandler::ProcessEntryL") ); |
|
466 } |
|
467 |
|
468 // ---------------------------------------------------------------------------- |
|
469 // CCsMsgHandler::ExtractAddressL |
|
470 // Extracts the addresses in the to field and updates them to server |
|
471 // ---------------------------------------------------------------------------- |
|
472 // |
|
473 void CCsMsgHandler::ExtractAddressesL( |
|
474 TMsvEntry aEntry, |
|
475 TEventType aEvent, |
|
476 RPointerArray<HBufC>& addressList ) |
|
477 { |
|
478 PRINT ( _L("Enter CCsMsgHandler::ExtractAddressesL") ); |
|
479 |
|
480 // For SMS read the whole body. |
|
481 // For bio type SMS read the iDescription |
|
482 // For other message types read the iDescription |
|
483 // Note: After the LoadMessageL() the iDescription is getting |
|
484 // deleted so need to make a copy before that. |
|
485 TPtrC description; |
|
486 HBufC* tmpBuffer = NULL; |
|
487 |
|
488 if ( (aEntry.iBioType && |
|
489 aEntry.iBioType != KUidMsgSubTypeMmsAudioMsg.iUid ) || |
|
490 aEntry.iMtm == KSenduiMtmBtUid ) |
|
491 { |
|
492 tmpBuffer = aEntry.iDescription.AllocL(); |
|
493 description.Set( tmpBuffer->Des() ); |
|
494 } |
|
495 else if ( aEntry.iMtm == KSenduiMtmSmsUid ) |
|
496 { |
|
497 iSmsMtm->SwitchCurrentEntryL( aEntry.Id() ); |
|
498 iSmsMtm->LoadMessageL(); |
|
499 |
|
500 CRichText& body = iSmsMtm->Body(); |
|
501 TInt smsLength = body.DocumentLength(); |
|
502 tmpBuffer = HBufC::NewL(smsLength); |
|
503 TPtr ptr(tmpBuffer->Des()); |
|
504 body.Extract(ptr, 0); |
|
505 description.Set( tmpBuffer->Des() ); |
|
506 } |
|
507 else if ( aEntry.iMtm == KSenduiMtmMmsUid || |
|
508 aEntry.iMtm == KSenduiMMSNotificationUid) |
|
509 { |
|
510 tmpBuffer = aEntry.iDescription.AllocL(); |
|
511 description.Set( tmpBuffer->Des() ); |
|
512 |
|
513 iMmsMtm->SwitchCurrentEntryL( aEntry.Id() ); |
|
514 iMmsMtm->LoadMessageL(); |
|
515 |
|
516 // Handle addresses |
|
517 if ( aEntry.Parent() == KMsvGlobalInBoxIndexEntryIdValue ) |
|
518 { |
|
519 HBufC* address = iMmsMtm->Sender().AllocL(); |
|
520 addressList.Append(address); |
|
521 } |
|
522 else if ( aEntry.Parent() == KMsvSentEntryIdValue || |
|
523 aEntry.Parent() == KMsvGlobalOutBoxIndexEntryIdValue ) |
|
524 { |
|
525 const CMsvRecipientList& addresses = iMmsMtm->AddresseeList(); |
|
526 TInt count = addresses.Count(); |
|
527 |
|
528 for( TInt i = 0; i < count; i++) |
|
529 { |
|
530 HBufC* address = addresses[i].AllocL(); |
|
531 TPtrC pureAddress = iMsgPluginUtility->PureAddress(*address); |
|
532 HBufC* address1 = pureAddress.AllocL(); |
|
533 addressList.Append(address1); |
|
534 delete address; |
|
535 } |
|
536 } |
|
537 } |
|
538 else |
|
539 { |
|
540 return; |
|
541 } |
|
542 |
|
543 if ( addressList.Count() > 0 ) |
|
544 { |
|
545 for ( int i = 0; i < addressList.Count(); i++ ) |
|
546 { |
|
547 HBufC* address = addressList[i]; |
|
548 ProcessEntryL(aEvent, *address, description, aEntry); |
|
549 } |
|
550 } |
|
551 else |
|
552 { |
|
553 // Unknown |
|
554 ProcessEntryL(aEvent, KNullDesC, description, aEntry); |
|
555 } |
|
556 |
|
557 if ( tmpBuffer ) |
|
558 { |
|
559 delete tmpBuffer; |
|
560 } |
|
561 |
|
562 PRINT ( _L("Exit CCsMsgHandler::ExtractAddressesL") ); |
|
563 } |
|
564 |
|
565 // ----------------------------------------------------------------------------- |
|
566 // CCsMsgHandler::UploadMsgL() |
|
567 // State machine to upload all messages |
|
568 // ----------------------------------------------------------------------------- |
|
569 // |
|
570 TInt CCsMsgHandler::UploadMsgL() |
|
571 { |
|
572 switch ( iState ) |
|
573 { |
|
574 case EReadInbox: |
|
575 { |
|
576 iRootEntry = iSession->GetEntryL(KMsvGlobalInBoxIndexEntryId); |
|
577 |
|
578 // Set sort order |
|
579 TMsvSelectionOrdering order; |
|
580 order.SetSorting(EMsvSortById); |
|
581 iRootEntry->SetSortTypeL(order); |
|
582 |
|
583 iMessages = iRootEntry->ChildrenL(); |
|
584 iMessageCount = iRootEntry->Count(); |
|
585 |
|
586 if ( iMessageCount ) |
|
587 iState = EProcessInbox; |
|
588 else |
|
589 { |
|
590 iState = EReadSent; |
|
591 CleanupL(); |
|
592 } |
|
593 |
|
594 return 1; |
|
595 } |
|
596 |
|
597 case EProcessInbox: |
|
598 { |
|
599 iMessageCount = iMessageCount - 1; |
|
600 TMsvEntry entry = iRootEntry->ChildDataL(iMessages->At(iMessageCount)); |
|
601 if(IsMtmSupported(entry.iMtm.iUid)) |
|
602 { |
|
603 ProcessResultsL(entry); |
|
604 } |
|
605 |
|
606 if ( iMessageCount ) |
|
607 iState = EProcessInbox; |
|
608 else |
|
609 { |
|
610 iState = EReadSent; |
|
611 CleanupL(); |
|
612 } |
|
613 |
|
614 return 1; |
|
615 } |
|
616 |
|
617 case EReadSent: |
|
618 { |
|
619 iRootEntry = iSession->GetEntryL(KMsvSentEntryId); |
|
620 |
|
621 // Set sort order |
|
622 TMsvSelectionOrdering order; |
|
623 order.SetSorting(EMsvSortById); |
|
624 iRootEntry->SetSortTypeL(order); |
|
625 |
|
626 iMessages = iRootEntry->ChildrenL(); |
|
627 iMessageCount = iRootEntry->Count(); |
|
628 |
|
629 if ( iMessageCount ) |
|
630 iState = EProcessSent; |
|
631 else |
|
632 { |
|
633 iState = EReadOutbox; |
|
634 CleanupL(); |
|
635 } |
|
636 |
|
637 return 1; |
|
638 } |
|
639 |
|
640 case EProcessSent: |
|
641 { |
|
642 iMessageCount = iMessageCount - 1; |
|
643 TMsvEntry entry = iRootEntry->ChildDataL(iMessages->At(iMessageCount)); |
|
644 if(IsMtmSupported(entry.iMtm.iUid)) |
|
645 { |
|
646 ProcessResultsL(entry); |
|
647 } |
|
648 |
|
649 if ( iMessageCount ) |
|
650 iState = EProcessSent; |
|
651 else |
|
652 { |
|
653 iState = EReadOutbox; |
|
654 CleanupL(); |
|
655 } |
|
656 |
|
657 return 1; |
|
658 } |
|
659 |
|
660 case EReadOutbox: |
|
661 { |
|
662 iRootEntry = iSession->GetEntryL(KMsvGlobalOutBoxIndexEntryId); |
|
663 |
|
664 // Set sort order |
|
665 TMsvSelectionOrdering order; |
|
666 order.SetSorting(EMsvSortById); |
|
667 iRootEntry->SetSortTypeL(order); |
|
668 |
|
669 iMessages = iRootEntry->ChildrenL(); |
|
670 iMessageCount = iRootEntry->Count(); |
|
671 |
|
672 if ( iMessageCount ) |
|
673 iState = EProcessOutbox; |
|
674 else |
|
675 { |
|
676 iState = EComplete; |
|
677 iMsgObserver->HandleCachingCompleted(); |
|
678 CleanupL(); |
|
679 return 0; // DONE |
|
680 } |
|
681 |
|
682 return 1; |
|
683 } |
|
684 |
|
685 case EProcessOutbox: |
|
686 { |
|
687 iMessageCount = iMessageCount - 1; |
|
688 TMsvEntry entry = iRootEntry->ChildDataL(iMessages->At(iMessageCount)); |
|
689 if(IsMtmSupported(entry.iMtm.iUid)) |
|
690 { |
|
691 ProcessResultsL(entry); |
|
692 } |
|
693 |
|
694 if ( iMessageCount ) |
|
695 iState = EProcessOutbox; |
|
696 else |
|
697 { |
|
698 iState = EComplete; |
|
699 iMsgObserver->HandleCachingCompleted(); |
|
700 CleanupL(); |
|
701 return 0; // DONE |
|
702 } |
|
703 |
|
704 return 1; |
|
705 } |
|
706 } |
|
707 |
|
708 return 0; |
|
709 } |
|
710 |
|
711 // ----------------------------------------------------------------------------- |
|
712 // CCsMsgHandler::UploadMsg() |
|
713 // CIdle callback |
|
714 // ----------------------------------------------------------------------------- |
|
715 // |
|
716 TInt CCsMsgHandler::UploadMsg(TAny* aArg) |
|
717 { |
|
718 CCsMsgHandler* handler = (CCsMsgHandler*) aArg; |
|
719 TInt ok = 0; |
|
720 TRAPD(err, ok = handler->UploadMsgL()); |
|
721 return ((err == KErrNone) && ok); |
|
722 } |
|
723 |
|
724 // ----------------------------------------------------------------------------- |
|
725 // CCsMsgHandler::StartL() |
|
726 // This function starts the state machine to fetch sms data from msvserver |
|
727 // ----------------------------------------------------------------------------- |
|
728 // |
|
729 void CCsMsgHandler::StartL() |
|
730 { |
|
731 PRINT ( _L("Enter CCsMsgHandler::Start") ); |
|
732 |
|
733 iState = EReadInbox; |
|
734 TCallBack callback = TCallBack(UploadMsg, (TAny*) this); |
|
735 iIdle = CIdle::NewL(CActive::EPriorityLow); |
|
736 iIdle->Start(callback); |
|
737 |
|
738 PRINT ( _L("End CCsMsgHandler::Start") ); |
|
739 } |
|
740 |
|
741 // ----------------------------------------------------------------------------- |
|
742 // CCsMsgHandler::CleanupL() |
|
743 // Helper function for state machine cleanup |
|
744 // ----------------------------------------------------------------------------- |
|
745 // |
|
746 void CCsMsgHandler::CleanupL() |
|
747 { |
|
748 if ( iRootEntry ) |
|
749 { |
|
750 delete iRootEntry; |
|
751 iRootEntry = NULL; |
|
752 } |
|
753 |
|
754 if ( iMessages ) |
|
755 { |
|
756 iMessages->Reset(); |
|
757 delete iMessages; |
|
758 iMessages = NULL; |
|
759 } |
|
760 |
|
761 iMessageCount = 0; |
|
762 } |
|
763 |
|
764 // ----------------------------------------------------------------------------- |
|
765 // CCsMsgHandler::IsMtmSupported() |
|
766 // |
|
767 // ----------------------------------------------------------------------------- |
|
768 // |
|
769 TBool CCsMsgHandler::IsMtmSupported(long uid) |
|
770 { |
|
771 if ( KSenduiMtmSmsUidValue == uid || \ |
|
772 KSenduiMtmBtUidValue == uid || \ |
|
773 KSenduiMtmMmsUidValue == uid || \ |
|
774 KSenduiMtmBioUidValue == uid || \ |
|
775 KSenduiMMSNotificationUidValue == uid || \ |
|
776 KUidMtmWapPush == TUid::Uid(uid) ) |
|
777 { |
|
778 return ETrue; |
|
779 } |
|
780 return EFalse; |
|
781 } |
|
782 |
|
783 // ----------------------------------------------------------------------------- |
|
784 // CCsMsgHandler::ExtractCsType() |
|
785 // Extracts the Message type based on the MTM Uid |
|
786 // ----------------------------------------------------------------------------- |
|
787 // |
|
788 TCsType CCsMsgHandler::ExtractCsType( const TMsvEntry& aEntry) |
|
789 { |
|
790 TCsType type = ECsUnknown; |
|
791 switch(aEntry.iMtm.iUid) |
|
792 { |
|
793 case KSenduiMtmSmsUidValue: |
|
794 type = ECsSMS; |
|
795 break; |
|
796 case KSenduiMtmBtUidValue: |
|
797 type = ECsBlueTooth; |
|
798 break; |
|
799 case KSenduiMtmMmsUidValue: |
|
800 if(aEntry.iBioType == KUidMsgSubTypeMmsAudioMsg.iUid) |
|
801 { |
|
802 type = ECsAudio; |
|
803 } |
|
804 else |
|
805 { |
|
806 type = ECsMMS; |
|
807 } |
|
808 break; |
|
809 case KSenduiMMSNotificationUidValue: |
|
810 type = ECsMmsNotification; |
|
811 break; |
|
812 case KSenduiMtmBioUidValue: |
|
813 { |
|
814 type = ECsBioMsg; |
|
815 |
|
816 // based on the biotype uid set message type |
|
817 if(aEntry.iBioType == KMsgBioUidRingingTone.iUid) |
|
818 { |
|
819 type = ECsRingingTone; |
|
820 } |
|
821 else if(aEntry.iBioType == KMsgBioProvisioningMessage.iUid) |
|
822 { |
|
823 type = ECsProvisioning; |
|
824 } |
|
825 else if (aEntry.iBioType == KMsgBioUidVCard.iUid) |
|
826 { |
|
827 type = ECsBioMsg_VCard; |
|
828 } |
|
829 else if (aEntry.iBioType == KMsgBioUidVCalendar.iUid) |
|
830 { |
|
831 type = ECsBioMsg_VCal; |
|
832 } |
|
833 } |
|
834 break; |
|
835 default: |
|
836 type = ECsUnknown; |
|
837 break; |
|
838 } |
|
839 return (type); |
|
840 } |
|
841 // End of file |
|
842 |