diff -r efd4f1afd43e -r d620048b4810 emailservices/psmruadapter/src/CPsMruAdapter.cpp --- a/emailservices/psmruadapter/src/CPsMruAdapter.cpp Mon Jun 21 15:20:54 2010 +0300 +++ b/emailservices/psmruadapter/src/CPsMruAdapter.cpp Thu Jul 15 18:19:25 2010 +0300 @@ -17,6 +17,7 @@ + #include #include #include @@ -53,7 +54,7 @@ // Get the PsData plugin parametrs TPsDataPluginParams* params = - reinterpret_cast(aPsDataPluginParameters ); + reinterpret_cast(aPsDataPluginParameters ); CPsMruAdapter* self = new ( ELeave ) CPsMruAdapter(); CleanupStack::PushL(self); self->ConstructL( params->iDataStoreObserver, params->iStoreListObserver ); @@ -83,7 +84,7 @@ void CPsMruAdapter::ConstructL( MDataStoreObserver* aObserverForDataStore, MStoreListObserver* aStoreListObserver ) { - FUNC_LOG; + FUNC_LOG; PRINT ( _L( "Enter CPsMruAdapter::ConstructL" ) ); // Mail client for FS Email framework @@ -109,7 +110,7 @@ // ---------------------------------------------------------------------------- CPsMruAdapter::~CPsMruAdapter() { - FUNC_LOG; + FUNC_LOG; PRINT ( _L( "Enter CPsMruAdapter::~CPsMruAdapter" ) ); iSupportedUris.ResetAndDestroy(); @@ -140,8 +141,8 @@ // // ---------------------------------------------------------------------------- void CPsMruAdapter::RequestForDataL( TDesC& aDataStoreURI ) - { - FUNC_LOG; + { + FUNC_LOG; PRINT ( _L( "Enter CPsMruAdapter::RequestForDataL" ) ); // Add data to datastore, fill only requested one @@ -158,7 +159,7 @@ void CPsMruAdapter::GetSupportedDataStoresL( RPointerArray &aDataStoresURIs ) { - FUNC_LOG; + FUNC_LOG; for ( TInt i = 0; i < iSupportedUris.Count(); i++ ) { aDataStoresURIs.Append( iSupportedUris[i] ); @@ -171,7 +172,7 @@ // ---------------------------------------------------------------------------- TAny* CPsMruAdapter::RequestForDataExtensionL(TInt /*aItemId*/) { - FUNC_LOG; + FUNC_LOG; // No extention required for this since we have and interger as itemId // Simply return NULL return NULL; @@ -183,7 +184,7 @@ // ---------------------------------------------------------------------------- void CPsMruAdapter::UpdateSupportedDataStoresList() { - FUNC_LOG; + FUNC_LOG; // Mailboxes will be fetched to this array RPointerArray mailBoxes; @@ -222,7 +223,7 @@ // ---------------------------------------------------------------------------- TBool CPsMruAdapter::FillDataStoreL( TDesC& aDataStoreURI ) { - FUNC_LOG; + FUNC_LOG; TBool result = EFalse; TFSMailMsgId dataStoreId; @@ -237,7 +238,7 @@ TBool CPsMruAdapter::FillDataStoreL( TFSMailMsgId& aId ) { - FUNC_LOG; + FUNC_LOG; TBool result = EFalse; // Create Uri for this mailbox @@ -252,7 +253,7 @@ void CPsMruAdapter::AddMruEmailsL( MDesCArray* aMruList, TDesC& aDataStoreURI ) { - FUNC_LOG; + FUNC_LOG; TInt entryIndex = 0; // Add all data to data store, the format is: // index0: displayname @@ -281,18 +282,20 @@ TBool CPsMruAdapter::FillDataStoreL( TFSMailMsgId& aId, TDesC& aDataStoreURI ) { - FUNC_LOG; + FUNC_LOG; TBool result = EFalse; // code was simplified not to trace all mailboxes // function has trap in Event() -case> TFSEventNewMailbox and in DeleayedMailboxCreationEventL() // should not leave when new mailbox only when new mail address +// TODO SK how to avoid extra calls? CFSMailBox *mailBox = iMailClient->GetMailBoxByUidLC(aId); if( mailBox ) { AddMailboxObserverL( aId ); // Get MRU list for this mailbox - MDesCArray* mruList = mailBox->ListMrusL(); + MDesCArray* mruList = mailBox->ListMrusL(); // TODO SK this value can be cached? + //TODO add to cleanup stack? // update the caching status as InProgress iDataStoreObserver->UpdateCachingStatus( aDataStoreURI, @@ -327,7 +330,7 @@ // ---------------------------------------------------------------------------- TBool CPsMruAdapter::IsDataStoresSupportedL( TDesC& aDataStoreURI ) { - FUNC_LOG; + FUNC_LOG; for ( TInt i = 0; i < iSupportedUris.Count(); i++ ) { if ( iSupportedUris[i]->Compare( aDataStoreURI ) == 0 ) @@ -342,7 +345,7 @@ // ---------------------------------------------------------------------------- void CPsMruAdapter::GetSupportedDataFieldsL( RArray& aDataFields ) { - FUNC_LOG; + FUNC_LOG; aDataFields.Append( R_VPBK_FIELD_TYPE_FIRSTNAME ); aDataFields.Append( R_VPBK_FIELD_TYPE_LASTNAME ); aDataFields.Append( R_VPBK_FIELD_TYPE_EMAILGEN ); @@ -350,7 +353,7 @@ TBool CPsMruAdapter::GetMailboxIdentifierFromUri( TDesC& aUri, TFSMailMsgId& aId ) { - FUNC_LOG; + FUNC_LOG; // Find first separator in reverse order TInt lastSeparator = aUri.LocateReverseF( KDefaultMailBoxURISeparator ); if ( lastSeparator == KErrNotFound ) @@ -392,7 +395,7 @@ TBool CPsMruAdapter::GetUriFromMailboxIdentifier( TFSMailMsgId& aId, HBufC& aUri ) { - FUNC_LOG; + FUNC_LOG; // Add the uri identifier aUri.Des().Copy( KDefaultMailBoxURI ); // Add plugin ID @@ -408,35 +411,48 @@ void CPsMruAdapter::EventL( TFSMailEvent aEvent, TFSMailMsgId aMailbox, TAny* /*aParam1*/, TAny* aParam2, TAny* /*aParam3*/ ) { - FUNC_LOG; + FUNC_LOG; switch ( aEvent ) { case TFSEventMailMoved: - case TFSEventMailCopied: + case TFSEventMailCopied: case TFSEventNewMail: { // Check the new parent folder id for this message // For all these events, param2 indicates the new parent folder TFSMailMsgId* parentFolderId = - static_cast< TFSMailMsgId* >( aParam2 ); + static_cast< TFSMailMsgId* >( aParam2 ); if ( parentFolderId ) { - // Get the parent folder object - CFSMailFolder* parentFolder = iMailClient->GetFolderByUidL( - aMailbox, *parentFolderId ); - if ( parentFolder ) + TFSFolderType folderType( EFSInbox ); + if ( (*parentFolderId) == iPreviousParentFolderId && aMailbox == iPreviousMailboxId ) + { + // we assume that folder with some id does not change + // its type during mail synchronization + folderType = iPreviousParentFolderType; + } + else { - CleanupStack::PushL( parentFolder ); - - // If it's sent/outbox folder, - // we'll consider that as a new message being sent - // and therefore we'll update the MRU list here - if ( ( parentFolder->GetFolderType() == EFSSentFolder ) || - ( parentFolder->GetFolderType() == EFSOutbox ) ) + // Get the parent folder object + CFSMailFolder* parentFolder = iMailClient->GetFolderByUidL( + aMailbox, *parentFolderId ); + if ( parentFolder ) { - FillDataStoreL( aMailbox ); + iPreviousParentFolderId = (*parentFolderId); + iPreviousMailboxId = aMailbox; + folderType = parentFolder->GetFolderType(); + iPreviousParentFolderType = folderType; + delete parentFolder; + parentFolder = NULL; } - CleanupStack::PopAndDestroy( parentFolder ); + } + // If it's sent/outbox folder, + // we'll consider that as a new message being sent + // and therefore we'll update the MRU list here + if ( ( folderType == EFSSentFolder ) || + ( folderType == EFSOutbox ) ) + { + FillDataStoreL( aMailbox ); } } } @@ -459,7 +475,7 @@ else { // mailbox still does not exist - DeleayMailboxCreationEventL( aMailbox ); // start timer to postpone creation + DeleayMailboxCreationEventL( aMailbox ); // start timer to postpone creation break; } @@ -510,14 +526,22 @@ } } delete identifier; + + iPreviousParentFolderId = TFSMailMsgId(); + iPreviousMailboxId = TFSMailMsgId(); + break; } + case TFSEventMailboxSettingsChanged: // TODO SK check + { + iPreviousParentFolderId = TFSMailMsgId(); + iPreviousMailboxId = TFSMailMsgId(); break; + } } } - TBool CPsMruAdapter::AddMailboxObserverL( TFSMailMsgId& aId ) { - FUNC_LOG; + FUNC_LOG; for( TInt index = 0; index < iObservedMailboxes.Count(); index++ ) { if( iObservedMailboxes[index] == aId ) @@ -534,7 +558,7 @@ TBool CPsMruAdapter::RemoveMailboxObserver( TFSMailMsgId& aId ) { - FUNC_LOG; + FUNC_LOG; for( TInt index = 0; index < iObservedMailboxes.Count(); index++ ) { if( iObservedMailboxes[index] == aId ) @@ -550,13 +574,13 @@ void CPsMruAdapter::RemoveAllMailboxObservers() { - FUNC_LOG; + FUNC_LOG; for( TInt index = 0; index < iObservedMailboxes.Count(); index++ ) { iMailClient->UnsubscribeMailboxEvents( iObservedMailboxes[index], *this ); } - iObservedMailboxes.Reset(); + iObservedMailboxes.Reset(); } /** @@ -564,7 +588,7 @@ * by CDelayMailboxCreationHelper timer to try it after some delay */ TBool CPsMruAdapter::DeleayedMailboxCreationEventL() - { + { FUNC_LOG; for ( int i = iDelayedCreatedMailboxes.Count()-1; i>=0; i-- ) { @@ -598,7 +622,7 @@ AddMailboxObserverL( iDelayedCreatedMailboxes[i] ); // will be added by FillDataStoreL CleanupStack::Pop( identifier ); - iDelayedCreatedMailboxes.Remove( i ); + iDelayedCreatedMailboxes.Remove( i ); } else { @@ -615,7 +639,7 @@ */ void CPsMruAdapter::DeleayMailboxCreationEventL( TFSMailMsgId &aMailbox ) { - FUNC_LOG; + FUNC_LOG; if ( NULL == iDelayMailboxCreationPtr ) { iDelayMailboxCreationPtr = CDelayMailboxCreationHelper::NewL( this ); @@ -648,7 +672,7 @@ } // used by MruAdapter when delayed datasource adding is needed -void CDelayMailboxCreationHelper::StartDelayedCall() +void CDelayMailboxCreationHelper::StartDelayedCall() { FUNC_LOG; if( IsActive() ) // don't call again in case the timer rq is pending