51 FUNC_LOG; |
52 FUNC_LOG; |
52 PRINT ( _L( "Enter CPsMruAdapter::NewL" ) ); |
53 PRINT ( _L( "Enter CPsMruAdapter::NewL" ) ); |
53 |
54 |
54 // Get the PsData plugin parametrs |
55 // Get the PsData plugin parametrs |
55 TPsDataPluginParams* params = |
56 TPsDataPluginParams* params = |
56 reinterpret_cast<TPsDataPluginParams*>(aPsDataPluginParameters ); |
57 reinterpret_cast<TPsDataPluginParams*>(aPsDataPluginParameters ); |
57 CPsMruAdapter* self = new ( ELeave ) CPsMruAdapter(); |
58 CPsMruAdapter* self = new ( ELeave ) CPsMruAdapter(); |
58 CleanupStack::PushL(self); |
59 CleanupStack::PushL(self); |
59 self->ConstructL( params->iDataStoreObserver, params->iStoreListObserver ); |
60 self->ConstructL( params->iDataStoreObserver, params->iStoreListObserver ); |
60 CleanupStack::Pop( self ); |
61 CleanupStack::Pop( self ); |
61 |
62 |
81 // Two Phase Construction |
82 // Two Phase Construction |
82 // ---------------------------------------------------------------------------- |
83 // ---------------------------------------------------------------------------- |
83 void CPsMruAdapter::ConstructL( MDataStoreObserver* aObserverForDataStore, |
84 void CPsMruAdapter::ConstructL( MDataStoreObserver* aObserverForDataStore, |
84 MStoreListObserver* aStoreListObserver ) |
85 MStoreListObserver* aStoreListObserver ) |
85 { |
86 { |
86 FUNC_LOG; |
87 FUNC_LOG; |
87 PRINT ( _L( "Enter CPsMruAdapter::ConstructL" ) ); |
88 PRINT ( _L( "Enter CPsMruAdapter::ConstructL" ) ); |
88 |
89 |
89 // Mail client for FS Email framework |
90 // Mail client for FS Email framework |
90 iMailClient = CFSMailClient::NewL(); |
91 iMailClient = CFSMailClient::NewL(); |
91 |
92 |
107 // CPsMruAdapter::~CPsMruAdapter |
108 // CPsMruAdapter::~CPsMruAdapter |
108 // Destructor |
109 // Destructor |
109 // ---------------------------------------------------------------------------- |
110 // ---------------------------------------------------------------------------- |
110 CPsMruAdapter::~CPsMruAdapter() |
111 CPsMruAdapter::~CPsMruAdapter() |
111 { |
112 { |
112 FUNC_LOG; |
113 FUNC_LOG; |
113 PRINT ( _L( "Enter CPsMruAdapter::~CPsMruAdapter" ) ); |
114 PRINT ( _L( "Enter CPsMruAdapter::~CPsMruAdapter" ) ); |
114 |
115 |
115 iSupportedUris.ResetAndDestroy(); |
116 iSupportedUris.ResetAndDestroy(); |
116 |
117 |
117 // Remove observer, we don't need it anymore because we're shutting down |
118 // Remove observer, we don't need it anymore because we're shutting down |
138 // ---------------------------------------------------------------------------- |
139 // ---------------------------------------------------------------------------- |
139 // CPsMruAdapter::RequestForDataL |
140 // CPsMruAdapter::RequestForDataL |
140 // |
141 // |
141 // ---------------------------------------------------------------------------- |
142 // ---------------------------------------------------------------------------- |
142 void CPsMruAdapter::RequestForDataL( TDesC& aDataStoreURI ) |
143 void CPsMruAdapter::RequestForDataL( TDesC& aDataStoreURI ) |
143 { |
144 { |
144 FUNC_LOG; |
145 FUNC_LOG; |
145 PRINT ( _L( "Enter CPsMruAdapter::RequestForDataL" ) ); |
146 PRINT ( _L( "Enter CPsMruAdapter::RequestForDataL" ) ); |
146 |
147 |
147 // Add data to datastore, fill only requested one |
148 // Add data to datastore, fill only requested one |
148 FillDataStoreL( aDataStoreURI ); |
149 FillDataStoreL( aDataStoreURI ); |
149 |
150 |
181 // CPsMruAdapter::UpdateSupportedDataStoresList |
182 // CPsMruAdapter::UpdateSupportedDataStoresList |
182 // |
183 // |
183 // ---------------------------------------------------------------------------- |
184 // ---------------------------------------------------------------------------- |
184 void CPsMruAdapter::UpdateSupportedDataStoresList() |
185 void CPsMruAdapter::UpdateSupportedDataStoresList() |
185 { |
186 { |
186 FUNC_LOG; |
187 FUNC_LOG; |
187 // Mailboxes will be fetched to this array |
188 // Mailboxes will be fetched to this array |
188 RPointerArray<CFSMailBox> mailBoxes; |
189 RPointerArray<CFSMailBox> mailBoxes; |
189 |
190 |
190 // List all mailboxes |
191 // List all mailboxes |
191 TFSMailMsgId plugin; |
192 TFSMailMsgId plugin; |
220 // ---------------------------------------------------------------------------- |
221 // ---------------------------------------------------------------------------- |
221 // CPsMruAdapter::FillDataStoreL |
222 // CPsMruAdapter::FillDataStoreL |
222 // ---------------------------------------------------------------------------- |
223 // ---------------------------------------------------------------------------- |
223 TBool CPsMruAdapter::FillDataStoreL( TDesC& aDataStoreURI ) |
224 TBool CPsMruAdapter::FillDataStoreL( TDesC& aDataStoreURI ) |
224 { |
225 { |
225 FUNC_LOG; |
226 FUNC_LOG; |
226 TBool result = EFalse; |
227 TBool result = EFalse; |
227 |
228 |
228 TFSMailMsgId dataStoreId; |
229 TFSMailMsgId dataStoreId; |
229 |
230 |
230 if ( GetMailboxIdentifierFromUri( aDataStoreURI, dataStoreId ) ) |
231 if ( GetMailboxIdentifierFromUri( aDataStoreURI, dataStoreId ) ) |
279 } |
280 } |
280 } |
281 } |
281 |
282 |
282 TBool CPsMruAdapter::FillDataStoreL( TFSMailMsgId& aId, TDesC& aDataStoreURI ) |
283 TBool CPsMruAdapter::FillDataStoreL( TFSMailMsgId& aId, TDesC& aDataStoreURI ) |
283 { |
284 { |
284 FUNC_LOG; |
285 FUNC_LOG; |
285 TBool result = EFalse; |
286 TBool result = EFalse; |
286 // code was simplified not to trace all mailboxes |
287 // code was simplified not to trace all mailboxes |
287 // function has trap in Event() -case> TFSEventNewMailbox and in DeleayedMailboxCreationEventL() |
288 // function has trap in Event() -case> TFSEventNewMailbox and in DeleayedMailboxCreationEventL() |
288 // should not leave when new mailbox only when new mail address |
289 // should not leave when new mailbox only when new mail address |
|
290 // TODO SK how to avoid extra calls? |
289 CFSMailBox *mailBox = iMailClient->GetMailBoxByUidLC(aId); |
291 CFSMailBox *mailBox = iMailClient->GetMailBoxByUidLC(aId); |
290 if( mailBox ) |
292 if( mailBox ) |
291 { |
293 { |
292 AddMailboxObserverL( aId ); |
294 AddMailboxObserverL( aId ); |
293 |
295 |
294 // Get MRU list for this mailbox |
296 // Get MRU list for this mailbox |
295 MDesCArray* mruList = mailBox->ListMrusL(); |
297 MDesCArray* mruList = mailBox->ListMrusL(); // TODO SK this value can be cached? |
|
298 //TODO add to cleanup stack? |
296 |
299 |
297 // update the caching status as InProgress |
300 // update the caching status as InProgress |
298 iDataStoreObserver->UpdateCachingStatus( aDataStoreURI, |
301 iDataStoreObserver->UpdateCachingStatus( aDataStoreURI, |
299 ECachingInProgress ); |
302 ECachingInProgress ); |
300 |
303 |
325 // CPsContactDataAdapter::IsDataStoresSupportedL |
328 // CPsContactDataAdapter::IsDataStoresSupportedL |
326 // |
329 // |
327 // ---------------------------------------------------------------------------- |
330 // ---------------------------------------------------------------------------- |
328 TBool CPsMruAdapter::IsDataStoresSupportedL( TDesC& aDataStoreURI ) |
331 TBool CPsMruAdapter::IsDataStoresSupportedL( TDesC& aDataStoreURI ) |
329 { |
332 { |
330 FUNC_LOG; |
333 FUNC_LOG; |
331 for ( TInt i = 0; i < iSupportedUris.Count(); i++ ) |
334 for ( TInt i = 0; i < iSupportedUris.Count(); i++ ) |
332 { |
335 { |
333 if ( iSupportedUris[i]->Compare( aDataStoreURI ) == 0 ) |
336 if ( iSupportedUris[i]->Compare( aDataStoreURI ) == 0 ) |
334 return ETrue; |
337 return ETrue; |
335 } |
338 } |
340 // CPsContactDataAdapter::GetSupportedDataFieldsL |
343 // CPsContactDataAdapter::GetSupportedDataFieldsL |
341 // |
344 // |
342 // ---------------------------------------------------------------------------- |
345 // ---------------------------------------------------------------------------- |
343 void CPsMruAdapter::GetSupportedDataFieldsL( RArray<TInt>& aDataFields ) |
346 void CPsMruAdapter::GetSupportedDataFieldsL( RArray<TInt>& aDataFields ) |
344 { |
347 { |
345 FUNC_LOG; |
348 FUNC_LOG; |
346 aDataFields.Append( R_VPBK_FIELD_TYPE_FIRSTNAME ); |
349 aDataFields.Append( R_VPBK_FIELD_TYPE_FIRSTNAME ); |
347 aDataFields.Append( R_VPBK_FIELD_TYPE_LASTNAME ); |
350 aDataFields.Append( R_VPBK_FIELD_TYPE_LASTNAME ); |
348 aDataFields.Append( R_VPBK_FIELD_TYPE_EMAILGEN ); |
351 aDataFields.Append( R_VPBK_FIELD_TYPE_EMAILGEN ); |
349 } |
352 } |
350 |
353 |
351 TBool CPsMruAdapter::GetMailboxIdentifierFromUri( TDesC& aUri, TFSMailMsgId& aId ) |
354 TBool CPsMruAdapter::GetMailboxIdentifierFromUri( TDesC& aUri, TFSMailMsgId& aId ) |
352 { |
355 { |
353 FUNC_LOG; |
356 FUNC_LOG; |
354 // Find first separator in reverse order |
357 // Find first separator in reverse order |
355 TInt lastSeparator = aUri.LocateReverseF( KDefaultMailBoxURISeparator ); |
358 TInt lastSeparator = aUri.LocateReverseF( KDefaultMailBoxURISeparator ); |
356 if ( lastSeparator == KErrNotFound ) |
359 if ( lastSeparator == KErrNotFound ) |
357 return EFalse; |
360 return EFalse; |
358 |
361 |
406 } |
409 } |
407 |
410 |
408 void CPsMruAdapter::EventL( TFSMailEvent aEvent, TFSMailMsgId aMailbox, |
411 void CPsMruAdapter::EventL( TFSMailEvent aEvent, TFSMailMsgId aMailbox, |
409 TAny* /*aParam1*/, TAny* aParam2, TAny* /*aParam3*/ ) |
412 TAny* /*aParam1*/, TAny* aParam2, TAny* /*aParam3*/ ) |
410 { |
413 { |
411 FUNC_LOG; |
414 FUNC_LOG; |
412 switch ( aEvent ) |
415 switch ( aEvent ) |
413 { |
416 { |
414 case TFSEventMailMoved: |
417 case TFSEventMailMoved: |
415 case TFSEventMailCopied: |
418 case TFSEventMailCopied: |
416 case TFSEventNewMail: |
419 case TFSEventNewMail: |
417 { |
420 { |
418 // Check the new parent folder id for this message |
421 // Check the new parent folder id for this message |
419 // For all these events, param2 indicates the new parent folder |
422 // For all these events, param2 indicates the new parent folder |
420 TFSMailMsgId* parentFolderId = |
423 TFSMailMsgId* parentFolderId = |
421 static_cast< TFSMailMsgId* >( aParam2 ); |
424 static_cast< TFSMailMsgId* >( aParam2 ); |
422 if ( parentFolderId ) |
425 if ( parentFolderId ) |
423 { |
426 { |
424 // Get the parent folder object |
427 TFSFolderType folderType( EFSInbox ); |
425 CFSMailFolder* parentFolder = iMailClient->GetFolderByUidL( |
428 if ( (*parentFolderId) == iPreviousParentFolderId && aMailbox == iPreviousMailboxId ) |
426 aMailbox, *parentFolderId ); |
|
427 if ( parentFolder ) |
|
428 { |
429 { |
429 CleanupStack::PushL( parentFolder ); |
430 // we assume that folder with some id does not change |
430 |
431 // its type during mail synchronization |
431 // If it's sent/outbox folder, |
432 folderType = iPreviousParentFolderType; |
432 // we'll consider that as a new message being sent |
433 } |
433 // and therefore we'll update the MRU list here |
434 else |
434 if ( ( parentFolder->GetFolderType() == EFSSentFolder ) || |
435 { |
435 ( parentFolder->GetFolderType() == EFSOutbox ) ) |
436 // Get the parent folder object |
|
437 CFSMailFolder* parentFolder = iMailClient->GetFolderByUidL( |
|
438 aMailbox, *parentFolderId ); |
|
439 if ( parentFolder ) |
436 { |
440 { |
437 FillDataStoreL( aMailbox ); |
441 iPreviousParentFolderId = (*parentFolderId); |
|
442 iPreviousMailboxId = aMailbox; |
|
443 folderType = parentFolder->GetFolderType(); |
|
444 iPreviousParentFolderType = folderType; |
|
445 delete parentFolder; |
|
446 parentFolder = NULL; |
438 } |
447 } |
439 CleanupStack::PopAndDestroy( parentFolder ); |
448 } |
|
449 // If it's sent/outbox folder, |
|
450 // we'll consider that as a new message being sent |
|
451 // and therefore we'll update the MRU list here |
|
452 if ( ( folderType == EFSSentFolder ) || |
|
453 ( folderType == EFSOutbox ) ) |
|
454 { |
|
455 FillDataStoreL( aMailbox ); |
440 } |
456 } |
441 } |
457 } |
442 } |
458 } |
443 break; |
459 break; |
444 |
460 |
548 return EFalse; |
572 return EFalse; |
549 } |
573 } |
550 |
574 |
551 void CPsMruAdapter::RemoveAllMailboxObservers() |
575 void CPsMruAdapter::RemoveAllMailboxObservers() |
552 { |
576 { |
553 FUNC_LOG; |
577 FUNC_LOG; |
554 for( TInt index = 0; index < iObservedMailboxes.Count(); index++ ) |
578 for( TInt index = 0; index < iObservedMailboxes.Count(); index++ ) |
555 { |
579 { |
556 iMailClient->UnsubscribeMailboxEvents( iObservedMailboxes[index], *this ); |
580 iMailClient->UnsubscribeMailboxEvents( iObservedMailboxes[index], *this ); |
557 } |
581 } |
558 |
582 |
559 iObservedMailboxes.Reset(); |
583 iObservedMailboxes.Reset(); |
560 } |
584 } |
561 |
585 |
562 /** |
586 /** |
563 * If problem with NewMailbox this function will be called |
587 * If problem with NewMailbox this function will be called |
564 * by CDelayMailboxCreationHelper timer to try it after some delay |
588 * by CDelayMailboxCreationHelper timer to try it after some delay |
565 */ |
589 */ |
566 TBool CPsMruAdapter::DeleayedMailboxCreationEventL() |
590 TBool CPsMruAdapter::DeleayedMailboxCreationEventL() |
567 { |
591 { |
568 FUNC_LOG; |
592 FUNC_LOG; |
569 for ( int i = iDelayedCreatedMailboxes.Count()-1; i>=0; i-- ) |
593 for ( int i = iDelayedCreatedMailboxes.Count()-1; i>=0; i-- ) |
570 { |
594 { |
571 CFSMailBox *mailboxPtr(NULL); |
595 CFSMailBox *mailboxPtr(NULL); |
572 // if mailbox is not ready it may leave there |
596 // if mailbox is not ready it may leave there |
613 * If problem with NewMailbox this function will use |
637 * If problem with NewMailbox this function will use |
614 * CDelayMailboxCreationHelper to try it after some delay |
638 * CDelayMailboxCreationHelper to try it after some delay |
615 */ |
639 */ |
616 void CPsMruAdapter::DeleayMailboxCreationEventL( TFSMailMsgId &aMailbox ) |
640 void CPsMruAdapter::DeleayMailboxCreationEventL( TFSMailMsgId &aMailbox ) |
617 { |
641 { |
618 FUNC_LOG; |
642 FUNC_LOG; |
619 if ( NULL == iDelayMailboxCreationPtr ) |
643 if ( NULL == iDelayMailboxCreationPtr ) |
620 { |
644 { |
621 iDelayMailboxCreationPtr = CDelayMailboxCreationHelper::NewL( this ); |
645 iDelayMailboxCreationPtr = CDelayMailboxCreationHelper::NewL( this ); |
622 } |
646 } |
623 iDelayedCreatedMailboxes.Append( aMailbox ); |
647 iDelayedCreatedMailboxes.Append( aMailbox ); |