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