mobilemessaging/smum/src/SmumServiceCentresDialog.cpp
changeset 79 2981cb3aa489
parent 0 72b543305e3a
equal deleted inserted replaced
25:84d9eb65b26f 79:2981cb3aa489
       
     1 /*
       
     2 * Copyright (c) 2002-2009 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 *     Service Centres dialog for Sms.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <eikmenup.h>                   // CEikMenuPane
       
    23 #include <akntitle.h>                   // CAknTitlePane
       
    24 #include <SMUM.rsg>                     // resource identifiers
       
    25 #include <smutset.h>                    // CSmsSettings
       
    26 #include <AknQueryDialog.h>             // CAknQueryDialog
       
    27 #include <StringLoader.h>               // StringLoader
       
    28 #include <aknlists.h>
       
    29 #include <aknPopup.h>
       
    30 #include <eiklbx.h>                     // EOwnedExternally
       
    31 #include <hlplch.h>                     // For HlpLauncher
       
    32 #include <bldvariant.hrh>
       
    33 #include <csxhelp/mce.hlp.hrh>
       
    34 #include <centralrepository.h> 
       
    35 #include <AvkonInternalCRKeys.h>  		// KAknMiddleSoftkeyEnabled
       
    36 #include <aknenv.h>                     // AppShutter
       
    37 // locals
       
    38 #include "SMSU.HRH"                     // resource header
       
    39 #include "SMSETDLG.H"                   // TSmumSCNameInfo, TSmsSettingSCNames, CSmumSCArray
       
    40 #include "SmumServiceCentreItemDialog.h"// CSmumAddEditServiceCentreDialog
       
    41 #include "SmumSettingsDialogGSM.h"         // KStringLength
       
    42 #include "SmumServiceCentresDialog.h"   // CSmumServiceCentresDialog
       
    43 #include "smsui.pan"                    // panics
       
    44 #include "SmumUtil.h"                   // SmumUtil
       
    45 
       
    46 //For logging
       
    47 #include "SmumLogging.h"
       
    48 
       
    49 // EXTERNAL DATA STRUCTURES
       
    50 
       
    51 // EXTERNAL FUNCTION PROTOTYPES  
       
    52 
       
    53 // CONSTANTS
       
    54 const TInt KNameListGranularity = 8;
       
    55 const TInt KSmumSCArray = 4;
       
    56 
       
    57 // ================= MEMBER FUNCTIONS =======================
       
    58 
       
    59 // C++ constructor can NOT contain any code, that
       
    60 // might leave.
       
    61 //
       
    62 CSmumServiceCentresDialog::CSmumServiceCentresDialog(
       
    63     CSmsSettings& aSettings, TInt& aExitCode, TBool aHelpFeatureSupported, TBool aSimSCsOnly )
       
    64         : iSettings ( aSettings ),
       
    65           iExitCode ( aExitCode ),
       
    66           iHelpFeatureSupported ( aHelpFeatureSupported ),
       
    67           iSimSCsOnly( aSimSCsOnly ),
       
    68           iIdle (NULL)
       
    69     {
       
    70     }
       
    71    
       
    72 // Destructor
       
    73 CSmumServiceCentresDialog::~CSmumServiceCentresDialog()
       
    74     {
       
    75     SMUMLOGGER_ENTERFN(" CSmumServiceCentresDialog::~CSmumServiceCentresDialog");
       
    76     if ( iListBox )
       
    77         {
       
    78         iListBox->SetScrollBarFrame( NULL, CEikListBox::EOwnedExternally );
       
    79         }
       
    80     delete iPreviousTitleText;
       
    81     delete iSCAddressesList;
       
    82     delete iIdle;
       
    83     // iListBox, iSettings(reference), iTitlePane are
       
    84     // plain pointers to objects owned by other classes which take
       
    85     // care also about deletion.
       
    86     SMUMLOGGER_LEAVEFN(" CSmumServiceCentresDialog::~CSmumServiceCentresDialog");
       
    87     }
       
    88 
       
    89 // ----------------------------------------------------
       
    90 // CSmumServiceCentresDialog::NewL
       
    91 //
       
    92 // ----------------------------------------------------
       
    93 CSmumServiceCentresDialog* CSmumServiceCentresDialog::NewL(
       
    94     CSmsSettings& aSettings,
       
    95     TInt& aExitCode,
       
    96     TInt aMenuTitleResourceId,
       
    97     TBool aHelpFeatureSupported,
       
    98     TBool aSimSCsOnly )
       
    99     {
       
   100     SMUMLOGGER_ENTERFN(" CSmumServiceCentresDialog::NewL");
       
   101     CSmumServiceCentresDialog* self = 
       
   102         new ( ELeave ) CSmumServiceCentresDialog( 
       
   103         	aSettings, aExitCode, aHelpFeatureSupported, aSimSCsOnly );
       
   104     CleanupStack::PushL( self );
       
   105     self->ConstructL( aMenuTitleResourceId );
       
   106     CleanupStack::Pop(); // self
       
   107     SMUMLOGGER_LEAVEFN(" CSmumServiceCentresDialog::NewL");
       
   108     return self;
       
   109     }
       
   110 
       
   111 // ----------------------------------------------------
       
   112 // CSmumServiceCentresDialog::ConstructL
       
   113 //
       
   114 // ----------------------------------------------------
       
   115 void CSmumServiceCentresDialog::ConstructL( TInt aMenuTitleResourceId )
       
   116     {
       
   117     SMUMLOGGER_ENTERFN(" CSmumServiceCentresDialog::ConstructL");
       
   118     // Creating the listbox-list for service centres
       
   119     iSCAddressesList = CSmumSCArray::NewL( KNameListGranularity );
       
   120     TInt serviceCentres = 0;
       
   121     // read Service centres from SmsSettings
       
   122     serviceCentres = iSettings.ServiceCenterCount();
       
   123     for ( TInt loop=0; loop < serviceCentres; loop++ )
       
   124         {
       
   125         TSmumSCNameInfo scAddress(iSettings.GetServiceCenter( loop ).Name(),
       
   126                                    iSettings.GetServiceCenter( loop ).Address());
       
   127         iSCAddressesList->AppendL( scAddress );
       
   128         }
       
   129     CAknDialog::ConstructL( aMenuTitleResourceId );
       
   130     CRepository* cenRep = NULL;
       
   131 	TRAPD(err, cenRep = CRepository::NewL( KCRUidAvkon ));
       
   132 	if (!err)
       
   133 		{
       
   134 		err = cenRep->Get( KAknMiddleSoftkeyEnabled, iMSKEnabledInPlatform );
       
   135 		delete cenRep;
       
   136 	    }
       
   137     SMUMLOGGER_LEAVEFN(" CSmumServiceCentresDialog::ConstructL");
       
   138     }
       
   139 
       
   140 // ----------------------------------------------------
       
   141 // CSmumServiceCentresDialog::OkToExitL
       
   142 //
       
   143 // ----------------------------------------------------
       
   144 TInt CSmumServiceCentresDialog::OkToExitL( TInt aButtonId )
       
   145     {
       
   146     SMUMLOGGER_ENTERFN(" CSmumServiceCentresDialog::OkToExitL");
       
   147     TInt returnValue;
       
   148 
       
   149     switch( aButtonId )
       
   150         {
       
   151         case ESmsSettingsChoiceMenuOpen:
       
   152 	        {
       
   153 	        ProcessCommandL( aButtonId );
       
   154 	        returnValue = EFalse; // Cannot exit, since MSK was pressed
       
   155 	        }     
       
   156 	        break;
       
   157         // system / menu exit
       
   158         case EAknSoftkeyCancel:
       
   159             {
       
   160             if ( iExitCode != ESmumSmsSettingsMenuExit &&
       
   161                 iExitCode != ESmumSmsSettingsSystemExit )
       
   162                 {
       
   163                 // system exit
       
   164                 iExitCode = ESmumSmsSettingsSystemExit;
       
   165                 }
       
   166             TRAP_IGNORE( ClosingServiceCentresDialogL() );// to be sure of not leaving and exiting
       
   167             returnValue = ETrue;
       
   168             }
       
   169             break;
       
   170         case EAknSoftkeyBack:
       
   171             {
       
   172             iExitCode = ESmumSmsSettingsBack;
       
   173             ClosingServiceCentresDialogL();
       
   174             returnValue = ETrue;
       
   175             }
       
   176             break;
       
   177         default :
       
   178             returnValue = CAknDialog::OkToExitL( aButtonId );
       
   179             break;
       
   180         }
       
   181     SMUMLOGGER_LEAVEFN(" CSmumServiceCentresDialog::OkToExitL");
       
   182     return returnValue;
       
   183     }
       
   184 
       
   185 // ----------------------------------------------------
       
   186 // CSmumServiceCentresDialog::HandleListBoxEventL
       
   187 //
       
   188 // ----------------------------------------------------
       
   189 void CSmumServiceCentresDialog::HandleListBoxEventL(
       
   190     CEikListBox* /*aListBox*/, 
       
   191     TListBoxEvent aEventType )
       
   192     {
       
   193     SMUMLOGGER_ENTERFN(" CSmumServiceCentresDialog::HandleListBoxEventL");
       
   194     switch ( aEventType )
       
   195         {
       
   196         case EEventEnterKeyPressed:
       
   197         case EEventItemSingleClicked:
       
   198             //for touch input
       
   199             if ( iSCAddressesList->Count())
       
   200                 {
       
   201                 EditServiceCentreL();
       
   202                 }
       
   203             else
       
   204                 {
       
   205                 AddServiceCentreL();
       
   206                 }            
       
   207             break;
       
   208         default :
       
   209             // panic?
       
   210             break;
       
   211         }
       
   212     SMUMLOGGER_LEAVEFN(" CSmumServiceCentresDialog::HandleListBoxEventL");
       
   213     }
       
   214 
       
   215 // ----------------------------------------------------
       
   216 // CSmumServiceCentresDialog::ProcessCommandL
       
   217 //
       
   218 // ----------------------------------------------------
       
   219 void CSmumServiceCentresDialog::ProcessCommandL( TInt aCommandId )
       
   220     {
       
   221     SMUMLOGGER_ENTERFN(" CSmumServiceCentresDialog::ProcessCommandL");
       
   222     CAknDialog::ProcessCommandL( aCommandId ) ;
       
   223     switch ( aCommandId )
       
   224         {
       
   225         case ESmsSettingsChoiceMenuEdit:
       
   226         case ESmsSettingsChoiceMenuOpen:
       
   227         if ( iSCAddressesList->Count())
       
   228                 {
       
   229                 EditServiceCentreL();
       
   230                 }
       
   231             else
       
   232                 {
       
   233                 AddServiceCentreL();
       
   234                 }            
       
   235             break;
       
   236         case ESmsSettingsChoiceMenuNew:
       
   237             AddServiceCentreL();
       
   238             break;
       
   239         case ESmsSettingsChoiceMenuDelete:
       
   240             DeleteServiceCentreL();
       
   241             break;
       
   242         case EAknCmdHelp:            
       
   243             LaunchHelpL();            
       
   244             break;
       
   245         case ESmsSettingsChoiceMenuExit:
       
   246             {
       
   247             iExitCode = ESmumSmsSettingsMenuExit;
       
   248             TryExitL( EAknSoftkeyCancel );
       
   249             }
       
   250             break;
       
   251         default :
       
   252             // panic
       
   253             break ;
       
   254         }
       
   255     SMUMLOGGER_LEAVEFN(" CSmumServiceCentresDialog::ProcessCommandL");
       
   256     }
       
   257 
       
   258 // ----------------------------------------------------
       
   259 // CSmumServiceCentresDialog::OfferKeyEventL
       
   260 //
       
   261 // ----------------------------------------------------
       
   262 TKeyResponse CSmumServiceCentresDialog::OfferKeyEventL(
       
   263     const TKeyEvent& aKeyEvent,
       
   264     TEventCode aType )
       
   265     {
       
   266 
       
   267     TKeyResponse returnValue = CAknDialog::OfferKeyEventL( aKeyEvent, aType );
       
   268    	if( aType == EEventKeyUp )
       
   269 		{
       
   270 		UpdateButtonVisibility();
       
   271 		}
       
   272     if ( aType == EEventKey )
       
   273         {
       
   274         if ( aKeyEvent.iCode == EKeyBackspace 
       
   275             && iListBox->CurrentItemIndex() != KErrNotFound )
       
   276             {
       
   277             ProcessCommandL( ESmsSettingsChoiceMenuDelete );
       
   278             returnValue = EKeyWasConsumed;
       
   279             }
       
   280         }
       
   281     
       
   282     return returnValue;
       
   283     }
       
   284 
       
   285 // ----------------------------------------------------
       
   286 // CSmumServiceCentresDialog::PreLayoutDynInitL
       
   287 //
       
   288 // ----------------------------------------------------
       
   289 void CSmumServiceCentresDialog::PreLayoutDynInitL()
       
   290     {
       
   291     SMUMLOGGER_ENTERFN(" CSmumServiceCentresDialog::PreLayoutDynInitL");
       
   292     // Initialising listbox
       
   293     iListBox = STATIC_CAST( CEikTextListBox*, Control( ESmsSCListId ));
       
   294     iListBox->SetListBoxObserver( this );
       
   295     CTextListBoxModel* model=iListBox->Model();
       
   296     model->SetItemTextArray( iSCAddressesList );
       
   297     model->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   298     
       
   299     // Get "no centres"-text from resources and save it to listbox-model
       
   300     HBufC* string = StringLoader::LoadLC( R_QTN_MCE_SETTINGS_SMS_NO_SC, iCoeEnv );
       
   301     iListBox->View()->SetListEmptyTextL( *string );
       
   302 
       
   303     // Setting scrollbar-indicators on
       
   304     iListBox->CreateScrollBarFrameL( ETrue );
       
   305     iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   306         CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
       
   307 
       
   308     // Fetch pointer to titlepane
       
   309     CEikStatusPane *sp = ( STATIC_CAST(
       
   310         CAknAppUi*,( CEikonEnv::Static()->EikAppUi())))->StatusPane();
       
   311     iTitlePane = STATIC_CAST(
       
   312         CAknTitlePane*,sp->ControlL( TUid::Uid( EEikStatusPaneUidTitle )));
       
   313 
       
   314     // Take old titlepane text safe
       
   315     iPreviousTitleText = ( *iTitlePane->Text()).Alloc();
       
   316         
       
   317     // Read new titletext and set it
       
   318     HBufC* text = StringLoader::LoadLC( R_QTN_MCE_SETTINGS_SMS_TITLE_SC, iCoeEnv );
       
   319     iTitlePane->SetTextL( *text );
       
   320     CleanupStack::PopAndDestroy(2); // text, string
       
   321     
       
   322     //Check need for MSK visibility
       
   323 	UpdateButtonVisibility();
       
   324     SMUMLOGGER_LEAVEFN(" CSmumServiceCentresDialog::PreLayoutDynInitL");
       
   325     }
       
   326 
       
   327 // ----------------------------------------------------
       
   328 // CSmumServiceCentresDialog::ClosingServiceCentresDialogL
       
   329 //
       
   330 // ----------------------------------------------------
       
   331 void CSmumServiceCentresDialog::ClosingServiceCentresDialogL() const
       
   332     {
       
   333     SMUMLOGGER_ENTERFN(" CSmumServiceCentresDialog::ClosingServiceCentresDialogL");
       
   334     // Replace title with old title text
       
   335     if ( iExitCode == ESmumSmsSettingsBack )
       
   336         {
       
   337         // Replace title with old title text
       
   338         iTitlePane->SetTextL( *iPreviousTitleText );
       
   339         }
       
   340 
       
   341     // Create sc list
       
   342     TInt loop = 0;
       
   343     TInt serviceCentres = 0;
       
   344     TInt scInUse = 0;
       
   345     serviceCentres = iSettings.ServiceCenterCount();
       
   346     scInUse = iSettings.DefaultServiceCenter();
       
   347     for ( loop = 0; loop < serviceCentres; loop++ )
       
   348         {
       
   349         iSettings.RemoveServiceCenter(0);
       
   350         }
       
   351 
       
   352     // Then add centres from the list to SmsSettings
       
   353     TInt count = iSCAddressesList->Count();
       
   354     for ( loop = 0; loop < count; loop++ )
       
   355         {
       
   356         iSettings.AddServiceCenterL(
       
   357             iSCAddressesList->SCNameInfo(loop).Name(), 
       
   358             iSCAddressesList->SCNameInfo(loop).Address());
       
   359         }
       
   360     
       
   361     // Set default SC
       
   362     if ( scInUse >= 0 )
       
   363         {
       
   364         iSettings.SetDefaultServiceCenter( scInUse );
       
   365         }
       
   366     SMUMLOGGER_LEAVEFN(" CSmumServiceCentresDialog::ClosingServiceCentresDialogL");
       
   367     }
       
   368 
       
   369 // ---------------------------------------------------------
       
   370 // CSmumServiceCentresDialog::DynInitMenuPaneL
       
   371 //
       
   372 // ---------------------------------------------------------
       
   373 void CSmumServiceCentresDialog::DynInitMenuPaneL(
       
   374     TInt aMenuId, 
       
   375     CEikMenuPane* aMenuPane)
       
   376     {
       
   377     SMUMLOGGER_ENTERFN(" CSmumServiceCentresDialog::DynInitMenuPaneL");
       
   378     switch ( aMenuId )
       
   379         {
       
   380         case R_SMS_SERVICECENTRES_CHOICE_MENUPANE:
       
   381             if ( !iSCAddressesList->Count() )
       
   382                 {
       
   383                 aMenuPane->SetItemDimmed( ESmsSettingsChoiceMenuDelete, ETrue );
       
   384                 aMenuPane->SetItemDimmed( ESmsSettingsChoiceMenuEdit, ETrue );
       
   385                 }
       
   386             if( iMSKEnabledInPlatform) //if MSK enabled
       
   387             	{
       
   388             	aMenuPane->SetItemDimmed( ESmsSettingsChoiceMenuEdit, ETrue );
       
   389             	}
       
   390             else
       
   391             	{
       
   392             	aMenuPane->SetItemDimmed( ESmsSettingsChoiceMenuOpen, ETrue );
       
   393                 }
       
   394 			if ( iSimSCsOnly ) // Only Sim SC's variation is on
       
   395                 {
       
   396                 // ESmsSettingsChoiceMenuEdit must be preserved so
       
   397                 // that user can check the SMSC number
       
   398 	            aMenuPane->SetItemDimmed( ESmsSettingsChoiceMenuDelete, ETrue );    	
       
   399                 aMenuPane->SetItemDimmed( ESmsSettingsChoiceMenuNew, ETrue );
       
   400                 }                
       
   401             // Help handling
       
   402             aMenuPane->SetItemDimmed( EAknCmdHelp, !iHelpFeatureSupported );
       
   403             break;
       
   404         default :
       
   405             // panic
       
   406             break;
       
   407         }
       
   408     SMUMLOGGER_LEAVEFN(" CSmumServiceCentresDialog::DynInitMenuPaneL");
       
   409     }
       
   410 
       
   411 // ----------------------------------------------------
       
   412 // CSmumServiceCentresDialog::AddServiceCentreL
       
   413 //
       
   414 // ----------------------------------------------------
       
   415 void CSmumServiceCentresDialog::AddServiceCentreL()
       
   416     {
       
   417     SMUMLOGGER_ENTERFN(" CSmumServiceCentresDialog::AddServiceCentreL");
       
   418     TBuf<KSmumStringLength> name;
       
   419     TBuf<KSmumStringLength> number;
       
   420 
       
   421     TInt originalSCamount = iSCAddressesList->Count();
       
   422 
       
   423     // Launch dialog for adding service centre
       
   424     TInt exitCode = ESmumSmsSettingsInitialvalue;
       
   425     CSmumAddEditServiceCentreDialog* scItemDialog = 
       
   426         new ( ELeave ) CSmumAddEditServiceCentreDialog(
       
   427             name, number, exitCode, iHelpFeatureSupported, iSCAddressesList );
       
   428     CleanupStack::PushL( scItemDialog );
       
   429     scItemDialog->ConstructL( R_SMS_SERVICECENTRE_ITEM_CHOICE_MENUBAR );
       
   430     CleanupStack::Pop(); // scItemDialog
       
   431     scItemDialog->ExecuteLD( R_ADD_EDIT_SERVICECENTRES );
       
   432     
       
   433     // Update Sc array & listbox if values ok (in anycase)
       
   434     if ( name.Size() && number.Size())
       
   435         {
       
   436         TSmumSCNameInfo scAddress( name, number );
       
   437         iSCAddressesList->AppendL( scAddress );
       
   438         iSettings.AddServiceCenterL( name, number );
       
   439         }
       
   440 
       
   441     if ( exitCode == ESmumSmsSettingsMenuExit ||
       
   442          exitCode == ESmumSmsSettingsSystemExit )
       
   443         {// Exiting...
       
   444         iExitCode = exitCode;
       
   445         DoDelayedExitL( 0 );
       
   446         }
       
   447     else
       
   448         {// not exiting, let's take care of drawing
       
   449         if ( iSCAddressesList->Count() > originalSCamount )
       
   450             { // added service centres
       
   451             iListBox->HandleItemAdditionL();
       
   452             iListBox->SetCurrentItemIndex( iSCAddressesList->Count() - 1 );
       
   453             }
       
   454         iListBox->DrawNow();
       
   455         }
       
   456     SMUMLOGGER_LEAVEFN(" CSmumServiceCentresDialog::AddServiceCentreL");
       
   457     }
       
   458 
       
   459 // ----------------------------------------------------
       
   460 // CSmumServiceCentresDialog::EditServiceCentreL
       
   461 //
       
   462 // ----------------------------------------------------
       
   463 void CSmumServiceCentresDialog::EditServiceCentreL()
       
   464     {
       
   465     SMUMLOGGER_ENTERFN(" CSmumServiceCentresDialog::EditServiceCentreL");
       
   466     const TInt index = iListBox->CurrentItemIndex();
       
   467     __ASSERT_DEBUG( index >= 0 , Panic( ESmsetdlgInvalidIndex ));
       
   468     
       
   469     TSmumSCNameInfo& tempSCName = iSCAddressesList->SCNameInfo( index );
       
   470     
       
   471     TBuf<KSmumStringLength> name = tempSCName.Name();
       
   472     TBuf<KSmumStringLength> number = tempSCName.Address();
       
   473     
       
   474     // Launch dialog for editing sc values
       
   475     TInt exitCode = ESmumSmsSettingsInitialvalue;
       
   476     CSmumAddEditServiceCentreDialog* scItemDialog = 
       
   477         new ( ELeave ) CSmumAddEditServiceCentreDialog(
       
   478         name, number, exitCode, iHelpFeatureSupported, iSCAddressesList, iSimSCsOnly );
       
   479     CleanupStack::PushL( scItemDialog );
       
   480     scItemDialog->ConstructL( R_SMS_SERVICECENTRE_ITEM_CHOICE_MENUBAR );
       
   481     CleanupStack::Pop(); // scItemDialog
       
   482     scItemDialog->ExecuteLD( R_ADD_EDIT_SERVICECENTRES );
       
   483     
       
   484     // Update scaddresseslist
       
   485     if ( name.Size() && number.Size()) 
       
   486         {
       
   487         // A valid entry
       
   488         TSmumSCNameInfo scAddress( name, number );
       
   489         iSCAddressesList->InsertL( index, scAddress );
       
   490         iSCAddressesList->Delete( index + 1 ); // delete old one            
       
   491         }
       
   492     else
       
   493         {
       
   494         // An invalid entry, delete
       
   495         iSCAddressesList->Delete( index );
       
   496         iListBox->HandleItemRemovalL();
       
   497         iSettings.RemoveServiceCenter( index );
       
   498         // Handle focus
       
   499         TInt numberOfItems = iListBox->Model()->NumberOfItems();
       
   500         if ( index + 1 > numberOfItems && index )
       
   501             {
       
   502             iListBox->SetCurrentItemIndex( index - 1 );
       
   503             }
       
   504         else if ( index + 1 <= numberOfItems && index )
       
   505             {
       
   506             iListBox->SetCurrentItemIndex( index );
       
   507             }
       
   508         }
       
   509     
       
   510     if ( exitCode == ESmumSmsSettingsMenuExit ||
       
   511          exitCode == ESmumSmsSettingsSystemExit )
       
   512         {// Exiting...
       
   513         iExitCode = exitCode;
       
   514         DoDelayedExitL( 0 );
       
   515         }
       
   516     else
       
   517         {// not exiting, let's take care of drawing
       
   518         iListBox->SetCurrentItemIndex(index);
       
   519         iListBox->HandleItemAdditionL();
       
   520         iListBox->DrawNow();
       
   521         }
       
   522     SMUMLOGGER_LEAVEFN(" CSmumServiceCentresDialog::EditServiceCentreL");
       
   523     }
       
   524 
       
   525 // ----------------------------------------------------
       
   526 // CSmumServiceCentresDialog::DeleteServiceCentreL
       
   527 //
       
   528 // ----------------------------------------------------
       
   529 void CSmumServiceCentresDialog::DeleteServiceCentreL()
       
   530     {
       
   531     SMUMLOGGER_ENTERFN(" CSmumServiceCentresDialog::DeleteServiceCentreL");
       
   532     TInt index = iListBox->CurrentItemIndex();
       
   533     __ASSERT_DEBUG( index >= 0 , Panic( ESmsetdlgInvalidIndex ));
       
   534 
       
   535 	if ( iSimSCsOnly ) // Only Sim SC's variation is on
       
   536 	    {
       
   537 	    // No delete/edit operations are allowed
       
   538 		SmumUtil::ShowInformationNoteL( R_QTN_SMS_EMAIL_SETT_CANNOT_CHANGE );
       
   539 		return;
       
   540 	    }
       
   541     // Text for deletion queries
       
   542     HBufC* scName = iSCAddressesList->SCNameInfo( index ).Name().AllocLC();
       
   543     TInt scDeletionValue;
       
   544     HBufC* wholeConfTextInQuery = NULL;
       
   545     TInt scInUseIndex = 0; 
       
   546     TInt amountOfSCs = 0;
       
   547     scInUseIndex = iSettings.DefaultServiceCenter();
       
   548     amountOfSCs = iSettings.ServiceCenterCount();
       
   549     // Last Service Centre?
       
   550     if ( ESmumScLastOne == amountOfSCs )
       
   551         {
       
   552         wholeConfTextInQuery = StringLoader::LoadLC( R_QTN_MCE_SETTINGS_SMS_QUEST_DEL, iCoeEnv );
       
   553         scDeletionValue = ESmumScLastOne;
       
   554         }
       
   555     // Service Centre in use?
       
   556     else if (scInUseIndex == index)
       
   557         {
       
   558         wholeConfTextInQuery = StringLoader::LoadLC( R_QTN_MCE_SETTINGS_SMS_QUEST_D, iCoeEnv );
       
   559         scDeletionValue = ESmumScInUse;
       
   560         }
       
   561     // Are you sure to delete?
       
   562     else
       
   563         {
       
   564         wholeConfTextInQuery = StringLoader::LoadLC( R_SMUM_DELETE_CONFIRMATION_COMMON, *scName, iCoeEnv );
       
   565         scDeletionValue = ESmumScNormalDelete;
       
   566         }
       
   567 
       
   568     CAknQueryDialog* dlg = CAknQueryDialog::NewL();
       
   569     // delete sc?
       
   570     if ( dlg->ExecuteLD( R_DELETE_SC_QUERY, *wholeConfTextInQuery ))
       
   571         { // yes
       
   572         // Delete sc from list & sc array
       
   573         iSCAddressesList->Delete( index );
       
   574         iSettings.RemoveServiceCenter( index );
       
   575         amountOfSCs = amountOfSCs - 1;
       
   576         iListBox->HandleItemRemovalL();
       
   577 
       
   578         switch ( scDeletionValue )
       
   579             {
       
   580             case ESmumScNormalDelete :
       
   581                 { // Normal deletion, handle Default SC if necessary
       
   582                 if ( index < scInUseIndex )
       
   583                     {
       
   584                     iSettings.SetDefaultServiceCenter( scInUseIndex - 1 );
       
   585                     } 
       
   586                 }
       
   587                 break;
       
   588             case ESmumScInUse :
       
   589                 { // Sc in use, launch list query for the user to select new one
       
   590                 if ( amountOfSCs > 1 )
       
   591                     {
       
   592                     LaunchScInUseListQueryL();
       
   593                     }
       
   594                 }
       
   595                 break;
       
   596             case ESmumScLastOne : 
       
   597             default :
       
   598                 break;
       
   599             }
       
   600 
       
   601         TInt indexToHighlight = index < iListBox->Model()->NumberOfItems() ?
       
   602                                    index : iListBox->Model()->NumberOfItems() - 1;                
       
   603         // Set focus after deletion if we have Service Centres
       
   604         if ( amountOfSCs >= 1 )
       
   605             {
       
   606             iListBox->SetCurrentItemIndex(
       
   607                   indexToHighlight >= 1 ? indexToHighlight : 0 );
       
   608             }
       
   609         }
       
   610     CleanupStack::PopAndDestroy( 2 ); // scName, wholeConfTextInQuery
       
   611     UpdateButtonVisibility();
       
   612     iListBox->DrawNow();
       
   613     SMUMLOGGER_LEAVEFN(" CSmumServiceCentresDialog::DeleteServiceCentreL - LAST");
       
   614     }
       
   615 
       
   616 // ----------------------------------------------------
       
   617 // CSmumServiceCentresDialog::LaunchScInUseListQuery
       
   618 //
       
   619 // ----------------------------------------------------
       
   620 void CSmumServiceCentresDialog::LaunchScInUseListQueryL()
       
   621     {    
       
   622     SMUMLOGGER_ENTERFN(" CSmumServiceCentresDialog::LaunchScInUseListQueryL");
       
   623     // Initialise listbox
       
   624     CAknSinglePopupMenuStyleListBox* list = 
       
   625         new(ELeave) CAknSinglePopupMenuStyleListBox;
       
   626     CleanupStack::PushL( list );
       
   627     CAknPopupList* popupList = CAknPopupList::NewL( 
       
   628         list, R_AVKON_SOFTKEYS_OK_EMPTY );
       
   629     CleanupStack::PushL( popupList );	
       
   630     list->ConstructL( popupList, CEikListBox::ELeftDownInViewRect );
       
   631     // Add scroll indicators
       
   632     list->CreateScrollBarFrameL( ETrue );
       
   633     list->ScrollBarFrame()->SetScrollBarVisibilityL( 
       
   634         CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
       
   635     
       
   636     // Create array and add recipient's numbers to it
       
   637     CDesCArrayFlat* items = new ( ELeave ) CDesCArrayFlat( KSmumSCArray );
       
   638     CleanupStack::PushL( items );
       
   639     
       
   640     TInt amountOfSCs = iSCAddressesList->Count();
       
   641     for ( TInt loop = 0 ; loop < amountOfSCs; loop++ )
       
   642         {
       
   643         items->AppendL( iSCAddressesList->SCNameInfo( loop ).Name());
       
   644         }
       
   645     
       
   646     // Give array to listbox model
       
   647     CTextListBoxModel* model = list->Model();
       
   648     model->SetItemTextArray( items );
       
   649     model->SetOwnershipType(ELbmOwnsItemArray);
       
   650     CleanupStack::Pop();// items - listbox model now owns this
       
   651     
       
   652     // Load txt to show in title
       
   653     HBufC* text = StringLoader::LoadLC( R_QTN_MCE_SETTINGS_SMS_LIST_SC, iCoeEnv );
       
   654     popupList->SetTitleL( *text );
       
   655     CleanupStack::PopAndDestroy(); // text
       
   656     
       
   657     // Launch popuplist and update choice
       
   658     TInt choice = KErrNotFound;
       
   659     CleanupStack::Pop();			//popupList
       
   660     if ( popupList->ExecuteLD() )
       
   661         {
       
   662         choice = list->CurrentItemIndex();
       
   663         }
       
   664     
       
   665     CleanupStack::PopAndDestroy();	// list
       
   666     
       
   667     // Take user's choice to use
       
   668     if ( choice != KErrNotFound )
       
   669         {
       
   670         iSettings.SetDefaultServiceCenter( choice );
       
   671         }
       
   672     SMUMLOGGER_LEAVEFN(" CSmumServiceCentresDialog::LaunchScInUseListQueryL");
       
   673     }
       
   674 
       
   675 // ----------------------------------------------------
       
   676 // CSmumServiceCentresDialog::LaunchHelpL
       
   677 // launch help using context
       
   678 //
       
   679 // ----------------------------------------------------
       
   680 void CSmumServiceCentresDialog::LaunchHelpL()
       
   681     {
       
   682     if ( iHelpFeatureSupported )
       
   683         {
       
   684         CCoeAppUi* editorAppUi = STATIC_CAST(CCoeAppUi*, ControlEnv()->AppUi());
       
   685         CArrayFix<TCoeHelpContext>* helpContext = editorAppUi->AppHelpContextL();
       
   686         HlpLauncher::LaunchHelpApplicationL( iEikonEnv->WsSession(), helpContext );
       
   687         }
       
   688     }
       
   689 
       
   690 
       
   691 // ----------------------------------------------------
       
   692 // CSmumServiceCentresDialog::GetHelpContext
       
   693 // returns helpcontext as aContext
       
   694 //
       
   695 // ----------------------------------------------------
       
   696 void CSmumServiceCentresDialog::GetHelpContext
       
   697         (TCoeHelpContext& aContext) const
       
   698     {    
       
   699     const TUid KUidMce ={0x100058C5};      
       
   700     aContext.iMajor = KUidMce;
       
   701     aContext.iContext = KSMS_HLP_SETTINGS_SCENTRES; 
       
   702     }
       
   703     
       
   704 // ---------------------------------------------------------
       
   705 // CSmumServiceCentresDialog::UpdateButtonVisibility
       
   706 // ---------------------------------------------------------
       
   707 //
       
   708 void CSmumServiceCentresDialog::UpdateButtonVisibility()
       
   709     {
       
   710     if ( ButtonGroupContainer().ControlOrNull( ESmsSettingsChoiceMenuOpen ) )
       
   711         {
       
   712         //Check need for MSK visibility
       
   713 	    if( iListBox->CurrentItemIndex() > -1 )
       
   714 	    	{
       
   715 	    	ButtonGroupContainer().MakeCommandVisible( ESmsSettingsChoiceMenuOpen, ETrue );
       
   716 	    	}
       
   717 	    else
       
   718 	    	{//no need to show
       
   719 	    	ButtonGroupContainer().MakeCommandVisible( ESmsSettingsChoiceMenuOpen, EFalse );
       
   720 	       	}
       
   721         }
       
   722     }
       
   723     
       
   724 // ---------------------------------------------------------
       
   725 // CSmumServiceCentresDialog::DoDelayedExitL
       
   726 // ---------------------------------------------------------
       
   727 void CSmumServiceCentresDialog::DoDelayedExitL( const TInt aDelay )
       
   728     {
       
   729     SMUMLOGGER_ENTERFN(" CSmumServiceCentresDialog::DoDelayedExitL");
       
   730     delete iIdle;
       
   731     iIdle = 0;
       
   732     iIdle = CPeriodic::NewL( EPriorityNormal - 1 );
       
   733     iIdle->Start(   aDelay,
       
   734                     aDelay,
       
   735                     TCallBack( DelayedExit, this ) );
       
   736     SMUMLOGGER_LEAVEFN(" CSmumServiceCentresDialog::DoDelayedExitL");
       
   737     }
       
   738 
       
   739 // ---------------------------------------------------------
       
   740 // CSmumServiceCentresDialog::DelayedExit
       
   741 // ---------------------------------------------------------
       
   742 TInt CSmumServiceCentresDialog::DelayedExit( TAny* aThis )
       
   743     {
       
   744     SMUMLOGGER_ENTERFN(" CSmumServiceCentresDialog::DelayedExit");
       
   745     CSmumServiceCentresDialog* settings = static_cast<CSmumServiceCentresDialog*>( aThis );
       
   746     TRAP_IGNORE( settings->ClosingServiceCentresDialogL() ); // to be sure of not leaving and exiting
       
   747     CAknEnv::RunAppShutter( );
       
   748     SMUMLOGGER_LEAVEFN(" CSmumServiceCentresDialog::DelayedExit");
       
   749     return KErrNone;
       
   750     }
       
   751 
       
   752     
       
   753 //  End of File  
       
   754