messagingappbase/mcesettings/src/MceSettingsMultipleServicesDialog.cpp
changeset 0 72b543305e3a
child 12 caea42e26caa
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2002 - 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:  
       
    15 *     Message centre's mail/smail dialog.
       
    16 *     Includes "remote mailboxes" and "Mailbox in use" setting items.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 // INCLUDE FILES
       
    23 
       
    24 #include <muiumsvuiserviceutilitiesinternal.h> //MsvUiServiceUtilities
       
    25 #include <msvuids.h>
       
    26 #include <AknQueryDialog.h> // CAknQueryDialog
       
    27 #include <aknViewAppUi.h>
       
    28 #include <aknradiobuttonsettingpage.h>
       
    29 #include <StringLoader.h>   // StringLoader
       
    30 #include <e32base.h>
       
    31 
       
    32 #include <msvids.h>         // KMsvUnknownServiceIndexEntryId
       
    33 #include "MceSettingsMultipleServicesDialog.h"
       
    34 #include "MceSettingsAccountManager.h"
       
    35 #include "MceSettingsIds.hrh"
       
    36 
       
    37 #include "MceSettingsArrays.h"
       
    38 #include "MceSettingsMtmServicesDialog.h"
       
    39 #include <MceSettings.rsg>
       
    40 
       
    41 #include <featmgr.h>
       
    42 #include <hlplch.h>             // For HlpLauncher
       
    43 #include <csxhelp/mbxs.hlp.hrh>
       
    44 #include "mce.hlp.hrh"
       
    45 
       
    46 #include <bldvariant.hrh>
       
    47 #include <SenduiMtmUids.h>
       
    48 
       
    49 #include <ImumInternalApi.h>
       
    50 #include <ImumInHealthServices.h>
       
    51 #include <muiuflags.h>
       
    52 #include "MceSettingsUtils.h"
       
    53 #include <muiuemailtools.h>
       
    54 #include <mtudreg.h>
       
    55 
       
    56 #include <centralrepository.h>
       
    57 #include <miutset.h>
       
    58 #include <MessagingDomainCRKeys.h>
       
    59 #include <akninputblock.h> // CAknInputBlock
       
    60 #ifdef RD_MESSAGING_GENERAL_SETTINGS_RENOVATION
       
    61 #include <data_caging_path_literals.hrh>
       
    62 #endif // RD_MESSAGING_GENERAL_SETTINGS_RENOVATION
       
    63 #include <imum.rsg>
       
    64 
       
    65 // CONSTANTS
       
    66 
       
    67 #define KMceApplicationUidValue         0x100058C5
       
    68 const TUid KMceApplicationUid           = {KMceApplicationUidValue};
       
    69 
       
    70 const TInt KMceSettingsRemoteMailboxInUseSelectableEmailInUse   = 0;
       
    71 const TInt KMceSettingsRemoteMailboxInUse   = 1;
       
    72 const TInt KMceSettingsMailboxTextLength    = 20;
       
    73 const TInt KMceSettingsArrayGranularity     = 4;
       
    74 
       
    75 const TInt KMceSettingsMtmNameBufLength     = KHumanReadableNameLength + 5;
       
    76 const TInt KMSKPosition = 3;
       
    77 
       
    78 _LIT(KMceMtmName1,"\t");
       
    79 _LIT(KMceMtmName2,"\t\t");
       
    80 #ifdef RD_MESSAGING_GENERAL_SETTINGS_RENOVATION
       
    81 _LIT( KMceDirAndFile,"MceSettings.rsc" );
       
    82 #endif // RD_MESSAGING_GENERAL_SETTINGS_RENOVATION
       
    83 
       
    84 // ================= MEMBER FUNCTIONS =======================
       
    85 // ---------------------------------------------------------------------------
       
    86 // CMceSettingsMultipleServicesDialog::CreateAndExecuteL()
       
    87 // ---------------------------------------------------------------------------
       
    88 //
       
    89 EXPORT_C TInt CMceSettingsMultipleServicesDialog::CreateAndExecuteL(
       
    90                                               MMceSettingsAccountManager& aManager,
       
    91                                               TUid aMessageType,
       
    92                                               CMsvSession* aSession )
       
    93     {
       
    94 #ifdef RD_MESSAGING_GENERAL_SETTINGS_RENOVATION
       
    95     CMceSettingsMultipleServicesDialog* mailDlg =new( ELeave ) CMceSettingsMultipleServicesDialog(aManager,  aMessageType, aSession );
       
    96     CleanupStack::PushL( mailDlg );
       
    97     FeatureManager::InitializeLibL();
       
    98     if ( FeatureManager::FeatureSupported( KFeatureIdSelectableEmail ) )  
       
    99     {
       
   100       mailDlg->ConstructL(R_MCE_SETTINGS_MULTIPLE_SERVICES_DIALOG_MENUBAR_WITH_SELECTABLE_EMAIL );
       
   101   	  CleanupStack::Pop( mailDlg );
       
   102       return mailDlg->ExecuteLD( R_MCE_SETTINGS_MULTIPLE_SERVICES_DIALOG_MENUBAR_WITH_SELECTABLE_EMAIL );
       
   103     }
       
   104    else
       
   105    {
       
   106   	  mailDlg->ConstructL( R_MCE_SETTINGS_MULTIPLE_SERVICES_DIALOG_MENUBAR );
       
   107   	  CleanupStack::Pop( mailDlg );
       
   108       return mailDlg->ExecuteLD( R_MCE_SETTINGS_MULTIPLE_SERVICES_DIALOG );
       
   109     
       
   110    }
       
   111    FeatureManager::UnInitializeLib();
       
   112 #else
       
   113     User::Leave( KErrNotSupported );
       
   114     return KErrNotSupported;
       
   115 #endif // RD_MESSAGING_GENERAL_SETTINGS_RENOVATION
       
   116     }
       
   117 
       
   118 // ----------------------------------------------------
       
   119 // C++ default constructor can NOT contain any code that
       
   120 // might leave.
       
   121 // ----------------------------------------------------
       
   122 CMceSettingsMultipleServicesDialog::CMceSettingsMultipleServicesDialog(
       
   123                                                 MMceSettingsAccountManager& aManager, 
       
   124                                                 TUid aMessageType,
       
   125                                                 CMsvSession* aSession )
       
   126     : 
       
   127     CMceSettingsTitlePaneHandlerDialog(),
       
   128     iManager( aManager ),
       
   129     iMessageType( aMessageType ),
       
   130     iSession( aSession )
       
   131 #ifdef RD_MESSAGING_GENERAL_SETTINGS_RENOVATION
       
   132     ,iResources( *CCoeEnv::Static() )
       
   133 #endif // RD_MESSAGING_GENERAL_SETTINGS_RENOVATION
       
   134 	,iSubDialogOpen(EFalse)
       
   135     ,iS60WizLaunched( EFalse )
       
   136     {
       
   137     }
       
   138 
       
   139 // ----------------------------------------------------
       
   140 // CMceSettingsMultipleServicesDialog::Destructor
       
   141 // ----------------------------------------------------
       
   142 CMceSettingsMultipleServicesDialog::~CMceSettingsMultipleServicesDialog()
       
   143     {
       
   144     if ( iMceIntegration )
       
   145         {
       
   146         if ( iAiwServiceHandler )
       
   147             {
       
   148             iAiwServiceHandler->Reset();
       
   149             }
       
   150         delete iAiwServiceHandler;
       
   151         iAiwServiceHandler = NULL;
       
   152         }
       
   153     // do not delete iMtmAccountTypesDlg only used to notify msgs changes
       
   154     if ( iSessionObserverAdded )
       
   155         {
       
   156         iManager.Session().RemoveObserver( *this );
       
   157         }
       
   158     delete iEmailApi;
       
   159     iEmailApi = NULL;
       
   160     iMailboxArray.Reset();  
       
   161 #ifdef RD_MESSAGING_GENERAL_SETTINGS_RENOVATION
       
   162     iResources.Close();
       
   163 #endif // RD_MESSAGING_GENERAL_SETTINGS_RENOVATION
       
   164     if ( iProductIncludesSelectableEmail )
       
   165         {
       
   166         if ( iAccountArray )
       
   167             {
       
   168             delete iAccountArray;		
       
   169             }
       
   170         }
       
   171     }
       
   172 
       
   173 
       
   174 // ---------------------------------------------------------------------------
       
   175 // CMceSettingsMultipleServicesDialog::ConstructL()
       
   176 // ---------------------------------------------------------------------------
       
   177 //
       
   178 void CMceSettingsMultipleServicesDialog::ConstructL(TInt aResource )
       
   179     {
       
   180     CRepository* repository = NULL;
       
   181     TRAPD( ret, repository = CRepository::NewL( KCRUidSelectableDefaultEmailSettings  ) );
       
   182 
       
   183     if ( ret == KErrNone )
       
   184         {
       
   185         // Check if there is other than platform email application registered
       
   186         // to handle S60 mailboxes  
       
   187         TInt err = repository->Get( KIntegratedEmailAppMtmPluginId , iMtmPluginId );
       
   188         if ( err != KErrNone )
       
   189             {
       
   190             iMtmPluginId = 0;
       
   191             }
       
   192         }
       
   193     delete repository;
       
   194 
       
   195     FeatureManager::InitializeLibL();
       
   196     if ( FeatureManager::FeatureSupported( KFeatureIdSelectableEmail ) )
       
   197         {
       
   198         iProductIncludesSelectableEmail = ETrue;
       
   199         }
       
   200     else
       
   201         {
       
   202         iProductIncludesSelectableEmail = EFalse;	
       
   203         }
       
   204     if( FeatureManager::FeatureSupported( KFeatureIdEmailMceIntegration ) )
       
   205         {
       
   206         iMceIntegration = ETrue;
       
   207         }
       
   208     else
       
   209         {
       
   210         iMceIntegration = EFalse;
       
   211         }
       
   212     FeatureManager::UnInitializeLib();
       
   213 #ifdef RD_MESSAGING_GENERAL_SETTINGS_RENOVATION
       
   214     TParse fp;
       
   215     fp.Set( KMceDirAndFile, &KDC_RESOURCE_FILES_DIR , NULL );
       
   216     TFileName fileName = fp.FullName();
       
   217     iResources.OpenL( fileName );
       
   218     CMceSettingsTitlePaneHandlerDialog::ConstructL( aResource );
       
   219 #endif // RD_MESSAGING_GENERAL_SETTINGS_RENOVATION
       
   220     iEmailApi = CreateEmailApiL( iSession );
       
   221     UpdateMailboxDataL();
       
   222     }
       
   223    
       
   224 // ---------------------------------------------------------------------------
       
   225 // CMceSettingsMultipleServicesDialog::ConstructL()
       
   226 // ---------------------------------------------------------------------------
       
   227 //
       
   228 void CMceSettingsMultipleServicesDialog::ConstructL()
       
   229     {
       
   230     CRepository* repository = NULL;
       
   231     TRAPD( ret, repository = CRepository::NewL( KCRUidSelectableDefaultEmailSettings  ) );
       
   232 
       
   233     if ( ret == KErrNone )
       
   234         {
       
   235         // Check if there is other than platform email application registered
       
   236         // to handle S60 mailboxes  
       
   237         TInt err = repository->Get( KIntegratedEmailAppMtmPluginId , iMtmPluginId );
       
   238         if ( err != KErrNone )
       
   239             {
       
   240             iMtmPluginId = 0;
       
   241             }
       
   242         }
       
   243     delete repository;
       
   244 
       
   245     FeatureManager::InitializeLibL();
       
   246     if ( FeatureManager::FeatureSupported( KFeatureIdSelectableEmail ) )
       
   247         {
       
   248         iProductIncludesSelectableEmail = ETrue;
       
   249         }
       
   250     else
       
   251         {
       
   252         iProductIncludesSelectableEmail = EFalse;	
       
   253         }
       
   254     if ( FeatureManager::FeatureSupported( KFeatureIdEmailMceIntegration ) )
       
   255         {
       
   256         iMceIntegration = ETrue;
       
   257         }
       
   258     else
       
   259         {
       
   260         iMceIntegration = EFalse;
       
   261         }
       
   262     FeatureManager::UnInitializeLib();
       
   263     iEmailApi = CreateEmailApiL( iSession );
       
   264     UpdateMailboxDataL();
       
   265     }
       
   266 
       
   267 // ----------------------------------------------------
       
   268 // CMceSettingsMultipleServicesDialog::OkToExitL
       
   269 // ----------------------------------------------------
       
   270 TInt CMceSettingsMultipleServicesDialog::OkToExitL( TInt aButtonId )
       
   271     {
       
   272     if ( iSubDialogOpen )
       
   273         {
       
   274         // Subdialog open, don't close yet
       
   275         return EFalse;
       
   276         }
       
   277     TBool okToExit = CAknDialog::OkToExitL( aButtonId );
       
   278     if ( ( aButtonId==EMceSettingsCmdSettingsDialogOpen ) ||
       
   279          ( aButtonId==EMceSettingsCmdSettingsDialogChange ) )
       
   280         {
       
   281         // Middle soft key pressed
       
   282         ProcessCommandL( aButtonId );
       
   283         okToExit = EFalse; // Cannot exit, since MSK was pressed
       
   284         }
       
   285     else if ( aButtonId != EEikBidCancel && okToExit )
       
   286         {
       
   287         RestoreTitleTextL();
       
   288         }
       
   289 
       
   290     return okToExit;
       
   291     }
       
   292  
       
   293 // ---------------------------------------------------------------------------
       
   294 // CMceSettingsMultipleServicesDialog::UpdateMailboxDataL()
       
   295 // ---------------------------------------------------------------------------
       
   296 //
       
   297 void CMceSettingsMultipleServicesDialog::UpdateMailboxDataL()
       
   298     {
       
   299     const MImumInHealthServices* healthApi = &iEmailApi->HealthServicesL();
       
   300     
       
   301     // Get the array of the mailboxes for the current view
       
   302     MceSettingsUtils::GetHealthyMailboxListL( 
       
   303         *healthApi,
       
   304         iMailboxArray,
       
   305         iMessageType != KSenduiMtmSyncMLEmailUid,
       
   306         iMessageType != KSenduiMtmSyncMLEmailUid,
       
   307         iMessageType == KSenduiMtmSyncMLEmailUid,
       
   308         EFalse );
       
   309     iNumberOfMailboxes = iMailboxArray.Count();
       
   310     }
       
   311 
       
   312 // ----------------------------------------------------
       
   313 // CMceSettingsMultipleServicesDialog::ProcessCommandL
       
   314 // ----------------------------------------------------
       
   315 void CMceSettingsMultipleServicesDialog::ProcessCommandL( TInt aCommandId )
       
   316     {
       
   317     if ( aCommandId == EMceSettingsCmdSettingsDialogExit )
       
   318         {
       
   319         CAknDialog::ProcessCommandL( aCommandId ); // hides menu
       
   320         if (iAvkonViewAppUi->ExitHidesInBackground()) 
       
   321             { 
       
   322             iAvkonViewAppUi->ProcessCommandL( EAknCmdHideInBackground );
       
   323             }
       
   324         else
       
   325             {
       
   326             iAvkonViewAppUi->ProcessCommandL( EAknCmdExit );
       
   327             }
       
   328         return;
       
   329         }
       
   330 
       
   331     CAknDialog::ProcessCommandL( aCommandId ); // hides menu
       
   332 
       
   333     if ( !iProductIncludesSelectableEmail )
       
   334         {
       
   335         if ( !iEmailApi )
       
   336             {
       
   337             iEmailApi = CreateEmailApiL( iSession );
       
   338             }
       
   339 
       
   340         const MImumInHealthServices* healthApi = &iEmailApi->HealthServicesL();
       
   341 
       
   342         TInt error = MceSettingsUtils::GetHealthyMailboxListL( *healthApi,
       
   343                                                                iMailboxArray,
       
   344                                                                ETrue,
       
   345                                                                ETrue,
       
   346                                                                ETrue,ETrue );
       
   347 
       
   348         iNumberOfMailboxes = iMailboxArray.Count();        
       
   349         iMailboxArray.Reset();        
       
   350         error = MceSettingsUtils::GetHealthyMailboxListL( *healthApi,
       
   351                                   iMailboxArray,
       
   352                                   iMessageType != KSenduiMtmSyncMLEmailUid,
       
   353                                   iMessageType != KSenduiMtmSyncMLEmailUid,
       
   354                                   iMessageType == KSenduiMtmSyncMLEmailUid,ETrue );
       
   355         }
       
   356     if ( iProductIncludesSelectableEmail )
       
   357         {
       
   358         CEikTextListBox* list=STATIC_CAST( CEikTextListBox*, 
       
   359                 Control( EMceSettingsMultipleServicesDialogChoiceList ) );
       
   360         TInt item = list->CurrentItemIndex();
       
   361 
       
   362         // first item in listbox is not account and must not be used
       
   363         if ( item > 0 )
       
   364             {
       
   365             item--;
       
   366             }
       
   367 
       
   368         TUid mtmType;
       
   369 
       
   370         if ( item >= 0 && iAccountArray->Count() &&
       
   371              ( iAccountArray->Count() > item ) ) 
       
   372             {
       
   373             TMsvEntry tentry;
       
   374             TMsvId dummyserviceid;
       
   375             if ( iSession->GetEntry( (*iAccountArray)[item].iUid.iUid,
       
   376                  dummyserviceid,
       
   377                  tentry ) == KErrNone )
       
   378                 {
       
   379                 mtmType = tentry.iMtm;
       
   380                 }
       
   381             else
       
   382                 {
       
   383                 mtmType.iUid = 0;
       
   384                 }
       
   385 
       
   386             if ( ( mtmType == KSenduiMtmImap4Uid ) ||
       
   387                  ( mtmType == KSenduiMtmPop3Uid ) )
       
   388                 {
       
   389                 mtmType = KSenduiMtmSmtpUid;
       
   390                 }
       
   391             }
       
   392 
       
   393         if ( iActiveMenuBar == EMultipleServices ) 
       
   394             {
       
   395             switch ( aCommandId )
       
   396                 {
       
   397                 case EMceSettingsCmdSettingsDialogChange:
       
   398                     {
       
   399                     ShowListBoxSettingPageL();
       
   400                     }
       
   401                     break;       
       
   402                 case EMceSettingsCmdSettingsDialogOpen:
       
   403                     iManager.EditAccountL( (*iAccountArray)[item].iUid.iUid );
       
   404                     break;
       
   405                 case EMceSettingsCmdSettingsDialogCreateNewEmpty:				
       
   406                     iManager.CreateNewAccountL( mtmType, KMsvNullIndexEntryId );
       
   407                     break;
       
   408                 case EMceSettingsCmdSettingsDialogCreateNewEmptyImap:				
       
   409                     CreateNewImapPopL();
       
   410                     break;
       
   411                 case EMceSettingsCmdSettingsDialogDelete:
       
   412                     iManager.DeleteAccountL( (*iAccountArray)[item].iUid.iUid );
       
   413                     break;
       
   414                 case EMceSettingsCmdSettingsDialogHelp:
       
   415                     {
       
   416                     LaunchHelpL();
       
   417                     }         
       
   418                     break;				                
       
   419                 default :
       
   420                     break;
       
   421                 }
       
   422             }
       
   423         }
       
   424     else // iProductIncludesSelectableEmail
       
   425         {
       
   426         switch ( aCommandId )
       
   427             {
       
   428             case EMceSettingsCmdSettingsDialogOpen:
       
   429                 EditServicesL();
       
   430                 break;
       
   431             case EMceSettingsCmdSettingsDialogChange:
       
   432                 ShowListBoxSettingPageL();
       
   433                 break;
       
   434             case EMceSettingsCmdSettingsDialogHelp:
       
   435                 {
       
   436                 LaunchHelpL();                
       
   437                 }
       
   438                 break;
       
   439             default :
       
   440                 break;
       
   441             }
       
   442         }
       
   443     }
       
   444 
       
   445 // ----------------------------------------------------
       
   446 // CMceSettingsMultipleServicesDialog::DynInitMenuPaneL
       
   447 // ----------------------------------------------------
       
   448 void CMceSettingsMultipleServicesDialog::DynInitMenuPaneL( TInt aResourceId, 
       
   449                                                                     CEikMenuPane* aMenuPane )
       
   450     {
       
   451     if ( iProductIncludesSelectableEmail )
       
   452         {
       
   453         CEikTextListBox* list = STATIC_CAST( CEikTextListBox*,
       
   454                 Control( EMceSettingsMultipleServicesDialogChoiceList ) );
       
   455         TInt item = list->CurrentItemIndex();    
       
   456 
       
   457         if ( aResourceId == R_MCE_SETTINGS_MULTIPLE_SERVICES_DIALOG_MENUPANE_WITH_SELECTABLE_EMAIL )
       
   458             {    			
       
   459             TInt offset = 0;
       
   460 
       
   461             if ( item > offset )
       
   462                 {
       
   463                 TUid mtmType;
       
   464 
       
   465                 aMenuPane->DeleteMenuItem(
       
   466                         EMceSettingsCmdSettingsDialogChange );				
       
   467                 aMenuPane->DeleteMenuItem(
       
   468                         EMceSettingsCmdSettingsDialogCreateNewEmpty );    	                      
       
   469 
       
   470                 aMenuPane->SetItemDimmed( EMceSettingsCmdSettingsDialogHelp,
       
   471                         !FeatureManager::FeatureSupported( KFeatureIdHelp ) );					
       
   472 
       
   473                 if ( iAccountArray->Count() &&
       
   474                    ( iAccountArray->Count() >= item ) )
       
   475                     {   	        		
       
   476                     CMsvEntry* entry = iSession->GetEntryL(
       
   477                                        (*iAccountArray)[item-1].iUid.iUid ); 
       
   478 
       
   479                     TMsvEntry tentry = entry->Entry();
       
   480                     mtmType = tentry.iMtm;
       
   481                     delete entry;
       
   482 
       
   483                     if ( iAccountArray->Count() >= KMceMaxNumberOfMailboxes )
       
   484                         {             
       
   485                         if ( ( mtmType != KSenduiMtmImap4Uid ) &&
       
   486                              ( mtmType != KSenduiMtmPop3Uid ) )
       
   487                             {
       
   488                             aMenuPane->DeleteMenuItem(
       
   489                                     EMceSettingsCmdSettingsDialogDelete ); 
       
   490                             }                		  	
       
   491                         aMenuPane->DeleteMenuItem(
       
   492                                 EMceSettingsCmdSettingsDialogCreateNewEmptyImap );
       
   493                         }        		
       
   494                     else if ( ( mtmType != KSenduiMtmImap4Uid ) &&
       
   495                               ( mtmType != KSenduiMtmPop3Uid ) &&
       
   496                               ( mtmType != KSenduiMtmSyncMLEmailUid ) )
       
   497                         {
       
   498                         aMenuPane->DeleteMenuItem(
       
   499                                 EMceSettingsCmdSettingsDialogCreateNewEmptyImap );
       
   500                         aMenuPane->DeleteMenuItem(
       
   501                                 EMceSettingsCmdSettingsDialogDelete );         	        
       
   502                         }
       
   503                     }
       
   504                 }
       
   505 
       
   506             else if ( item == KMceSettingsRemoteMailboxInUseSelectableEmailInUse )
       
   507                 {
       
   508                 aMenuPane->DeleteMenuItem(
       
   509                         EMceSettingsCmdSettingsDialogOpen );
       
   510                 aMenuPane->DeleteMenuItem(
       
   511                         EMceSettingsCmdSettingsDialogDelete );        
       
   512                 aMenuPane->DeleteMenuItem(
       
   513                         EMceSettingsCmdSettingsDialogCreateNewEmpty );      	    
       
   514 
       
   515                 aMenuPane->SetItemDimmed( EMceSettingsCmdSettingsDialogHelp,
       
   516                         !FeatureManager::FeatureSupported( KFeatureIdHelp ) ); 	
       
   517 
       
   518                 if ( iAccountArray->Count() >= KMceMaxNumberOfMailboxes )
       
   519                     {
       
   520                     aMenuPane->DeleteMenuItem(
       
   521                             EMceSettingsCmdSettingsDialogCreateNewEmptyImap );
       
   522                     }	            	                  	
       
   523                 }
       
   524             else
       
   525                 {
       
   526                 aMenuPane->DeleteMenuItem(
       
   527                         EMceSettingsCmdSettingsDialogChange );				
       
   528                 aMenuPane->DeleteMenuItem(
       
   529                         EMceSettingsCmdSettingsDialogCreateNewEmptyImap ); 
       
   530 
       
   531                 aMenuPane->SetItemDimmed( EMceSettingsCmdSettingsDialogHelp,
       
   532                         !FeatureManager::FeatureSupported( KFeatureIdHelp ) ); 					
       
   533 
       
   534                 if ( iAccountArray->Count() >= KMceMaxNumberOfMailboxes )
       
   535                     {            		
       
   536                     TUid mtmType;
       
   537 
       
   538                     CMsvEntry* entry = iSession->GetEntryL(
       
   539                                        (*iAccountArray)[item-1].iUid.iUid ); 
       
   540 
       
   541                     TMsvEntry tentry = entry->Entry();
       
   542                     mtmType = tentry.iMtm;
       
   543                     delete entry;            		
       
   544 
       
   545                     if ( ( mtmType != KSenduiMtmImap4Uid ) &&
       
   546                          ( mtmType != KSenduiMtmPop3Uid ) )
       
   547                         {
       
   548                         aMenuPane->DeleteMenuItem(
       
   549                                 EMceSettingsCmdSettingsDialogDelete ); 
       
   550                         }              		
       
   551                     aMenuPane->DeleteMenuItem(
       
   552                             EMceSettingsCmdSettingsDialogCreateNewEmpty );
       
   553                     }
       
   554                 }
       
   555             }
       
   556         } // iProductIncludesSelectableEmail
       
   557     else
       
   558         {
       
   559     if ( aResourceId == R_MCE_SETTINGS_MULTIPLE_SERVICES_DIALOG_MENUPANE )
       
   560         {
       
   561             aMenuPane->SetItemDimmed( EMceSettingsCmdSettingsDialogHelp,
       
   562             !FeatureManager::FeatureSupported( KFeatureIdHelp ) );
       
   563 
       
   564         CEikTextListBox* list = STATIC_CAST( CEikTextListBox*, 
       
   565                                   Control( EMceSettingsMultipleServicesDialogChoiceList ) );
       
   566         if ( list->CurrentItemIndex() == 0 )
       
   567             {
       
   568             aMenuPane->DeleteMenuItem( EMceSettingsCmdSettingsDialogChange );
       
   569             }
       
   570         else
       
   571             {
       
   572             aMenuPane->DeleteMenuItem( EMceSettingsCmdSettingsDialogOpen );
       
   573             }
       
   574         }
       
   575     }
       
   576     }
       
   577 // ----------------------------------------------------
       
   578 // CMceSettingsMultipleServicesDialog::PreLayoutDynInitL
       
   579 // ----------------------------------------------------
       
   580 void CMceSettingsMultipleServicesDialog::PreLayoutDynInitL( )
       
   581     {
       
   582     CEikTextListBox* list = STATIC_CAST( CEikTextListBox*, 
       
   583                                 Control( EMceSettingsMultipleServicesDialogChoiceList ) );
       
   584 
       
   585     THumanReadableName mtmName;
       
   586 
       
   587     iSettingsItemArray = new (ELeave) CDesCArrayFlat(
       
   588                          KMceSettingsArrayGranularity );
       
   589     if ( iProductIncludesSelectableEmail )
       
   590         {
       
   591         if ( !iAccountArray )
       
   592             {
       
   593             iAccountArray = new (ELeave) CUidNameArray(
       
   594                             KMceSettingsArrayGranularity );
       
   595             }	
       
   596 
       
   597         SetAccountInUseL();
       
   598         mtmName = iManager.MtmName( iMessageType );
       
   599         UpdateServicesArrayL();
       
   600         // Scrollbar
       
   601         list->CreateScrollBarFrameL( ETrue );
       
   602         list->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   603                 CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
       
   604         }
       
   605     else // iProductIncludesSelectableEmail
       
   606         {
       
   607         mtmName = iManager.MtmName( iMessageType );
       
   608     if ( iMessageType == KSenduiMtmSmtpUid )
       
   609         {
       
   610         // email
       
   611         HBufC* text = StringLoader::LoadLC(
       
   612             R_MCE_SETTINGS_MAIL_REMOTE_MAILBOXES, iEikonEnv );
       
   613         iSettingsItemArray->AppendL( *text );
       
   614         CleanupStack::PopAndDestroy( text );
       
   615         }
       
   616     else if ( iMessageType == KSenduiMtmSyncMLEmailUid )
       
   617         {
       
   618         // syncML
       
   619         HBufC* text = StringLoader::LoadLC(
       
   620             R_MCE_SETTINGS_SYNCMAIL_MAILBOXES, iEikonEnv );
       
   621         iSettingsItemArray->AppendL( *text );
       
   622         CleanupStack::PopAndDestroy( text );
       
   623         }
       
   624     else
       
   625         {
       
   626         // not email/syncML
       
   627         TBuf<KMceSettingsMtmNameBufLength> mtms;
       
   628         mtms.Copy( KMceMtmName1 );
       
   629         mtms.Append( mtmName );
       
   630         mtms.Append ( KMceMtmName2 );
       
   631         iSettingsItemArray->AppendL( mtms );
       
   632         }
       
   633     
       
   634     SetAccountInUseL();
       
   635         } // iProductIncludesSelectableEmail
       
   636 
       
   637     CTextListBoxModel* model=list->Model();
       
   638     model->SetItemTextArray( iSettingsItemArray );
       
   639     list->SetListBoxObserver(this);
       
   640 
       
   641     if ( iMessageType == KSenduiMtmSmtpUid )
       
   642         {
       
   643         // email
       
   644         HBufC* newText = StringLoader::LoadLC(
       
   645             R_MCE_EMAIL_SETTINGS_TITLE, iEikonEnv );
       
   646         StoreTitleTextAndSetNewL( *newText );
       
   647         CleanupStack::PopAndDestroy( newText );
       
   648         }
       
   649     else if ( iMessageType == KSenduiMtmSyncMLEmailUid )
       
   650         {
       
   651         // syncML
       
   652         HBufC* newText = StringLoader::LoadLC(
       
   653             R_MCE_TITLE_SETTINGS_SYNCMAIL, iEikonEnv );
       
   654         StoreTitleTextAndSetNewL( *newText );
       
   655         CleanupStack::PopAndDestroy(  newText );
       
   656         }
       
   657     else
       
   658         {
       
   659         // not email/syncML
       
   660         StoreTitleTextAndSetNewL( mtmName );
       
   661         }     
       
   662 
       
   663     iManager.Session().AddObserverL( *this );
       
   664     iSessionObserverAdded = ETrue;
       
   665     SetMSKButtonL();
       
   666     }
       
   667 
       
   668 // ----------------------------------------------------
       
   669 // CMceSettingsMultipleServicesDialog::ShowListBoxSettingPageL
       
   670 // ----------------------------------------------------
       
   671 void CMceSettingsMultipleServicesDialog::ShowListBoxSettingPageL()
       
   672     {
       
   673     TInt count = 0;
       
   674     TBool nbrOfMailboxesOk = ETrue;
       
   675     CUidNameArray* sel = NULL; // Used for iProductIncludesSelectableEmail
       
   676 
       
   677     //Produce radiobutton list of mailboxes for selecting the default mailbox
       
   678     if ( iProductIncludesSelectableEmail )
       
   679         {
       
   680         sel = MtmEmailAccountsL();
       
   681         CleanupStack::PushL( sel );
       
   682         count = sel->Count();
       
   683         }
       
   684     else
       
   685         {
       
   686         count = iMailboxArray.Count();
       
   687         if ( iNumberOfMailboxes >= KMceMaxNumberOfMailboxes )
       
   688             {
       
   689             nbrOfMailboxesOk = EFalse;
       
   690             }
       
   691         }
       
   692     if ( count == 0 && nbrOfMailboxesOk )
       
   693         {
       
   694         if ( HandleNoMailboxesL() )
       
   695             {
       
   696             if( iMceIntegration )
       
   697                 {
       
   698                 if ( iS60WizLaunched )
       
   699                     {
       
   700                     iS60WizLaunched = EFalse;
       
   701                     EditServicesL();
       
   702                     }
       
   703                 }
       
   704             else // iMceIntegration
       
   705                 {
       
   706                 EditServicesL();
       
   707                 } // iMceIntegration
       
   708             }
       
   709         if ( iProductIncludesSelectableEmail )
       
   710             {
       
   711             CleanupStack::PopAndDestroy( sel );
       
   712             }
       
   713         return;
       
   714         }
       
   715     UpdateMailboxDataL();
       
   716     CDesCArrayFlat* items = new( ELeave )CDesCArrayFlat(
       
   717         KMceSettingsArrayGranularity );
       
   718     CleanupStack::PushL( items );
       
   719 
       
   720     TMsvId id = MsvUiServiceUtilitiesInternal::DefaultServiceForMTML(
       
   721         iManager.Session(),
       
   722         iMessageType,
       
   723         ETrue );
       
   724 
       
   725     if ( iProductIncludesSelectableEmail &&
       
   726             ( iMessageType != KSenduiMtmSyncMLEmailUid ) )
       
   727         {
       
   728         CRepository* repository = NULL;
       
   729         TRAPD( ret, repository = CRepository::NewL(
       
   730                                  KCRUidSelectableDefaultEmailSettings  ) );
       
   731         CleanupStack::PushL( repository );
       
   732         TInt val;
       
   733 
       
   734         if ( ret == KErrNone )
       
   735             {
       
   736             if ( repository->Get(
       
   737                     KSelectableDefaultMailAccount , val ) == KErrNone )
       
   738                 {
       
   739                 id = val;
       
   740                 }
       
   741             }
       
   742         CleanupStack::PopAndDestroy( repository );		    
       
   743         } // iProductIncludesSelectableEmail
       
   744     TMsvEntry mailboxEntry;
       
   745     TMsvId serviceId; // not used but needed by GetEntry function
       
   746     TBool foundService = iManager.Session().GetEntry( id, serviceId, mailboxEntry ) == KErrNone;
       
   747 
       
   748     TInt currentItem = 0;
       
   749     for ( TInt loop = 0; loop < count; loop++ )
       
   750         {
       
   751         TMsvId arrayItemId;
       
   752         if ( iProductIncludesSelectableEmail )
       
   753             {
       
   754             items->AppendL( (*sel)[loop].iName );
       
   755             arrayItemId = (*sel)[loop].iUid.iUid;
       
   756             }
       
   757         else
       
   758             {
       
   759             TMsvEntry tentry =
       
   760                     iEmailApi->MailboxUtilitiesL().GetMailboxEntryL( 
       
   761                     iMailboxArray[loop],
       
   762                     MImumInMailboxUtilities::ERequestSending );
       
   763             items->AppendL( tentry.iDetails );
       
   764             arrayItemId = iMailboxArray[loop];
       
   765             }
       
   766         // iRelatedId is compared because array can include both smtp and
       
   767         // imap4/pop3 services
       
   768         if ( foundService &&
       
   769            ( id == arrayItemId || mailboxEntry.iRelatedId == arrayItemId ) )
       
   770             {
       
   771             currentItem = loop;
       
   772             }
       
   773         } // for
       
   774 
       
   775     CAknRadioButtonSettingPage* dlg =
       
   776             new ( ELeave )CAknRadioButtonSettingPage(
       
   777             R_MCE_GENERAL_SETTINGS_LISTBOX, 
       
   778             currentItem, items);
       
   779     CleanupStack::PushL( dlg );    
       
   780 
       
   781     THumanReadableName mtmName = iManager.MtmName( iMessageType );    
       
   782     if ( iMessageType == KSenduiMtmSmtpUid )
       
   783         {
       
   784         // email
       
   785         HBufC* titleText = StringLoader::LoadLC(
       
   786                            R_MCE_SETTINGS_MAIL_TITLE_TITLEDEFAULT,
       
   787                            iEikonEnv );
       
   788         dlg->SetSettingTextL( *titleText );
       
   789         CleanupStack::PopAndDestroy( titleText );
       
   790         }
       
   791     else if ( iMessageType == KSenduiMtmSyncMLEmailUid )
       
   792         {
       
   793         // syncML
       
   794         HBufC* titleText = StringLoader::LoadLC(
       
   795                            R_MCE_SETTINGS_MAIL_TITLE_TITLEDEFAULT,
       
   796                            iEikonEnv );
       
   797         dlg->SetSettingTextL( *titleText );
       
   798         CleanupStack::PopAndDestroy( titleText );
       
   799         }
       
   800     else
       
   801         {
       
   802         // not email/syncML
       
   803         dlg->SetSettingTextL( mtmName );
       
   804         }
       
   805 
       
   806     CleanupStack::Pop( dlg );
       
   807 
       
   808     if ( dlg->ExecuteLD( CAknSettingPage::EUpdateWhenChanged ) )
       
   809         {
       
   810         if ( iProductIncludesSelectableEmail )
       
   811             {
       
   812             id = (*sel)[currentItem].iUid.iUid;
       
   813             }
       
   814         else
       
   815             {
       
   816             id = iMailboxArray[currentItem];
       
   817             }
       
   818         CMsvSession& session = iManager.Session();
       
   819         TMsvEntry entry;
       
   820         TMsvId serviceid;
       
   821         if ( session.GetEntry( id, serviceid, entry ) == KErrNone )
       
   822             {
       
   823             // idTemp is used only if iProductIncludesSelectableEmail
       
   824             TInt idTemp = entry.Id();
       
   825             MsvUiServiceUtilitiesInternal::SetDefaultServiceForMTML(
       
   826                                            session, entry.iMtm, id );
       
   827 
       
   828             // set related service's default too...
       
   829             if ( session.GetEntry(
       
   830                     entry.iRelatedId, serviceid, entry ) == KErrNone )
       
   831                 {
       
   832                 MsvUiServiceUtilitiesInternal::SetDefaultServiceForMTML(
       
   833                                                session, entry.iMtm, entry.Id() );
       
   834                 }
       
   835 
       
   836             if( iProductIncludesSelectableEmail &&
       
   837                     ( ( entry.iMtm == KSenduiMtmImap4Uid ) ||
       
   838                             ( entry.iMtm == KSenduiMtmPop3Uid ) ||
       
   839                             ( entry.iMtm == KSenduiMtmSmtpUid ) ) )
       
   840                 {		               
       
   841                 CRepository* repository = NULL;
       
   842                 TRAPD( ret, repository =
       
   843                 CRepository::NewL( KCRUidSelectableDefaultEmailSettings  ) );
       
   844                 CleanupStack::PushL( repository );
       
   845 
       
   846                 if ( ret == KErrNone )
       
   847                     {
       
   848                     TInt value = entry.Id();
       
   849                     repository->Set( KSelectableDefaultMailAccount , idTemp );
       
   850                     }
       
   851                 CleanupStack::PopAndDestroy( repository );		
       
   852                 } // iProductIncludesSelectableEmail
       
   853             }               
       
   854         SetAccountInUseL();
       
   855 
       
   856         CEikTextListBox* list = STATIC_CAST( CEikTextListBox*, 
       
   857                 Control( EMceSettingsMultipleServicesDialogChoiceList ) );
       
   858         list->DrawDeferred();
       
   859         }
       
   860 
       
   861     CleanupStack::PopAndDestroy( items );       
       
   862 
       
   863     if ( iProductIncludesSelectableEmail )
       
   864         {
       
   865         CleanupStack::PopAndDestroy( sel );
       
   866         }
       
   867     }
       
   868 
       
   869 // ---------------------------------------------------------------------------
       
   870 // CMceSettingsMultipleServicesDialog::LaunchDialogL()
       
   871 // ---------------------------------------------------------------------------
       
   872 //
       
   873 void CMceSettingsMultipleServicesDialog::LaunchDialogL( 
       
   874     MMceSettingsAccountManager& aManager, 
       
   875     const TUid& aMessageType, 
       
   876     CMsvSession& aSession,
       
   877     const TInt& aMenuResource,
       
   878     const TInt& aDialogResource )
       
   879     {
       
   880     // if mtm supports account creation then open new dialog to 
       
   881     // handle many accounts
       
   882     CMceSettingsMultipleServicesDialog* mailDlg =
       
   883         new( ELeave ) CMceSettingsMultipleServicesDialog( 
       
   884         aManager, aMessageType, &aSession );
       
   885     CleanupStack::PushL( mailDlg );
       
   886     mailDlg->ConstructL();
       
   887     static_cast<CAknDialog*>( mailDlg )->ConstructL( aMenuResource );
       
   888     CleanupStack::Pop( mailDlg );
       
   889     mailDlg->ExecuteLD( aDialogResource );    
       
   890     }
       
   891 
       
   892 // ----------------------------------------------------
       
   893 // CMceSettingsMultipleServicesDialog::EditServicesL
       
   894 // ----------------------------------------------------
       
   895 void CMceSettingsMultipleServicesDialog::EditServicesL()
       
   896     {
       
   897     CUidNameArray* sel = iManager.MtmAccountsL( iMessageType );
       
   898     UpdateMailboxDataL();
       
   899     iSubDialogForceClosed = ETrue;
       
   900     
       
   901     if ( ( iNumberOfMailboxes < KMceMaxNumberOfMailboxes ) &&
       
   902          ( iMailboxArray.Count() == 0 ) )
       
   903         {
       
   904         delete sel;
       
   905         if ( HandleNoMailboxesL() && ( iSubDialogForceClosed == TRUE ) )
       
   906             {    	    
       
   907 			if( iMceIntegration )
       
   908 				{
       
   909             	if ( iS60WizLaunched )
       
   910                 	{
       
   911                 	iS60WizLaunched = EFalse;
       
   912                     EditServicesL();
       
   913                 	}
       
   914 				} // iMceIntegration
       
   915 			else
       
   916 				{
       
   917             	EditServicesL();
       
   918                 }
       
   919             }
       
   920         return;
       
   921         }
       
   922     delete sel;
       
   923     if ( iProductIncludesSelectableEmail )
       
   924         {
       
   925         CEikTextListBox* list = STATIC_CAST( CEikTextListBox*,
       
   926                 Control( EMceSettingsMultipleServicesDialogChoiceList ) );
       
   927         list->DrawDeferred();
       
   928 
       
   929         SetAccountInUseL();
       
   930         SetMSKButtonL();
       
   931         }
       
   932     else // iProductIncludesSelectableEmail
       
   933         {
       
   934         CMceSettingsMtmServicesDialog* dlg =
       
   935         new( ELeave ) CMceSettingsMtmServicesDialog( iMessageType,
       
   936                                                      iManager,
       
   937                                                      iSession,
       
   938                                                      *this );
       
   939     CleanupStack::PushL( dlg );
       
   940     dlg->ConstructL( R_MCE_SETTINGS_MTM_SERVICES_DIALOG_MENUBAR );
       
   941     CleanupStack::Pop( dlg );
       
   942 
       
   943     CleanupStack::PushL( TCleanupItem( ResetMtmServicesDialog, this ) );
       
   944     iSubDialogOpen = ETrue;
       
   945     dlg->ExecuteLD( R_MCE_SETTINGS_MTM_SERVICES_DIALOG );
       
   946     CleanupStack::Pop(); //ResetMtmServicesDialog
       
   947     iSubDialogOpen = EFalse;
       
   948     
       
   949     if ( iSubDialogForceClosed == TRUE )
       
   950         {
       
   951         SetAccountInUseL();    
       
   952 
       
   953         CEikTextListBox* list=STATIC_CAST( CEikTextListBox*, 
       
   954                                                                     Control( EMceSettingsMultipleServicesDialogChoiceList ) );
       
   955         list->SetCurrentItemIndex( 0 );
       
   956         list->DrawDeferred();
       
   957         SetMSKButtonL();
       
   958         }
       
   959         }
       
   960     }
       
   961 
       
   962 // ----------------------------------------------------
       
   963 // CMceSettingsMultipleServicesDialog::HandleNoMailboxesL
       
   964 // ----------------------------------------------------
       
   965 TBool CMceSettingsMultipleServicesDialog::HandleNoMailboxesL()
       
   966     {
       
   967     //Deny creating new mail account if TARM is active.
       
   968     if( !iEmailApi->IsEmailFeatureSupportedL( 
       
   969         CImumInternalApi::EMailLockedSettings, R_QTN_SELEC_PROTECTED_SETTING ) )
       
   970         {
       
   971         CAknQueryDialog* confDialog = CAknQueryDialog::NewL();
       
   972 
       
   973         THumanReadableName mtmName = iManager.MtmName( iMessageType );
       
   974         
       
   975         if ( iMessageType == KSenduiMtmSyncMLEmailUid )
       
   976             {
       
   977             // syncML
       
   978             HBufC* text = StringLoader::LoadLC( 
       
   979             R_MCE_SETTINGS_SMAIL_NEW, iEikonEnv );               
       
   980             confDialog->SetPromptL( *text );
       
   981             CleanupStack::PopAndDestroy( text ); // text        
       
   982             }
       
   983         else if ( iMessageType != KSenduiMtmSmtpUid )
       
   984             {
       
   985             // not email/SyncML
       
   986             HBufC* text = StringLoader::LoadLC( 
       
   987             R_MCE_MTM_CREATE_NEW, mtmName, iEikonEnv );               
       
   988             confDialog->SetPromptL( *text );
       
   989             CleanupStack::PopAndDestroy( text ); // text
       
   990             }
       
   991         else
       
   992             {        
       
   993             // if KSenduiMtmSmtpUid, the confDialog text has been set in
       
   994             // R_MCE_SETTINGS_CREATE_NEW_MBOX_CONFIRMATION
       
   995             }
       
   996 
       
   997         if ( confDialog->ExecuteLD(
       
   998                 R_MCE_SETTINGS_CREATE_NEW_MBOX_CONFIRMATION ) )
       
   999             {
       
  1000             if( iMceIntegration )
       
  1001                 {
       
  1002                 // In MCE wizard integration's case this return value
       
  1003                 // is not used
       
  1004                 return LaunchWizardL();
       
  1005                 }
       
  1006             else // iMceIntegration
       
  1007                 {
       
  1008                 return iManager.CreateNewAccountL(
       
  1009                         iMessageType, KMsvNullIndexEntryId );
       
  1010                 } // iMceIntegration
       
  1011             }
       
  1012         }
       
  1013     return EFalse;
       
  1014     }
       
  1015 // ----------------------------------------------------
       
  1016 // CMceSettingsMultipleServicesDialog::CreateNewImapPopL
       
  1017 // ----------------------------------------------------
       
  1018 TBool CMceSettingsMultipleServicesDialog::CreateNewImapPopL()
       
  1019     {
       
  1020     TBool ret;
       
  1021     if( iMceIntegration )
       
  1022         {
       
  1023         // In MCE wizard integration's case this return value is not used
       
  1024         // just resetting this boolean to its original value
       
  1025         ret = LaunchWizardL();     
       
  1026         iS60WizLaunched = EFalse;  
       
  1027         }
       
  1028     else
       
  1029         {
       
  1030         ret = iManager.CreateNewAccountL(
       
  1031                 iMessageType, KMsvNullIndexEntryId );
       
  1032         }
       
  1033     return ret;
       
  1034     }
       
  1035 
       
  1036 
       
  1037 // ----------------------------------------------------
       
  1038 // CMceSettingsMultipleServicesDialog::LaunchWizardL
       
  1039 // ----------------------------------------------------
       
  1040 TBool CMceSettingsMultipleServicesDialog::LaunchWizardL()
       
  1041     {
       
  1042     TBool ret;
       
  1043     // launch S60 wizard
       
  1044     iS60WizLaunched = ETrue;
       
  1045     ret = iManager.CreateNewAccountL(
       
  1046             iMessageType, KMsvNullIndexEntryId );
       
  1047     return ret;
       
  1048     }
       
  1049 
       
  1050 // ----------------------------------------------------
       
  1051 // CMceSettingsMultipleServicesDialog::SetAccountInUseL
       
  1052 // ----------------------------------------------------
       
  1053 void CMceSettingsMultipleServicesDialog::SetAccountInUseL()
       
  1054     {
       
  1055     TMsvId id = MsvUiServiceUtilitiesInternal::DefaultServiceForMTML(
       
  1056         iManager.Session(),
       
  1057         iMessageType,
       
  1058         ETrue );
       
  1059 
       
  1060     if( iProductIncludesSelectableEmail )
       
  1061         {
       
  1062         // Get all healthy mailbox array, especially necessary after a new
       
  1063         // account is created while there are invalid email accounts.
       
  1064         if ( !iEmailApi )
       
  1065             {
       
  1066             iEmailApi = CreateEmailApiL( iSession );
       
  1067             }
       
  1068 
       
  1069         const MImumInHealthServices* healthApi =
       
  1070         &iEmailApi->HealthServicesL();
       
  1071 
       
  1072         TInt error;
       
  1073         iMailboxArray.Reset();
       
  1074         if ( iMessageType == KSenduiMtmSyncMLEmailUid )
       
  1075             {
       
  1076             error = MceSettingsUtils::GetHealthyMailboxListL( *healthApi,
       
  1077                                                               iMailboxArray,
       
  1078                                                               EFalse,
       
  1079                                                               EFalse,
       
  1080                                                               ETrue,EFalse );
       
  1081             }
       
  1082         else
       
  1083             {
       
  1084             error = MceSettingsUtils::GetHealthyMailboxListL( *healthApi,
       
  1085                                                               iMailboxArray,
       
  1086                                                               ETrue,
       
  1087                                                               ETrue,
       
  1088                                                               EFalse,ETrue );
       
  1089             }
       
  1090 
       
  1091         CRepository* repository = NULL;
       
  1092         TRAPD( ret, repository = CRepository::NewL(
       
  1093                                  KCRUidSelectableDefaultEmailSettings  ) );
       
  1094         CleanupStack::PushL( repository );
       
  1095         TInt val;
       
  1096         THumanReadableName mtmName;
       
  1097         TMsvEntry entryMail;
       
  1098         TBool nameGet = EFalse;
       
  1099         TBool setDefault( EFalse );
       
  1100         if ( ret == KErrNone && iMessageType != KSenduiMtmSyncMLEmailUid )
       
  1101             {
       
  1102             if ( repository->Get(
       
  1103                     KSelectableDefaultMailAccount , val ) == KErrNone )
       
  1104                 {
       
  1105                 id = val;
       
  1106                 TMsvId serviceId;
       
  1107                 TInt err = iSession->GetEntry( id, serviceId, entryMail );
       
  1108                 CMtmUiDataRegistry* uiRegistry =
       
  1109                     CMtmUiDataRegistry::NewL( *iSession );
       
  1110                 CleanupStack::PushL( uiRegistry );
       
  1111                 TUid mailMTMTechType =
       
  1112                     uiRegistry->TechnologyTypeUid( KUidMsgTypePOP3 );
       
  1113 
       
  1114                 // Need check if the mailbox is healthy.
       
  1115                 if ( ( healthApi->IsMailboxHealthy( entryMail.Id() ) || 
       
  1116                      ( ( entryMail.iType == KUidMsvServiceEntry) && 
       
  1117                        ( entryMail.Id() != KMsvLocalServiceIndexEntryId ) && 
       
  1118                        ( !MuiuEmailTools::IsMailMtm(
       
  1119                          entryMail.iMtm, ETrue ) ) ) )
       
  1120                          && err == KErrNone
       
  1121                          && ( entryMail.Visible() ||
       
  1122                          uiRegistry->TechnologyTypeUid( entryMail.iMtm )
       
  1123                          == mailMTMTechType ) )
       
  1124                     {
       
  1125                     mtmName.Append( entryMail.iDetails );
       
  1126                     nameGet = ETrue;
       
  1127                     }
       
  1128                 else
       
  1129                     {
       
  1130                     err = iSession->GetEntry(
       
  1131                             entryMail.iRelatedId, serviceId, entryMail );
       
  1132                     if ( ( healthApi->IsMailboxHealthy( entryMail.Id() ) || 
       
  1133                          ( ( entryMail.iType == KUidMsvServiceEntry) && 
       
  1134                            ( entryMail.Id() != KMsvLocalServiceIndexEntryId )
       
  1135                              && ( !MuiuEmailTools::IsMailMtm(
       
  1136                              entryMail.iMtm, ETrue ) ) ) )
       
  1137                              && err == KErrNone 
       
  1138                              && ( entryMail.Visible() ||
       
  1139                              uiRegistry->TechnologyTypeUid( entryMail.iMtm )
       
  1140                              == mailMTMTechType ) )
       
  1141                         {
       
  1142                         mtmName.Append( entryMail.iDetails );
       
  1143                         nameGet = ETrue;
       
  1144                         }
       
  1145                     }
       
  1146                 CleanupStack::PopAndDestroy( uiRegistry );
       
  1147 
       
  1148                 // If it cannot get the default account and there is a
       
  1149                 // healthy mailbox created by user, then the mailbox should
       
  1150                 // be set as default.
       
  1151                 if ( !nameGet && iMailboxArray.Count() != 0 )
       
  1152                     {
       
  1153                     id = iMailboxArray[0];
       
  1154                     CMsvSession& session = iManager.Session();
       
  1155                     TMsvEntry entry;
       
  1156                     TMsvId serviceid;
       
  1157                     if ( session.GetEntry( id, serviceid, entry ) == KErrNone
       
  1158                             && ( entry.iMtm == KSenduiMtmImap4Uid
       
  1159                             || entry.iMtm == KSenduiMtmPop3Uid 
       
  1160                             || entry.iMtm == KSenduiMtmSmtpUid ) )
       
  1161                         {
       
  1162                         setDefault = ETrue;
       
  1163                         mtmName.Append( entry.iDetails );
       
  1164                         nameGet = ETrue;
       
  1165 
       
  1166                         TInt idTemp = entry.Id();
       
  1167                         MsvUiServiceUtilitiesInternal::
       
  1168                         SetDefaultServiceForMTML( session, entry.iMtm, id );
       
  1169 
       
  1170                         // set related service's default too...
       
  1171                         if ( session.GetEntry(
       
  1172                                 entry.iRelatedId, serviceid, entry ) == KErrNone )
       
  1173                             {
       
  1174                             MsvUiServiceUtilitiesInternal::
       
  1175                             SetDefaultServiceForMTML( session, entry.iMtm, entry.Id() );
       
  1176                             }
       
  1177 
       
  1178                         // Set default mailbox.
       
  1179                         repository->Set( KSelectableDefaultMailAccount ,idTemp );                    
       
  1180                         }
       
  1181                     }
       
  1182                 }
       
  1183             }
       
  1184         CleanupStack::PopAndDestroy( repository );
       
  1185         iMailboxArray.Reset();
       
  1186 
       
  1187         HBufC* mailboxInUseListBoxText = NULL;
       
  1188         TMsvEntry mailboxEntry;
       
  1189         TMsvId serviceId; // not used but needed by GetEntry function
       
  1190 
       
  1191         if(!nameGet)
       
  1192             {
       
  1193             THumanReadableName mtmName = iManager.MtmName( iMessageType );
       
  1194             }
       
  1195 
       
  1196         if ( id != KMsvUnknownServiceIndexEntryId
       
  1197              && iManager.Session().GetEntry( id, serviceId, mailboxEntry )
       
  1198              == KErrNone
       
  1199              && ( healthApi->IsMailboxHealthy( mailboxEntry.Id() ) || 
       
  1200              ( ( mailboxEntry.iType == KUidMsvServiceEntry ) && 
       
  1201              ( mailboxEntry.Id() != KMsvLocalServiceIndexEntryId ) && 
       
  1202              ( !MuiuEmailTools::IsMailMtm( mailboxEntry.iMtm, ETrue ) ) ) ) )
       
  1203             {
       
  1204             TInt mailboxNameLength;
       
  1205             if(!nameGet)
       
  1206                 {
       
  1207                 mailboxNameLength = mailboxEntry.iDetails.Left(
       
  1208                         KMceSettingsMailboxTextLength ).Length();
       
  1209                 }
       
  1210             else
       
  1211                 {
       
  1212                 mailboxNameLength =	entryMail.iDetails.Left(
       
  1213                         KMceSettingsMailboxTextLength ).Length();
       
  1214                 }
       
  1215 
       
  1216             HBufC* mailboxInUseDefaultText = NULL;
       
  1217 
       
  1218             if ( iMessageType == KSenduiMtmSmtpUid )
       
  1219                 {
       
  1220                 //remote mailboxes
       
  1221                 mailboxInUseDefaultText = StringLoader::LoadLC(
       
  1222                                           R_MCE_SETTINGS_MAIL_DEFAULT, iEikonEnv );
       
  1223                 }
       
  1224             else if ( iMessageType == KSenduiMtmSyncMLEmailUid )
       
  1225                 {
       
  1226                 //syncML remote mailboxes
       
  1227                 mailboxInUseDefaultText = StringLoader::LoadLC(
       
  1228                                           R_MCE_SETTINGS_SYNCMAIL_INUSE, iEikonEnv );
       
  1229                 }
       
  1230             else
       
  1231                 {
       
  1232                 mailboxInUseDefaultText = StringLoader::LoadLC(
       
  1233                                           R_MCE_MTM_IN_USE, mtmName, iEikonEnv );
       
  1234                 }
       
  1235 
       
  1236             mailboxInUseListBoxText = HBufC::NewLC(
       
  1237                 mailboxInUseDefaultText->Length() + mailboxNameLength );
       
  1238 
       
  1239             mailboxInUseListBoxText->Des().Copy( *mailboxInUseDefaultText );
       
  1240             if ( !nameGet )
       
  1241                 {
       
  1242                 mailboxInUseListBoxText->Des().Append(
       
  1243                         mailboxEntry.iDetails.Left( mailboxNameLength ) );
       
  1244                 }
       
  1245             else
       
  1246                 {
       
  1247                 if ( setDefault )
       
  1248                     {
       
  1249                     mailboxInUseListBoxText->Des().Append(
       
  1250                             mtmName.Left( mailboxNameLength ) );
       
  1251                     }
       
  1252                 else
       
  1253                     {
       
  1254                     mailboxInUseListBoxText->Des().Append(
       
  1255                             entryMail.iDetails.Left( mailboxNameLength ) );
       
  1256                     }
       
  1257                 }
       
  1258 
       
  1259             CleanupStack::Pop( mailboxInUseListBoxText );
       
  1260             CleanupStack::PopAndDestroy( mailboxInUseDefaultText );
       
  1261             }
       
  1262         else
       
  1263             {
       
  1264             if ( iMessageType == KSenduiMtmSmtpUid )
       
  1265                 {
       
  1266                 //remote mailboxes
       
  1267                 mailboxInUseListBoxText = StringLoader::LoadL(
       
  1268                                           R_MCE_SETTINGS_MAIL_DEFAULT_IN_USE_NONE, iEikonEnv );
       
  1269                 }
       
  1270             else if ( iMessageType == KSenduiMtmSyncMLEmailUid )
       
  1271                 {
       
  1272                 //syncML remote mailboxes
       
  1273                 mailboxInUseListBoxText = StringLoader::LoadL(
       
  1274                                           R_MCE_SETTINGS_SYNCMAIL_INUSE_NONE, iEikonEnv );
       
  1275                 }
       
  1276             else
       
  1277                 {
       
  1278                 mailboxInUseListBoxText = StringLoader::LoadL( 
       
  1279                                           R_MCE_MTM_IN_USE_NONE, mtmName, iEikonEnv );  
       
  1280                 }        
       
  1281             }
       
  1282 
       
  1283         if ( iSettingsItemArray->Count() > 1 )
       
  1284             {
       
  1285             // delete dummy item because we are adding 'real' item below
       
  1286             iSettingsItemArray->Delete(
       
  1287                     KMceSettingsRemoteMailboxInUseSelectableEmailInUse );
       
  1288             }
       
  1289 
       
  1290         CleanupStack::PushL( mailboxInUseListBoxText );
       
  1291         iSettingsItemArray->InsertL( 0, *mailboxInUseListBoxText );
       
  1292         CleanupStack::PopAndDestroy( mailboxInUseListBoxText );
       
  1293 
       
  1294         }
       
  1295     else // iProductIncludesSelectableEmail
       
  1296         {
       
  1297         HBufC* mailboxInUseListBoxText = NULL;
       
  1298     TMsvEntry mailboxEntry;
       
  1299     TMsvId serviceId; // not used but needed by GetEntry function
       
  1300     
       
  1301     THumanReadableName mtmName = iManager.MtmName( iMessageType );
       
  1302 
       
  1303     if ( id != KMsvUnknownServiceIndexEntryId &&
       
  1304          iManager.Session().GetEntry( id, serviceId, mailboxEntry ) == KErrNone )
       
  1305         {
       
  1306         const TInt mailboxNameLength =
       
  1307             mailboxEntry.iDetails.Left( KMceSettingsMailboxTextLength ).Length();
       
  1308 
       
  1309         HBufC* mailboxInUseDefaultText = NULL;
       
  1310         
       
  1311         if ( iMessageType == KSenduiMtmSmtpUid )
       
  1312             {
       
  1313             //remote mailboxes
       
  1314             mailboxInUseDefaultText = StringLoader::LoadLC(
       
  1315                 R_MCE_SETTINGS_MAIL_RM_IN_USE, iEikonEnv );            
       
  1316             }
       
  1317         else if ( iMessageType == KSenduiMtmSyncMLEmailUid )
       
  1318             {
       
  1319             //syncML remote mailboxes
       
  1320             mailboxInUseDefaultText = StringLoader::LoadLC(
       
  1321                 R_MCE_SETTINGS_SYNCMAIL_INUSE, iEikonEnv );            
       
  1322             }
       
  1323         else
       
  1324             {
       
  1325             mailboxInUseDefaultText = StringLoader::LoadLC( 
       
  1326                 R_MCE_MTM_IN_USE, mtmName, iEikonEnv );            
       
  1327             }
       
  1328 
       
  1329         mailboxInUseListBoxText = HBufC::NewLC(
       
  1330             mailboxInUseDefaultText->Length() + mailboxNameLength );
       
  1331 
       
  1332         mailboxInUseListBoxText->Des().Copy( *mailboxInUseDefaultText );
       
  1333         mailboxInUseListBoxText->Des().Append(
       
  1334             mailboxEntry.iDetails.Left( mailboxNameLength ) );
       
  1335 
       
  1336         CleanupStack::Pop( mailboxInUseListBoxText );
       
  1337         CleanupStack::PopAndDestroy( mailboxInUseDefaultText );
       
  1338         }
       
  1339     else
       
  1340         {
       
  1341         if ( iMessageType == KSenduiMtmSmtpUid )
       
  1342             {
       
  1343             //remote mailboxes
       
  1344             mailboxInUseListBoxText = StringLoader::LoadL( 
       
  1345                                                             R_MCE_SETTINGS_MAIL_RM_IN_USE_NONE, 
       
  1346                                                             iEikonEnv );
       
  1347             }
       
  1348         else if ( iMessageType == KSenduiMtmSyncMLEmailUid )
       
  1349             {
       
  1350             //syncML remote mailboxes
       
  1351             mailboxInUseListBoxText = StringLoader::LoadL( 
       
  1352                                                             R_MCE_SETTINGS_SYNCMAIL_INUSE_NONE, 
       
  1353                                                             iEikonEnv );
       
  1354             }
       
  1355         else
       
  1356             {
       
  1357             mailboxInUseListBoxText = StringLoader::LoadL( 
       
  1358                 R_MCE_MTM_IN_USE_NONE, mtmName, iEikonEnv );  
       
  1359             }        
       
  1360         }
       
  1361 
       
  1362     if ( iSettingsItemArray->Count() > 1 )
       
  1363         {
       
  1364         // delete dummy item because we are adding 'real' item below
       
  1365         iSettingsItemArray->Delete( KMceSettingsRemoteMailboxInUse );
       
  1366         }
       
  1367 
       
  1368     CleanupStack::PushL( mailboxInUseListBoxText );
       
  1369     iSettingsItemArray->AppendL( *mailboxInUseListBoxText );
       
  1370     CleanupStack::PopAndDestroy( mailboxInUseListBoxText );
       
  1371         }
       
  1372     }
       
  1373 
       
  1374 // ----------------------------------------------------
       
  1375 // CMceSettingsMultipleServicesDialog::HandleSessionEventL
       
  1376 // ----------------------------------------------------
       
  1377 void CMceSettingsMultipleServicesDialog::HandleSessionEventL(
       
  1378     TMsvSessionEvent aEvent, TAny* aArg1, TAny* aArg2, TAny* /*aArg3*/)
       
  1379     {
       
  1380     switch ( aEvent )
       
  1381         {
       
  1382         case EMsvEntriesCreated:
       
  1383             if ( KMsvRootIndexEntryId == (*(TMsvId*) (aArg2)) )
       
  1384                 {                
       
  1385                 HandleEntriesCreatedL( (CMsvEntrySelection*) aArg1 );               
       
  1386 				if( iProductIncludesSelectableEmail )
       
  1387 					{
       
  1388                 	UpdateServicesArrayL();
       
  1389 					}
       
  1390                 }
       
  1391             break;
       
  1392         case EMsvEntriesChanged:
       
  1393         case EMsvEntriesDeleted:
       
  1394         case EMsvMediaAvailable:
       
  1395             UpdateMailboxDataL();           
       
  1396         default:
       
  1397             // just ignore
       
  1398             break;
       
  1399         }
       
  1400     }
       
  1401 
       
  1402 // ----------------------------------------------------
       
  1403 // CMceSettingsMultipleServicesDialog::HandleEntriesCreatedL
       
  1404 // ----------------------------------------------------
       
  1405 void CMceSettingsMultipleServicesDialog::HandleEntriesCreatedL( CMsvEntrySelection* aSelection )
       
  1406     {     
       
  1407     UpdateMailboxDataL();   
       
  1408     if ( aSelection->Count() )
       
  1409         {
       
  1410         TMsvEntry currentEntry;
       
  1411         TMsvId serviceId; // not used here but needed by GetEntry function
       
  1412         if ( iManager.Session().GetEntry( aSelection->At( 0 ), serviceId, currentEntry ) == KErrNone
       
  1413                 && currentEntry.iType == KUidMsvServiceEntry 
       
  1414                 && currentEntry.iMtm == iMessageType )
       
  1415             {
       
  1416             SetAccountInUseL();
       
  1417             }
       
  1418 	CEikTextListBox* list = STATIC_CAST( CEikTextListBox*, 
       
  1419 	                                 Control( EMceSettingsMultipleServicesDialogChoiceList ) );
       
  1420 	list->DrawDeferred();
       
  1421         }
       
  1422     }
       
  1423 
       
  1424 // ----------------------------------------------------
       
  1425 // CMceSettingsMultipleServicesDialog::HandleListBoxEventL
       
  1426 // ----------------------------------------------------
       
  1427 void CMceSettingsMultipleServicesDialog::HandleListBoxEventL(
       
  1428     CEikListBox* /*aListBox*/,
       
  1429     TListBoxEvent aEventType )
       
  1430     {
       
  1431     CEikTextListBox* list = STATIC_CAST( CEikTextListBox*, 
       
  1432                                         Control( EMceSettingsMultipleServicesDialogChoiceList ) );
       
  1433     switch( aEventType )
       
  1434         {
       
  1435         case EEventEnterKeyPressed:
       
  1436         case EEventItemSingleClicked:
       
  1437 			if ( iProductIncludesSelectableEmail )
       
  1438 				{
       
  1439 	            if ( list->CurrentItemIndex() == 0 )
       
  1440     	            {
       
  1441                 	ProcessCommandL( EMceSettingsCmdSettingsDialogChange );                
       
  1442                 	}
       
  1443             	else
       
  1444                 	{
       
  1445 					ProcessCommandL( EMceSettingsCmdSettingsDialogOpen );
       
  1446                 	}
       
  1447                 }
       
  1448             else // iProductIncludesSelectableEmail
       
  1449             	{
       
  1450 	            if ( list->CurrentItemIndex() == 0 )
       
  1451 					{
       
  1452                 	ProcessCommandL( EMceSettingsCmdSettingsDialogOpen );
       
  1453                 	}
       
  1454             	else
       
  1455                 	{
       
  1456                 	ProcessCommandL( EMceSettingsCmdSettingsDialogChange );
       
  1457                 	}
       
  1458                 }
       
  1459         break;
       
  1460         case EEventItemDraggingActioned:
       
  1461             SetMSKButtonL();
       
  1462         break;
       
  1463         default:
       
  1464         break;
       
  1465         }
       
  1466     }
       
  1467 
       
  1468 // ----------------------------------------------------
       
  1469 // CMceSettingsMultipleServicesDialog::GetHelpContext
       
  1470 // returns helpcontext as aContext
       
  1471 //
       
  1472 // ----------------------------------------------------
       
  1473 void CMceSettingsMultipleServicesDialog::GetHelpContext
       
  1474         ( TCoeHelpContext& aContext ) const
       
  1475     {
       
  1476     aContext.iMajor = KMceApplicationUid;
       
  1477 	if ( iProductIncludesSelectableEmail )
       
  1478 	    {
       
  1479 	    CEikTextListBox* list = STATIC_CAST(
       
  1480 	            CEikTextListBox*,
       
  1481 	            Control( EMceSettingsMultipleServicesDialogChoiceList ) );       
       
  1482 
       
  1483 	    if ( list->CurrentItemIndex() ==
       
  1484 	    KMceSettingsRemoteMailboxInUseSelectableEmailInUse )
       
  1485 	        {
       
  1486 	        aContext.iContext = KES_HLP_EMAIL_SETTING;
       
  1487 	        }
       
  1488 	    else
       
  1489 	        {
       
  1490 	        // start        	
       
  1491 	        TUid mtmType;
       
  1492 	        TInt item = list->CurrentItemIndex();      	        		
       
  1493 	        CMsvEntry* entry = NULL;
       
  1494 
       
  1495 	        TRAPD( error, entry = iSession->GetEntryL(
       
  1496 	                (*iAccountArray)[item-1].iUid.iUid )); 
       
  1497 
       
  1498 	        if ( entry )
       
  1499 	            {
       
  1500 	            TMsvEntry tentry = entry->Entry();
       
  1501 	            mtmType = tentry.iMtm;
       
  1502 	            delete entry;            		
       
  1503 
       
  1504 	            if ( ( mtmType != KSenduiMtmImap4Uid ) &&
       
  1505 	                    ( mtmType != KSenduiMtmPop3Uid ) )
       
  1506 	                {
       
  1507 	                aContext.iContext = KES_HLP_THIRDPARTY_MAILBOX;
       
  1508 	                }
       
  1509 	            else
       
  1510 	                {
       
  1511 	                aContext.iContext = KES_HLP_SMTP_MAILBOX;
       
  1512 	                }						              		
       
  1513 	            }
       
  1514 	        }
       
  1515 	    }
       
  1516 	else // iProductIncludesSelectableEmail
       
  1517 	    { 
       
  1518     if ( iMessageType == KSenduiMtmSyncMLEmailUid )
       
  1519         {
       
  1520         aContext.iContext = KMCE_HLP_SETT_SMAILBOX/*KMCE_HLP_SETTINGS_SMAIL*/;
       
  1521         }
       
  1522     else
       
  1523         {
       
  1524         aContext.iContext = KMCE_HLP_SETTINGS_EMAIL;
       
  1525         } 
       
  1526     }
       
  1527 	}
       
  1528 
       
  1529 // ----------------------------------------------------
       
  1530 // CMceSettingsMultipleServicesDialog::LaunchHelpL
       
  1531 // Launch help using context
       
  1532 // 
       
  1533 // ----------------------------------------------------
       
  1534 void CMceSettingsMultipleServicesDialog::LaunchHelpL() const
       
  1535     { 
       
  1536     CCoeAppUi* appUi = STATIC_CAST( CCoeAppUi*, ControlEnv()->AppUi() );       
       
  1537     CArrayFix<TCoeHelpContext>* helpContext = appUi->AppHelpContextL();   
       
  1538     HlpLauncher::LaunchHelpApplicationL( iEikonEnv->WsSession(), helpContext );
       
  1539     }
       
  1540 
       
  1541 
       
  1542 // ----------------------------------------------------
       
  1543 // CMceSettingsMultipleServicesDialog::ResetMtmServicesDialog
       
  1544 // Sets the flag to indicate that the MTM services subdialog
       
  1545 // is not open
       
  1546 // ----------------------------------------------------
       
  1547 void CMceSettingsMultipleServicesDialog::ResetMtmServicesDialog( TAny* aAny )
       
  1548     {
       
  1549     CMceSettingsMultipleServicesDialog* serviceDialog = ( CMceSettingsMultipleServicesDialog*)aAny;
       
  1550     serviceDialog->iSubDialogOpen = EFalse;
       
  1551     }
       
  1552 
       
  1553 // ----------------------------------------------------
       
  1554 // CMceSettingsMultipleServicesDialog::OfferKeyEventL
       
  1555 // Handles this setting dialog view's arrow keys.
       
  1556 // Forwards other keys.
       
  1557 //
       
  1558 // ----------------------------------------------------
       
  1559 TKeyResponse CMceSettingsMultipleServicesDialog::OfferKeyEventL(
       
  1560                                                 const TKeyEvent& aKeyEvent,
       
  1561                                                 TEventCode aType )
       
  1562     {
       
  1563     if ( aType == EEventKey &&
       
  1564          ( aKeyEvent.iCode==EKeyUpArrow || aKeyEvent.iCode==EKeyDownArrow ) )
       
  1565         {
       
  1566         CEikTextListBox* list=STATIC_CAST(
       
  1567                         CEikTextListBox*,
       
  1568                         Control( EMceSettingsMultipleServicesDialogChoiceList ) );
       
  1569         list->OfferKeyEventL( aKeyEvent, aType );        
       
  1570         SetMSKButtonL();
       
  1571         return EKeyWasConsumed;
       
  1572         }    
       
  1573     return CAknDialog::OfferKeyEventL( aKeyEvent, aType );
       
  1574     }
       
  1575 
       
  1576 // ----------------------------------------------------
       
  1577 // CMceSettingsMultipleServicesDialog::SetMSKButtonL
       
  1578 // Sets the MSK for the view
       
  1579 //
       
  1580 // ----------------------------------------------------
       
  1581 void CMceSettingsMultipleServicesDialog::SetMSKButtonL()
       
  1582     {
       
  1583     CEikTextListBox* list=STATIC_CAST(
       
  1584                     CEikTextListBox*,
       
  1585                     Control( EMceSettingsMultipleServicesDialogChoiceList ) );
       
  1586     const TInt index = list->CurrentItemIndex();
       
  1587     const TInt numberOfItem = list->Model()->NumberOfItems();
       
  1588     TInt resourceId;
       
  1589 	if ( iProductIncludesSelectableEmail )
       
  1590 		{
       
  1591 		 resourceId =
       
  1592 	              index==0 ? R_MCE_MSK_BUTTON_CHANGE : R_MCE_MSK_BUTTON_OPEN;
       
  1593 		}
       
  1594 	else
       
  1595 		{
       
  1596 		resourceId =
       
  1597                   index==0 ? R_MCE_MSK_BUTTON_OPEN : R_MCE_MSK_BUTTON_CHANGE;
       
  1598 		}
       
  1599     CEikButtonGroupContainer& cba = ButtonGroupContainer();
       
  1600     cba.SetCommandL( KMSKPosition, resourceId );
       
  1601     cba.DrawNow();
       
  1602     }
       
  1603 
       
  1604 // ----------------------------------------------------
       
  1605 // CMceSettingsMultipleServicesDialog::SubdialogClosed
       
  1606 // Informs that subdialog has been closed
       
  1607 //
       
  1608 // ----------------------------------------------------
       
  1609 void CMceSettingsMultipleServicesDialog::SubdialogClosed()
       
  1610     {
       
  1611     iSubDialogOpen = EFalse;
       
  1612     iSubDialogForceClosed = EFalse;
       
  1613     }
       
  1614 
       
  1615 // ----------------------------------------------------
       
  1616 CMsvEntrySelection* CMceSettingsMultipleServicesDialog::GetEmailAccountsL(
       
  1617 		CMsvSession& aSession )
       
  1618     {
       
  1619     CMsvEntrySelection* sel = new( ELeave ) CMsvEntrySelection();
       
  1620     CleanupStack::PushL( sel );
       
  1621     CMsvEntry* entry = aSession.GetEntryL( KMsvRootIndexEntryIdValue );
       
  1622     CleanupStack::PushL( entry );
       
  1623     if ( iMceIntegration )
       
  1624     	{
       
  1625     TInt cnt = entry->Count();
       
  1626     if ( cnt != 0 )
       
  1627         {
       
  1628         entry->SetSortTypeL( TMsvSelectionOrdering(
       
  1629         		                KMsvGroupByType | KMsvGroupByStandardFolders,
       
  1630         		                EMsvSortByDetailsReverse, ETrue ) );
       
  1631         const TMsvEntry* tentry;
       
  1632         for ( TInt cc = entry->Count(); --cc >= 0; )
       
  1633            {
       
  1634             tentry = &(*entry)[cc];
       
  1635                 
       
  1636             if ( tentry->iType.iUid == KUidMsvServiceEntryValue &&
       
  1637             	 tentry->Id() != KMsvLocalServiceIndexEntryIdValue )
       
  1638                 {
       
  1639                 const TBool noRelatedId =
       
  1640                                 tentry->iRelatedId == KMsvNullIndexEntryId ||
       
  1641                                 tentry->iRelatedId == tentry->Id();
       
  1642                 
       
  1643                 TBool appendEmail = EFalse;
       
  1644                 
       
  1645                 if ( tentry->Visible() )
       
  1646                     {
       
  1647                     appendEmail = ETrue;
       
  1648                     }
       
  1649                 else
       
  1650                     {
       
  1651                     CMtmUiDataRegistry* uiRegistry =
       
  1652                                        CMtmUiDataRegistry::NewL( *iSession );
       
  1653                     CleanupStack::PushL(uiRegistry);             
       
  1654                     if ( uiRegistry->IsPresent( tentry->iMtm ) &&
       
  1655                     	 uiRegistry->IsPresent( KUidMsgTypePOP3 ) )
       
  1656                         {            
       
  1657                         if( uiRegistry->TechnologyTypeUid( tentry->iMtm ) ==
       
  1658                                                         KSenduiTechnologyMailUid  )
       
  1659                             {
       
  1660                             appendEmail = ETrue;                    
       
  1661                             }
       
  1662                         }
       
  1663                     CleanupStack::PopAndDestroy( uiRegistry );
       
  1664                     }                    
       
  1665                 
       
  1666                 if ( appendEmail )
       
  1667                     {
       
  1668                     // Add this service if:
       
  1669                     // it is visible, or,there is no associated related
       
  1670                     // service, or, we have been asked to list all services.
       
  1671                     sel->AppendL( tentry->Id() );
       
  1672     					}
       
  1673                     }
       
  1674                 }
       
  1675             }
       
  1676         }
       
  1677     CleanupStack::PopAndDestroy( entry );
       
  1678     CleanupStack::Pop( sel );
       
  1679     return sel;
       
  1680     }
       
  1681 
       
  1682 // ----------------------------------------------------
       
  1683 // CMceSettingsMultipleServicesDialog::MtmAccountsL
       
  1684 // ----------------------------------------------------
       
  1685 CUidNameArray* CMceSettingsMultipleServicesDialog::MtmEmailAccountsL()
       
  1686     {
       
  1687     CUidNameArray* accounts = new (ELeave) CUidNameArray(
       
  1688                               KMceSettingsArrayGranularity );
       
  1689     CleanupStack::PushL( accounts );
       
  1690 
       
  1691     CMsvEntrySelection* sel = NULL;
       
  1692 
       
  1693 	sel = GetEmailAccountsL( *iSession );
       
  1694 
       
  1695     CleanupStack::PushL( sel );
       
  1696 
       
  1697     CMsvEntry* rootEntry=CMsvEntry::NewL(
       
  1698         *iSession,
       
  1699         KMsvRootIndexEntryId,
       
  1700         TMsvSelectionOrdering( KMsvNoGrouping, EMsvSortByNone, ETrue ) );
       
  1701 	CleanupStack::PushL( rootEntry );
       
  1702 
       
  1703 	if ( !iEmailApi )
       
  1704         {
       
  1705         iEmailApi = CreateEmailApiL( iSession );
       
  1706         }
       
  1707 
       
  1708    	const MImumInHealthServices* healthApi = &iEmailApi->HealthServicesL();
       
  1709 
       
  1710    	TInt error = MceSettingsUtils::GetHealthyMailboxListL(
       
  1711    			                      *healthApi,
       
  1712         	                      iMailboxArray,
       
  1713 								  iMessageType != KSenduiMtmSyncMLEmailUid,
       
  1714         						  iMessageType != KSenduiMtmSyncMLEmailUid,
       
  1715         				          iMessageType == KSenduiMtmSyncMLEmailUid,ETrue );
       
  1716     if ( error == KErrNone &&
       
  1717             ( iMtmPluginId == 0 || iMessageType == KSenduiMtmSyncMLEmailUid ) )
       
  1718         {
       
  1719         const TInt mailboxArrayCount = iMailboxArray.Count();
       
  1720         TBool foundServiceArray = EFalse;
       
  1721         TMsvId msvId;
       
  1722 
       
  1723         for ( TInt cc = 0; cc < mailboxArrayCount; cc++)
       
  1724             {
       
  1725             msvId = iMailboxArray[cc];
       
  1726 
       
  1727             TMsvEntry tentry2;
       
  1728             TRAPD( err2, ( tentry2 = rootEntry->ChildDataL( msvId ) ) );
       
  1729 
       
  1730             const TInt count = accounts->Count();
       
  1731             TBool foundService = EFalse;
       
  1732             
       
  1733             if ( err2 == KErrNone )
       
  1734                 {
       
  1735                 
       
  1736                 //check that related service is not already added to array
       
  1737                 for ( TInt loop = 0; loop < count; loop ++ )
       
  1738                     {
       
  1739                     if ( tentry2.iRelatedId == iMailboxArray[loop] )
       
  1740                         {
       
  1741                         foundService = ETrue;
       
  1742                         break;
       
  1743                         }
       
  1744                     }
       
  1745                 if ( !foundService )
       
  1746                     {               
       
  1747                     TUid uid;
       
  1748                     uid.iUid = tentry2.Id();
       
  1749                     TUidNameInfo info( uid, tentry2.iDetails.Left(
       
  1750                     		               KMceSettingsMailboxTextLength ) );
       
  1751                     accounts->AppendL( info );
       
  1752                     }    
       
  1753             
       
  1754                 }
       
  1755             }
       
  1756         }
       
  1757     TUid uid;
       
  1758 	CMtmUiDataRegistry* uiRegistry = CMtmUiDataRegistry::NewL( *iSession );
       
  1759     CleanupStack::PushL( uiRegistry );
       
  1760     const TInt numAccounts = sel->Count();
       
  1761     for ( TInt cc = 0; cc < numAccounts; cc++)
       
  1762         {
       
  1763         uid.iUid = sel->At( cc );
       
  1764         TMsvEntry tentry;
       
  1765         TRAPD( err, ( tentry = rootEntry->ChildDataL( uid.iUid ) ) );
       
  1766         
       
  1767         TBool appendEmail = EFalse;
       
  1768         
       
  1769         // This avoids FS boxes to show in SyncML list
       
  1770         if ( iMessageType != KSenduiMtmSyncMLEmailUid )
       
  1771             {
       
  1772             if ( tentry.Visible() )
       
  1773                 {
       
  1774                 appendEmail = ETrue;
       
  1775                 }
       
  1776             else
       
  1777                 {                
       
  1778                 if ( uiRegistry->IsPresent( tentry.iMtm ) &&
       
  1779                      uiRegistry->IsPresent( KUidMsgTypePOP3 ) )
       
  1780                     {            
       
  1781                     TUid mailMTMTechType =
       
  1782                         uiRegistry->TechnologyTypeUid( KUidMsgTypePOP3 );                                          
       
  1783                     if( uiRegistry->TechnologyTypeUid( tentry.iMtm ) ==
       
  1784                         mailMTMTechType )
       
  1785                         {
       
  1786                         appendEmail = ETrue;                    
       
  1787                         }
       
  1788                     }
       
  1789                 }            
       
  1790 
       
  1791             // Remove 3'rd party mailboxes which are not registered to handle
       
  1792             // S60 mailboxes 
       
  1793             if ( iMtmPluginId != 0 &&
       
  1794                     tentry.iMtm.iUid != iMtmPluginId )
       
  1795                 {
       
  1796                 appendEmail = EFalse;
       
  1797                 }
       
  1798             } // != KSenduiMtmSyncMLEmailUid
       
  1799 
       
  1800         if ( err == KErrNone &&
       
  1801                 uiRegistry->IsPresent( tentry.iMtm ) && appendEmail )
       
  1802             {
       
  1803             const TInt count = accounts->Count();
       
  1804             TBool foundService = EFalse;
       
  1805             //check that related service is not already added to array
       
  1806             for ( TInt loop = 0; loop < count; loop ++ )
       
  1807                 {
       
  1808                 if ( tentry.iRelatedId == (*accounts)[loop].iUid.iUid )
       
  1809                     {
       
  1810                     foundService = ETrue;
       
  1811                     break;
       
  1812                     }
       
  1813                 }
       
  1814             if ( !foundService )
       
  1815                 {
       
  1816                 TUidNameInfo info( uid, tentry.iDetails.Left(
       
  1817                         KMceSettingsMailboxTextLength ) );
       
  1818                 accounts->AppendL( info );
       
  1819                 }
       
  1820             }
       
  1821         }
       
  1822     CleanupStack::PopAndDestroy( uiRegistry );
       
  1823     CleanupStack::PopAndDestroy( rootEntry );
       
  1824     CleanupStack::PopAndDestroy( sel );
       
  1825     CleanupStack::Pop( accounts );
       
  1826     return accounts;
       
  1827     }
       
  1828 
       
  1829 // ----------------------------------------------------
       
  1830 // CMceSettingsMultipleServicesDialog::UpdateForArrayChangeL
       
  1831 // ----------------------------------------------------
       
  1832 void CMceSettingsMultipleServicesDialog::UpdateServicesArrayL()
       
  1833     {        
       
  1834     CEikTextListBox* list = STATIC_CAST( CEikTextListBox*, 
       
  1835         Control( EMceSettingsMultipleServicesDialogChoiceList ) );
       
  1836 
       
  1837     TInt selectedIndex = list->CurrentItemIndex();
       
  1838     const TInt count = iAccountArray->Count();
       
  1839     CUidNameArray* sel = MtmEmailAccountsL();
       
  1840     CleanupStack::PushL( sel );
       
  1841     const TInt newCount = sel->Count();
       
  1842     iAccountArray->Reset();
       
  1843 	iSettingsItemArray->Reset();
       
  1844 	SetAccountInUseL();
       
  1845 	TBuf <KMceSettingsMtmNameBufLength> mtms;
       
  1846     
       
  1847 	for ( TInt loop = 0; loop < newCount; loop++ )
       
  1848         {
       
  1849         iAccountArray->AppendL( sel->At( loop ) );
       
  1850 
       
  1851 
       
  1852 		mtms.Copy( KMceMtmName1 );
       
  1853 		mtms.Append( (*sel)[loop].iName );
       
  1854 		mtms.Append( KMceMtmName2 );
       
  1855 		iSettingsItemArray->AppendL( mtms );
       
  1856 		mtms.Zero();
       
  1857         }
       
  1858     CleanupStack::PopAndDestroy( sel );
       
  1859 
       
  1860     if ( newCount > count )
       
  1861         {
       
  1862         list->HandleItemAdditionL();
       
  1863         }
       
  1864     else if ( newCount < count )
       
  1865         {
       
  1866         list->HandleItemRemovalL();
       
  1867         }
       
  1868     else
       
  1869         {
       
  1870         // no action
       
  1871         }
       
  1872 
       
  1873     if ( newCount > 0 )
       
  1874         {
       
  1875         if ( selectedIndex >= 0 && selectedIndex < newCount )
       
  1876             {
       
  1877             list->SetCurrentItemIndex( selectedIndex );
       
  1878             }
       
  1879         else
       
  1880             {
       
  1881             list->SetCurrentItemIndex( 0/*newCount - 1*/ );
       
  1882             }
       
  1883         }
       
  1884     list->DrawNow();
       
  1885     }
       
  1886 
       
  1887 //  End of File