14 * Description: ES Protocol Framework branding manager interface definition |
14 * Description: ES Protocol Framework branding manager interface definition |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 |
18 |
|
19 #include <nmcommonheaders.h> |
19 #include "emailtrace.h" |
20 #include "emailtrace.h" |
20 #include <fsmailbrandmanager.rsg> |
21 #include <FSMAILBRANDMANAGER.rsg> |
21 #include <barsread.h> |
22 #include <barsread.h> |
22 #include <bautils.h> |
23 #include <bautils.h> |
23 #include <mmf/common/mmfcontrollerpluginresolver.h> // CleanupResetAndDestroy |
|
24 // <gmail_brand_issue> |
|
25 #include <etelmm.h> |
|
26 #include <mmtsy_names.h> |
|
27 #include <startupdomainpskeys.h> |
|
28 #include <tzlocalizer.h> // CTzLocalizer |
|
29 #include <centralrepository.h> |
|
30 // </gmail_brand_issue> |
|
31 //<cmail> |
24 //<cmail> |
32 #include "CFSMailClient.h" |
25 #include "CFSMailClient.h" |
33 //</cmail> |
26 //</cmail> |
34 |
27 |
35 #include "CFSMailBrandManagerImpl.h" |
28 #include "CFSMailBrandManagerImpl.h" |
36 #include "CFSMailBrand.h" |
29 #include "CFSMailBrand.h" |
37 |
30 |
38 |
31 |
39 const TInt KBrandArrayGranularity = 5; |
32 const TInt KBrandArrayGranularity = 5; |
40 _LIT( KResourceFilePath,"\\resource\\fsmailbrandmanager.rsc" ); |
33 _LIT( KResourceFilePath,"\\resource\\fsmailbrandmanager.rsc" ); |
41 |
|
42 // The following are needed to convert "Gmail" brand name to "Google Mail" |
|
43 // in certain countries. |
|
44 // <gmail_brand_issue> |
|
45 |
|
46 _LIT( KBrandNameGmail, "Gmail" ); |
|
47 _LIT( KBrandNameGoogleMail, "Google Mail" ); |
|
48 |
|
49 _LIT( KMCCGermany, "262" ); |
|
50 _LIT( KMCCUK1, "234" ); |
|
51 _LIT( KMCCUK2, "235" ); |
|
52 |
|
53 const TUint8 KGermanyTzId = 36; |
|
54 const TUint8 KUKTzId = 104; |
|
55 |
|
56 const TInt KMCCValueMaxLength = 3; |
|
57 |
|
58 #ifdef __WINS__ |
|
59 LOCAL_C void RetrieveNextToken( TDes8& aContent, TDes& aToken ) |
|
60 { |
|
61 _LIT8( KComma, "," ); |
|
62 TInt pos = aContent.Find( KComma ); |
|
63 if ( pos != KErrNotFound ) |
|
64 { |
|
65 aToken.Copy( aContent.MidTPtr( 0, pos ) ); |
|
66 aContent.Copy( |
|
67 aContent.RightTPtr( aContent.Length() - pos - 1 ) ); |
|
68 } |
|
69 } |
|
70 #endif // __WINS__ |
|
71 // </gmail_brand_issue> |
|
72 |
34 |
73 // ----------------------------------------------------------------------------- |
35 // ----------------------------------------------------------------------------- |
74 // CFSMailBrandManagerImpl::CFSMailBrandManagerImpl |
36 // CFSMailBrandManagerImpl::CFSMailBrandManagerImpl |
75 // ----------------------------------------------------------------------------- |
37 // ----------------------------------------------------------------------------- |
76 CFSMailBrandManagerImpl::CFSMailBrandManagerImpl( |
38 CFSMailBrandManagerImpl::CFSMailBrandManagerImpl( |
169 { |
131 { |
170 FUNC_LOG; |
132 FUNC_LOG; |
171 |
133 |
172 // list all mailboxes |
134 // list all mailboxes |
173 RPointerArray<CFSMailBox> mailBoxes; |
135 RPointerArray<CFSMailBox> mailBoxes; |
174 CleanupResetAndDestroyPushL( mailBoxes ); |
136 TInt rcode = iMailClient.ListMailBoxes( TFSMailMsgId(), mailBoxes ); |
175 iMailClient.ListMailBoxes( TFSMailMsgId(), mailBoxes ); |
137 if( rcode == KErrNone ) |
176 // Check is there need to change the name of the mailbox |
138 { |
177 TPtrC name = GetTextL( EFSMailboxName, aMailBoxId); |
139 // Check is there need to change the name of the mailbox |
178 // <gmail_brand_issue> |
140 TPtrC name = GetTextL( EFSMailboxName, aMailBoxId); |
179 VerifyMailAccountName( name ); |
141 if( name.Length() ) |
180 // </gmail_brand_issue> |
|
181 if( name.Length() ) |
|
182 { |
|
183 // check duplicates |
|
184 TInt orderNumber(2); |
|
185 TBool duplicate(ETrue); |
|
186 HBufC* newName = HBufC::NewL(name.Length()+6); |
|
187 TPtrC brandedName = name; |
|
188 while(duplicate != EFalse) |
|
189 { |
142 { |
190 duplicate = EFalse; |
143 // check duplicates |
191 for(TInt i = 0; i < mailBoxes.Count( );i++) |
144 TInt orderNumber(2); |
|
145 TBool duplicate(ETrue); |
|
146 HBufC* newName = HBufC::NewL(name.Length()+6); |
|
147 TPtrC brandedName = name; |
|
148 while(duplicate != EFalse) |
192 { |
149 { |
193 if(brandedName == mailBoxes[i]->GetName() && |
150 duplicate = EFalse; |
194 aMailBoxId != mailBoxes[i]->GetId( )) |
151 for(TInt i = 0; i < mailBoxes.Count( );i++) |
195 { |
152 { |
196 duplicate = ETrue; |
153 if(brandedName == mailBoxes[i]->GetName() && |
197 newName->Des().Copy(name); |
154 aMailBoxId != mailBoxes[i]->GetId( )) |
198 newName->Des().Append(' '); |
155 { |
199 newName->Des().Append('('); |
156 duplicate = ETrue; |
200 newName->Des().AppendNum(orderNumber++); |
157 newName->Des().Copy(name); |
201 newName->Des().Append(')'); |
158 newName->Des().Append(' '); |
202 brandedName.Set(newName->Des()); |
159 newName->Des().Append('('); |
203 break; |
160 newName->Des().AppendNum(orderNumber++); |
|
161 newName->Des().Append(')'); |
|
162 brandedName.Set(newName->Des()); |
|
163 break; |
|
164 } |
204 } |
165 } |
205 } |
166 } |
|
167 iMailClient.SetMailboxName(aMailBoxId,brandedName); |
|
168 delete newName; |
206 } |
169 } |
207 iMailClient.SetMailboxName(aMailBoxId,brandedName); |
170 } |
208 delete newName; |
171 mailBoxes.ResetAndDestroy(); |
209 } |
|
210 CleanupStack::PopAndDestroy( &mailBoxes ); |
|
211 } |
172 } |
212 |
173 |
213 // ----------------------------------------------------------------------------- |
174 // ----------------------------------------------------------------------------- |
214 // CFSMailBrandManagerImpl::GetGraphicL |
175 // CFSMailBrandManagerImpl::GetGraphicL |
215 // ----------------------------------------------------------------------------- |
176 // ----------------------------------------------------------------------------- |
238 } |
199 } |
239 |
200 |
240 return brand->GetGraphicL( aElement ); |
201 return brand->GetGraphicL( aElement ); |
241 } |
202 } |
242 |
203 |
243 // ----------------------------------------------------------------------------- |
|
244 // CFSMailBrandManagerImpl::GetGraphicL |
|
245 // ----------------------------------------------------------------------------- |
|
246 CGulIcon* CFSMailBrandManagerImpl::GetGraphicL( |
|
247 TFSBrandElement aElement, |
|
248 const TDesC& aBrandId ) |
|
249 { |
|
250 FUNC_LOG; |
|
251 CFSMailBrand* brand = FindMatchingBrandL( aBrandId ); |
|
252 if ( brand == NULL ) |
|
253 { |
|
254 return NULL; |
|
255 } |
|
256 return brand->GetGraphicL( aElement ); |
|
257 } |
|
258 |
|
259 // ----------------------------------------------------------------------------- |
204 // ----------------------------------------------------------------------------- |
260 // CFSMailBrandManagerImpl::GetGraphicIdsL |
205 // CFSMailBrandManagerImpl::GetGraphicIdsL |
261 // ----------------------------------------------------------------------------- |
206 // ----------------------------------------------------------------------------- |
262 TInt CFSMailBrandManagerImpl::GetGraphicIdsL( |
207 TInt CFSMailBrandManagerImpl::GetGraphicIdsL( |
263 TFSBrandElement aElement, |
208 TFSBrandElement aElement, |
389 // CFSMailBrandManagerImpl::FindMatchingBrandL |
334 // CFSMailBrandManagerImpl::FindMatchingBrandL |
390 // ----------------------------------------------------------------------------- |
335 // ----------------------------------------------------------------------------- |
391 CFSMailBrand* CFSMailBrandManagerImpl::FindMatchingBrandL( const TDesC& aBrandId ) |
336 CFSMailBrand* CFSMailBrandManagerImpl::FindMatchingBrandL( const TDesC& aBrandId ) |
392 { |
337 { |
393 FUNC_LOG; |
338 FUNC_LOG; |
394 if( aBrandId.Length() ) |
339 TInt brandCount( iBrands->Count() ); |
395 { |
340 for ( TInt i( 0 ); i < brandCount; i++ ) |
396 TInt brandCount( iBrands->Count() ); |
341 { |
397 for ( TInt i( 0 ); i < brandCount; i++ ) |
342 if ( (*iBrands)[ i ]->IsMatching( aBrandId ) ) |
398 { |
343 return (*iBrands)[ i ]; |
399 if ( (*iBrands)[ i ]->IsMatching( aBrandId ) ) |
|
400 return (*iBrands)[ i ]; |
|
401 } |
|
402 } |
344 } |
403 return NULL; |
345 return NULL; |
404 } |
346 } |
405 |
347 |
406 // ----------------------------------------------------------------------------- |
348 // ----------------------------------------------------------------------------- |
407 // CFSMailBrandManagerImpl::MailboxMatchingBrandIdL |
349 // CFSMailBrandManagerImpl::MailboxMatchingBrandIdL |
408 // ----------------------------------------------------------------------------- |
350 // ----------------------------------------------------------------------------- |
409 CFSMailBox* CFSMailBrandManagerImpl::MailboxMatchingBrandIdL( |
351 CFSMailBox* CFSMailBrandManagerImpl::MailboxMatchingBrandIdL( |
410 const TDesC& aBrandId ) const |
352 const TDesC& aBrandId ) const |
411 { |
353 { |
|
354 FUNC_LOG; |
412 RPointerArray<CFSMailBox> mailboxes; |
355 RPointerArray<CFSMailBox> mailboxes; |
413 |
356 TInt outcome( KErrNone ); |
414 CleanupResetAndDestroyPushL( mailboxes ); |
357 |
415 |
358 outcome = iMailClient.ListMailBoxes( TFSMailMsgId(), mailboxes ); |
416 iMailClient.ListMailBoxes( TFSMailMsgId(), mailboxes ); |
359 if ( outcome != KErrNone ) |
417 |
360 { |
|
361 mailboxes.ResetAndDestroy(); |
|
362 User::Leave( outcome ); |
|
363 } |
|
364 |
418 TInt mailboxCount( mailboxes.Count() ); |
365 TInt mailboxCount( mailboxes.Count() ); |
419 TInt mailboxIndexer( 0 ); |
366 TInt mailboxIndexer( 0 ); |
420 while ( mailboxIndexer < mailboxCount ) |
367 while ( mailboxIndexer < mailboxCount ) |
421 { |
368 { |
422 TDesC* brandId( NULL ); |
369 TDesC* brandId( NULL ); |
437 } |
384 } |
438 |
385 |
439 ++mailboxIndexer; |
386 ++mailboxIndexer; |
440 } |
387 } |
441 |
388 |
442 CleanupStack::PopAndDestroy( &mailboxes ); |
389 mailboxes.ResetAndDestroy(); |
443 User::Leave( KErrNotFound ); |
390 User::Leave( KErrNotFound ); |
444 return NULL; // To prevent warning |
391 return NULL; // To prevent warning |
445 } |
392 } |
446 |
393 |
447 // <gmail_brand_issue> |
|
448 // ----------------------------------------------------------------------------- |
|
449 // CFSMailBrandManagerImpl::GetMCCValueL |
|
450 // ----------------------------------------------------------------------------- |
|
451 void CFSMailBrandManagerImpl::GetMCCValueL( TDes& aMcc ) const |
|
452 { |
|
453 aMcc.Zero(); |
|
454 |
|
455 TInt err = KErrNone; |
|
456 |
|
457 #ifndef __WINS__ |
|
458 |
|
459 TBool isSimPresent = EFalse; |
|
460 |
|
461 TInt simStatus( 0 ); |
|
462 |
|
463 err = RProperty::Get( KPSUidStartup, KPSSimStatus, simStatus ); |
|
464 |
|
465 if ( err == KErrNone && |
|
466 simStatus != ESimNotPresent && |
|
467 simStatus != ESimNotSupported ) |
|
468 { |
|
469 isSimPresent = ETrue; |
|
470 } |
|
471 |
|
472 if ( isSimPresent ) |
|
473 { |
|
474 // We cannot let the method leave here |
|
475 TRAP( err, GetMCCValueFromSIML( aMcc ) ); |
|
476 |
|
477 // If reading from SIM fails one time try again after 0.5 secs |
|
478 if ( err != KErrNone ) |
|
479 { |
|
480 const TInt KHalfSecond = 500000; |
|
481 |
|
482 User::After( KHalfSecond ); |
|
483 |
|
484 err = KErrNone; |
|
485 |
|
486 // We cannot let the method leave here |
|
487 TRAP( err, GetMCCValueFromSIML( aMcc ) ); |
|
488 } |
|
489 } |
|
490 |
|
491 #else // __WINS__ |
|
492 |
|
493 _LIT( KSIMInfo, "C:\\data\\Settings\\SIMInfo.txt" ); |
|
494 |
|
495 RFs fs; |
|
496 |
|
497 User::LeaveIfError( fs.Connect() ); |
|
498 |
|
499 RFile simFile; |
|
500 |
|
501 err = simFile.Open( fs, KSIMInfo(), EFileShareReadersOnly | |
|
502 EFileStream | |
|
503 EFileRead ); |
|
504 if ( err == KErrNone ) |
|
505 { |
|
506 TBuf8<100> content; |
|
507 TBuf<100> dummy; |
|
508 |
|
509 simFile.Read( content ); |
|
510 |
|
511 simFile.Close(); |
|
512 |
|
513 fs.Close(); |
|
514 |
|
515 if ( content.Length() > 0 ) |
|
516 { |
|
517 RetrieveNextToken( content, dummy ); |
|
518 RetrieveNextToken( content, dummy ); |
|
519 RetrieveNextToken( content, dummy ); |
|
520 RetrieveNextToken( content, dummy ); |
|
521 |
|
522 RMobilePhone::TMobilePhoneSubscriberId subscriberId; |
|
523 |
|
524 RetrieveNextToken( content, subscriberId ); |
|
525 |
|
526 if ( subscriberId.Length() >= KMCCValueMaxLength ) |
|
527 { |
|
528 aMcc = subscriberId.Left( KMCCValueMaxLength ); |
|
529 } |
|
530 } |
|
531 } |
|
532 |
|
533 #endif // __WINS__ |
|
534 |
|
535 } |
|
536 |
|
537 // ---------------------------------------------------------------------------- |
|
538 // CFSMailBrandManagerImpl::GetMCCValueFromSIML |
|
539 // ---------------------------------------------------------------------------- |
|
540 // |
|
541 void CFSMailBrandManagerImpl::GetMCCValueFromSIML( TDes& aMcc ) const |
|
542 { |
|
543 RTelServer telServer; |
|
544 |
|
545 CleanupClosePushL( telServer ); |
|
546 |
|
547 User::LeaveIfError( telServer.Connect() ); |
|
548 |
|
549 User::LeaveIfError( telServer.LoadPhoneModule( KMmTsyModuleName ) ); |
|
550 |
|
551 RMobilePhone mobilePhone; |
|
552 |
|
553 CleanupClosePushL( mobilePhone ); |
|
554 |
|
555 User::LeaveIfError( mobilePhone.Open( telServer, KMmTsyPhoneName ) ); |
|
556 |
|
557 TRequestStatus status; |
|
558 |
|
559 RMobilePhone::TMobilePhoneSubscriberId subscriberId; |
|
560 |
|
561 mobilePhone.GetSubscriberId( status, subscriberId ); |
|
562 |
|
563 User::WaitForRequest( status ); |
|
564 |
|
565 User::LeaveIfError( status.Int() ); |
|
566 |
|
567 CleanupStack::PopAndDestroy( &mobilePhone ); |
|
568 |
|
569 CleanupStack::PopAndDestroy( &telServer ); |
|
570 |
|
571 if ( subscriberId.Length() >= KMCCValueMaxLength ) |
|
572 { |
|
573 aMcc = subscriberId.Left( KMCCValueMaxLength ); |
|
574 } |
|
575 } |
|
576 |
|
577 // ---------------------------------------------------------------------------- |
|
578 // CFSMailBrandManagerImpl::GetCurrentCountryL |
|
579 // ---------------------------------------------------------------------------- |
|
580 // |
|
581 TUint8 CFSMailBrandManagerImpl::GetCurrentCountryL() const |
|
582 { |
|
583 CTzLocalizer* localizer = CTzLocalizer::NewLC(); |
|
584 |
|
585 CTzLocalizedCity* city = localizer->GetFrequentlyUsedZoneCityL( |
|
586 CTzLocalizedTimeZone::ECurrentZone ); |
|
587 |
|
588 CleanupStack::PushL( city ); |
|
589 |
|
590 CTzLocalizedCityGroup* cityGroup = |
|
591 localizer->GetCityGroupL( city->GroupId() ); |
|
592 |
|
593 TUint8 countryId = cityGroup->Id(); |
|
594 |
|
595 delete cityGroup; |
|
596 cityGroup = NULL; |
|
597 |
|
598 CleanupStack::PopAndDestroy( 2, localizer ); |
|
599 |
|
600 return countryId; |
|
601 } |
|
602 |
|
603 // ----------------------------------------------------------------------------- |
|
604 // CFSMailBrandManagerImpl::VerifyMailAccountName |
|
605 // ----------------------------------------------------------------------------- |
|
606 void CFSMailBrandManagerImpl::VerifyMailAccountName( |
|
607 TPtrC& aBrandedName ) const |
|
608 { |
|
609 // Due to legal reasons we don't show brand name "Gmail" in Germany and UK |
|
610 if ( !aBrandedName.CompareF( KBrandNameGmail ) ) |
|
611 { |
|
612 // First check timezone id |
|
613 TUint8 timeZone = 0; |
|
614 |
|
615 TRAPD( err, timeZone = GetCurrentCountryL() ); |
|
616 |
|
617 if ( err == KErrNone && ( timeZone == KGermanyTzId || |
|
618 timeZone == KUKTzId ) ) |
|
619 { |
|
620 aBrandedName.Set( KBrandNameGoogleMail ); |
|
621 } |
|
622 // Then if necessary check MCC |
|
623 else |
|
624 { |
|
625 TBuf<KMCCValueMaxLength> mcc; |
|
626 |
|
627 TRAPD( err2, GetMCCValueL( mcc ) ); |
|
628 |
|
629 if ( err2 == KErrNone && ( mcc == KMCCGermany || |
|
630 mcc == KMCCUK1 || |
|
631 mcc == KMCCUK2 ) ) |
|
632 { |
|
633 aBrandedName.Set( KBrandNameGoogleMail ); |
|
634 } |
|
635 } |
|
636 |
|
637 } |
|
638 } |
|
639 // </gmail_brand_issue> |
|