email/imum/Utils/Src/MuiuDynamicSettingsDialog.cpp
branchRCL_3
changeset 60 7fdbb852d323
parent 0 72b543305e3a
equal deleted inserted replaced
57:ebe688cedc25 60:7fdbb852d323
       
     1 /*
       
     2 * Copyright (c) 2006 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:  MuiuDynamicSettingsDialog.cpp
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <e32base.h>
       
    22 #include <eiktxlbx.h>               // CEikTextListBox
       
    23 #include <badesca.h>                // CDesCArray
       
    24 #include <eiktxlbm.h>               // CTextListBoxModel
       
    25 #include <AknUtils.h>               // CAknTextUtils
       
    26 #include <akntitle.h>               // CAknTitlePane
       
    27 #include <AknQueryDialog.h>         // CAknQueryDialog
       
    28 #include <aknsettingpage.h>         // CAknSettingPage
       
    29 #include <aknradiobuttonsettingpage.h> // CAknRadioButtonSettingPage
       
    30 #include <aknpasswordsettingpage.h> // CAknPasswordSettingPage
       
    31 #include <akntextsettingpage.h>     // CAknTextSettingPage
       
    32 #include <eikbtgpc.h>               // CEikButtonGroupContainer
       
    33 #include <StringLoader.h>           // StringLoader
       
    34 #include "MuiuDynamicSettingsDialog.h" // CMuiuDynamicSettingsDialog
       
    35 #include "IMSWCheckBoxPage.h"   // CIMSSettingsWizardCheckBoxPage
       
    36 
       
    37 #include <muiu_internal.rsg>
       
    38 #include <ImumUtils.rsg>                 // R_IMAS_MSK_OPEN, should be temporary
       
    39 
       
    40 // EXTERNAL DATA STRUCTURES
       
    41 // EXTERNAL FUNCTION PROTOTYPES
       
    42 // CONSTANTS
       
    43 
       
    44 // Prevent any looping problems by defining maximum amount of editor openings
       
    45 const TInt KMuiuMaxEditors = 100;
       
    46 
       
    47 // MACROS
       
    48 // LOCAL CONSTANTS AND MACROS
       
    49 // MODULE DATA STRUCTURES
       
    50 // LOCAL FUNCTION PROTOTYPES
       
    51 // FORWARD DECLARATIONS
       
    52 
       
    53 // ============================ MEMBER FUNCTIONS ==============================
       
    54 
       
    55 // ----------------------------------------------------------------------------
       
    56 // CMuiuDynamicSettingsDialog::CMuiuDynamicSettingsDialog()
       
    57 // ----------------------------------------------------------------------------
       
    58 //
       
    59 CMuiuDynamicSettingsDialog::CMuiuDynamicSettingsDialog(
       
    60     CEikFormattedCellListBox& aListBox,
       
    61     CAknTitlePane& aTitlePane )
       
    62     :
       
    63     CMuiuDynamicSettingsArray(),
       
    64     iListBox( aListBox ),
       
    65     iTitlePane( aTitlePane ),
       
    66     iSettingValue( KErrNotFound )
       
    67     {
       
    68     }
       
    69 
       
    70 // ----------------------------------------------------------------------------
       
    71 // CMuiuDynamicSettingsDialog::~CMuiuDynamicSettingsDialog()
       
    72 // ----------------------------------------------------------------------------
       
    73 //
       
    74 CMuiuDynamicSettingsDialog::~CMuiuDynamicSettingsDialog()
       
    75     {
       
    76     // Remove the scrollbar from listbox
       
    77     iListBox.SetScrollBarFrame( NULL, CEikListBox::EOwnedExternally );
       
    78 
       
    79     if ( iSoftkeys )
       
    80         {
       
    81         iSoftkeys->SetObserver( EFalse, EFalse, EFalse, *this );
       
    82         delete iSoftkeys;
       
    83         }
       
    84     iSoftkeys = NULL;
       
    85 
       
    86     delete iSettingPageResources;
       
    87     iSettingPageResources = NULL;
       
    88 
       
    89     if ( iSettingsLastItemIndex )
       
    90         {
       
    91         iSettingsLastItemIndex->Reset();
       
    92         }
       
    93 
       
    94     delete iSettingsLastItemIndex;
       
    95     iSettingsLastItemIndex = NULL;
       
    96 
       
    97     if ( iCheckboxArray )
       
    98         {
       
    99         iCheckboxArray->ResetAndDestroy();
       
   100         }
       
   101 
       
   102     if ( iSettingsPageArray )
       
   103         {
       
   104         iSettingsPageArray->Reset();
       
   105         }
       
   106 
       
   107     if ( iBackupArray )
       
   108         {
       
   109         iBackupArray->ResetAndDestroy();
       
   110         }
       
   111 
       
   112     delete iBackupArray;
       
   113     iBackupArray = NULL;
       
   114     delete iSettingsPageArray;
       
   115     iSettingsPageArray = NULL;
       
   116     delete iCheckboxArray;
       
   117     iCheckboxArray = NULL;
       
   118     delete iOldTitleText;
       
   119     iOldTitleText = NULL;
       
   120     delete iQueryDialog;
       
   121     iQueryDialog = NULL;
       
   122     delete iSettingPage;
       
   123     iSettingPage = NULL;
       
   124     delete iButtonArray;
       
   125     iButtonArray = NULL;
       
   126     delete iSettingText;
       
   127     iSettingText = NULL;
       
   128     delete iNewPassword;
       
   129     iNewPassword = NULL;
       
   130     delete iOldPassword;
       
   131     iOldPassword = NULL;
       
   132     iScrollBar = NULL;
       
   133     }
       
   134 
       
   135 // ----------------------------------------------------------------------------
       
   136 // CMuiuDynamicSettingsDialog::SettingsConstructL()
       
   137 // ----------------------------------------------------------------------------
       
   138 //
       
   139 void CMuiuDynamicSettingsDialog::SettingsConstructL(
       
   140     CEikButtonGroupContainer& aSoftkeys,
       
   141     const TInt aResource,
       
   142     const TBool aUpdateMSK,
       
   143     const TBool aLockedSettings )
       
   144     {
       
   145     BaseConstructL( aResource, aLockedSettings );
       
   146 
       
   147     // Set as observer
       
   148     iListBox.SetListBoxObserver( this );
       
   149     iListBox.View()->SetListEmptyTextL( KNullDesC );
       
   150 
       
   151     // Get scrollbar
       
   152     iScrollBar = iListBox.CreateScrollBarFrameL( ETrue );
       
   153     iScrollBar->SetScrollBarVisibilityL(
       
   154         CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
       
   155 
       
   156     // Create array
       
   157     CTextListBoxModel* model = iListBox.Model();
       
   158     model->SetItemTextArray( this );
       
   159     model->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   160 
       
   161     // Set this dialog for button listening
       
   162     iSoftkeys = CIMSSoftkeyControl::NewL( aSoftkeys );
       
   163     iSoftkeys->SetObserver( ETrue, ETrue, ETrue, *this );
       
   164     iSoftkeys->SetMSKLabelling( aUpdateMSK );
       
   165     UpdateMskL();
       
   166 
       
   167     // Prepare setting page arrays
       
   168     iSettingPageResources = CIMSPageResourceControl::NewL();
       
   169     iSettingsLastItemIndex =
       
   170         new ( ELeave ) CMuiuDynSetIntArray( KMuiuDynArrayGranularity );
       
   171 
       
   172     // Add array to store the backup items
       
   173     iBackupArray = new ( ELeave ) CMuiuDynSetItemArray( KMuiuDynArrayGranularity );
       
   174 
       
   175     // Define setting pages in enumeration order
       
   176     iSettingPageResources->CreateStackL( R_MUIU_SETTINGS_DIALOG_LISTBOX );
       
   177     iSettingPageResources->CreateStackL( R_MUIU_SETTINGS_DIALOG_CHECKLISTBOX );
       
   178     iSettingPageResources->CreateStackL( R_MUIU_SETTINGS_DIALOG_TEXT );
       
   179     iSettingPageResources->CreateStackL( R_MUIU_SETTINGS_DIALOG_NUMBER );
       
   180     iSettingPageResources->CreateStackL( R_MUIU_SETTINGS_DIALOG_SC_NUMBER );
       
   181     iSettingPageResources->CreateStackL( R_MUIU_SETTINGS_DIALOG_PASSWORD );
       
   182     iSettingPageResources->CreateStackL( NULL );
       
   183     }
       
   184 
       
   185 // ----------------------------------------------------------------------------
       
   186 // CMuiuDynamicSettingsDialog::HandleListBoxEventL()
       
   187 // ----------------------------------------------------------------------------
       
   188 //
       
   189 void CMuiuDynamicSettingsDialog::HandleListBoxEventL(
       
   190     CEikListBox* /* aListBox */,
       
   191     TListBoxEvent aEventType )
       
   192     {
       
   193     switch ( aEventType )
       
   194         {
       
   195         // Note for TouchUi. When focused item is tapped, both
       
   196         // EEventItemClicked and EEventItemDoubleClicked events
       
   197         // are received. When unfocused item is tapped, EEventItemClicked
       
   198         // event is received. Double tap to focused item produces
       
   199         // the same events as a single tap.
       
   200         case EEventEnterKeyPressed:
       
   201         case EEventItemDoubleClicked:
       
   202         case EEventItemActioned:
       
   203             OpenSettingPageL();
       
   204             break;
       
   205 
       
   206         case EEventItemClicked:
       
   207         case EEventItemDraggingActioned:
       
   208             UpdateMskL();
       
   209             break;
       
   210         default:
       
   211             break;
       
   212         }
       
   213     }
       
   214 
       
   215 // ----------------------------------------------------------------------------
       
   216 // CMuiuDynamicSettingsDialog::OfferKeyEventL
       
   217 // ----------------------------------------------------------------------------
       
   218 //
       
   219 TKeyResponse CMuiuDynamicSettingsDialog::OfferKeyEventL(
       
   220     const TKeyEvent& /* aKeyEvent */,
       
   221     TEventCode aType )
       
   222     {
       
   223     if ( aType == EEventKeyUp )
       
   224         {
       
   225         UpdateMskL();
       
   226         }
       
   227 
       
   228     return EKeyWasNotConsumed;
       
   229     }
       
   230 
       
   231 // ----------------------------------------------------------------------------
       
   232 // CMuiuDynamicSettingsDialog::SetTitlePaneTextL()
       
   233 // ----------------------------------------------------------------------------
       
   234 //
       
   235 void CMuiuDynamicSettingsDialog::SetTitlePaneTextL(
       
   236     const TDesC& aText,
       
   237     const TBool aSaveCurrent )
       
   238     {
       
   239     HBufC* text = aText.Alloc();
       
   240     CleanupStack::PushL( text );
       
   241 
       
   242     if ( aSaveCurrent )
       
   243         {
       
   244         delete iOldTitleText;
       
   245         iOldTitleText = NULL;
       
   246         iOldTitleText = iTitlePane.Text()->Alloc();
       
   247         }
       
   248 
       
   249     iTitlePane.SetTextL( *text );
       
   250     CleanupStack::PopAndDestroy( text );
       
   251     text = NULL;
       
   252     }
       
   253 
       
   254 // ----------------------------------------------------------------------------
       
   255 // CMuiuDynamicSettingsDialog::SetPreviousTitlePaneText()
       
   256 // ----------------------------------------------------------------------------
       
   257 //
       
   258 void CMuiuDynamicSettingsDialog::SetPreviousTitlePaneText(
       
   259     const TBool aSaveCurrent )
       
   260     {
       
   261     TRAP_IGNORE( SetTitlePaneTextL( *iOldTitleText, aSaveCurrent ) );
       
   262     }
       
   263 
       
   264 /******************************************************************************
       
   265 
       
   266     Settingpage opening
       
   267 
       
   268     - Find out the item to be edited
       
   269     - Send start editing event with the item
       
   270     - Check the item type
       
   271     - Check the resources
       
   272     - If no resources available, ask them
       
   273     - Start editing
       
   274     - Send end editing event
       
   275 
       
   276 ******************************************************************************/
       
   277 
       
   278 // ----------------------------------------------------------------------------
       
   279 // CMuiuDynamicSettingsDialog::OpenSettingPageL()
       
   280 // ----------------------------------------------------------------------------
       
   281 //
       
   282 TMuiuPageResult CMuiuDynamicSettingsDialog::OpenSettingPageL(
       
   283     const TInt aIndex )
       
   284     {
       
   285     // To open setting page, check if the Setting Page index is provided,
       
   286     // if not get the current item index in array
       
   287     TInt index = ( aIndex == KErrNotFound ) ?
       
   288         iListBox.CurrentItemIndex() : aIndex;
       
   289 
       
   290     // Search for the item and open it
       
   291     return SettingPageOpenL( *GetItem( index ) );
       
   292     }
       
   293 
       
   294 // ----------------------------------------------------------------------------
       
   295 // CMuiuDynamicSettingsDialog::OpenSettingPageL()
       
   296 // ----------------------------------------------------------------------------
       
   297 //
       
   298 TMuiuPageResult CMuiuDynamicSettingsDialog::OpenSettingPageL(
       
   299     CMuiuSettingBase& aBaseItem )
       
   300     {
       
   301     return SettingPageOpenL( aBaseItem );
       
   302     }
       
   303 
       
   304 // ----------------------------------------------------------------------------
       
   305 // CMuiuDynamicSettingsDialog::SettingPageOpenL()
       
   306 //
       
   307 // This function contains the main logic for the setting editor handling
       
   308 // in the settings dialog. The setting editors are kept opening as long
       
   309 // as the all the settings are gone through or the editor is dismissed.
       
   310 // ----------------------------------------------------------------------------
       
   311 //
       
   312 TMuiuPageResult CMuiuDynamicSettingsDialog::SettingPageOpenL(
       
   313     CMuiuSettingBase& aBaseItem )
       
   314     {
       
   315     // Don't open the editor for read-only items
       
   316     if ( aBaseItem.iItemFlags.Flag( EMuiuDynItemReadOnly ) )
       
   317         {
       
   318         return EMuiuPageResultReadOnly;
       
   319         }
       
   320     else if( aBaseItem.iItemFlags.Flag( EMuiuDynItemLockableSetting ) &&
       
   321         iArrayFlags.Flag( EMuiuEMailLockedSettings ) )
       
   322         {
       
   323         return EMuiuPageResultPageLocked;
       
   324         }
       
   325 
       
   326     // Store current focused item for last item index array
       
   327     iCurrentItemIndex = iListBox.CurrentItemIndex();
       
   328 
       
   329     // Starting editing of the item, do not allow updating during editing
       
   330     iListBox.MakeVisible( EFalse );
       
   331     iArrayFlags.ClearFlag( EMuiuDynArrayAllowRefresh );
       
   332 
       
   333     // When starting to edit page, send event so that item can be prepared
       
   334     // for the editing. In case of error, editing won't start
       
   335     TMuiuPageEventResult eventResult = EventItemEditStartsL( aBaseItem );
       
   336     TMuiuPageResult result;
       
   337 
       
   338     if ( eventResult == EMuiuPageEventResultApproved )
       
   339         {
       
   340         // Create the array if it doesn't exist yet
       
   341         if ( !iSettingsPageArray )
       
   342             {
       
   343             iSettingsPageArray = new ( ELeave ) CMuiuDynSetItemArray(
       
   344                 KMuiuDynArrayGranularity );
       
   345             }
       
   346 
       
   347         // Clear the array and add the editable item to array
       
   348         CleanBackupArray();
       
   349         iSettingsPageArray->Reset();
       
   350         SetCurrentSettingsPage( aBaseItem );
       
   351         result = SettingsPageOpenCheckL();
       
   352 
       
   353         do
       
   354             {
       
   355             if ( result == EMuiuPageResultEditing )
       
   356                 {
       
   357                 // Open the setting page
       
   358                 result = SettingPageOpenEditorL();
       
   359 
       
   360                 // Do open check. Note that the result can be modified!
       
   361                 SettingsCheckNextEditorOpen( result );
       
   362                 }
       
   363 
       
   364             // Finish the editing of the item
       
   365             SettingPageOpenFinishL();
       
   366             }
       
   367         while ( result == EMuiuPageResultEditing );
       
   368         }
       
   369     else if ( eventResult == EMuiuPageEventResultDisapproved )
       
   370         {
       
   371         result = EMuiuPageResultOk;
       
   372         }
       
   373     else
       
   374         {
       
   375         result = EMuiuPageResultEventCancel;
       
   376         }
       
   377 
       
   378     // Send item edit ends
       
   379     EventItemEditEndsL( aBaseItem );
       
   380     aBaseItem.iItemFlags.ClearFlag( EMuiuDynItemOneTimeForceViewOpen );
       
   381 
       
   382     iArrayFlags.SetFlag( EMuiuDynArrayAllowRefresh );
       
   383     iListBox.MakeVisible( ETrue );
       
   384 
       
   385     // Update the listbox
       
   386     Refresh();
       
   387 
       
   388     return result;
       
   389     }
       
   390 
       
   391 // ----------------------------------------------------------------------------
       
   392 // CMuiuDynamicSettingsDialog::EventPrepareSubArrayL()
       
   393 // ----------------------------------------------------------------------------
       
   394 //
       
   395 TInt CMuiuDynamicSettingsDialog::EventPrepareSubArrayL(
       
   396     CMuiuSettingBase& aBaseItem,
       
   397     const TBool aForward )
       
   398     {
       
   399     // Check direction in array
       
   400     if ( aForward )
       
   401         {
       
   402         // Store the index and set to beginning
       
   403         SetSettingsLastItemIndexL( iCurrentItemIndex );
       
   404         iListBox.SetCurrentItemIndex( 0 );
       
   405         }
       
   406     // When going backwards
       
   407     else
       
   408         {
       
   409         // Restore previous index
       
   410         iListBox.SetCurrentItemIndex( SettingsLastItemIndex() );
       
   411         }
       
   412 
       
   413     return EventSubArrayChangeL( aBaseItem );
       
   414     }
       
   415 
       
   416 /******************************************************************************
       
   417 
       
   418     Settingpage creation
       
   419 
       
   420 ******************************************************************************/
       
   421 
       
   422 // ----------------------------------------------------------------------------
       
   423 // CMuiuDynamicSettingsDialog::SettingsPageOpenCheckL()
       
   424 // ----------------------------------------------------------------------------
       
   425 //
       
   426 TMuiuPageResult CMuiuDynamicSettingsDialog::SettingsPageOpenCheckL()
       
   427     {
       
   428     CMuiuSettingBase* base = CurrentSettingsPage();
       
   429 
       
   430     // Before starting to open the page, check that item type is not
       
   431     // menuarray. In case of menuarray, just open the next level
       
   432     if ( HandleStackForwardL( *base ) == EMuiuStackResultSubMenuOpen )
       
   433         {
       
   434         UpdateMskL();
       
   435         return EMuiuPageResultSubMenuOpen;
       
   436         }
       
   437 
       
   438     // Don't open read only items
       
   439     if ( base->iItemFlags.Flag( EMuiuDynItemReadOnly ) )
       
   440         {
       
   441         return EMuiuPageResultReadOnly;
       
   442         }
       
   443 
       
   444     // The page is ok is for edit
       
   445     return EMuiuPageResultEditing;
       
   446     }
       
   447 
       
   448 // ----------------------------------------------------------------------------
       
   449 // CMuiuDynamicSettingsDialog::SettingsCheckNextEditorOpen()
       
   450 // ----------------------------------------------------------------------------
       
   451 //
       
   452 void CMuiuDynamicSettingsDialog::SettingsCheckNextEditorOpen(
       
   453     TMuiuPageResult& aResult )
       
   454     {
       
   455     // The settings user have selected, must be available to user.
       
   456     // For this reason, items shall restored to main array only, when
       
   457     // returning from editors
       
   458 
       
   459     switch ( aResult )
       
   460         {
       
   461         // Handle approved
       
   462         case EMuiuPageResultOk:
       
   463             aResult = HandleEditorOk();
       
   464             break;
       
   465 
       
   466         // Handle the cancelled editor page
       
   467         case EMuiuPageResultCancelled:
       
   468             aResult = HandleEditorCancel();
       
   469             break;
       
   470 
       
   471         // Continue editing
       
   472         case EMuiuPageResultEditing:
       
   473             aResult = HandleEditorDisapproved();
       
   474             break;
       
   475 
       
   476         default:
       
   477             __ASSERT_DEBUG( EFalse, User::Panic(
       
   478                 KMuiuDynSetDialogPanic, KErrUnknown ) );
       
   479             break;
       
   480         }
       
   481     }
       
   482 
       
   483 // ----------------------------------------------------------------------------
       
   484 // CMuiuDynamicSettingsDialog::HandleEditorCancel()
       
   485 // ----------------------------------------------------------------------------
       
   486 //
       
   487 TMuiuPageResult CMuiuDynamicSettingsDialog::HandleEditorCancel()
       
   488     {
       
   489     // The editor was cancelled, so the first check needed to make
       
   490     // is deterimine, if the editor was first in the line.
       
   491     TMuiuPageResult result = EMuiuPageResultInvalidResult;
       
   492 
       
   493     TInt editorCount = iSettingsPageArray->Count();
       
   494     if ( editorCount == 1 )
       
   495         {
       
   496         // Restore all of the items
       
   497         RestoreFromBackup();
       
   498         result = EMuiuPageResultCancelled;
       
   499         }
       
   500     // More than one page in the array, just jump back to the previous
       
   501     // and remove the previous value
       
   502     else if ( editorCount > 0 )
       
   503         {
       
   504         RemoveLastBackupItem();
       
   505         iSettingsPageArray->Delete( editorCount-1 );
       
   506         result = EMuiuPageResultEditing;
       
   507         }
       
   508     // Array is empty, unexpected situation
       
   509     else
       
   510         {
       
   511         __ASSERT_DEBUG( EFalse, User::Panic(
       
   512             KMuiuDynSetDialogPanic, KErrNotFound ) );
       
   513         }
       
   514 
       
   515     return result;
       
   516     }
       
   517 
       
   518 // ----------------------------------------------------------------------------
       
   519 // CMuiuDynamicSettingsDialog::HandleEditorOk()
       
   520 // ----------------------------------------------------------------------------
       
   521 //
       
   522 TMuiuPageResult CMuiuDynamicSettingsDialog::HandleEditorOk()
       
   523     {
       
   524     CMuiuSettingBase* nextItem = NULL;
       
   525 
       
   526     // Check if current selection contains subeditors
       
   527     if ( iSettingValue >= 0 )
       
   528         {
       
   529         nextItem = SettingFindEditor(
       
   530             *CurrentSettingsPage(), iSettingValue );
       
   531         }
       
   532 
       
   533     TMuiuPageResult result = EMuiuPageResultInvalidResult;
       
   534 
       
   535     // In case subeditor is found, set the item to list and continue
       
   536     // editing
       
   537     if ( nextItem )
       
   538         {
       
   539         SetCurrentSettingsPage( *nextItem );
       
   540         result = EMuiuPageResultEditing;
       
   541         }
       
   542     // Cleanup the array and stop editing
       
   543     else
       
   544         {
       
   545         CleanBackupArray();
       
   546         result = EMuiuPageResultOk;
       
   547         }
       
   548 
       
   549     return result;
       
   550     }
       
   551 
       
   552 // ----------------------------------------------------------------------------
       
   553 // CMuiuDynamicSettingsDialog::HandleEditorDisapproved()
       
   554 // ----------------------------------------------------------------------------
       
   555 //
       
   556 TMuiuPageResult CMuiuDynamicSettingsDialog::HandleEditorDisapproved()
       
   557     {
       
   558     // Get current setting page
       
   559     CurrentSettingsPage()->SetText( iSettingText );
       
   560 
       
   561     return EMuiuPageResultEditing;
       
   562     }
       
   563 
       
   564 // ----------------------------------------------------------------------------
       
   565 // CMuiuDynamicSettingsDialog::SettingPageOpenEditorL()
       
   566 // ----------------------------------------------------------------------------
       
   567 //
       
   568 TMuiuPageResult CMuiuDynamicSettingsDialog::SettingPageOpenEditorL()
       
   569     {
       
   570     CMuiuSettingBase* currentEditor = CurrentSettingsPage();
       
   571 
       
   572     // Prepare setting page. The setting page shall be acquired
       
   573     // from the owner class, if required, or the setting page is
       
   574     // created with default values
       
   575     TMuiuDynSetUpdateMode updateMode;
       
   576     TMuiuFlags editorFlags = currentEditor->iItemFlags;
       
   577 
       
   578     // If enter pressed is set, the setting page won't be opened,
       
   579     // which means creation of page is not needed either
       
   580     if ( !editorFlags.Flag( EMuiuDynItemEnterPressed ) ||
       
   581          editorFlags.Flag( EMuiuDynItemOneTimeForceViewOpen ) )
       
   582         {
       
   583         if ( editorFlags.Flag( EMuiuDynItemAcquireCustomPage ) )
       
   584             {
       
   585             SettingPrepareAcquireL( updateMode, *currentEditor );
       
   586             __ASSERT_DEBUG( iSettingPage != NULL,
       
   587                 User::Panic( KMuiuDynSetDialogPanic, KErrUnknown ) );
       
   588             }
       
   589         else
       
   590             {
       
   591             SettingCreateEditorL( *currentEditor, updateMode );
       
   592             }
       
   593         }
       
   594 
       
   595     // Finally launch the editor
       
   596     return SettingLaunchPageLD( *currentEditor, updateMode );
       
   597     }
       
   598 
       
   599 // ----------------------------------------------------------------------------
       
   600 // CMuiuDynamicSettingsDialog::SettingPageOpenFinishL()
       
   601 // ----------------------------------------------------------------------------
       
   602 //
       
   603 void CMuiuDynamicSettingsDialog::SettingPageOpenFinishL()
       
   604     {
       
   605     // Clean up
       
   606     iDynSettingsFlags.ClearFlag( EMuiuDynSetRunningCustomPage );
       
   607     delete iButtonArray;
       
   608     iButtonArray = NULL;
       
   609     if ( iCheckboxArray )
       
   610         {
       
   611         iCheckboxArray->ResetAndDestroy();
       
   612         }
       
   613     delete iCheckboxArray;
       
   614     iCheckboxArray = NULL;
       
   615     iSettingPage = NULL;
       
   616     iSettingValue = KErrNotFound;
       
   617     delete iSettingText;
       
   618     iSettingText = NULL;
       
   619     delete iNewPassword;
       
   620     iNewPassword = NULL;
       
   621     delete iOldPassword;
       
   622     iOldPassword = NULL;
       
   623     }
       
   624 
       
   625 /******************************************************************************
       
   626 
       
   627     Settingpage Open
       
   628 
       
   629 ******************************************************************************/
       
   630 
       
   631 // ----------------------------------------------------------------------------
       
   632 // CIMSSettingsDialog::SettingFindEditor()
       
   633 // ----------------------------------------------------------------------------
       
   634 //
       
   635 CMuiuSettingBase* CMuiuDynamicSettingsDialog::SettingFindEditor(
       
   636     const CMuiuSettingBase& aBaseItem,
       
   637     const TInt aIndex,
       
   638     const TBool aExcludeHidden )
       
   639     {
       
   640     // The settings structure is constructed in a way, that the radiobutton
       
   641     // or the checkbox editor has the array of buttons. To retrieve the editor
       
   642     // first the radiobutton has to be retrieved, then inside the radiobutton,
       
   643     // the editor can be taken.
       
   644     CMuiuSettingBase* volunteerBase =
       
   645         GetSubItem( aBaseItem, aIndex, aExcludeHidden );
       
   646 
       
   647     // Make sure the item is found and check that it is
       
   648     if ( volunteerBase )
       
   649         {
       
   650         volunteerBase = GetSubItem( *volunteerBase, 0, EFalse );
       
   651         }
       
   652     else
       
   653         {
       
   654         volunteerBase = NULL;
       
   655         }
       
   656 
       
   657     // return the item
       
   658     return volunteerBase;
       
   659     }
       
   660 
       
   661 // ----------------------------------------------------------------------------
       
   662 // CIMSSettingsDialog::SettingFindEditor()
       
   663 // ----------------------------------------------------------------------------
       
   664 //
       
   665 CMuiuSettingBase* CMuiuDynamicSettingsDialog::SettingFindEditor(
       
   666     const CMuiuSettingBase& aBaseItem,
       
   667     const TUid& aId,
       
   668     const TBool aExcludeHidden )
       
   669     {
       
   670     // The settings structure is constructed in a way, that the radiobutton
       
   671     // or the checkbox editor has the array of buttons. To retrieve the editor
       
   672     // first the radiobutton has to be retrieved, then inside the radiobutton,
       
   673     // the editor can be taken.
       
   674     CMuiuSettingBase* volunteerBase =
       
   675         GetSubItem( aBaseItem, aId, aExcludeHidden );
       
   676 
       
   677     // Make sure the item is found and check that it is
       
   678     if ( volunteerBase )
       
   679         {
       
   680         volunteerBase = GetSubItem( *volunteerBase, 0, EFalse );
       
   681         }
       
   682     else
       
   683         {
       
   684         volunteerBase = NULL;
       
   685         }
       
   686 
       
   687     // return the item
       
   688     return volunteerBase;
       
   689     }
       
   690 
       
   691 // ----------------------------------------------------------------------------
       
   692 // CMuiuDynamicSettingsDialog::SettingPrepareAcquireRadioButtonPageL()
       
   693 // ----------------------------------------------------------------------------
       
   694 //
       
   695 void CMuiuDynamicSettingsDialog::SettingPrepareAcquireRadioButtonPageL(
       
   696     CMuiuSettingBase& aBaseItem )
       
   697     {
       
   698     // Convert the base item to link item and define button array
       
   699     CMuiuSettingsLink* radio = static_cast<CMuiuSettingsLink*>( &aBaseItem );
       
   700 
       
   701     // Make sure the link exist
       
   702     if ( !radio->iItemLinkArray )
       
   703         {
       
   704         radio->iItemLinkArray =
       
   705             new ( ELeave ) CMuiuDynSetItemArray( KMuiuDynArrayGranularity );
       
   706         }
       
   707 
       
   708     SettingCreateButtonArrayL( *radio->iItemLinkArray );
       
   709 
       
   710     iSettingValue = radio->Value();
       
   711     radio = NULL;
       
   712     }
       
   713 
       
   714 // ----------------------------------------------------------------------------
       
   715 // CMuiuDynamicSettingsDialog::SettingPrepareAcquireCheckboxPageL()
       
   716 // ----------------------------------------------------------------------------
       
   717 //
       
   718 void CMuiuDynamicSettingsDialog::SettingPrepareAcquireCheckboxPageL(
       
   719     CMuiuSettingBase& aBaseItem )
       
   720     {
       
   721     // Convert the base item to link item and define button array
       
   722     CMuiuSettingsLink* link = static_cast<CMuiuSettingsLink*>( &aBaseItem );
       
   723 
       
   724     // Make sure the link array exist
       
   725     if ( link->iItemLinkArray )
       
   726         {
       
   727         SettingCreateButtonArrayL( *link->iItemLinkArray );
       
   728         }
       
   729 
       
   730     link = NULL;
       
   731     }
       
   732 
       
   733 // ----------------------------------------------------------------------------
       
   734 // CMuiuDynamicSettingsDialog::SettingPrepareAcquireTextEditorPageL()
       
   735 // ----------------------------------------------------------------------------
       
   736 //
       
   737 void CMuiuDynamicSettingsDialog::SettingPrepareAcquireTextEditorPageL(
       
   738     CMuiuSettingBase& aBaseItem )
       
   739     {
       
   740     // Create either password or plain texts
       
   741     if ( aBaseItem.iItemFlags.Flag( EMuiuDynItemPassword ) )
       
   742         {
       
   743         iNewPassword = new ( ELeave ) TMuiuPasswordText( *aBaseItem.Text() );
       
   744         iOldPassword = new ( ELeave ) TMuiuPasswordText( *aBaseItem.Text() );
       
   745         }
       
   746     else
       
   747         {
       
   748         iSettingText = new ( ELeave ) TMuiuSettingsText( *aBaseItem.Text() );
       
   749         }
       
   750     }
       
   751 
       
   752 // ----------------------------------------------------------------------------
       
   753 // CMuiuDynamicSettingsDialog::SettingPrepareAcquireValueEditorPageL()
       
   754 // ----------------------------------------------------------------------------
       
   755 //
       
   756 void CMuiuDynamicSettingsDialog::SettingPrepareAcquireValueEditorPageL(
       
   757     CMuiuSettingBase& aBaseItem )
       
   758     {
       
   759     iSettingValue = aBaseItem.Value();
       
   760     }
       
   761 
       
   762 // ----------------------------------------------------------------------------
       
   763 // CMuiuDynamicSettingsDialog::SettingPrepareAcquireL()
       
   764 // ----------------------------------------------------------------------------
       
   765 //
       
   766 void CMuiuDynamicSettingsDialog::SettingPrepareAcquireL(
       
   767     TMuiuDynSetUpdateMode& aUpdateMode,
       
   768     CMuiuSettingBase& aBaseItem )
       
   769     {
       
   770     // Handle the item, based on the type
       
   771     switch ( aBaseItem.Type() )
       
   772         {
       
   773         // Radio button page
       
   774         case EMuiuDynSetRadioButtonArray:
       
   775             SettingPrepareAcquireRadioButtonPageL( aBaseItem );
       
   776             break;
       
   777 
       
   778         // Checkbox page
       
   779         case EMuiuDynSetCheckBoxArray:
       
   780             SettingPrepareAcquireCheckboxPageL( aBaseItem );
       
   781             break;
       
   782 
       
   783         // Text editor
       
   784         case EMuiuDynSetItemEditText:
       
   785             SettingPrepareAcquireTextEditorPageL( aBaseItem );
       
   786             break;
       
   787 
       
   788         // Number editor
       
   789         case EMuiuDynSetItemEditValue:
       
   790             SettingPrepareAcquireValueEditorPageL( aBaseItem );
       
   791             break;
       
   792 
       
   793         // Type is not recognized
       
   794         default:
       
   795             __ASSERT_DEBUG( EFalse,
       
   796                 User::Panic( KMuiuDynSetDialogPanic, KErrUnknown ) );
       
   797             User::Leave( KErrUnknown );
       
   798         }
       
   799 
       
   800     // Acquire the custom setting page
       
   801     AcquireCustomSettingPageL(
       
   802         iSettingPage, aUpdateMode, iSettingValue,
       
   803         *iSettingText, *iButtonArray, aBaseItem );
       
   804     }
       
   805 
       
   806 // ----------------------------------------------------------------------------
       
   807 // CMuiuDynamicSettingsDialog::AcquireCustomSettingPageL()
       
   808 // ----------------------------------------------------------------------------
       
   809 //
       
   810 void CMuiuDynamicSettingsDialog::AcquireCustomSettingPageL(
       
   811     CAknSettingPage*& /* aReturnPage */,
       
   812     TMuiuDynSetUpdateMode& /* aReturnUpdateMode */,
       
   813     TInt& /* aReturnSettingValue */,
       
   814     TMuiuSettingsText& /* aReturnSettingText */,
       
   815     CDesCArrayFlat& /* aParamRadioButtonArray */,
       
   816     CMuiuSettingBase& /* aParamBaseItem */ )
       
   817     {
       
   818     }
       
   819 
       
   820 // ----------------------------------------------------------------------------
       
   821 // CMuiuDynamicSettingsDialog::SettingCreateEditorL()
       
   822 // ----------------------------------------------------------------------------
       
   823 //
       
   824 void CMuiuDynamicSettingsDialog::SettingCreateEditorL(
       
   825     CMuiuSettingBase& aBaseItem,
       
   826     TMuiuDynSetUpdateMode& aUpdateMode )
       
   827     {
       
   828     // Create different editors for password settings
       
   829     if ( aBaseItem.iItemFlags.Flag( EMuiuDynItemPassword ) )
       
   830         {
       
   831         switch ( aBaseItem.iItemType )
       
   832             {
       
   833             case EMuiuDynSetItemEditText:
       
   834                 SettingCreatePasswordTextEditorPageL(
       
   835                     aBaseItem, aUpdateMode );
       
   836                 break;
       
   837 
       
   838             }
       
   839         }
       
   840     // Normal editors
       
   841     else
       
   842         {
       
   843         switch ( aBaseItem.iItemType )
       
   844             {
       
   845             case EMuiuDynSetRadioButtonArray:
       
   846                 SettingCreateRadioButtonPageL( aBaseItem, aUpdateMode );
       
   847                 break;
       
   848 
       
   849             case EMuiuDynSetCheckBoxArray:
       
   850                 SettingCreateCheckboxPageL( aBaseItem, aUpdateMode );
       
   851                 break;
       
   852 
       
   853             case EMuiuDynSetItemEditText:
       
   854                 SettingCreatePlainTextEditorPageL(
       
   855                     aBaseItem, aUpdateMode );
       
   856                 break;
       
   857 
       
   858             case EMuiuDynSetItemEditValue:
       
   859                 SettingCreatePlainNumberEditorPageL(
       
   860                     aBaseItem, aUpdateMode );
       
   861                 break;
       
   862 
       
   863             case EMuiuDynSetItemEditScValue:
       
   864                 SettingCreateScNumberEditorPageL(
       
   865                     aBaseItem, aUpdateMode );
       
   866                 break;
       
   867 
       
   868             default:
       
   869                 break;
       
   870             }
       
   871         }
       
   872     }
       
   873 
       
   874 // ----------------------------------------------------------------------------
       
   875 // CMuiuDynamicSettingsDialog::DefineDefaultSettingPageL()
       
   876 // ----------------------------------------------------------------------------
       
   877 //
       
   878 TMuiuDynSetUpdateMode CMuiuDynamicSettingsDialog::DefineDefaultSettingPageL(
       
   879     const CMuiuSettingBase& aBase )
       
   880     {
       
   881     // Create the aSetting page
       
   882     iSettingPage->SetSettingTextL( *aBase.iItemLabel );
       
   883 
       
   884     // Determine the update mode
       
   885     return aBase.iItemFlags.Flag( EMuiuDynItemUpdateOnChange ) ?
       
   886             CAknSettingPage::EUpdateWhenChanged :
       
   887             CAknSettingPage::EUpdateWhenAccepted;
       
   888     }
       
   889 
       
   890 // ----------------------------------------------------------------------------
       
   891 // CMuiuDynamicSettingsDialog::SettingCreateButtonArrayL()
       
   892 // ----------------------------------------------------------------------------
       
   893 //
       
   894 void CMuiuDynamicSettingsDialog::SettingCreateButtonArrayL(
       
   895     CMuiuDynSetItemArray& aButtonArray )
       
   896     {
       
   897     // Get the item count in array
       
   898     const TInt count = aButtonArray.Count();
       
   899     iButtonArray = new ( ELeave ) CDesCArrayFlat( KMuiuDynArrayGranularity );
       
   900 
       
   901     // Do number conversion to all items and add them to temporary array
       
   902     for ( TInt item = 0; item < count; item++ )
       
   903         {
       
   904         CMuiuSettingBase* base = aButtonArray[item];
       
   905 
       
   906         // Append only visible items on the list
       
   907         if ( !IsHidden( *base ) )
       
   908             {
       
   909             HBufC* label = base->iItemLabel->AllocLC();
       
   910             TPtr labelPtr = label->Des();
       
   911 
       
   912             // Do number conversion when needed
       
   913             if ( base->iItemFlags.Flag( EMuiuDynItemLangSpecificNumConv ) )
       
   914                 {
       
   915                 AknTextUtils::DisplayTextLanguageSpecificNumberConversion(
       
   916                     labelPtr );
       
   917                 }
       
   918 
       
   919             // Insert to array and delete old item
       
   920             iButtonArray->AppendL( *label );
       
   921             CleanupStack::PopAndDestroy( label );
       
   922             label = NULL;
       
   923             }
       
   924         }
       
   925     }
       
   926 
       
   927 // ----------------------------------------------------------------------------
       
   928 // CMuiuDynamicSettingsDialog::SettingCreateCheckboxArrayL()
       
   929 // ----------------------------------------------------------------------------
       
   930 //
       
   931 void CMuiuDynamicSettingsDialog::SettingCreateCheckboxArrayL(
       
   932     CMuiuDynSetItemArray& aButtonArray )
       
   933     {
       
   934     // Get the item count in array
       
   935     const TInt count = aButtonArray.Count();
       
   936     iCheckboxArray =
       
   937         new ( ELeave ) CSelectionItemList( KMuiuDynArrayGranularity );
       
   938 
       
   939     // Do number conversion to all items and add them to temporary array
       
   940     for ( TInt item = 0; item < count; item++ )
       
   941         {
       
   942         CMuiuSettingBase* base = aButtonArray[item];
       
   943 
       
   944         // Append only visible items on the list
       
   945         if ( !IsHidden( *base ) )
       
   946             {
       
   947             HBufC* label = base->iItemLabel->AllocLC();
       
   948             TPtr labelPtr = label->Des();
       
   949 
       
   950             // Do number conversion when needed
       
   951             if ( base->iItemFlags.Flag( EMuiuDynItemLangSpecificNumConv ) )
       
   952                 {
       
   953                 AknTextUtils::DisplayTextLanguageSpecificNumberConversion(
       
   954                     labelPtr );
       
   955                 }
       
   956 
       
   957             // Create item and check it
       
   958             CSelectableItem* checkbox =
       
   959                 new ( ELeave ) CSelectableItem(
       
   960                     *label, base->iItemFlags.Flag( EMuiuDynItemChecked ) );
       
   961             CleanupStack::PushL( checkbox );
       
   962             checkbox->ConstructL();
       
   963 
       
   964             // Insert to array and delete old item
       
   965             iCheckboxArray->AppendL( checkbox );
       
   966             CleanupStack::Pop( checkbox );
       
   967             CleanupStack::PopAndDestroy( label );
       
   968             label = NULL;
       
   969             }
       
   970         }
       
   971     }
       
   972 
       
   973 // ----------------------------------------------------------------------------
       
   974 // CMuiuDynamicSettingsDialog::SettingCreateRadioButtonPageL()
       
   975 // ----------------------------------------------------------------------------
       
   976 //
       
   977 void CMuiuDynamicSettingsDialog::SettingCreateRadioButtonPageL(
       
   978     CMuiuSettingBase& aBaseItem,
       
   979     TMuiuDynSetUpdateMode& aUpdateMode )
       
   980     {
       
   981     // Convert the base item to radiobutton item
       
   982     CMuiuSettingsLinkExtended* radioArray =
       
   983         static_cast<CMuiuSettingsLinkExtended*>( &aBaseItem );
       
   984 
       
   985     // Create button array for the page and set the selection for page
       
   986     SettingCreateButtonArrayL( *radioArray->iItemLinkArray );
       
   987     iSettingValue = radioArray->Value();
       
   988 
       
   989     // Create the setting page to member
       
   990     iSettingPage = ( new ( ELeave ) CAknRadioButtonSettingPage(
       
   991         ( *iSettingPageResources )[EIPRRadioButton],
       
   992         iSettingValue, iButtonArray ) );
       
   993 
       
   994     // Apply defaults
       
   995     aUpdateMode = DefineDefaultSettingPageL( aBaseItem );
       
   996     }
       
   997 
       
   998 // ----------------------------------------------------------------------------
       
   999 // CMuiuDynamicSettingsDialog::SettingCreateCheckboxPageL()
       
  1000 // ----------------------------------------------------------------------------
       
  1001 //
       
  1002 void CMuiuDynamicSettingsDialog::SettingCreateCheckboxPageL(
       
  1003     CMuiuSettingBase& aBaseItem,
       
  1004     TMuiuDynSetUpdateMode& aUpdateMode )
       
  1005     {
       
  1006     // Convert the base item to radiobutton item
       
  1007     CMuiuSettingsLink* radioArray =
       
  1008         static_cast<CMuiuSettingsLink*>( &aBaseItem );
       
  1009 
       
  1010     // Create button array for the page
       
  1011     SettingCreateCheckboxArrayL( *radioArray->iItemLinkArray );
       
  1012 
       
  1013     // Create the setting page to member
       
  1014     iSettingPage = new ( ELeave ) CIMSSettingsWizardCheckBoxPage(
       
  1015         ( *iSettingPageResources )[EIPRCheckbox], iCheckboxArray,
       
  1016         aBaseItem.iItemFlags.Flag( EMuiuDynItemForceMustFill ) );
       
  1017 
       
  1018     // Apply defaults
       
  1019     aUpdateMode = DefineDefaultSettingPageL( aBaseItem );
       
  1020     }
       
  1021 
       
  1022 // ----------------------------------------------------------------------------
       
  1023 // CMuiuDynamicSettingsDialog::SettingCreatePlainTextEditorPageL()
       
  1024 // ----------------------------------------------------------------------------
       
  1025 //
       
  1026 void CMuiuDynamicSettingsDialog::SettingCreatePlainTextEditorPageL(
       
  1027     CMuiuSettingBase& aBaseItem,
       
  1028     TMuiuDynSetUpdateMode& aUpdateMode )
       
  1029     {
       
  1030     // Get the text to be edited
       
  1031     CMuiuSettingsEditText* textEditor =
       
  1032         static_cast<CMuiuSettingsEditText*>( &aBaseItem );
       
  1033     iSettingText = new ( ELeave ) TMuiuSettingsText( *textEditor->Text() );
       
  1034     iSettingText->Copy( *textEditor->Text() );
       
  1035 
       
  1036     // Define flags according to item
       
  1037     TInt flags = GetTextEditorFlags( aBaseItem );
       
  1038 
       
  1039     // Create the setting page using the flags
       
  1040     TInt pageResource = ( *iSettingPageResources )[EIPRText];
       
  1041     CAknTextSettingPage* settingPage =
       
  1042         new ( ELeave ) CAknTextSettingPage(
       
  1043             pageResource, *iSettingText, flags );
       
  1044     CleanupStack::PushL( settingPage );
       
  1045     settingPage->ConstructL();
       
  1046     CEikEdwin& txtCtrl = *settingPage->TextControl();
       
  1047     txtCtrl.SetTextLimit( textEditor->iItemMaxLength );
       
  1048 
       
  1049     if ( textEditor->iItemFlags.Flag( EMuiuDynItemLatinOnly ) )
       
  1050         {
       
  1051         txtCtrl.SetAknEditorFlags(
       
  1052             EAknEditorFlagLatinInputModesOnly | EAknEditorFlagNoT9 );
       
  1053         }
       
  1054 
       
  1055     iSettingPage = settingPage;
       
  1056     CleanupStack::Pop( settingPage );
       
  1057 
       
  1058     // Apply defaults
       
  1059     aUpdateMode = DefineDefaultSettingPageL( aBaseItem );
       
  1060     }
       
  1061 
       
  1062 // ----------------------------------------------------------------------------
       
  1063 // CMuiuDynamicSettingsDialog::SettingCreatePasswordTextEditorPageL()
       
  1064 // ----------------------------------------------------------------------------
       
  1065 //
       
  1066 void CMuiuDynamicSettingsDialog::SettingCreatePasswordTextEditorPageL(
       
  1067     CMuiuSettingBase& aBaseItem,
       
  1068     TMuiuDynSetUpdateMode& aUpdateMode )
       
  1069     {
       
  1070     // Prepare password and save the old
       
  1071     CMuiuSettingsEditText* textEditor =
       
  1072         static_cast<CMuiuSettingsEditText*>( &aBaseItem );
       
  1073 
       
  1074     iNewPassword = new ( ELeave ) TMuiuPasswordText(
       
  1075         textEditor->Text()->Left( KMuiuDynMaxPasswordLength ) );
       
  1076     iOldPassword = new ( ELeave ) TMuiuPasswordText(
       
  1077         textEditor->Text()->Left( KMuiuDynMaxPasswordLength ) );
       
  1078 
       
  1079     // Create the settings page
       
  1080     iSettingPage = ( new ( ELeave ) CAknAlphaPasswordSettingPage(
       
  1081         ( *iSettingPageResources )[EIPRSecret],
       
  1082         *iNewPassword, *iOldPassword ) );
       
  1083     iSettingPage->ConstructL();
       
  1084     CAknAlphaPasswordSettingPage* pwPage =
       
  1085         static_cast<CAknAlphaPasswordSettingPage*>( iSettingPage );
       
  1086     pwPage->SetMaxPasswordLength( textEditor->iItemMaxLength );
       
  1087     if ( pwPage->AlphaPasswordEditor() )
       
  1088         {
       
  1089         pwPage->AlphaPasswordEditor()->SetMaxLength(
       
  1090             textEditor->iItemMaxLength );
       
  1091         }
       
  1092 
       
  1093     // Apply defaults
       
  1094     aUpdateMode = DefineDefaultSettingPageL( aBaseItem );
       
  1095     }
       
  1096 
       
  1097 // ----------------------------------------------------------------------------
       
  1098 // CMuiuDynamicSettingsDialog::SettingCreatePlainNumberEditorPageL()
       
  1099 // ----------------------------------------------------------------------------
       
  1100 //
       
  1101 void CMuiuDynamicSettingsDialog::SettingCreatePlainNumberEditorPageL(
       
  1102     CMuiuSettingBase& aBaseItem,
       
  1103     TMuiuDynSetUpdateMode& aUpdateMode )
       
  1104     {
       
  1105     // Conver item and set the value
       
  1106     CMuiuSettingsEditValue* numberEditor =
       
  1107         static_cast<CMuiuSettingsEditValue*>( &aBaseItem );
       
  1108     iSettingValue = numberEditor->Value();
       
  1109 
       
  1110     // Define flags according to item
       
  1111     TInt flags = GetValueEditorFlags( aBaseItem );
       
  1112 
       
  1113     // Create aSetting page
       
  1114     iSettingPage = ( new ( ELeave ) CAknIntegerSettingPage(
       
  1115         ( *iSettingPageResources )[EIPRNumber],
       
  1116             *&iSettingValue , flags ) );
       
  1117     iSettingPage->ConstructL();
       
  1118 
       
  1119     CEikEdwin* textControl = static_cast<CAknIntegerSettingPage*>(
       
  1120                                         iSettingPage )->TextControl();
       
  1121 
       
  1122 
       
  1123     textControl->SetTextLimit( numberEditor->iItemMaxLength );
       
  1124     textControl->SetAknEditorNumericKeymap( EAknEditorPlainNumberModeKeymap );
       
  1125 
       
  1126 
       
  1127     // Apply defaults, for number editors, the update mode has to be onchange
       
  1128     aBaseItem.iItemFlags.SetFlag( EMuiuDynItemUpdateOnChange );
       
  1129     aUpdateMode = DefineDefaultSettingPageL( aBaseItem );
       
  1130     }
       
  1131 
       
  1132 // ----------------------------------------------------------------------------
       
  1133 // CMuiuDynamicSettingsDialog::SettingCreateScNumberEditorPageL()
       
  1134 // ----------------------------------------------------------------------------
       
  1135 //
       
  1136 void CMuiuDynamicSettingsDialog::SettingCreateScNumberEditorPageL(
       
  1137     CMuiuSettingBase& aBaseItem,
       
  1138     TMuiuDynSetUpdateMode& aUpdateMode )
       
  1139     {
       
  1140     // Conver item and set the value
       
  1141     CMuiuSettingsEditText* textEditor =
       
  1142         static_cast<CMuiuSettingsEditText*>( &aBaseItem );
       
  1143     iSettingText = new ( ELeave ) TMuiuSettingsText( *textEditor->Text() );
       
  1144     iSettingText->Copy( *textEditor->Text() );
       
  1145 
       
  1146     if ( aBaseItem.iItemFlags.Flag( EMuiuDynItemLangSpecificNumConv ) )
       
  1147         {
       
  1148         AknTextUtils::DisplayTextLanguageSpecificNumberConversion(
       
  1149             *iSettingText );
       
  1150         }
       
  1151 
       
  1152     // Define flags according to item
       
  1153     TInt flags = CAknIntegerSettingPage::EInvalidValueNotOffered;
       
  1154     flags |= !aBaseItem.iItemFlags.Flag( EMuiuDynItemForceMustFill ) &
       
  1155         CAknIntegerSettingPage::EEmptyValueAllowed;
       
  1156     flags |= aBaseItem.iItemFlags.Flag( EMuiuDynItemNoInitialSelection ) &
       
  1157         CAknIntegerSettingPage::ENoInitialSelection;
       
  1158     flags |= aBaseItem.iItemFlags.Flag( EMuiuDynItemEditorCursorAtBeginning ) &
       
  1159         CAknIntegerSettingPage::EPutCursorAtBeginning;
       
  1160 
       
  1161     // Create aSetting page
       
  1162     iSettingPage = ( new ( ELeave ) CAknTextSettingPage(
       
  1163         ( *iSettingPageResources )[EIPRScNumber],
       
  1164         *iSettingText, flags ) );
       
  1165     iSettingPage->ConstructL();
       
  1166     static_cast<CAknTextSettingPage*>( iSettingPage
       
  1167         )->TextControl()->SetTextLimit( textEditor->iItemMaxLength );
       
  1168     iSettingPage->SetSettingTextL( *textEditor->iItemLabel );
       
  1169 
       
  1170     // Apply defaults
       
  1171     aUpdateMode = DefineDefaultSettingPageL( aBaseItem );
       
  1172     }
       
  1173 
       
  1174 // ----------------------------------------------------------------------------
       
  1175 // CMuiuDynamicSettingsDialog::SettingLaunchPageLD()
       
  1176 // ----------------------------------------------------------------------------
       
  1177 //
       
  1178 TMuiuPageResult CMuiuDynamicSettingsDialog::SettingLaunchPageLD(
       
  1179     CMuiuSettingBase& aBaseItem,
       
  1180     TMuiuDynSetUpdateMode& aUpdateMode )
       
  1181     {
       
  1182     switch ( aBaseItem.Type() )
       
  1183         {
       
  1184         case EMuiuDynSetRadioButtonArray:
       
  1185             return SettingLaunchRadioButtonPageLD(
       
  1186                 aBaseItem, aUpdateMode );
       
  1187 
       
  1188         case EMuiuDynSetCheckBoxArray:
       
  1189             return SettingLaunchCheckboxPageLD( aBaseItem, aUpdateMode );
       
  1190 
       
  1191         case EMuiuDynSetItemEditText:
       
  1192         case EMuiuDynSetItemEditScValue:
       
  1193             return SettingLaunchTextEditorPageLD( aBaseItem, aUpdateMode );
       
  1194 
       
  1195         case EMuiuDynSetItemEditValue:
       
  1196             return SettingLaunchNumberEditorPageLD( aBaseItem, aUpdateMode );
       
  1197 
       
  1198         // Multiline dialogs are launched from client only
       
  1199         case EMuiuDynSetItemMultiLine:
       
  1200             return SettingLaunchMultilinePageL( aBaseItem, aUpdateMode );
       
  1201 
       
  1202         default:
       
  1203             __ASSERT_DEBUG( EFalse, User::Panic(
       
  1204                 KMuiuDynSetDialogPanic, KErrUnknown ) );
       
  1205             return EMuiuPageResultCancelled;
       
  1206         }
       
  1207     }
       
  1208 
       
  1209 // ----------------------------------------------------------------------------
       
  1210 // CMuiuDynamicSettingsDialog::SettingLaunchRadioButtonPageLD()
       
  1211 // ----------------------------------------------------------------------------
       
  1212 //
       
  1213 TMuiuPageResult CMuiuDynamicSettingsDialog::SettingLaunchRadioButtonPageLD(
       
  1214     CMuiuSettingBase& aBaseItem,
       
  1215     TMuiuDynSetUpdateMode& aUpdateMode )
       
  1216     {
       
  1217     // Convert the base item to radio item
       
  1218     CMuiuSettingsLink* linkArray = static_cast<CMuiuSettingsLink*>( &aBaseItem );
       
  1219     TMuiuPageResult result = EMuiuPageResultOk;
       
  1220 
       
  1221     if ( linkArray->iItemFlags.Flag( EMuiuDynItemEnterPressed ) &&
       
  1222          !linkArray->iItemFlags.Flag( EMuiuDynItemOneTimeForceViewOpen ) )
       
  1223         {
       
  1224         TInt value = !linkArray->Value();
       
  1225         TMuiuPageEventResult evaluation =
       
  1226             EventItemEvaluateRadioButton( *linkArray, value );
       
  1227 
       
  1228         // Handle approved item
       
  1229         if ( evaluation == EMuiuPageEventResultApproved )
       
  1230             {
       
  1231             // Change the value and the text
       
  1232             linkArray->SetValue( value );
       
  1233             linkArray->iItemSettingText->Copy(
       
  1234                 *( *linkArray->iItemLinkArray
       
  1235                     )[value]->iItemLabel );
       
  1236             }
       
  1237 
       
  1238         result = EMuiuPageResultOk;
       
  1239         }
       
  1240     else
       
  1241         {
       
  1242         // Opening the editor, clear flag immediately
       
  1243         linkArray->iItemFlags.ClearFlag( EMuiuDynItemOneTimeForceViewOpen );
       
  1244 
       
  1245         // Launch the settings dialog and update the item, if item is valid
       
  1246         if ( iSettingPage->ExecuteLD( aUpdateMode ) > 0 )
       
  1247             {
       
  1248             iSettingPage = NULL;
       
  1249             TMuiuPageEventResult evaluation =
       
  1250                 EventItemEvaluateRadioButton( *linkArray, iSettingValue );
       
  1251 
       
  1252             // Handle approved item
       
  1253             if ( evaluation == EMuiuPageEventResultApproved )
       
  1254                 {
       
  1255                 // First store the index value from the visible radiobutton array
       
  1256                 linkArray->SetValue( iSettingValue );
       
  1257                 CMuiuSettingBase* subItem =
       
  1258                     GetSubItem( *linkArray, iSettingValue );
       
  1259 
       
  1260                 // Mark the item as checked and copy the text
       
  1261                 if ( subItem )
       
  1262                     {
       
  1263                     CheckRadioButton( *linkArray, subItem->iItemId );
       
  1264                     linkArray->iItemSettingText->Copy( *subItem->iItemLabel );
       
  1265                     }
       
  1266 
       
  1267                 result = EMuiuPageResultOk;
       
  1268                 }
       
  1269             // Handle disapproved item
       
  1270             else if ( evaluation == EMuiuPageEventResultDisapproved )
       
  1271                 {
       
  1272                 result = EMuiuPageResultEditing;
       
  1273                 }
       
  1274             // Handle cancelled item
       
  1275             else
       
  1276                 {
       
  1277                 result = EMuiuPageResultCancelled;
       
  1278                 }
       
  1279             }
       
  1280         else
       
  1281             {
       
  1282             // Editor cancelled
       
  1283             iSettingPage = NULL;
       
  1284             result = EMuiuPageResultCancelled;
       
  1285             }
       
  1286         }
       
  1287 
       
  1288     linkArray = NULL;
       
  1289 
       
  1290     // Return the result
       
  1291     return result;
       
  1292     }
       
  1293 
       
  1294 // ----------------------------------------------------------------------------
       
  1295 // CMuiuDynamicSettingsDialog::SettingLaunchCheckboxPageLD()
       
  1296 // ----------------------------------------------------------------------------
       
  1297 //
       
  1298 TMuiuPageResult CMuiuDynamicSettingsDialog::SettingLaunchCheckboxPageLD(
       
  1299     CMuiuSettingBase& aBaseItem,
       
  1300     TMuiuDynSetUpdateMode& aUpdateMode )
       
  1301     {
       
  1302     // Convert the base item to link item
       
  1303     CMuiuSettingsLinkExtended* checkboxArray =
       
  1304         static_cast<CMuiuSettingsLinkExtended*>( &aBaseItem );
       
  1305     TMuiuPageResult result = EMuiuPageResultOk;
       
  1306 
       
  1307     // Launch the settings dialog and update the item, if item is valid
       
  1308     if ( iSettingPage->ExecuteLD( aUpdateMode ) )
       
  1309         {
       
  1310         iSettingPage = NULL;
       
  1311         TMuiuPageEventResult evaluation =
       
  1312             EventItemEvaluateValue( aBaseItem, iSettingValue );
       
  1313 
       
  1314         if ( evaluation == EMuiuPageEventResultApproved )
       
  1315             {
       
  1316             // Clean the value
       
  1317             TInt checkbox = 0;
       
  1318 
       
  1319             // Check all items in the array, and set the flags to item
       
  1320             for ( TInt item = iCheckboxArray->Count(); --item >= 0; )
       
  1321                 {
       
  1322                 TBool checked = iCheckboxArray->At( item )->SelectionStatus();
       
  1323                 checkboxArray->iItemLinkArray->At( item )->iItemFlags.ChangeFlag(
       
  1324                     EMuiuDynItemChecked, checked );
       
  1325 
       
  1326                 checkbox |= ( checked << item );
       
  1327                 }
       
  1328 
       
  1329             checkboxArray->SetValue( checkbox );
       
  1330 
       
  1331             result = EMuiuPageResultOk;
       
  1332             }
       
  1333         // Handle disapproved item
       
  1334         else if ( evaluation == EMuiuPageEventResultDisapproved )
       
  1335             {
       
  1336             result = EMuiuPageResultEditing;
       
  1337             }
       
  1338         // Handle cancelled item
       
  1339         else
       
  1340             {
       
  1341             result = EMuiuPageResultCancelled;
       
  1342             }
       
  1343         }
       
  1344     else
       
  1345         {
       
  1346         // Editor cancelled
       
  1347         iSettingPage = NULL;
       
  1348         result = EMuiuPageResultCancelled;
       
  1349         }
       
  1350 
       
  1351     return result;
       
  1352     }
       
  1353 
       
  1354 // ----------------------------------------------------------------------------
       
  1355 // CMuiuDynamicSettingsDialog::SettingLaunchTextEditorPageLD()
       
  1356 // ----------------------------------------------------------------------------
       
  1357 //
       
  1358 TMuiuPageResult CMuiuDynamicSettingsDialog::SettingLaunchTextEditorPageLD(
       
  1359     CMuiuSettingBase& aBaseItem,
       
  1360     TMuiuDynSetUpdateMode& aUpdateMode )
       
  1361     {
       
  1362     TMuiuPageResult result = EMuiuPageResultOk;
       
  1363 
       
  1364     if ( iSettingPage->ExecuteLD( aUpdateMode ) > 0 )
       
  1365         {
       
  1366         iSettingPage = NULL;
       
  1367         TMuiuSettingsText* settingText = new(ELeave) TMuiuSettingsText;
       
  1368 
       
  1369         // Depending on the text editor, choose the correct text
       
  1370         if ( aBaseItem.iItemFlags.Flag( EMuiuDynItemPassword ) )
       
  1371             {
       
  1372             settingText->Copy( *iNewPassword );
       
  1373             }
       
  1374         else
       
  1375             {
       
  1376             settingText->Copy( *iSettingText );
       
  1377             }
       
  1378 
       
  1379         TMuiuPageEventResult evaluation =
       
  1380             EventItemEvaluateText( aBaseItem, *settingText );
       
  1381 
       
  1382         if ( evaluation == EMuiuPageEventResultApproved )
       
  1383             {
       
  1384             // Text is ok, store the text and close editor
       
  1385             aBaseItem.SetText( settingText );
       
  1386             }
       
  1387         // Handle disapproved item
       
  1388         else if ( evaluation == EMuiuPageEventResultDisapproved )
       
  1389             {
       
  1390             result = EMuiuPageResultEditing;
       
  1391             }
       
  1392         // Handle cancelled item
       
  1393         else
       
  1394             {
       
  1395             result = EMuiuPageResultCancelled;
       
  1396             }
       
  1397         }
       
  1398     else
       
  1399         {
       
  1400         iSettingPage = NULL;
       
  1401         result = EMuiuPageResultCancelled;
       
  1402         }
       
  1403 
       
  1404     return result;
       
  1405     }
       
  1406 
       
  1407 // ----------------------------------------------------------------------------
       
  1408 // CMuiuDynamicSettingsDialog::SettingLaunchNumberEditorPageLD()
       
  1409 // ----------------------------------------------------------------------------
       
  1410 //
       
  1411 TMuiuPageResult CMuiuDynamicSettingsDialog::SettingLaunchNumberEditorPageLD(
       
  1412     CMuiuSettingBase& aBaseItem,
       
  1413     TMuiuDynSetUpdateMode& aUpdateMode )
       
  1414     {
       
  1415     TMuiuPageResult result = EMuiuPageResultOk;
       
  1416 
       
  1417     // Convert baseitem to number editor
       
  1418     CMuiuSettingsEditValue* numberEdit =
       
  1419         static_cast<CMuiuSettingsEditValue*>( &aBaseItem );
       
  1420 
       
  1421     // Launch the editor and fill the settings if approved
       
  1422     if ( iSettingPage->ExecuteLD( aUpdateMode ) )
       
  1423         {
       
  1424         iSettingPage = NULL;
       
  1425         TMuiuPageEventResult evaluation =
       
  1426             EventItemEvaluateValue( aBaseItem, iSettingValue );
       
  1427 
       
  1428         // Evaluate item
       
  1429         if ( evaluation == EMuiuPageEventResultApproved )
       
  1430             {
       
  1431             // Item ok
       
  1432             numberEdit->SetValue( iSettingValue );
       
  1433             numberEdit->iItemSettingText->Num( iSettingValue );
       
  1434             result = EMuiuPageResultOk;
       
  1435             }
       
  1436         // Handle disapproved item
       
  1437         else if ( evaluation == EMuiuPageEventResultDisapproved )
       
  1438             {
       
  1439             result = EMuiuPageResultEditing;
       
  1440             }
       
  1441         // Handle cancelled item
       
  1442         else
       
  1443             {
       
  1444             result = EMuiuPageResultCancelled;
       
  1445             }
       
  1446         }
       
  1447     else
       
  1448         {
       
  1449         // Editor cancelled
       
  1450         iSettingPage = NULL;
       
  1451         result = EMuiuPageResultCancelled;
       
  1452         }
       
  1453 
       
  1454     return result;
       
  1455     }
       
  1456 
       
  1457 // ----------------------------------------------------------------------------
       
  1458 // CMuiuDynamicSettingsDialog::SettingLaunchScNumberEditorPageLD()
       
  1459 // ----------------------------------------------------------------------------
       
  1460 //
       
  1461 TMuiuPageResult CMuiuDynamicSettingsDialog::SettingLaunchScNumberEditorPageLD(
       
  1462     CMuiuSettingBase& aBaseItem,
       
  1463     TMuiuDynSetUpdateMode& aUpdateMode )
       
  1464     {
       
  1465     // Convert baseitem to number editor
       
  1466     CMuiuSettingsEditText* textEditor =
       
  1467         static_cast<CMuiuSettingsEditText*>( &aBaseItem );
       
  1468     TMuiuPageResult result = EMuiuPageResultOk;
       
  1469 
       
  1470     // Launch the editor and fill the settings if approved
       
  1471     if ( iSettingPage->ExecuteLD( aUpdateMode ) )
       
  1472         {
       
  1473         iSettingPage = NULL;
       
  1474         TMuiuPageEventResult evaluation =
       
  1475             EventItemEvaluateText( aBaseItem, *iSettingText );
       
  1476 
       
  1477         if ( evaluation == EMuiuPageEventResultApproved )
       
  1478             {
       
  1479             // Item ok
       
  1480             AknTextUtils::ConvertDigitsTo( *iSettingText, EDigitTypeWestern );
       
  1481             textEditor->SetText( iSettingText );
       
  1482             result = EMuiuPageResultOk;
       
  1483             }
       
  1484         // Handle disapproved item
       
  1485         else if ( evaluation == EMuiuPageEventResultDisapproved )
       
  1486             {
       
  1487             result = EMuiuPageResultEditing;
       
  1488             }
       
  1489         // Handle cancelled item
       
  1490         else
       
  1491             {
       
  1492             result = EMuiuPageResultCancelled;
       
  1493             }
       
  1494         }
       
  1495     else
       
  1496         {
       
  1497         // Editor cancelled
       
  1498         iSettingPage = NULL;
       
  1499         result = EMuiuPageResultCancelled;
       
  1500         }
       
  1501 
       
  1502     return result;
       
  1503     }
       
  1504 
       
  1505 // ----------------------------------------------------------------------------
       
  1506 // CMuiuDynamicSettingsDialog::SettingLaunchMultilinePageL()
       
  1507 // ----------------------------------------------------------------------------
       
  1508 //
       
  1509 TMuiuPageResult CMuiuDynamicSettingsDialog::SettingLaunchMultilinePageL(
       
  1510     CMuiuSettingBase& aBaseItem,
       
  1511     TMuiuDynSetUpdateMode& aUpdateMode )
       
  1512     {
       
  1513     TMuiuPageEventResult result =
       
  1514         SettingLaunchMultilineEditorL( aBaseItem, aUpdateMode );
       
  1515 
       
  1516     switch ( result )
       
  1517         {
       
  1518         case EMuiuPageEventResultApproved:
       
  1519             return EMuiuPageResultOk;
       
  1520 
       
  1521         case EMuiuPageEventResultDisapproved:
       
  1522             return EMuiuPageResultEditing;
       
  1523 
       
  1524         default:
       
  1525         case EMuiuPageEventResultCancel:
       
  1526             break;
       
  1527         }
       
  1528 
       
  1529     return EMuiuPageResultCancelled;
       
  1530     }
       
  1531 
       
  1532 // ----------------------------------------------------------------------------
       
  1533 // CMuiuDynamicSettingsDialog::SettingLaunchMultilineEditorL()
       
  1534 // ----------------------------------------------------------------------------
       
  1535 //
       
  1536 TMuiuPageEventResult CMuiuDynamicSettingsDialog::SettingLaunchMultilineEditorL(
       
  1537     CMuiuSettingBase& /* aBaseItem */,
       
  1538     TMuiuDynSetUpdateMode& /* aUpdateMode */ )
       
  1539     {
       
  1540     // This should be called from the client side
       
  1541     __ASSERT_DEBUG( EFalse,
       
  1542         User::Panic( KMuiuDynSetDialogPanic, KErrUnknown ) );
       
  1543 
       
  1544     return EMuiuPageEventResultCancel;
       
  1545     }
       
  1546 
       
  1547 /******************************************************************************
       
  1548 
       
  1549     Event handling
       
  1550 
       
  1551 ******************************************************************************/
       
  1552 
       
  1553 // ----------------------------------------------------------------------------
       
  1554 // CMuiuDynamicSettingsDialog::EventArrayChangedL()
       
  1555 // ----------------------------------------------------------------------------
       
  1556 //
       
  1557 TInt CMuiuDynamicSettingsDialog::EventArrayChangedL(
       
  1558     const TMuiuArrayEvents aEvent )
       
  1559     {
       
  1560     switch ( aEvent )
       
  1561         {
       
  1562         case EMuiuDynArrayAdded:
       
  1563             iListBox.HandleItemAdditionL();
       
  1564             break;
       
  1565 
       
  1566         case EMuiuDynArrayRemoved:
       
  1567             iListBox.HandleItemRemovalL();
       
  1568             break;
       
  1569 
       
  1570         // When array has changed, send event before updating listbox
       
  1571         case EMuiuDynArrayStackForward:
       
  1572         case EMuiuDynArrayStackBackward:
       
  1573             EventPrepareSubArrayL(
       
  1574                 *GetItem( 0 ),
       
  1575                 aEvent == EMuiuDynArrayStackForward ? ETrue : EFalse );
       
  1576 
       
  1577         //lint -fallthrough
       
  1578         case EMuiuDynArrayChanged:
       
  1579             iListBox.HandleItemRemovalL();
       
  1580             iListBox.HandleItemAdditionL();
       
  1581             break;
       
  1582         }
       
  1583 
       
  1584     return KErrNone;
       
  1585     }
       
  1586 
       
  1587 
       
  1588 // ----------------------------------------------------------------------------
       
  1589 // CMuiuDynamicSettingsDialog::EventSubArrayChangeL()
       
  1590 // ----------------------------------------------------------------------------
       
  1591 //
       
  1592 TInt CMuiuDynamicSettingsDialog::EventSubArrayChangeL(
       
  1593     CMuiuSettingBase& /* aBaseItem */ )
       
  1594     {
       
  1595     return KErrNone;
       
  1596     }
       
  1597 
       
  1598 // ----------------------------------------------------------------------------
       
  1599 // CMuiuDynamicSettingsDialog::EventItemEditStartsL()
       
  1600 // ----------------------------------------------------------------------------
       
  1601 //
       
  1602 TMuiuPageEventResult CMuiuDynamicSettingsDialog::EventItemEditStartsL(
       
  1603     CMuiuSettingBase& /* aBaseItem */ )
       
  1604     {
       
  1605     return EMuiuPageEventResultApproved;
       
  1606     }
       
  1607 
       
  1608 // ----------------------------------------------------------------------------
       
  1609 // CMuiuDynamicSettingsDialog::EventItemEditEndsL()
       
  1610 // ----------------------------------------------------------------------------
       
  1611 //
       
  1612 TInt CMuiuDynamicSettingsDialog::EventItemEditEndsL(
       
  1613     CMuiuSettingBase& /* aBaseItem */ )
       
  1614     {
       
  1615     return KErrNone;
       
  1616     }
       
  1617 
       
  1618 // ----------------------------------------------------------------------------
       
  1619 // CMuiuDynamicSettingsDialog::EventItemEvaluateRadioButton()
       
  1620 // ----------------------------------------------------------------------------
       
  1621 //
       
  1622 TMuiuPageEventResult CMuiuDynamicSettingsDialog::EventItemEvaluateRadioButton(
       
  1623     const CMuiuSettingBase& /* aBaseItem */,
       
  1624     TInt& /* aNewValue */ )
       
  1625     {
       
  1626     // This check fails always
       
  1627     return EMuiuPageEventResultApproved;
       
  1628     }
       
  1629 
       
  1630 // ----------------------------------------------------------------------------
       
  1631 // CMuiuDynamicSettingsDialog::EventItemEvaluateValue()
       
  1632 // ----------------------------------------------------------------------------
       
  1633 //
       
  1634 TMuiuPageEventResult CMuiuDynamicSettingsDialog::EventItemEvaluateValue(
       
  1635     const CMuiuSettingBase& /* aBaseItem */,
       
  1636     TInt& /* aNewValue */ )
       
  1637     {
       
  1638     // This check always true
       
  1639     return EMuiuPageEventResultApproved;
       
  1640     }
       
  1641 
       
  1642 // ----------------------------------------------------------------------------
       
  1643 // CMuiuDynamicSettingsDialog::EventItemEvaluateText()
       
  1644 // ----------------------------------------------------------------------------
       
  1645 //
       
  1646 TMuiuPageEventResult CMuiuDynamicSettingsDialog::EventItemEvaluateText(
       
  1647     const CMuiuSettingBase& /* aBaseItem */,
       
  1648     TDes& /* aNewText */ )
       
  1649     {
       
  1650     // This check fails always
       
  1651     return EMuiuPageEventResultApproved;
       
  1652     }
       
  1653 
       
  1654 // ----------------------------------------------------------------------------
       
  1655 // CMuiuDynamicSettingsDialog::EventCustomMdcaPoint()
       
  1656 // ----------------------------------------------------------------------------
       
  1657 //
       
  1658 TBool CMuiuDynamicSettingsDialog::EventCustomMdcaPoint(
       
  1659     const TUid& /* aId */,
       
  1660     TPtr& /* aString */ ) const
       
  1661     {
       
  1662     return EFalse;
       
  1663     }
       
  1664 
       
  1665 /******************************************************************************
       
  1666 
       
  1667     Utilities
       
  1668 
       
  1669 ******************************************************************************/
       
  1670 
       
  1671 // ----------------------------------------------------------------------------
       
  1672 // CMuiuDynamicSettingsDialog::SettingsStartedL()
       
  1673 // ----------------------------------------------------------------------------
       
  1674 //
       
  1675 TInt CMuiuDynamicSettingsDialog::SettingsStartedL()
       
  1676     {
       
  1677     return KErrNone;
       
  1678     }
       
  1679 
       
  1680 // ----------------------------------------------------------------------------
       
  1681 // CMuiuDynamicSettingsDialog::SettingPageResource()
       
  1682 // ----------------------------------------------------------------------------
       
  1683 //
       
  1684 TInt CMuiuDynamicSettingsDialog::SettingPageResource(
       
  1685     const TIMSPageResource aSettingPage ) const
       
  1686     {
       
  1687     return ( *iSettingPageResources )[aSettingPage];
       
  1688     }
       
  1689 
       
  1690 
       
  1691 
       
  1692 // ----------------------------------------------------------------------------
       
  1693 // CMuiuDynamicSettingsDialog::SetSettingPageResource()
       
  1694 // ----------------------------------------------------------------------------
       
  1695 //
       
  1696 void CMuiuDynamicSettingsDialog::SetSettingPageResource(
       
  1697     const TIMSPageResource aSettingPage,
       
  1698     const TInt aResourceId )
       
  1699     {
       
  1700     TRAP_IGNORE( iSettingPageResources->PushResourceL( aSettingPage, aResourceId ) );
       
  1701     }
       
  1702 
       
  1703 
       
  1704 // ----------------------------------------------------------------------------
       
  1705 // CMuiuDynamicSettingsDialog::ShowCustomQueryL()
       
  1706 // ----------------------------------------------------------------------------
       
  1707 //
       
  1708 TInt CMuiuDynamicSettingsDialog::ShowCustomQueryL(
       
  1709     const TInt aResourceStringId )
       
  1710     {
       
  1711     iQueryDialog = CAknQueryDialog::NewL();
       
  1712     TInt result = iQueryDialog->ExecuteLD( aResourceStringId );
       
  1713     iQueryDialog = NULL;
       
  1714     return result;
       
  1715     }
       
  1716 
       
  1717 // ----------------------------------------------------------------------------
       
  1718 // CMuiuDynamicSettingsDialog::CurrentItemIndex()
       
  1719 // ----------------------------------------------------------------------------
       
  1720 //
       
  1721 TInt CMuiuDynamicSettingsDialog::CurrentItemIndex() const
       
  1722     {
       
  1723     return iListBox.CurrentItemIndex();
       
  1724     }
       
  1725 
       
  1726 // ----------------------------------------------------------------------------
       
  1727 // CMuiuDynamicSettingsDialog::CurrentItem()
       
  1728 // ----------------------------------------------------------------------------
       
  1729 //
       
  1730 CMuiuSettingBase* CMuiuDynamicSettingsDialog::CurrentItem() const
       
  1731     {
       
  1732     return GetItem( iListBox.CurrentItemIndex() );
       
  1733     }
       
  1734 
       
  1735 // ----------------------------------------------------------------------------
       
  1736 // CMuiuDynamicSettingsDialog::GetValueEditorFlags()
       
  1737 // ----------------------------------------------------------------------------
       
  1738 //
       
  1739 TInt CMuiuDynamicSettingsDialog::GetValueEditorFlags(
       
  1740     const CMuiuSettingBase& aBaseItem )
       
  1741     {
       
  1742     // Get the flags for editor
       
  1743     TInt flags =
       
  1744         CAknIntegerSettingPage::EInvalidValueNotOffered;
       
  1745     flags |= !aBaseItem.iItemFlags.Flag( EMuiuDynItemForceMustFill ) ?
       
  1746         CAknIntegerSettingPage::EEmptyValueAllowed : 0;
       
  1747     flags |= aBaseItem.iItemFlags.Flag( EMuiuDynItemNoInitialSelection ) ?
       
  1748         CAknIntegerSettingPage::ENoInitialSelection : 0;
       
  1749     flags |= aBaseItem.iItemFlags.Flag( EMuiuDynItemEditorCursorAtBeginning ) ?
       
  1750         CAknIntegerSettingPage::EPutCursorAtBeginning : 0;
       
  1751 
       
  1752     return flags;
       
  1753     }
       
  1754 
       
  1755 // ----------------------------------------------------------------------------
       
  1756 // CMuiuDynamicSettingsDialog::GetTextEditorFlags()
       
  1757 // ----------------------------------------------------------------------------
       
  1758 //
       
  1759 TInt CMuiuDynamicSettingsDialog::GetTextEditorFlags(
       
  1760     const CMuiuSettingBase& aBaseItem )
       
  1761     {
       
  1762     TInt flags =
       
  1763         CAknTextSettingPage::EZeroLengthNotOffered;
       
  1764     flags |= !aBaseItem.iItemFlags.Flag( EMuiuDynItemForceMustFill ) ?
       
  1765         CAknTextSettingPage::EZeroLengthAllowed : 0;
       
  1766     flags |= aBaseItem.iItemFlags.Flag( EMuiuDynItemNoInitialSelection ) ?
       
  1767         CAknTextSettingPage::ENoInitialSelection : 0;
       
  1768     flags |= aBaseItem.iItemFlags.Flag( EMuiuDynItemEditorCursorAtBeginning ) ?
       
  1769         CAknTextSettingPage::EPutCursorAtBeginning : 0;
       
  1770 
       
  1771     return flags;
       
  1772     }
       
  1773 
       
  1774 /******************************************************************************
       
  1775 
       
  1776     Item initialization
       
  1777 
       
  1778 ******************************************************************************/
       
  1779 
       
  1780 // ----------------------------------------------------------------------------
       
  1781 // CMuiuDynamicSettingsDialog::InitAnyItem()
       
  1782 // ----------------------------------------------------------------------------
       
  1783 //
       
  1784 TInt CMuiuDynamicSettingsDialog::InitAnyItem(
       
  1785     CMuiuSettingBase& aBaseItem,
       
  1786     const TInt aValue,
       
  1787     const TMuiuSettingsText* aText )
       
  1788     {
       
  1789     TInt error = KErrNone;
       
  1790 
       
  1791     // Initialize any item
       
  1792     switch ( aBaseItem.Type() )
       
  1793         {
       
  1794         case EMuiuDynSetMenuArray:
       
  1795             error = InitArrayLink( aBaseItem, aText );
       
  1796             break;
       
  1797 
       
  1798         case EMuiuDynSetRadioButtonArray:
       
  1799             error = InitArrayRadioButton( aBaseItem, aValue, aText );
       
  1800             break;
       
  1801 
       
  1802         case EMuiuDynSetCheckBoxArray:
       
  1803             error = InitArrayCheckBox( aBaseItem, aValue, aText );
       
  1804             break;
       
  1805 
       
  1806         case EMuiuDynSetItemEditText:
       
  1807             error = InitItemTextEdit( aBaseItem, aText );
       
  1808             break;
       
  1809 
       
  1810         case EMuiuDynSetItemEditValue:
       
  1811             error = InitItemNumberEdit( aBaseItem, aValue, aText );
       
  1812             break;
       
  1813 
       
  1814         // Radiobutton and checkbox initialization is done during
       
  1815         // the array initialization
       
  1816         default:
       
  1817             error = KErrNotFound;
       
  1818             break;
       
  1819         }
       
  1820 
       
  1821     // Set the initialized flag on for the item
       
  1822     aBaseItem.iItemFlags.ChangeFlag(
       
  1823         EMuiuDynItemIsInitialized, error == KErrNone );
       
  1824     return error;
       
  1825     }
       
  1826 
       
  1827 // ----------------------------------------------------------------------------
       
  1828 // CMuiuDynamicSettingsDialog::InitAnyMultiItem()
       
  1829 // ----------------------------------------------------------------------------
       
  1830 //
       
  1831 TInt CMuiuDynamicSettingsDialog::InitAnyMultiItem(
       
  1832     const CMuiuDynInitItemIdArray* aStartTree,
       
  1833     const CMuiuDynInitItemIdArray& aIdArray,
       
  1834     const CMuiuDynInitItemValueArray* aValueArray,
       
  1835     const CMuiuDynInitItemTextArray* aDescArray,
       
  1836     const CMuiuDynInitInfoArray* aInitInfoArray )
       
  1837     {
       
  1838     // Make sure there are items in array
       
  1839     if ( !aIdArray.Count() )
       
  1840         {
       
  1841         return KErrNotFound;
       
  1842         }
       
  1843 
       
  1844     // Count the items in the tree if provided.
       
  1845     TInt count = aStartTree ? aStartTree->Count() : KErrNotFound;
       
  1846     CMuiuSettingBase* base = NULL;
       
  1847 
       
  1848     // if the starting point has been provided and there is items,
       
  1849     // try to find the starting point.
       
  1850     if ( count > 0 )
       
  1851         {
       
  1852         // Get the starting point
       
  1853         base = GetItem( aStartTree->At( 0 ) );
       
  1854 
       
  1855         // Go as deep as there are items provided
       
  1856         for ( TInt item = 0; ++item < count; )
       
  1857             {
       
  1858             base = GetSubItem( *base, aStartTree->At( item ) );
       
  1859             }
       
  1860         }
       
  1861 
       
  1862     // Seek the starting point. If the item has not been found during
       
  1863     // the tree search, try to find the given item by normal means.
       
  1864     if ( base )
       
  1865         {
       
  1866         base = GetSubItem( *base, aIdArray.At( 0 ) );
       
  1867         }
       
  1868     else
       
  1869         {
       
  1870         base = GetItem( aIdArray.At( 0 ) );
       
  1871         }
       
  1872 
       
  1873     // The item has been found initialize item
       
  1874     if ( base )
       
  1875         {
       
  1876         // Prepare
       
  1877         TInt valueIndex = 0;
       
  1878         TInt textIndex = 0;
       
  1879         TInt item = 0;
       
  1880         count = aIdArray.Count();
       
  1881 
       
  1882         do
       
  1883             {
       
  1884             // Intialize the item
       
  1885             PrepareInit(
       
  1886                 *base, aValueArray, aDescArray,
       
  1887                 aInitInfoArray, valueIndex, textIndex, item );
       
  1888 
       
  1889             // Check if the next item is defined and find it
       
  1890             base = ++item < count ?
       
  1891                 SettingFindEditor( *base, aIdArray.At( item ) ) : NULL;
       
  1892             }
       
  1893         while ( base );
       
  1894         }
       
  1895 
       
  1896     return base ? KErrNone : KErrNotFound;
       
  1897     }
       
  1898 
       
  1899 // ----------------------------------------------------------------------------
       
  1900 // CMuiuDynamicSettingsDialog::PrepareInit()
       
  1901 // ----------------------------------------------------------------------------
       
  1902 //
       
  1903 void CMuiuDynamicSettingsDialog::PrepareInit(
       
  1904     CMuiuSettingBase& aBaseItem,
       
  1905     const CMuiuDynInitItemValueArray* aValueArray,
       
  1906     const CMuiuDynInitItemTextArray* aDescArray,
       
  1907     const CMuiuDynInitInfoArray* aInitInfoArray,
       
  1908     TInt& aValueIndex,
       
  1909     TInt& aTextIndex,
       
  1910     TInt aIndex )
       
  1911     {
       
  1912     // Prepare temporary array
       
  1913     CMuiuDynInitItemValueArray* valueArray =
       
  1914         const_cast<CMuiuDynInitItemValueArray*>( aValueArray );
       
  1915     CMuiuDynInitItemTextArray* descArray =
       
  1916         const_cast<CMuiuDynInitItemTextArray*>( aDescArray );
       
  1917 
       
  1918     // If info array is defined, check, which one should be used
       
  1919     if ( aInitInfoArray && aIndex >= 0 && aIndex < aInitInfoArray->Count() )
       
  1920         {
       
  1921         TMuiuDynInitInfo info = aInitInfoArray->At( aIndex );
       
  1922 
       
  1923         valueArray = ( info == EMuiuDynInitInfoValue ) ?
       
  1924             valueArray : NULL;
       
  1925         descArray = ( info == EMuiuDynInitInfoText ) ?
       
  1926             descArray : NULL;
       
  1927         }
       
  1928 
       
  1929     // Initialize item as value
       
  1930     if ( valueArray && valueArray->Count() )
       
  1931         {
       
  1932         InitAnyItem( aBaseItem, valueArray->At( aValueIndex++ ), NULL );
       
  1933         }
       
  1934     // Initialize item as text
       
  1935     else if ( descArray && descArray->Count() )
       
  1936         {
       
  1937         InitAnyItem( aBaseItem, NULL, descArray->At( aTextIndex++ ) );
       
  1938         }
       
  1939     else
       
  1940         {
       
  1941         // Unidentified combination
       
  1942         __ASSERT_DEBUG( EFalse,
       
  1943             User::Panic( KMuiuDynSetDialogPanic, KErrUnknown ) );
       
  1944         }
       
  1945 
       
  1946     }
       
  1947 
       
  1948 // ----------------------------------------------------------------------------
       
  1949 // CMuiuDynamicSettingsDialog::InitArrayLink()
       
  1950 // ----------------------------------------------------------------------------
       
  1951 //
       
  1952 TInt CMuiuDynamicSettingsDialog::InitArrayLink(
       
  1953     CMuiuSettingBase& aBaseItem,
       
  1954     const TMuiuSettingsText* aText )
       
  1955     {
       
  1956     // Convert item
       
  1957     CMuiuSettingsLink* link = static_cast<CMuiuSettingsLink*>( &aBaseItem );
       
  1958 
       
  1959     // Get the item count in array
       
  1960     TInt items = KErrNotFound;
       
  1961     if ( link->iItemLinkArray )
       
  1962         {
       
  1963         items = link->iItemLinkArray->Count();
       
  1964         }
       
  1965 
       
  1966     // Clear checked flag from all items
       
  1967     while ( --items >= 0 )
       
  1968         {
       
  1969         link->iItemFlags.ClearFlag( EMuiuDynItemChecked );
       
  1970 
       
  1971         // Uncheck the buttons in the array
       
  1972         CMuiuSettingBase* base = GetSubItem( aBaseItem, items );
       
  1973         if ( base )
       
  1974             {
       
  1975             base->iItemFlags.ClearFlag( EMuiuDynItemChecked );
       
  1976             base = NULL;
       
  1977             }
       
  1978         }
       
  1979 
       
  1980     // Set the text if provided
       
  1981     if ( aText && link->iItemSettingText )
       
  1982         {
       
  1983         link->iItemSettingText->Copy( *aText );
       
  1984         }
       
  1985 
       
  1986     return KErrNone;
       
  1987     }
       
  1988 
       
  1989 // ----------------------------------------------------------------------------
       
  1990 // CMuiuDynamicSettingsDialog::InitArrayRadioButton()
       
  1991 // ----------------------------------------------------------------------------
       
  1992 //
       
  1993 TInt CMuiuDynamicSettingsDialog::InitArrayRadioButton(
       
  1994     CMuiuSettingBase& aBaseItem,
       
  1995     const TInt aValue,
       
  1996     const TMuiuSettingsText* aText )
       
  1997     {
       
  1998     // Convert item
       
  1999     CMuiuSettingsLinkExtended* radioArray =
       
  2000         static_cast<CMuiuSettingsLinkExtended*>( &aBaseItem );
       
  2001     CMuiuSettingBase* base = NULL;
       
  2002 
       
  2003     // Do normal link array initialization
       
  2004     InitArrayLink( aBaseItem, NULL );
       
  2005 
       
  2006     TInt result = KErrNotFound;
       
  2007 
       
  2008     // If the item has no value, check if any of the radiobuttons is
       
  2009     // checked, and get the index from there
       
  2010     if ( aValue == KErrNotFound && radioArray->iItemLinkArray )
       
  2011         {
       
  2012         TUid id = TUid::Uid( 0 );
       
  2013         TInt index;
       
  2014         FindCheckedRadiobutton( *radioArray, id, index );
       
  2015         base = GetSubItem( *radioArray, id );
       
  2016 
       
  2017         radioArray->SetValue( index );
       
  2018         }
       
  2019     // For listbox item, simply check one of the buttons
       
  2020     else if ( aValue >= 0 && radioArray->iItemLinkArray &&
       
  2021          aValue < radioArray->iItemLinkArray->Count() )
       
  2022         {
       
  2023         // In initialization phase, the received index value is from
       
  2024         // the main resource. Get the visible array's item index
       
  2025         // and setting the item checked and getting the checked item
       
  2026         TInt value = GetSubItemIndex( *radioArray, aValue, EFalse );
       
  2027         CheckRadioButton( *radioArray, value );
       
  2028         base = GetSubItem( *radioArray, value );
       
  2029 
       
  2030         // Set number of radiobox item to indicate the checked item
       
  2031         radioArray->SetValue( value );
       
  2032         result = KErrNone;
       
  2033         }
       
  2034     else
       
  2035         {
       
  2036         result = KErrNotFound;
       
  2037         }
       
  2038 
       
  2039     // Make sure the setting text exist and copy text if provided
       
  2040     if ( result == KErrNone && radioArray->iItemSettingText &&
       
  2041         ( aText || ( base && base->iItemLabel ) ) )
       
  2042         {
       
  2043         radioArray->iItemSettingText->Copy(
       
  2044             aText != NULL ? *aText : *base->iItemLabel );
       
  2045         }
       
  2046 
       
  2047     base = NULL;
       
  2048     radioArray = NULL;
       
  2049 
       
  2050     return result;
       
  2051     }
       
  2052 
       
  2053 // ----------------------------------------------------------------------------
       
  2054 // CMuiuDynamicSettingsDialog::InitArrayCheckBox()
       
  2055 // ----------------------------------------------------------------------------
       
  2056 //
       
  2057 TInt CMuiuDynamicSettingsDialog::InitArrayCheckBox(
       
  2058     CMuiuSettingBase& aBaseItem,
       
  2059     const TInt aValue,
       
  2060     const TMuiuSettingsText* aText )
       
  2061     {
       
  2062     // Convert item
       
  2063     CMuiuSettingsLinkExtended* link =
       
  2064         static_cast<CMuiuSettingsLinkExtended*>( &aBaseItem );
       
  2065     CMuiuSettingBase* base;
       
  2066 
       
  2067     // Do normal link array initialization
       
  2068     InitArrayLink( aBaseItem, NULL );
       
  2069     link->SetValue( aValue );
       
  2070 
       
  2071     // aValue can contain value KErrNotFound, which means 32 flags set.
       
  2072     // This function trusts the user provides correct value in the field
       
  2073     if ( link->iItemLinkArray )
       
  2074         {
       
  2075         // Get the item count in array
       
  2076         TInt buttons = link->iItemLinkArray->Count();
       
  2077 
       
  2078         // Check the checkbox buttons
       
  2079         while ( --buttons >= 0 )
       
  2080             {
       
  2081             base = link->iItemLinkArray->At( buttons );
       
  2082 
       
  2083             base->iItemFlags.ChangeFlag(
       
  2084                 EMuiuDynItemChecked, ( aValue >> buttons ) & 0x01 );
       
  2085             }
       
  2086         }
       
  2087 
       
  2088     // Make sure the setting text exist and copy text if provided
       
  2089     if ( aText && link->iItemSettingText )
       
  2090         {
       
  2091         link->iItemSettingText->Copy( *aText );
       
  2092         }
       
  2093 
       
  2094     link = NULL;
       
  2095     base = NULL;
       
  2096 
       
  2097     return KErrNone;
       
  2098     }
       
  2099 
       
  2100 // ----------------------------------------------------------------------------
       
  2101 // CMuiuDynamicSettingsDialog::InitItemTextEdit()
       
  2102 // ----------------------------------------------------------------------------
       
  2103 //
       
  2104 TInt CMuiuDynamicSettingsDialog::InitItemTextEdit(
       
  2105     CMuiuSettingBase& aBaseItem,
       
  2106     const TMuiuSettingsText* aText )
       
  2107     {
       
  2108     // Make sure the text fields exists and fill the item if possible
       
  2109     if ( aText && aBaseItem.Text() )
       
  2110         {
       
  2111         CMuiuSettingsEditText* textEditor =
       
  2112             static_cast<CMuiuSettingsEditText*>( &aBaseItem );
       
  2113         TMuiuSettingsText tempText;
       
  2114         tempText.Copy( aText->Left( textEditor->iItemMaxLength ) );
       
  2115         aBaseItem.SetText( &tempText );
       
  2116         }
       
  2117 
       
  2118     return KErrNone;
       
  2119     }
       
  2120 
       
  2121 // ----------------------------------------------------------------------------
       
  2122 // CMuiuDynamicSettingsDialog::InitItemNumberEdit()
       
  2123 // ----------------------------------------------------------------------------
       
  2124 //
       
  2125 TInt CMuiuDynamicSettingsDialog::InitItemNumberEdit(
       
  2126     CMuiuSettingBase& aBaseItem,
       
  2127     const TInt aValue,
       
  2128     const TMuiuSettingsText* aText )
       
  2129     {
       
  2130     // Convert item
       
  2131     CMuiuSettingsEditValue* numberEditor =
       
  2132         static_cast<CMuiuSettingsEditValue*>( &aBaseItem );
       
  2133 
       
  2134     // Fill the existing fields
       
  2135     numberEditor->SetValue( aValue );
       
  2136 
       
  2137     // Make sure all of the fields exists
       
  2138     if ( numberEditor->iItemSettingText )
       
  2139         {
       
  2140          if ( !aText )
       
  2141             {
       
  2142             numberEditor->iItemSettingText->Num( aValue );
       
  2143             }
       
  2144          else
       
  2145             {
       
  2146             numberEditor->iItemSettingText->Copy( *aText );
       
  2147             }
       
  2148         }
       
  2149 
       
  2150     return KErrNone;
       
  2151     }
       
  2152 
       
  2153 // ----------------------------------------------------------------------------
       
  2154 // CMuiuDynamicSettingsDialog::InitItemUnidentified()
       
  2155 // ----------------------------------------------------------------------------
       
  2156 //
       
  2157 TInt CMuiuDynamicSettingsDialog::InitItemUnidentified(
       
  2158     CMuiuSettingBase& /* aBaseItem */,
       
  2159     const TInt /* aValue */,
       
  2160     const TMuiuSettingsText* /* aText */ )
       
  2161     {
       
  2162     return KErrNotFound;
       
  2163     }
       
  2164 
       
  2165 // ----------------------------------------------------------------------------
       
  2166 // CMuiuDynamicSettingsDialog::SettingsLastItemIndex()
       
  2167 // ----------------------------------------------------------------------------
       
  2168 //
       
  2169 TInt CMuiuDynamicSettingsDialog::SettingsLastItemIndex(
       
  2170     const TBool aRemove ) const
       
  2171     {
       
  2172     // Store the last index to speed up fetching and removing
       
  2173     TInt lastIndex = iSettingsLastItemIndex->Count() - 1;
       
  2174 
       
  2175     // Fetch the last item in the list and remove it
       
  2176     TInt lastItem = iSettingsLastItemIndex->At( lastIndex );
       
  2177 
       
  2178     if ( aRemove )
       
  2179         {
       
  2180         iSettingsLastItemIndex->Delete( lastIndex );
       
  2181         }
       
  2182 
       
  2183     // in case the array has been changed, set the new index in the boundaries
       
  2184     // of the new array
       
  2185     SetBetweenValues( lastItem, 0, MdcaCount() );
       
  2186 
       
  2187     return lastItem;
       
  2188     }
       
  2189 
       
  2190 // ----------------------------------------------------------------------------
       
  2191 // CMuiuDynamicSettingsDialog::SetSettingsLastItemIndexL()
       
  2192 // ----------------------------------------------------------------------------
       
  2193 //
       
  2194 void CMuiuDynamicSettingsDialog::SetSettingsLastItemIndexL(
       
  2195     const TInt aLastItemIndex )
       
  2196     {
       
  2197     iSettingsLastItemIndex->AppendL( aLastItemIndex );
       
  2198     }
       
  2199 
       
  2200 // ----------------------------------------------------------------------------
       
  2201 // CMuiuDynamicSettingsDialog::SetListboxEmptyTextL()
       
  2202 // ----------------------------------------------------------------------------
       
  2203 //
       
  2204 void CMuiuDynamicSettingsDialog::SetListboxEmptyTextL(
       
  2205     const TDesC& aText )
       
  2206     {
       
  2207     iListBox.View()->SetListEmptyTextL( aText );
       
  2208     }
       
  2209 
       
  2210 // ----------------------------------------------------------------------------
       
  2211 // CMuiuDynamicSettingsDialog::CurrentSettingsPage()
       
  2212 // ----------------------------------------------------------------------------
       
  2213 //
       
  2214 CMuiuSettingBase* CMuiuDynamicSettingsDialog::CurrentSettingsPage(
       
  2215     const TBool aRemove )
       
  2216     {
       
  2217     // Get the last item in the array
       
  2218     TInt lastIndex = iSettingsPageArray->Count() - 1;
       
  2219 
       
  2220     // Get item
       
  2221     CMuiuSettingBase* currentItem = NULL;
       
  2222 
       
  2223     if ( lastIndex >= 0 )
       
  2224         {
       
  2225         currentItem = iSettingsPageArray->At( lastIndex );
       
  2226         }
       
  2227 
       
  2228     // Remove the item when required
       
  2229     if ( aRemove )
       
  2230         {
       
  2231         iSettingsPageArray->Delete( lastIndex );
       
  2232         }
       
  2233 
       
  2234     return currentItem;
       
  2235     }
       
  2236 
       
  2237 // ----------------------------------------------------------------------------
       
  2238 // CMuiuDynamicSettingsDialog::SetCurrentSettingsPage()
       
  2239 // ----------------------------------------------------------------------------
       
  2240 //
       
  2241 void CMuiuDynamicSettingsDialog::SetCurrentSettingsPage(
       
  2242     CMuiuSettingBase& aBaseItem )
       
  2243     {
       
  2244     if ( iSettingsPageArray->Count() < KMuiuMaxEditors )
       
  2245         {
       
  2246         // Set the new item as a last item
       
  2247         TRAP_IGNORE( iSettingsPageArray->AppendL( &aBaseItem ) );
       
  2248 
       
  2249         // Insert the backup item to array
       
  2250         TRAP_IGNORE( AddBackupItemL( aBaseItem ) );
       
  2251         }
       
  2252     else
       
  2253         {
       
  2254         // Too many editors, something is wrong
       
  2255         __ASSERT_DEBUG( EFalse, User::Panic(
       
  2256             KMuiuDynSetDialogPanic, KErrOverflow ) );
       
  2257         }
       
  2258     }
       
  2259 
       
  2260 // ----------------------------------------------------------------------------
       
  2261 // CMuiuDynamicSettingsDialog::CheckRadioButton()
       
  2262 // ----------------------------------------------------------------------------
       
  2263 //
       
  2264 void CMuiuDynamicSettingsDialog::CheckRadioButton(
       
  2265     CMuiuSettingsLink& aRadioButtonArray,
       
  2266     const TInt aRadioButtonIndex )
       
  2267     {
       
  2268     // Make sure the array exists
       
  2269     if ( aRadioButtonArray.iItemLinkArray )
       
  2270         {
       
  2271         CMuiuDynSetItemArray& array = *aRadioButtonArray.iItemLinkArray;
       
  2272 
       
  2273         // The loop must return the index of the item from the visible list
       
  2274         // All items must be searched through
       
  2275         // Each item has to be checked from their hidden properties
       
  2276         const TInt buttons = array.Count();
       
  2277         TInt index = buttons;
       
  2278 
       
  2279         // First, the item flags needs to be cleared
       
  2280         while ( --index >= 0 )
       
  2281             {
       
  2282             array[index]->iItemFlags.ClearFlag( EMuiuDynItemChecked );
       
  2283             }
       
  2284 
       
  2285         // Get the item from the actual list
       
  2286         CMuiuSettingBase* subItem =
       
  2287             GetSubItem( aRadioButtonArray, aRadioButtonIndex );
       
  2288 
       
  2289         if ( subItem )
       
  2290             {
       
  2291             subItem->iItemFlags.SetFlag( EMuiuDynItemChecked );
       
  2292             }
       
  2293         }
       
  2294     }
       
  2295 
       
  2296 // ----------------------------------------------------------------------------
       
  2297 // CMuiuDynamicSettingsDialog::CheckRadioButton()
       
  2298 // ----------------------------------------------------------------------------
       
  2299 //
       
  2300 void CMuiuDynamicSettingsDialog::CheckRadioButton(
       
  2301     CMuiuSettingsLink& aRadioButtonArray,
       
  2302     const TUid& aId )
       
  2303     {
       
  2304     // Make sure the array exists
       
  2305     if ( aRadioButtonArray.iItemLinkArray )
       
  2306         {
       
  2307         CMuiuSettingBase* radioButton = NULL;
       
  2308 
       
  2309         TInt buttons = aRadioButtonArray.iItemLinkArray->Count();
       
  2310 
       
  2311         // Check the selected radiobutton
       
  2312         while ( --buttons >= 0 )
       
  2313             {
       
  2314             radioButton = ( *aRadioButtonArray.iItemLinkArray )[buttons];
       
  2315             radioButton->iItemFlags.ChangeFlag(
       
  2316                 EMuiuDynItemChecked, radioButton->iItemId == aId );
       
  2317             }
       
  2318         }
       
  2319 
       
  2320     }
       
  2321 
       
  2322 // ----------------------------------------------------------------------------
       
  2323 // CMuiuDynamicSettingsDialog::FindCheckedRadiobutton()
       
  2324 // ----------------------------------------------------------------------------
       
  2325 //
       
  2326 TInt CMuiuDynamicSettingsDialog::FindCheckedRadiobutton(
       
  2327     const CMuiuSettingsLinkExtended& aArray,
       
  2328     TUid& aId,
       
  2329     TInt& aIndex )
       
  2330     {
       
  2331     CMuiuSettingBase* radioButton = NULL;
       
  2332     aId.iUid = KErrNotFound;
       
  2333     aIndex = KErrNotFound;
       
  2334 
       
  2335     if ( aArray.iItemLinkArray )
       
  2336         {
       
  2337         // Find the checked radio button, as there can be only one!
       
  2338         for ( TInt count = aArray.iItemLinkArray->Count(); --count >= 0; )
       
  2339             {
       
  2340             radioButton = ( *aArray.iItemLinkArray )[count];
       
  2341 
       
  2342             // Search for the radiobuttons but ignore hidden ones,
       
  2343             // even if it is checked
       
  2344             if ( radioButton && !IsHidden( *radioButton ) )
       
  2345                 {
       
  2346                 ++aIndex;
       
  2347 
       
  2348                 // If checked, return the value
       
  2349                 if ( radioButton->iItemFlags.Flag( EMuiuDynItemChecked ) )
       
  2350                     {
       
  2351                     aId = radioButton->iItemId;
       
  2352                     return KErrNone;
       
  2353                     }
       
  2354                 }
       
  2355             }
       
  2356         }
       
  2357 
       
  2358     return KErrNotFound;
       
  2359     }
       
  2360 
       
  2361 // ----------------------------------------------------------------------------
       
  2362 // CMuiuDynamicSettingsDialog::AddBackupItemL()
       
  2363 // ----------------------------------------------------------------------------
       
  2364 //
       
  2365 void CMuiuDynamicSettingsDialog::AddBackupItemL(
       
  2366     const CMuiuSettingBase& aBaseItem )
       
  2367     {
       
  2368     switch ( aBaseItem.iItemType )
       
  2369         {
       
  2370         case EMuiuDynSetItemMultiLine:
       
  2371         case EMuiuDynSetRadioButtonArray:
       
  2372         case EMuiuDynSetCheckBoxArray:
       
  2373             BackupItemCreateRadioL( aBaseItem );
       
  2374             break;
       
  2375 
       
  2376         case EMuiuDynSetItemEditScValue:
       
  2377         case EMuiuDynSetItemEditText:
       
  2378             BackupItemCreateTextL( aBaseItem );
       
  2379             break;
       
  2380 
       
  2381         case EMuiuDynSetItemEditValue:
       
  2382             BackupItemCreateValueL( aBaseItem );
       
  2383             break;
       
  2384 
       
  2385         case EMuiuDynSetUndefined:
       
  2386             BackupItemCreateUndefinedL( aBaseItem );
       
  2387             break;
       
  2388 
       
  2389         default:
       
  2390             // No need to backup, or unsupported
       
  2391             break;
       
  2392         }
       
  2393     }
       
  2394 
       
  2395 // ----------------------------------------------------------------------------
       
  2396 // CMuiuDynamicSettingsDialog::RemoveLastBackupItem()
       
  2397 // ----------------------------------------------------------------------------
       
  2398 //
       
  2399 void CMuiuDynamicSettingsDialog::RemoveLastBackupItem()
       
  2400     {
       
  2401     CMuiuSettingBase* base = GetLastBackupItem();
       
  2402     iBackupArray->Delete( iBackupArray->Count() - 1 );
       
  2403 
       
  2404     if ( base )
       
  2405         {
       
  2406         // With link items do not delete array, since the pointer points
       
  2407         // directly to original array. So set the pointer to null before
       
  2408         // deleting the item.
       
  2409         if ( base->HasLinkArray() )
       
  2410             {
       
  2411             static_cast<CMuiuSettingsLink*>( &*base )->iItemLinkArray = NULL;
       
  2412             }
       
  2413 
       
  2414         delete base;
       
  2415         base = NULL;
       
  2416         }
       
  2417     }
       
  2418 
       
  2419 // ----------------------------------------------------------------------------
       
  2420 // CMuiuDynamicSettingsDialog::GetLastBackupItem()
       
  2421 // ----------------------------------------------------------------------------
       
  2422 //
       
  2423 CMuiuSettingBase* CMuiuDynamicSettingsDialog::GetLastBackupItem()
       
  2424     {
       
  2425     return iBackupArray->At( iBackupArray->Count() - 1 );
       
  2426     }
       
  2427 
       
  2428 // ----------------------------------------------------------------------------
       
  2429 // CMuiuDynamicSettingsDialog::RestoreFromBackup()
       
  2430 // ----------------------------------------------------------------------------
       
  2431 //
       
  2432 void CMuiuDynamicSettingsDialog::RestoreFromBackup()
       
  2433     {
       
  2434     // Restore
       
  2435     for ( TInt count = iSettingsPageArray->Count(); --count >= 0; )
       
  2436         {
       
  2437         TInt lastPageNum = iSettingsPageArray->Count() - 1;
       
  2438         TInt lastBackupNum = iBackupArray->Count() - 1;
       
  2439         CMuiuSettingBase* currentPage = iSettingsPageArray->At( lastPageNum );
       
  2440         CMuiuSettingBase* backupPage = iBackupArray->At( lastBackupNum );
       
  2441 
       
  2442         // Restore values
       
  2443         const TMuiuSettingsText* text = ItemText( *backupPage );
       
  2444         if ( text )
       
  2445             {
       
  2446             SetItemText( *currentPage, *text );
       
  2447             }
       
  2448 
       
  2449         currentPage->SetValue( backupPage->Value() );
       
  2450         currentPage->SetText( backupPage->Text() );
       
  2451 
       
  2452         if ( currentPage->iItemType == EMuiuDynSetRadioButtonArray )
       
  2453         	{
       
  2454         	// Convert item and check radiobutton from backup array
       
  2455 	        CMuiuSettingsLinkExtended* radioArray =
       
  2456     	    	static_cast<CMuiuSettingsLinkExtended*>( currentPage );
       
  2457         	CheckRadioButton( *radioArray, backupPage->Value() );
       
  2458         	}
       
  2459 
       
  2460         iSettingsPageArray->Delete( lastPageNum );
       
  2461         RemoveLastBackupItem();
       
  2462         }
       
  2463     }
       
  2464 
       
  2465 // ----------------------------------------------------------------------------
       
  2466 // CMuiuDynamicSettingsDialog::CleanBackupArray()
       
  2467 // ----------------------------------------------------------------------------
       
  2468 //
       
  2469 void CMuiuDynamicSettingsDialog::CleanBackupArray()
       
  2470     {
       
  2471     for ( TInt count = iBackupArray->Count(); --count >= 0; )
       
  2472         {
       
  2473         RemoveLastBackupItem();
       
  2474         }
       
  2475     }
       
  2476 
       
  2477 // ----------------------------------------------------------------------------
       
  2478 // CMuiuDynamicSettingsDialog::BackupItemCreateLinkL()
       
  2479 // ----------------------------------------------------------------------------
       
  2480 //
       
  2481 void CMuiuDynamicSettingsDialog::BackupItemCreateLinkL(
       
  2482     const CMuiuSettingBase& aBaseItem )
       
  2483     {
       
  2484     CMuiuSettingsLink* linkBackup = CMuiuSettingsLink::NewL();
       
  2485     const CMuiuSettingsLink* link =
       
  2486         static_cast<const CMuiuSettingsLink*>( &aBaseItem );
       
  2487     *linkBackup = *link;
       
  2488 
       
  2489     iBackupArray->AppendL( linkBackup );
       
  2490     }
       
  2491 
       
  2492 // ----------------------------------------------------------------------------
       
  2493 // CMuiuDynamicSettingsDialog::BackupItemCreateRadioL()
       
  2494 // ----------------------------------------------------------------------------
       
  2495 //
       
  2496 void CMuiuDynamicSettingsDialog::BackupItemCreateRadioL(
       
  2497     const CMuiuSettingBase& aBaseItem )
       
  2498     {
       
  2499     CMuiuSettingsLinkExtended* radioBackup = CMuiuSettingsLinkExtended::NewL();
       
  2500     const CMuiuSettingsLinkExtended* radio =
       
  2501         static_cast<const CMuiuSettingsLinkExtended*>( &aBaseItem );
       
  2502     *radioBackup = *radio;
       
  2503 
       
  2504     iBackupArray->AppendL( radioBackup );
       
  2505     }
       
  2506 
       
  2507 // ----------------------------------------------------------------------------
       
  2508 // CMuiuDynamicSettingsDialog::BackupItemCreateValueL()
       
  2509 // ----------------------------------------------------------------------------
       
  2510 //
       
  2511 void CMuiuDynamicSettingsDialog::BackupItemCreateValueL(
       
  2512     const CMuiuSettingBase& aBaseItem )
       
  2513     {
       
  2514     CMuiuSettingsEditValue* valueBackup = CMuiuSettingsEditValue::NewL();
       
  2515     const CMuiuSettingsEditValue* value =
       
  2516         static_cast<const CMuiuSettingsEditValue*>( &aBaseItem );
       
  2517     *valueBackup = *value;
       
  2518 
       
  2519     iBackupArray->AppendL( valueBackup );
       
  2520     }
       
  2521 
       
  2522 // ----------------------------------------------------------------------------
       
  2523 // CMuiuDynamicSettingsDialog::BackupItemCreateTextL()
       
  2524 // ----------------------------------------------------------------------------
       
  2525 //
       
  2526 void CMuiuDynamicSettingsDialog::BackupItemCreateTextL(
       
  2527     const CMuiuSettingBase& aBaseItem )
       
  2528     {
       
  2529     CMuiuSettingsEditText* textBackup = CMuiuSettingsEditText::NewL();
       
  2530     const CMuiuSettingsEditText* text =
       
  2531         static_cast<const CMuiuSettingsEditText*>( &aBaseItem );
       
  2532     *textBackup = *text;
       
  2533 
       
  2534     iBackupArray->AppendL( textBackup );
       
  2535     }
       
  2536 
       
  2537 // ----------------------------------------------------------------------------
       
  2538 // CMuiuDynamicSettingsDialog::BackupItemCreateUndefinedL()
       
  2539 // ----------------------------------------------------------------------------
       
  2540 //
       
  2541 void CMuiuDynamicSettingsDialog::BackupItemCreateUndefinedL(
       
  2542     const CMuiuSettingBase& aBaseItem )
       
  2543     {
       
  2544     CMuiuSettingBase* base = CreateItemForBackupL( aBaseItem );
       
  2545 
       
  2546     iBackupArray->AppendL( base );
       
  2547     }
       
  2548 
       
  2549 // ----------------------------------------------------------------------------
       
  2550 // CMuiuDynamicSettingsDialog::CreateItemForBackupL()
       
  2551 // ----------------------------------------------------------------------------
       
  2552 //
       
  2553 CMuiuSettingBase* CMuiuDynamicSettingsDialog::CreateItemForBackupL(
       
  2554     const CMuiuSettingBase& aBaseItem )
       
  2555     {
       
  2556     CMuiuSettingsLinkExtended* radioBackup = CMuiuSettingsLinkExtended::NewL();
       
  2557     const CMuiuSettingsLinkExtended* radio =
       
  2558         static_cast<const CMuiuSettingsLinkExtended*>( &aBaseItem );
       
  2559     *radioBackup = *radio;
       
  2560 
       
  2561     return radioBackup;
       
  2562     }
       
  2563 
       
  2564 // ----------------------------------------------------------------------------
       
  2565 // CMuiuDynamicSettingsDialog::UpdateMskL()
       
  2566 // ----------------------------------------------------------------------------
       
  2567 //
       
  2568 void CMuiuDynamicSettingsDialog::UpdateMskL()
       
  2569     {
       
  2570     if ( iSoftkeys->MSKLabelling() )
       
  2571         {
       
  2572         SetMskL();
       
  2573         }
       
  2574     }
       
  2575 
       
  2576 // ----------------------------------------------------------------------------
       
  2577 // CMuiuDynamicSettingsDialog::SetMskL()
       
  2578 // ----------------------------------------------------------------------------
       
  2579 //
       
  2580 void CMuiuDynamicSettingsDialog::SetMskL()
       
  2581     {
       
  2582     CMuiuSettingBase* item = CurrentItem();
       
  2583     __ASSERT_DEBUG( item != NULL, User::Panic(
       
  2584         KMuiuDynSetDialogPanic, KErrNotFound ) );
       
  2585 
       
  2586     TInt resource = R_IMAS_MSK_OPEN;
       
  2587     if ( item && !ItemSubArrayCheck( *item ) )
       
  2588         {
       
  2589         resource = R_IMAS_MSK_CHANGE;
       
  2590         }
       
  2591     iSoftkeys->UpdateMiddleSoftkeyLabelL( resource, MskCommand(), this );
       
  2592     }
       
  2593 
       
  2594 // ----------------------------------------------------------------------------
       
  2595 // CMuiuDynamicSettingsDialog::MskCommand()
       
  2596 // ----------------------------------------------------------------------------
       
  2597 //
       
  2598 TInt CMuiuDynamicSettingsDialog::MskCommand()
       
  2599     {
       
  2600     // This function is intended for derived classes to get current msk
       
  2601     // command value. Though it's a constant now. It could vary in the future.
       
  2602     return EAknSoftkeyOk;
       
  2603     }
       
  2604 
       
  2605 //  End of File