diff -r e7aa27f58ae1 -r 578830873419 emailservices/emailframework/src/CFSMailBrandManagerImpl.cpp --- a/emailservices/emailframework/src/CFSMailBrandManagerImpl.cpp Tue Feb 02 00:02:40 2010 +0200 +++ b/emailservices/emailframework/src/CFSMailBrandManagerImpl.cpp Fri Apr 16 14:51:52 2010 +0300 @@ -16,18 +16,11 @@ */ +#include #include "emailtrace.h" -#include +#include #include #include -#include // CleanupResetAndDestroy -// -#include -#include -#include -#include // CTzLocalizer -#include -// // #include "CFSMailClient.h" // @@ -39,37 +32,6 @@ const TInt KBrandArrayGranularity = 5; _LIT( KResourceFilePath,"\\resource\\fsmailbrandmanager.rsc" ); -// The following are needed to convert "Gmail" brand name to "Google Mail" -// in certain countries. -// - -_LIT( KBrandNameGmail, "Gmail" ); -_LIT( KBrandNameGoogleMail, "Google Mail" ); - -_LIT( KMCCGermany, "262" ); -_LIT( KMCCUK1, "234" ); -_LIT( KMCCUK2, "235" ); - -const TUint8 KGermanyTzId = 36; -const TUint8 KUKTzId = 104; - -const TInt KMCCValueMaxLength = 3; - -#ifdef __WINS__ -LOCAL_C void RetrieveNextToken( TDes8& aContent, TDes& aToken ) - { - _LIT8( KComma, "," ); - TInt pos = aContent.Find( KComma ); - if ( pos != KErrNotFound ) - { - aToken.Copy( aContent.MidTPtr( 0, pos ) ); - aContent.Copy( - aContent.RightTPtr( aContent.Length() - pos - 1 ) ); - } - } -#endif // __WINS__ -// - // ----------------------------------------------------------------------------- // CFSMailBrandManagerImpl::CFSMailBrandManagerImpl // ----------------------------------------------------------------------------- @@ -171,43 +133,42 @@ // list all mailboxes RPointerArray mailBoxes; - CleanupResetAndDestroyPushL( mailBoxes ); - iMailClient.ListMailBoxes( TFSMailMsgId(), mailBoxes ); - // Check is there need to change the name of the mailbox - TPtrC name = GetTextL( EFSMailboxName, aMailBoxId); - // - VerifyMailAccountName( name ); - // - if( name.Length() ) + TInt rcode = iMailClient.ListMailBoxes( TFSMailMsgId(), mailBoxes ); + if( rcode == KErrNone ) { - // check duplicates - TInt orderNumber(2); - TBool duplicate(ETrue); - HBufC* newName = HBufC::NewL(name.Length()+6); - TPtrC brandedName = name; - while(duplicate != EFalse) + // Check is there need to change the name of the mailbox + TPtrC name = GetTextL( EFSMailboxName, aMailBoxId); + if( name.Length() ) { - duplicate = EFalse; - for(TInt i = 0; i < mailBoxes.Count( );i++) + // check duplicates + TInt orderNumber(2); + TBool duplicate(ETrue); + HBufC* newName = HBufC::NewL(name.Length()+6); + TPtrC brandedName = name; + while(duplicate != EFalse) { - if(brandedName == mailBoxes[i]->GetName() && - aMailBoxId != mailBoxes[i]->GetId( )) + duplicate = EFalse; + for(TInt i = 0; i < mailBoxes.Count( );i++) { - duplicate = ETrue; - newName->Des().Copy(name); - newName->Des().Append(' '); - newName->Des().Append('('); - newName->Des().AppendNum(orderNumber++); - newName->Des().Append(')'); - brandedName.Set(newName->Des()); - break; + if(brandedName == mailBoxes[i]->GetName() && + aMailBoxId != mailBoxes[i]->GetId( )) + { + duplicate = ETrue; + newName->Des().Copy(name); + newName->Des().Append(' '); + newName->Des().Append('('); + newName->Des().AppendNum(orderNumber++); + newName->Des().Append(')'); + brandedName.Set(newName->Des()); + break; + } } } + iMailClient.SetMailboxName(aMailBoxId,brandedName); + delete newName; } - iMailClient.SetMailboxName(aMailBoxId,brandedName); - delete newName; } - CleanupStack::PopAndDestroy( &mailBoxes ); + mailBoxes.ResetAndDestroy(); } // ----------------------------------------------------------------------------- @@ -241,22 +202,6 @@ } // ----------------------------------------------------------------------------- -// CFSMailBrandManagerImpl::GetGraphicL -// ----------------------------------------------------------------------------- -CGulIcon* CFSMailBrandManagerImpl::GetGraphicL( - TFSBrandElement aElement, - const TDesC& aBrandId ) - { - FUNC_LOG; - CFSMailBrand* brand = FindMatchingBrandL( aBrandId ); - if ( brand == NULL ) - { - return NULL; - } - return brand->GetGraphicL( aElement ); - } - -// ----------------------------------------------------------------------------- // CFSMailBrandManagerImpl::GetGraphicIdsL // ----------------------------------------------------------------------------- TInt CFSMailBrandManagerImpl::GetGraphicIdsL( @@ -391,14 +336,11 @@ CFSMailBrand* CFSMailBrandManagerImpl::FindMatchingBrandL( const TDesC& aBrandId ) { FUNC_LOG; - if( aBrandId.Length() ) + TInt brandCount( iBrands->Count() ); + for ( TInt i( 0 ); i < brandCount; i++ ) { - TInt brandCount( iBrands->Count() ); - for ( TInt i( 0 ); i < brandCount; i++ ) - { - if ( (*iBrands)[ i ]->IsMatching( aBrandId ) ) - return (*iBrands)[ i ]; - } + if ( (*iBrands)[ i ]->IsMatching( aBrandId ) ) + return (*iBrands)[ i ]; } return NULL; } @@ -408,13 +350,18 @@ // ----------------------------------------------------------------------------- CFSMailBox* CFSMailBrandManagerImpl::MailboxMatchingBrandIdL( const TDesC& aBrandId ) const - { + { + FUNC_LOG; RPointerArray mailboxes; - - CleanupResetAndDestroyPushL( mailboxes ); - - iMailClient.ListMailBoxes( TFSMailMsgId(), mailboxes ); - + TInt outcome( KErrNone ); + + outcome = iMailClient.ListMailBoxes( TFSMailMsgId(), mailboxes ); + if ( outcome != KErrNone ) + { + mailboxes.ResetAndDestroy(); + User::Leave( outcome ); + } + TInt mailboxCount( mailboxes.Count() ); TInt mailboxIndexer( 0 ); while ( mailboxIndexer < mailboxCount ) @@ -439,201 +386,8 @@ ++mailboxIndexer; } - CleanupStack::PopAndDestroy( &mailboxes ); + mailboxes.ResetAndDestroy(); User::Leave( KErrNotFound ); return NULL; // To prevent warning } -// -// ----------------------------------------------------------------------------- -// CFSMailBrandManagerImpl::GetMCCValueL -// ----------------------------------------------------------------------------- -void CFSMailBrandManagerImpl::GetMCCValueL( TDes& aMcc ) const - { - aMcc.Zero(); - - TInt err = KErrNone; - -#ifndef __WINS__ - - TBool isSimPresent = EFalse; - - TInt simStatus( 0 ); - - err = RProperty::Get( KPSUidStartup, KPSSimStatus, simStatus ); - - if ( err == KErrNone && - simStatus != ESimNotPresent && - simStatus != ESimNotSupported ) - { - isSimPresent = ETrue; - } - - if ( isSimPresent ) - { - // We cannot let the method leave here - TRAP( err, GetMCCValueFromSIML( aMcc ) ); - - // If reading from SIM fails one time try again after 0.5 secs - if ( err != KErrNone ) - { - const TInt KHalfSecond = 500000; - - User::After( KHalfSecond ); - - err = KErrNone; - - // We cannot let the method leave here - TRAP( err, GetMCCValueFromSIML( aMcc ) ); - } - } - -#else // __WINS__ - - _LIT( KSIMInfo, "C:\\data\\Settings\\SIMInfo.txt" ); - - RFs fs; - - User::LeaveIfError( fs.Connect() ); - - RFile simFile; - - err = simFile.Open( fs, KSIMInfo(), EFileShareReadersOnly | - EFileStream | - EFileRead ); - if ( err == KErrNone ) - { - TBuf8<100> content; - TBuf<100> dummy; - - simFile.Read( content ); - - simFile.Close(); - - fs.Close(); - - if ( content.Length() > 0 ) - { - RetrieveNextToken( content, dummy ); - RetrieveNextToken( content, dummy ); - RetrieveNextToken( content, dummy ); - RetrieveNextToken( content, dummy ); - - RMobilePhone::TMobilePhoneSubscriberId subscriberId; - - RetrieveNextToken( content, subscriberId ); - - if ( subscriberId.Length() >= KMCCValueMaxLength ) - { - aMcc = subscriberId.Left( KMCCValueMaxLength ); - } - } - } - -#endif // __WINS__ - - } - -// ---------------------------------------------------------------------------- -// CFSMailBrandManagerImpl::GetMCCValueFromSIML -// ---------------------------------------------------------------------------- -// -void CFSMailBrandManagerImpl::GetMCCValueFromSIML( TDes& aMcc ) const - { - RTelServer telServer; - - CleanupClosePushL( telServer ); - - User::LeaveIfError( telServer.Connect() ); - - User::LeaveIfError( telServer.LoadPhoneModule( KMmTsyModuleName ) ); - - RMobilePhone mobilePhone; - - CleanupClosePushL( mobilePhone ); - - User::LeaveIfError( mobilePhone.Open( telServer, KMmTsyPhoneName ) ); - - TRequestStatus status; - - RMobilePhone::TMobilePhoneSubscriberId subscriberId; - - mobilePhone.GetSubscriberId( status, subscriberId ); - - User::WaitForRequest( status ); - - User::LeaveIfError( status.Int() ); - - CleanupStack::PopAndDestroy( &mobilePhone ); - - CleanupStack::PopAndDestroy( &telServer ); - - if ( subscriberId.Length() >= KMCCValueMaxLength ) - { - aMcc = subscriberId.Left( KMCCValueMaxLength ); - } - } - -// ---------------------------------------------------------------------------- -// CFSMailBrandManagerImpl::GetCurrentCountryL -// ---------------------------------------------------------------------------- -// -TUint8 CFSMailBrandManagerImpl::GetCurrentCountryL() const - { - CTzLocalizer* localizer = CTzLocalizer::NewLC(); - - CTzLocalizedCity* city = localizer->GetFrequentlyUsedZoneCityL( - CTzLocalizedTimeZone::ECurrentZone ); - - CleanupStack::PushL( city ); - - CTzLocalizedCityGroup* cityGroup = - localizer->GetCityGroupL( city->GroupId() ); - - TUint8 countryId = cityGroup->Id(); - - delete cityGroup; - cityGroup = NULL; - - CleanupStack::PopAndDestroy( 2, localizer ); - - return countryId; - } - -// ----------------------------------------------------------------------------- -// CFSMailBrandManagerImpl::VerifyMailAccountName -// ----------------------------------------------------------------------------- -void CFSMailBrandManagerImpl::VerifyMailAccountName( - TPtrC& aBrandedName ) const - { - // Due to legal reasons we don't show brand name "Gmail" in Germany and UK - if ( !aBrandedName.CompareF( KBrandNameGmail ) ) - { - // First check timezone id - TUint8 timeZone = 0; - - TRAPD( err, timeZone = GetCurrentCountryL() ); - - if ( err == KErrNone && ( timeZone == KGermanyTzId || - timeZone == KUKTzId ) ) - { - aBrandedName.Set( KBrandNameGoogleMail ); - } - // Then if necessary check MCC - else - { - TBuf mcc; - - TRAPD( err2, GetMCCValueL( mcc ) ); - - if ( err2 == KErrNone && ( mcc == KMCCGermany || - mcc == KMCCUK1 || - mcc == KMCCUK2 ) ) - { - aBrandedName.Set( KBrandNameGoogleMail ); - } - } - - } - } -//