email/imum/Utils/Src/MuiuDynamicSettingsArray.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     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:  MuiuDynamicSettingsArray.cpp
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <e32base.h>            // Base symbian include
       
    22 #include <gulutil.h>            // KColumnListSeparator
       
    23 #include <eikrutil.h>           // EikResourceUtils
       
    24 #include <AknUtils.h>           // AknTextUtils
       
    25 #include <barsread.h>           // TResourceReader
       
    26 #include "MuiuDynamicSettingsArray.h"
       
    27 #include "MuiuDynamicSettingItemBase.h"      // CMuiuSettingBase
       
    28 #include "MuiuDynamicSettingItemEditValue.h" // CMuiuSettingEditValue
       
    29 #include "MuiuDynamicSettingItemEditText.h"  // CMuiuSettingEditText
       
    30 #include "MuiuDynamicSettingItemLink.h"      // CMuiuSettingLink
       
    31 #include "MuiuDynamicSettingItemExtLink.h"   // CMuiuSettingExtLink
       
    32 #include <StringLoader.h>
       
    33 #include <ImumUtils.rsg>
       
    34 #include <data_caging_path_literals.hrh>
       
    35 #include <muiu_internal.rsg>
       
    36 
       
    37 #include "EmailFeatureUtils.h"
       
    38 #include "MuiuDynamicSettingsItemFinder.h"
       
    39 
       
    40 // EXTERNAL DATA STRUCTURES
       
    41 // EXTERNAL FUNCTION PROTOTYPES
       
    42 // CONSTANTS
       
    43 
       
    44 // This is added at the end of the locked setting item string
       
    45 _LIT( KMuiuDynStrProtected, "\t\t\t\t\t0" );
       
    46 // This is added at the end of the compulsory setting item string
       
    47 _LIT( KMuiuDynStrCompulsory, "\t*" );
       
    48 // Muiu resource file
       
    49 _LIT( KMuiuResFileName, "z:muiu_internal.rsc" );
       
    50 // The number of characters that can be shown in the screen
       
    51 const TInt KMuiuDynVisibleTextLength = 30;
       
    52 // The number of characters that is shown in password field
       
    53 const TInt KMuiuDynVisiblePasswordChars = 4;
       
    54 
       
    55 // MACROS
       
    56 // LOCAL CONSTANTS AND MACROS
       
    57 // MODULE DATA STRUCTURES
       
    58 // LOCAL FUNCTION PROTOTYPES
       
    59 // FORWARD DECLARATIONS
       
    60 
       
    61 // ============================ MEMBER FUNCTIONS ===============================
       
    62 
       
    63 // ----------------------------------------------------------------------------
       
    64 // CMuiuDynamicSettingsArray::CMuiuDynamicSettingsArray()
       
    65 // ----------------------------------------------------------------------------
       
    66 //
       
    67 CMuiuDynamicSettingsArray::CMuiuDynamicSettingsArray()
       
    68     :
       
    69     iResourceLoader( *CCoeEnv::Static() ),
       
    70     iFinder( NULL ),
       
    71     iItemArray( NULL ),
       
    72     iCompulsoryText( NULL ),
       
    73     iPasswordFill( 0x00 ),
       
    74     iActiveCount( 0 ),
       
    75     iError( KErrNone ),
       
    76     iEnv( CEikonEnv::Static() )
       
    77     {
       
    78     }
       
    79 
       
    80 // ----------------------------------------------------------------------------
       
    81 // CMuiuDynamicSettingsArray::~CMuiuDynamicSettingsArray()
       
    82 // ----------------------------------------------------------------------------
       
    83 //
       
    84 CMuiuDynamicSettingsArray::~CMuiuDynamicSettingsArray()
       
    85     {
       
    86     CleanArrayItems();
       
    87 
       
    88     if ( iResourceStack )
       
    89         {
       
    90         iResourceStack->Reset();
       
    91         delete iResourceStack;
       
    92         iResourceStack = NULL;
       
    93         }
       
    94     delete iItemArray;
       
    95     iItemArray = NULL;
       
    96     delete iTempText;
       
    97     iTempText = NULL;
       
    98     delete iResourceText;
       
    99     iResourceText = NULL;
       
   100     delete iCompulsoryText;
       
   101     iCompulsoryText = NULL;
       
   102     delete iFinder;
       
   103     iFinder = NULL;
       
   104     iResourceLoader.Close();
       
   105 
       
   106     iEnv = NULL;
       
   107     }
       
   108 
       
   109 // ----------------------------------------------------------------------------
       
   110 // CMuiuDynamicSettingsArray::BaseConstructL()
       
   111 // ----------------------------------------------------------------------------
       
   112 //
       
   113 void CMuiuDynamicSettingsArray::BaseConstructL( const TBool aLockedSettings )
       
   114     {
       
   115     // Prepare the arrays
       
   116     iItemArray = new ( ELeave ) CMuiuDynSetItemArray( KMuiuDynArrayGranularity );
       
   117     iResourceStack = new ( ELeave ) RResourceStack( KMuiuDynArrayGranularity );
       
   118     iFinder = CMuiuDynamicSettingsItemFinder::NewL( *this );
       
   119 
       
   120     // Define resource file and open it
       
   121     TParse parse;
       
   122     parse.Set( KMuiuResFileName, &KDC_RESOURCE_FILES_DIR, NULL );
       
   123     TFileName fileName( parse.FullName() );
       
   124     iResourceLoader.OpenL( fileName );
       
   125     iArrayFlags.SetFlag( EMuiuDynArrayAllowRefresh );
       
   126     iArrayFlags.ChangeFlag( EMuiuEMailLockedSettings, aLockedSettings );
       
   127 
       
   128     // Prepare strings
       
   129     iTempText = HBufC::NewL( KMuiuDynMaxSettingsTextLength );
       
   130     iResourceText = iEnv->AllocReadResourceL(
       
   131         R_IMUM_SELEC_SETT_VAL_FIELD_NONE );
       
   132     iPasswordFill = EikResourceUtils::ReadTInt16L(
       
   133         R_MUIU_SETTINGS_DIALOG_PASSWORD_FILL, iEnv );
       
   134     iCompulsoryText = iEnv->AllocReadResourceL(
       
   135         R_MUIU_SETTINGS_DIALOG_COMPULSORY_FILL );
       
   136     }
       
   137 
       
   138 // ----------------------------------------------------------------------------
       
   139 // CMuiuDynamicSettingsArray::BaseConstructL()
       
   140 // ----------------------------------------------------------------------------
       
   141 //
       
   142 void CMuiuDynamicSettingsArray::BaseConstructL(
       
   143     const TInt aResourceId,
       
   144     const TBool aLockedSettings )
       
   145     {
       
   146     // Initialize the members
       
   147     BaseConstructL( aLockedSettings );
       
   148 
       
   149     // If resource provided add it into the setting array
       
   150     LoadSettingArrayFromResourceL( aResourceId );
       
   151 
       
   152     UpdateActiveItemsCount();
       
   153     }
       
   154 
       
   155 // ----------------------------------------------------------------------------
       
   156 // CMuiuDynamicSettingsArray::CleanArrayItems()
       
   157 // ----------------------------------------------------------------------------
       
   158 //
       
   159 void CMuiuDynamicSettingsArray::CleanArrayItems()
       
   160     {
       
   161     if ( iItemArray )
       
   162         {
       
   163         // Delete items from the array
       
   164         TInt index = iItemArray->Count() - 1;
       
   165 
       
   166         // Search through all items in the array
       
   167         for ( ; index >= 0; index-- )
       
   168             {
       
   169             // Only certain type of items can contain subarrays
       
   170             CMuiuSettingBase* base = ( *iItemArray )[index];
       
   171             delete base;
       
   172             base = NULL;
       
   173             }
       
   174         }
       
   175     }
       
   176 
       
   177 // ----------------------------------------------------------------------------
       
   178 // CMuiuDynamicSettingsArray::CreateCustomItemToArrayLC()
       
   179 // ----------------------------------------------------------------------------
       
   180 //
       
   181 CMuiuSettingBase* CMuiuDynamicSettingsArray::CreateCustomItemToArrayLC(
       
   182     const TUid& /* aId */ )
       
   183     {
       
   184     return NULL;
       
   185     }
       
   186 
       
   187 // ----------------------------------------------------------------------------
       
   188 // CMuiuDynamicSettingsArray::ListboxItemFillMultiLineLabel()
       
   189 // ----------------------------------------------------------------------------
       
   190 //
       
   191 void CMuiuDynamicSettingsArray::ListboxItemFillMultiLineLabel(
       
   192     const CMuiuSettingBase& aBaseItem,
       
   193     TMuiuSettingsText& aText ) const
       
   194     {
       
   195     aText = static_cast<const CMuiuSettingsLink*>(
       
   196         &aBaseItem )->iItemSettingText->Left( KMuiuDynVisibleTextLength );
       
   197     }
       
   198 
       
   199 // ----------------------------------------------------------------------------
       
   200 // CMuiuDynamicSettingsArray::ListboxItemFillEditTextLabel()
       
   201 // ----------------------------------------------------------------------------
       
   202 //
       
   203 void CMuiuDynamicSettingsArray::ListboxItemFillEditTextLabel(
       
   204     const CMuiuSettingBase& aBaseItem,
       
   205     TMuiuSettingsText& aText ) const
       
   206     {
       
   207     aText.Copy( aBaseItem.VisibleText().Left( KMuiuDynVisibleTextLength ) );
       
   208     }
       
   209 
       
   210 // ----------------------------------------------------------------------------
       
   211 // CMuiuDynamicSettingsArray::ListboxItemFillEditValueLabel()
       
   212 // ----------------------------------------------------------------------------
       
   213 //
       
   214 void CMuiuDynamicSettingsArray::ListboxItemFillEditValueLabel(
       
   215     const CMuiuSettingBase& aBaseItem,
       
   216     TMuiuSettingsText& aText ) const
       
   217     {
       
   218     aText.Append( aBaseItem.Value() );
       
   219     aText.SetLength( KMuiuDynVisibleTextLength );
       
   220     }
       
   221 
       
   222 // ----------------------------------------------------------------------------
       
   223 // CMuiuDynamicSettingsArray::ListboxItemFillEditTimeLabel()
       
   224 // ----------------------------------------------------------------------------
       
   225 //
       
   226 void CMuiuDynamicSettingsArray::ListboxItemFillEditTimeLabel(
       
   227     const CMuiuSettingBase& aBaseItem,
       
   228     TMuiuSettingsText& aText ) const
       
   229     {
       
   230     aText.Append( aBaseItem.Value() );
       
   231     aText.SetLength( KMuiuDynVisibleTextLength );
       
   232     }
       
   233 
       
   234 // ----------------------------------------------------------------------------
       
   235 // CMuiuDynamicSettingsArray::ListboxUndefinedFillLabel()
       
   236 // ----------------------------------------------------------------------------
       
   237 //
       
   238 void CMuiuDynamicSettingsArray::ListboxUndefinedFillLabel(
       
   239     const CMuiuSettingBase& aBaseItem,
       
   240     TMuiuSettingsText& aText ) const
       
   241     {
       
   242     aText = static_cast<const CMuiuSettingsLinkExtended*>(
       
   243         &aBaseItem )->iItemSettingText->Left( KMuiuDynVisibleTextLength );
       
   244     }
       
   245 
       
   246 // ----------------------------------------------------------------------------
       
   247 // CMuiuDynamicSettingsArray::ListboxRadioButtonFillArrayLabel()
       
   248 // ----------------------------------------------------------------------------
       
   249 //
       
   250 void CMuiuDynamicSettingsArray::ListboxRadioButtonFillArrayLabel(
       
   251     const CMuiuSettingBase& aBaseItem,
       
   252     TMuiuSettingsText& aText ) const
       
   253     {
       
   254     aText = static_cast<const CMuiuSettingsLinkExtended*>(
       
   255         &aBaseItem )->iItemSettingText->Left( KMuiuDynVisibleTextLength );
       
   256     }
       
   257 
       
   258 // ----------------------------------------------------------------------------
       
   259 // CMuiuDynamicSettingsArray::ListboxCheckboxFillArrayLabel()
       
   260 // ----------------------------------------------------------------------------
       
   261 //
       
   262 void CMuiuDynamicSettingsArray::ListboxCheckboxFillArrayLabel(
       
   263     const CMuiuSettingBase& aBaseItem,
       
   264     TMuiuSettingsText& aText ) const
       
   265     {
       
   266     aText = static_cast<const CMuiuSettingsLinkExtended*>(
       
   267         &aBaseItem )->iItemSettingText->Left( KMuiuDynVisibleTextLength );
       
   268     }
       
   269 
       
   270 // ----------------------------------------------------------------------------
       
   271 // CMuiuDynamicSettingsArray::ListboxItemLabelFillL()
       
   272 // ----------------------------------------------------------------------------
       
   273 //
       
   274 TPtrC16 CMuiuDynamicSettingsArray::ListboxItemLabelFillL(
       
   275     CMuiuSettingBase& aBaseItem ) const
       
   276     {
       
   277     // Get the type of the setting item
       
   278     TMuiuDynSettingsType type = aBaseItem.iItemType;
       
   279     TMuiuSettingsText tempSettingText;
       
   280     tempSettingText.Zero();
       
   281 
       
   282     switch ( type )
       
   283         {
       
   284         case EMuiuDynSetItemMultiLine:
       
   285             ListboxItemFillMultiLineLabel( aBaseItem, tempSettingText );
       
   286             break;
       
   287 
       
   288         case EMuiuDynSetUndefined:
       
   289             ListboxUndefinedFillLabel( aBaseItem, tempSettingText );
       
   290             break;
       
   291 
       
   292         case EMuiuDynSetRadioButtonArray:
       
   293             ListboxRadioButtonFillArrayLabel( aBaseItem, tempSettingText );
       
   294             break;
       
   295 
       
   296         case EMuiuDynSetCheckBoxArray:
       
   297             ListboxCheckboxFillArrayLabel( aBaseItem, tempSettingText );
       
   298             break;
       
   299 
       
   300         case EMuiuDynSetItemEditText:
       
   301             ListboxItemFillEditTextLabel( aBaseItem, tempSettingText );
       
   302             break;
       
   303 
       
   304         case EMuiuDynSetItemEditValue:
       
   305             ListboxItemFillEditValueLabel( aBaseItem, tempSettingText );
       
   306             break;
       
   307 
       
   308         case EMuiuDynSetItemEditTime:
       
   309             ListboxItemFillEditTimeLabel( aBaseItem, tempSettingText );
       
   310             break;
       
   311 
       
   312         default:
       
   313             // Nothing to show, send empty text
       
   314             break;
       
   315         }
       
   316 
       
   317     // If the setting is marked as password, fill special character
       
   318     // instead of readable text
       
   319     TInt length = tempSettingText.Length();
       
   320     if ( length > 0 && aBaseItem.iItemFlags.Flag( EMuiuDynItemPassword ) )
       
   321         {
       
   322         // Add special chars to all type characters in setting field
       
   323         TChar passFill = TChar( iPasswordFill );
       
   324         tempSettingText.Zero();
       
   325         tempSettingText.AppendFill( passFill, KMuiuDynVisiblePasswordChars );
       
   326         }
       
   327 
       
   328     return tempSettingText;
       
   329     }
       
   330 
       
   331 /******************************************************************************
       
   332 
       
   333     Item property editors
       
   334 
       
   335 ******************************************************************************/
       
   336 
       
   337 // ----------------------------------------------------------------------------
       
   338 // CMuiuDynamicSettingsArray::SetItemValue()
       
   339 // ----------------------------------------------------------------------------
       
   340 //
       
   341 void CMuiuDynamicSettingsArray::SetItemValue(
       
   342     const TUid& aId,
       
   343     const TInt aValue,
       
   344     const TBool aUpdate )
       
   345     {
       
   346     CMuiuSettingBase* baseItem = GetItem( aId, EFalse );
       
   347 
       
   348     if ( baseItem )
       
   349         {
       
   350         SetItemValue( *baseItem, aValue, aUpdate );
       
   351         }
       
   352 
       
   353     baseItem = NULL;
       
   354     }
       
   355 
       
   356 // ----------------------------------------------------------------------------
       
   357 // CMuiuDynamicSettingsArray::SetItemValue()
       
   358 // ----------------------------------------------------------------------------
       
   359 //
       
   360 void CMuiuDynamicSettingsArray::SetItemValue(
       
   361     const TInt aIndex,
       
   362     const TInt aValue,
       
   363     const TBool aUpdate )
       
   364     {
       
   365     CMuiuSettingBase* baseItem = iItemArray->At( aIndex );
       
   366 
       
   367     if ( baseItem )
       
   368         {
       
   369         SetItemValue( *baseItem, aValue, aUpdate );
       
   370         }
       
   371 
       
   372     baseItem = NULL;
       
   373     }
       
   374 
       
   375 // ----------------------------------------------------------------------------
       
   376 // CMuiuDynamicSettingsArray::SetItemValue()
       
   377 // ----------------------------------------------------------------------------
       
   378 //
       
   379 void CMuiuDynamicSettingsArray::SetItemValue(
       
   380     CMuiuSettingBase& aBaseItem,
       
   381     const TInt aValue,
       
   382     const TBool aUpdate )
       
   383     {
       
   384     aBaseItem.SetValue( aValue );
       
   385 
       
   386     // Issue update when needed
       
   387     if ( aUpdate )
       
   388         {
       
   389         Refresh();
       
   390         }
       
   391     }
       
   392 
       
   393 // ----------------------------------------------------------------------------
       
   394 // CMuiuDynamicSettingsArray::SetItemText()
       
   395 // ----------------------------------------------------------------------------
       
   396 //
       
   397 void CMuiuDynamicSettingsArray::SetItemText(
       
   398     const TUid& aId,
       
   399     const TMuiuSettingsText& aText,
       
   400     const TBool aUpdate )
       
   401     {
       
   402     CMuiuSettingBase* baseItem = GetItem( aId, EFalse );
       
   403 
       
   404     if ( baseItem )
       
   405         {
       
   406         SetItemText( *baseItem, aText, aUpdate );
       
   407         }
       
   408 
       
   409     baseItem = NULL;
       
   410     }
       
   411 
       
   412 // ----------------------------------------------------------------------------
       
   413 // CMuiuDynamicSettingsArray::SetItemText()
       
   414 // ----------------------------------------------------------------------------
       
   415 //
       
   416 void CMuiuDynamicSettingsArray::SetItemText(
       
   417     const TInt aIndex,
       
   418     const TMuiuSettingsText& aText,
       
   419     const TBool aUpdate )
       
   420     {
       
   421     CMuiuSettingBase* baseItem = iItemArray->At( aIndex );
       
   422 
       
   423     if ( baseItem )
       
   424         {
       
   425         SetItemText( *baseItem, aText, aUpdate );
       
   426         }
       
   427 
       
   428     baseItem = NULL;
       
   429     }
       
   430 
       
   431 // ----------------------------------------------------------------------------
       
   432 // CMuiuDynamicSettingsArray::SetItemText()
       
   433 // ----------------------------------------------------------------------------
       
   434 //
       
   435 void CMuiuDynamicSettingsArray::SetItemText(
       
   436     CMuiuSettingBase& aBaseItem,
       
   437     const TMuiuSettingsText& aText,
       
   438     const TBool aUpdate )
       
   439     {
       
   440     switch ( aBaseItem.iItemType )
       
   441         {
       
   442         case EMuiuDynSetItemEditValue:
       
   443             static_cast<CMuiuSettingsEditValue*>(
       
   444                 &aBaseItem )->iItemSettingText->Copy( aText );
       
   445             break;
       
   446 
       
   447         case EMuiuDynSetRadioButtonArray:
       
   448         case EMuiuDynSetCheckBoxArray:
       
   449             static_cast<CMuiuSettingsLinkExtended*>(
       
   450                 &aBaseItem )->iItemSettingText->Copy( aText );
       
   451             break;
       
   452 
       
   453         default:
       
   454             aBaseItem.SetText( &aText );
       
   455             break;
       
   456         }
       
   457 
       
   458     // Issue update when needed
       
   459     if ( aUpdate )
       
   460         {
       
   461         Refresh();
       
   462         }
       
   463     }
       
   464 
       
   465 // ----------------------------------------------------------------------------
       
   466 // CMuiuDynamicSettingsArray::ItemText()
       
   467 // ----------------------------------------------------------------------------
       
   468 //
       
   469 const TMuiuSettingsText* CMuiuDynamicSettingsArray::ItemText(
       
   470     CMuiuSettingBase& aBaseItem )
       
   471     {
       
   472     switch ( aBaseItem.iItemType )
       
   473         {
       
   474         case EMuiuDynSetItemEditValue:
       
   475             return static_cast<CMuiuSettingsEditValue*>(
       
   476                 &aBaseItem )->iItemSettingText;
       
   477 
       
   478         case EMuiuDynSetRadioButtonArray:
       
   479         case EMuiuDynSetCheckBoxArray:
       
   480             return static_cast<CMuiuSettingsLinkExtended*>(
       
   481                 &aBaseItem )->iItemSettingText;
       
   482         }
       
   483 
       
   484     return aBaseItem.Text();
       
   485     }
       
   486 
       
   487 /******************************************************************************
       
   488 
       
   489     Base class function definitions
       
   490 
       
   491 ******************************************************************************/
       
   492 
       
   493 // ----------------------------------------------------------------------------
       
   494 // CMuiuDynamicSettingsArray::SearchDoError()
       
   495 // ----------------------------------------------------------------------------
       
   496 //
       
   497 TBool CMuiuDynamicSettingsArray::SearchDoError()
       
   498     {
       
   499     return ETrue;
       
   500     }
       
   501 
       
   502 // ----------------------------------------------------------------------------
       
   503 // CMuiuDynamicSettingsArray::SearchDoContinuationCheck()
       
   504 // ----------------------------------------------------------------------------
       
   505 //
       
   506 TBool CMuiuDynamicSettingsArray::SearchDoContinuationCheck(
       
   507     const CMuiuSettingBase& /* aItem */,
       
   508     const TInt /* aIndex */ )
       
   509     {
       
   510     return ETrue;
       
   511     }
       
   512 
       
   513 // ----------------------------------------------------------------------------
       
   514 // CMuiuDynamicSettingsArray::SearchDoItemCheck()
       
   515 // ----------------------------------------------------------------------------
       
   516 //
       
   517 TBool CMuiuDynamicSettingsArray::SearchDoItemCheck(
       
   518     CMuiuSettingBase& /* aItem */ )
       
   519     {
       
   520     return ETrue;
       
   521     }
       
   522 
       
   523 // ----------------------------------------------------------------------------
       
   524 // CMuiuDynamicSettingsArray::MdcaCount()
       
   525 // ----------------------------------------------------------------------------
       
   526 //
       
   527 TInt CMuiuDynamicSettingsArray::MdcaCount() const
       
   528     {
       
   529     return iActiveCount;
       
   530     }
       
   531 
       
   532 // ----------------------------------------------------------------------------
       
   533 // CMuiuDynamicSettingsArray::MdcaPoint()
       
   534 // ----------------------------------------------------------------------------
       
   535 //
       
   536 TPtrC16 CMuiuDynamicSettingsArray::MdcaPoint( TInt aIndex ) const
       
   537     {
       
   538     // First search the currently active resource to array and check
       
   539     // the given index is in the current array
       
   540     __ASSERT_DEBUG( aIndex < StackCountItems(),
       
   541         User::Panic( KMuiuDynSettingsArrayPanic, KErrOverflow ) );
       
   542 
       
   543     // Search for item from the active array
       
   544     CMuiuSettingBase* setting = iFinder->FinderArray()->At( aIndex ).iItem;
       
   545     __ASSERT_DEBUG( setting != NULL,
       
   546         User::Panic( KMuiuDynSettingsArrayPanic, KErrNotFound ) );
       
   547 
       
   548     // Prepare strings
       
   549     TPtr tempText = iTempText->Des();
       
   550 
       
   551     // Send custom event and if not used, prepare default
       
   552     if ( !EventCustomMdcaPoint( setting->iItemId, tempText ) )
       
   553         {
       
   554         // Initialize string
       
   555         tempText.Zero();
       
   556         tempText.Append( KMuiuDynStrSpace );
       
   557         tempText.Append( KColumnListSeparator );
       
   558         tempText.Append( *setting->iItemLabel );
       
   559 
       
   560         // Submenus doesn't contain other information
       
   561         if ( !ItemSubArrayCheck( *setting ) )
       
   562             {
       
   563             tempText.Append( KColumnListSeparator );
       
   564             tempText.Append( KColumnListSeparator );
       
   565 
       
   566             TMuiuSettingsText tempSettingText;
       
   567             // Try to add the text, error detected in next if
       
   568             TRAP_IGNORE( tempSettingText =
       
   569                 ListboxItemLabelFillL( *setting ) );
       
   570 
       
   571             // Fill the setting text with string
       
   572             if ( tempSettingText.Length() )
       
   573                 {
       
   574                 tempText.Append( tempSettingText );
       
   575                 }
       
   576             else
       
   577                 {
       
   578                 // Write compulsory text to required fields
       
   579                 if ( setting->iItemFlags.Flag( EMuiuDynItemCompulsory ) )
       
   580                     {
       
   581                     tempText.Append( *iCompulsoryText );
       
   582                     }
       
   583                 else if( setting->iItemFlags.Flag( EMuiuDynItemPassword ) )
       
   584                     {
       
   585                     tempText.Append( KMuiuDynStrSpace );
       
   586                     }
       
   587                 else
       
   588                     {
       
   589                     tempText.Append( *iResourceText );
       
   590                     }
       
   591                 }
       
   592 
       
   593             // Add the special string after compulsory fields
       
   594             if ( setting->iItemFlags.Flag( EMuiuDynItemCompulsory ) )
       
   595                 {
       
   596                 tempText.Append( KMuiuDynStrCompulsory );
       
   597                 }
       
   598 
       
   599             // Do the number conversion, if allowed
       
   600             if ( setting->iItemFlags.Flag( EMuiuDynItemLangSpecificNumConv ) )
       
   601                 {
       
   602                 AknTextUtils::DisplayTextLanguageSpecificNumberConversion(
       
   603                     tempText );
       
   604                 }
       
   605             }
       
   606         else if( iArrayFlags.Flag( EMuiuEMailLockedSettings ) &&
       
   607             setting->iItemFlags.Flag( EMuiuDynItemLockableSetting ) )
       
   608             {
       
   609             tempText.Append( KMuiuDynStrProtected );
       
   610             }
       
   611         }
       
   612 
       
   613     setting = NULL;
       
   614     return tempText;
       
   615     }
       
   616 
       
   617 /******************************************************************************
       
   618 
       
   619     Resource loading functions
       
   620 
       
   621 ******************************************************************************/
       
   622 
       
   623 // ----------------------------------------------------------------------------
       
   624 // CMuiuDynamicSettingsArray::LoadDynamicSettingItemL()
       
   625 // ----------------------------------------------------------------------------
       
   626 //
       
   627 void CMuiuDynamicSettingsArray::LoadDynamicSettingItemL(
       
   628     TResourceReader& aReader,
       
   629     CMuiuSettingBase& aBaseItem )
       
   630     {
       
   631     // Read rest of the settings first
       
   632     // STRUCT MUIU_DYNAMIC_SETTINGS_ITEM : LTEXT itemlabel
       
   633     HBufC* txt = aReader.ReadHBufCL();   // message text
       
   634 
       
   635     if ( txt )
       
   636         {
       
   637         aBaseItem.iItemLabel->Copy( *txt );
       
   638         }
       
   639 
       
   640     delete txt;
       
   641     txt = NULL;
       
   642 
       
   643     // STRUCT MUIU_DYNAMIC_SETTINGS_ITEM : WORD itemmaxlength
       
   644     TInt maxLength = aReader.ReadInt16();
       
   645 
       
   646     // STRUCT MUIU_DYNAMIC_SETTINGS_ITEM : LTEXT itememptytext
       
   647     HBufC* empty = aReader.ReadHBufCL();
       
   648     CleanupStack::PushL( empty );
       
   649 
       
   650     // STRUCT MUIU_DYNAMIC_SETTINGS_ITEM : LONG itemflags
       
   651     aBaseItem.iItemFlags = MAKE_TUINT64( aReader.ReadInt32(), 0 );
       
   652 
       
   653     // STRUCT MUIU_DYNAMIC_SETTINGS_ITEM : LLINK itemarray
       
   654     TInt linkResourceId = aReader.ReadInt32();
       
   655 
       
   656     // STRUCT MUIU_DYNAMIC_SETTINGS_ITEM : WORD itemsubtype
       
   657     TMuiuDynSettingsType subtype =
       
   658         static_cast<TMuiuDynSettingsType>( aReader.ReadInt16() );
       
   659 
       
   660     // Finally add the item to list
       
   661     HandleDynamicSettingsItemL(
       
   662         aBaseItem, maxLength, subtype, linkResourceId, empty );
       
   663 
       
   664     CleanupStack::PopAndDestroy( empty );
       
   665     }
       
   666 
       
   667 // ----------------------------------------------------------------------------
       
   668 // CMuiuDynamicSettingsArray::UpdateItemEditTextL()
       
   669 // ----------------------------------------------------------------------------
       
   670 //
       
   671 void CMuiuDynamicSettingsArray::UpdateItemEditTextL(
       
   672     CMuiuSettingBase& aBaseItem,
       
   673     const TInt aMaxLength,
       
   674     const TDesC* aEmptyText )
       
   675     {
       
   676     CMuiuSettingsEditText* text =
       
   677         static_cast<CMuiuSettingsEditText*>( &aBaseItem );
       
   678     text->iItemMaxLength = aMaxLength;
       
   679     if( aEmptyText )
       
   680         {
       
   681         text->SetEmptyText( *aEmptyText );
       
   682         }
       
   683     }
       
   684 
       
   685 // ----------------------------------------------------------------------------
       
   686 // CMuiuDynamicSettingsArray::UpdateItemEditValueL()
       
   687 // ----------------------------------------------------------------------------
       
   688 //
       
   689 void CMuiuDynamicSettingsArray::UpdateItemEditValueL(
       
   690     CMuiuSettingBase& aBaseItem,
       
   691     const TInt aMaxLength )
       
   692     {
       
   693     CMuiuSettingsEditValue* value =
       
   694         static_cast<CMuiuSettingsEditValue*>( &aBaseItem );
       
   695     value->iItemMaxLength = aMaxLength;
       
   696     }
       
   697 
       
   698 // ----------------------------------------------------------------------------
       
   699 // CMuiuDynamicSettingsArray::HandleDynamicSettingsItemL()
       
   700 // ----------------------------------------------------------------------------
       
   701 //
       
   702 void CMuiuDynamicSettingsArray::HandleDynamicSettingsItemL(
       
   703     CMuiuSettingBase& aBaseItem,
       
   704     const TInt aMaxLength,
       
   705     const TMuiuDynSettingsType aSubType,
       
   706     const TInt aLinkResourceId,
       
   707     const TDesC* aEmptyText )
       
   708     {
       
   709     switch ( aBaseItem.Type() )
       
   710         {
       
   711         // Load dynamically linked items or submenus
       
   712         case EMuiuDynSetMenuArray:
       
   713         case EMuiuDynSetRadioButtonArray:
       
   714         case EMuiuDynSetCheckBoxArray:
       
   715         case EMuiuDynSetItemMultiLine:
       
   716             LoadDynamicSettingsItemLinkItemL(
       
   717                 aBaseItem, aSubType, aLinkResourceId );
       
   718             break;
       
   719 
       
   720         // Finish text item
       
   721         case EMuiuDynSetItemEditText:
       
   722             UpdateItemEditTextL( aBaseItem, aMaxLength, aEmptyText );
       
   723             break;
       
   724 
       
   725         // Finish number item
       
   726         case EMuiuDynSetItemEditValue:
       
   727         case EMuiuDynSetItemEditTime:
       
   728             UpdateItemEditValueL( aBaseItem, aMaxLength );
       
   729             break;
       
   730 
       
   731         // Other items are already finished
       
   732         case EMuiuDynSetItemRadioButton:
       
   733         case EMuiuDynSetItemCheckBox:
       
   734         default:
       
   735             break;
       
   736         }
       
   737     }
       
   738 
       
   739 // ----------------------------------------------------------------------------
       
   740 // CMuiuDynamicSettingsArray::CreateItemToArrayL()
       
   741 // ----------------------------------------------------------------------------
       
   742 //
       
   743 CMuiuSettingBase* CMuiuDynamicSettingsArray::CreateItemToArrayL(
       
   744     const TMuiuDynSettingsType aType,
       
   745     const TUid& aId,
       
   746     CMuiuDynSetItemArray& aItemArray )
       
   747     {
       
   748     CMuiuSettingBase* base = NULL;
       
   749 
       
   750     switch ( aType )
       
   751         {
       
   752         // Create array item
       
   753         case EMuiuDynSetMenuArray:
       
   754             base = CMuiuSettingsLink::NewLC();
       
   755             break;
       
   756 
       
   757         // Force manual item creation
       
   758         case EMuiuDynSetUndefined:
       
   759             base = CreateCustomItemToArrayLC( aId );
       
   760             __ASSERT_DEBUG( base != NULL,
       
   761                 User::Panic( KMuiuDynSettingsArrayPanic, KErrUnknown ) );
       
   762             break;
       
   763 
       
   764         // Create radiobutton array item
       
   765         case EMuiuDynSetRadioButtonArray:
       
   766         case EMuiuDynSetCheckBoxArray:
       
   767         case EMuiuDynSetItemMultiLine:
       
   768             base = CMuiuSettingsLinkExtended::NewLC();
       
   769             break;
       
   770 
       
   771         // Create edit text item
       
   772         case EMuiuDynSetItemEditText:
       
   773             base = CMuiuSettingsEditText::NewLC();
       
   774             break;
       
   775 
       
   776         // Create edit number item
       
   777         case EMuiuDynSetItemEditValue:
       
   778         case EMuiuDynSetItemEditTime:
       
   779             base = CMuiuSettingsEditValue::NewLC();
       
   780             break;
       
   781 
       
   782         // Create normal base item
       
   783         case EMuiuDynSetItemRadioButton:
       
   784         case EMuiuDynSetItemCheckBox:
       
   785         default:
       
   786             base = CMuiuSettingBase::NewLC();
       
   787             break;
       
   788         }
       
   789 
       
   790     // Add to array
       
   791     aItemArray.AppendL( base );
       
   792     CleanupStack::Pop( base );
       
   793 
       
   794     return base;
       
   795     }
       
   796 
       
   797 // ----------------------------------------------------------------------------
       
   798 // CMuiuDynamicSettingsArray::LoadDynamicSettingsItemLinkItemL()
       
   799 // ----------------------------------------------------------------------------
       
   800 //
       
   801 void CMuiuDynamicSettingsArray::LoadDynamicSettingsItemLinkItemL(
       
   802     CMuiuSettingBase& aBaseItem,
       
   803     const TMuiuDynSettingsType aSubType,
       
   804     const TInt aLinkResourceId )
       
   805     {
       
   806     // Prepare the item
       
   807     CMuiuSettingsLink* linkItem = static_cast<CMuiuSettingsLink*>( &aBaseItem );
       
   808     linkItem->iItemSubType = aSubType;
       
   809     linkItem->iItemFlags.SetFlag( EMuiuDynItemUpdateOnChange );
       
   810 
       
   811     // Start reading only if resource is provided
       
   812     if ( aLinkResourceId )
       
   813         {
       
   814         linkItem->iItemLinkArray =
       
   815             new ( ELeave ) CMuiuDynSetItemArray(
       
   816                 KMuiuDynArrayGranularity );
       
   817 
       
   818         // Start loading the settings
       
   819         LoadSettingItemsToArrayL( aLinkResourceId, *linkItem->iItemLinkArray );
       
   820         }
       
   821 
       
   822     linkItem = NULL;
       
   823     }
       
   824 
       
   825 // ----------------------------------------------------------------------------
       
   826 // CMuiuDynamicSettingsArray::LoadSettingArrayFromResource()
       
   827 // ----------------------------------------------------------------------------
       
   828 //
       
   829 void CMuiuDynamicSettingsArray::LoadSettingArrayFromResourceL(
       
   830     const TInt aResourceId )
       
   831     {
       
   832     // Start reading only if resource is provided
       
   833     if ( aResourceId )
       
   834         {
       
   835         iResourceStack->AppendL( aResourceId );
       
   836         const TInt items = iItemArray->Count();
       
   837 
       
   838         // Begin to read the items from the resource
       
   839         TInt count = LoadSettingItemsToArrayL( aResourceId, *iItemArray );
       
   840 
       
   841         // Update the item count
       
   842         UpdateActiveItemsCount( count );
       
   843         }
       
   844     }
       
   845 
       
   846 // ----------------------------------------------------------------------------
       
   847 // CMuiuDynamicSettingsArray::LoadSettingItemsToArrayL()
       
   848 // ----------------------------------------------------------------------------
       
   849 //
       
   850 TInt CMuiuDynamicSettingsArray::LoadSettingItemsToArrayL(
       
   851     const TInt aResourceId,
       
   852     CMuiuDynSetItemArray& aItemArray )
       
   853     {
       
   854     // Define new read based on last item
       
   855     TResourceReader reader;
       
   856     iEnv->CreateResourceReaderLC(
       
   857         reader, aResourceId );
       
   858 
       
   859     // Get the count of items in resource
       
   860     TInt count = reader.ReadInt16();
       
   861     for ( TInt loop = 0; loop < count; loop++ )
       
   862         {
       
   863         // Read the settings from the resource
       
   864 
       
   865         // STRUCT MUIU_DYNAMIC_SETTINGS_ITEM : WORD itemtype
       
   866         TMuiuDynSettingsType type =
       
   867             static_cast<TMuiuDynSettingsType>( reader.ReadInt16() );
       
   868 
       
   869         // STRUCT MUIU_DYNAMIC_SETTINGS_ITEM : WORD itemid
       
   870         TUid id = TUid::Uid( reader.ReadInt16() );
       
   871 
       
   872         // Create the setting item
       
   873         CMuiuSettingBase* base =
       
   874             CreateItemToArrayL( type, id, aItemArray );
       
   875         base->iItemId = id;
       
   876         base->iItemType = type;
       
   877         base->iItemResourceId = aResourceId;
       
   878 
       
   879         // Start loading the item, based on item type
       
   880         LoadDynamicSettingItemL( reader, *base );
       
   881         base = NULL;
       
   882         }
       
   883 
       
   884     CleanupStack::PopAndDestroy(); // reader
       
   885 
       
   886     return count;
       
   887     }
       
   888 
       
   889 /******************************************************************************
       
   890 
       
   891     Item addition and deletion functions
       
   892 
       
   893 ******************************************************************************/
       
   894 
       
   895 // ----------------------------------------------------------------------------
       
   896 // CMuiuDynamicSettingsArray::AddItemsL()
       
   897 // ----------------------------------------------------------------------------
       
   898 //
       
   899 TInt CMuiuDynamicSettingsArray::AddItemsL( const TInt aResource )
       
   900     {
       
   901     // Load the resource and add it to array
       
   902     LoadSettingArrayFromResourceL( aResource );
       
   903 
       
   904     iError = EventArrayChangedL( EMuiuDynArrayAdded );
       
   905 
       
   906     // return the error state
       
   907     return iError;
       
   908     }
       
   909 
       
   910 /******************************************************************************
       
   911 
       
   912     Item hide functions
       
   913 
       
   914 ******************************************************************************/
       
   915 
       
   916 // ----------------------------------------------------------------------------
       
   917 // CMuiuDynamicSettingsArray::IsHidden()
       
   918 // ----------------------------------------------------------------------------
       
   919 //
       
   920 TInt CMuiuDynamicSettingsArray::IsHidden( const TUid& aId ) const
       
   921     {
       
   922     return IsHidden( *GetItem( aId ) );
       
   923     }
       
   924 
       
   925 // ----------------------------------------------------------------------------
       
   926 // CMuiuDynamicSettingsArray::IsHidden()
       
   927 // ----------------------------------------------------------------------------
       
   928 //
       
   929 TInt CMuiuDynamicSettingsArray::IsHidden(
       
   930     const CMuiuSettingBase& aItem ) const
       
   931     {
       
   932     if ( aItem.iItemFlags.Flag( EMuiuDynItemPermanentlyHidden ) )
       
   933         {
       
   934         return KErrNotSupported;
       
   935         }
       
   936     else if ( aItem.iItemFlags.Flag( EMuiuDynItemHidden ) )
       
   937         {
       
   938         return KErrNotFound;
       
   939         }
       
   940     else
       
   941         {
       
   942         return KErrNone;
       
   943         }
       
   944     }
       
   945 
       
   946 // ----------------------------------------------------------------------------
       
   947 // CMuiuDynamicSettingsArray::IsHidden()
       
   948 // ----------------------------------------------------------------------------
       
   949 //
       
   950 TInt CMuiuDynamicSettingsArray::IsHidden( const TInt aIndex ) const
       
   951     {
       
   952     return IsHidden( *GetItem( aIndex ) );
       
   953     }
       
   954 
       
   955 // ----------------------------------------------------------------------------
       
   956 // CMuiuDynamicSettingsArray::DoHideItems()
       
   957 // ----------------------------------------------------------------------------
       
   958 //
       
   959 void CMuiuDynamicSettingsArray::DoHideItems( const TBool aHide )
       
   960     {
       
   961     // All items collected, set their flags hidden flags
       
   962     CMuiuDynFinderItemArray& array = *iFinder->FinderArray();
       
   963     TInt item = array.Count();
       
   964     while ( --item >= 0 )
       
   965         {
       
   966         CMuiuSettingBase* base = array[item].iItem;
       
   967         base->iItemFlags.ChangeFlag( EMuiuDynItemHidden, aHide );
       
   968         }
       
   969     }
       
   970 
       
   971 // ----------------------------------------------------------------------------
       
   972 // CMuiuDynamicSettingsArray::HideItems()
       
   973 // ----------------------------------------------------------------------------
       
   974 //
       
   975 void CMuiuDynamicSettingsArray::SetHideItems(
       
   976     const TBool aHide,
       
   977     const TInt aResourceId,
       
   978     const TBool aUpdate )
       
   979     {
       
   980     // When hiding all, search through all subfolders and allow the state
       
   981     // change
       
   982     TMuiuFlags search;
       
   983     search.SetFlag( CMuiuDynamicSettingsItemFinder::EFinderSearchSubFolders );
       
   984     search.SetFlag( CMuiuDynamicSettingsItemFinder::EFinderResourceSearch );
       
   985     iFinder->SetSearchFlags( search );
       
   986 
       
   987     // Try to hide items and panic in any error
       
   988     TRAPD( error, iFinder->StartSearchL( *iItemArray, aResourceId ) );
       
   989     if ( error != KErrNone )
       
   990         {
       
   991         __ASSERT_DEBUG( EFalse,
       
   992             User::Panic( KMuiuDynSettingsArrayPanic, error ) );
       
   993         }
       
   994 
       
   995     DoHideItems( aHide );
       
   996 
       
   997     // Handle the array change
       
   998     if ( aUpdate )
       
   999         {
       
  1000         Refresh();
       
  1001         }
       
  1002     }
       
  1003 
       
  1004 // ----------------------------------------------------------------------------
       
  1005 // CMuiuDynamicSettingsArray::SetHideAll()
       
  1006 // ----------------------------------------------------------------------------
       
  1007 //
       
  1008 void CMuiuDynamicSettingsArray::SetHideAll(
       
  1009     const TBool aHide,
       
  1010     const TBool aUpdate )
       
  1011     {
       
  1012     // When hiding all, search through all subfolders and allow the state
       
  1013     // change
       
  1014     TMuiuFlags search;
       
  1015     search.SetFlag( CMuiuDynamicSettingsItemFinder::EFinderSearchSubFolders );
       
  1016     search.SetFlag( CMuiuDynamicSettingsItemFinder::EFinderSearchAll );
       
  1017     iFinder->SetSearchFlags( search );
       
  1018 
       
  1019     // Try to hide items and panic in any error
       
  1020     TRAPD( error, iFinder->StartSearchL( *iItemArray, KErrNotFound ) );
       
  1021     if ( error != KErrNone )
       
  1022         {
       
  1023         __ASSERT_DEBUG( EFalse,
       
  1024             User::Panic( KMuiuDynSettingsArrayPanic, error ) );
       
  1025         }
       
  1026 
       
  1027     // Do hide action
       
  1028     DoHideItems( aHide );
       
  1029 
       
  1030     // Handle the array change
       
  1031     if ( aUpdate )
       
  1032         {
       
  1033         Refresh();
       
  1034         }
       
  1035     }
       
  1036 
       
  1037 // ----------------------------------------------------------------------------
       
  1038 // CMuiuDynamicSettingsArray::SetHideItem()
       
  1039 // ----------------------------------------------------------------------------
       
  1040 //
       
  1041 void CMuiuDynamicSettingsArray::SetHideItem(
       
  1042     const TBool aHide,
       
  1043     const TInt aIndex,
       
  1044     const TBool aUpdate )
       
  1045     {
       
  1046     GetItem( aIndex )->iItemFlags.ChangeFlag( EMuiuDynItemHidden, aHide );
       
  1047 
       
  1048     // Handle the array change
       
  1049     if ( aUpdate )
       
  1050         {
       
  1051         Refresh();
       
  1052         }
       
  1053     }
       
  1054 
       
  1055 // ----------------------------------------------------------------------------
       
  1056 // CMuiuDynamicSettingsArray::SetHideItem()
       
  1057 // ----------------------------------------------------------------------------
       
  1058 //
       
  1059 void CMuiuDynamicSettingsArray::SetHideItem(
       
  1060     const TBool aHide,
       
  1061     const TUid& aId,
       
  1062     const TBool aUpdate )
       
  1063     {
       
  1064     GetItem( aId )->iItemFlags.ChangeFlag( EMuiuDynItemHidden, aHide );
       
  1065 
       
  1066     // Handle the array change
       
  1067     if ( aUpdate )
       
  1068         {
       
  1069         Refresh();
       
  1070         }
       
  1071     }
       
  1072 
       
  1073 // ----------------------------------------------------------------------------
       
  1074 // CMuiuDynamicSettingsArray::SetHideItemsExceptIn()
       
  1075 // ----------------------------------------------------------------------------
       
  1076 //
       
  1077 void CMuiuDynamicSettingsArray::SetHideItemsExceptIn(
       
  1078     const TBool aHide,
       
  1079     const TInt aResource,
       
  1080     const TBool aUpdate )
       
  1081     {
       
  1082     // When hiding all, search through all subfolders and allow the state
       
  1083     // change
       
  1084     TMuiuFlags search;
       
  1085     search.SetFlag( CMuiuDynamicSettingsItemFinder::EFinderSearchSubFolders );
       
  1086     search.SetFlag( CMuiuDynamicSettingsItemFinder::EFinderExlusiveSearch );
       
  1087     search.SetFlag( CMuiuDynamicSettingsItemFinder::EFinderResourceSearch );
       
  1088     iFinder->SetSearchFlags( search );
       
  1089 
       
  1090     // Try to hide items and panic in any error
       
  1091     TRAPD( error, iFinder->StartSearchL( *iItemArray, aResource ) );
       
  1092     if ( error != KErrNone )
       
  1093         {
       
  1094         __ASSERT_DEBUG( EFalse,
       
  1095             User::Panic( KMuiuDynSettingsArrayPanic, error ) );
       
  1096         }
       
  1097 
       
  1098     // Do hide action
       
  1099     DoHideItems( aHide );
       
  1100 
       
  1101     // Handle the array change
       
  1102     if ( aUpdate )
       
  1103         {
       
  1104         Refresh();
       
  1105         }
       
  1106     }
       
  1107 
       
  1108 /******************************************************************************
       
  1109 
       
  1110     Item search functions
       
  1111 
       
  1112 ******************************************************************************/
       
  1113 
       
  1114 // ----------------------------------------------------------------------------
       
  1115 // CMuiuDynamicSettingsArray::InitDefaultSearch()
       
  1116 // ----------------------------------------------------------------------------
       
  1117 //
       
  1118 void CMuiuDynamicSettingsArray::InitDefaultSearch(
       
  1119     const TBool aExcludeHidden ) const
       
  1120     {
       
  1121     // In default search, subfolders are included and hidden items are not
       
  1122     // included into the search
       
  1123     TMuiuFlags search;
       
  1124     search.SetFlag( CMuiuDynamicSettingsItemFinder::EFinderSearchSubFolders );
       
  1125     search.ChangeFlag(
       
  1126         CMuiuDynamicSettingsItemFinder::EFinderDoHideCheck, aExcludeHidden );
       
  1127     iFinder->SetSearchFlags( search );
       
  1128     }
       
  1129 
       
  1130 // ----------------------------------------------------------------------------
       
  1131 // CMuiuDynamicSettingsArray::ItemIndex()
       
  1132 // ----------------------------------------------------------------------------
       
  1133 //
       
  1134 TInt CMuiuDynamicSettingsArray::ItemIndex(
       
  1135     const TUid& aId,
       
  1136     const TBool aExcludeHidden ) const
       
  1137     {
       
  1138     InitDefaultSearch( aExcludeHidden );
       
  1139 
       
  1140     // Try to make the search, but if the search fails, allow caller
       
  1141     // to handle the result
       
  1142     TRAP_IGNORE( iFinder->StartSearchL( *iItemArray, aId ) );
       
  1143 
       
  1144     // Return the found item
       
  1145     return iFinder->FinderArray()->At( 0 ).iIndex;
       
  1146     }
       
  1147 
       
  1148 // ----------------------------------------------------------------------------
       
  1149 // CMuiuDynamicSettingsArray::GetItem()
       
  1150 // ----------------------------------------------------------------------------
       
  1151 //
       
  1152 CMuiuSettingBase* CMuiuDynamicSettingsArray::GetItem(
       
  1153     const TInt aIndex,
       
  1154     const TBool aExcludeHidden ) const
       
  1155     {
       
  1156     // First search the currently active resource to array and check
       
  1157     // the given index is in the current array
       
  1158     TBool ok = aIndex < StackCountItems( aExcludeHidden );
       
  1159     __ASSERT_DEBUG( ok,
       
  1160         User::Panic( KMuiuDynSettingsArrayPanic, KErrOverflow ) );
       
  1161     __ASSERT_DEBUG( aIndex >= 0,
       
  1162         User::Panic( KMuiuDynSettingsArrayPanic, KErrUnderflow ) );
       
  1163 
       
  1164     // Return the found item
       
  1165     return ok ? iFinder->FinderArray()->At( aIndex ).iItem : NULL;
       
  1166     }
       
  1167 
       
  1168 // ----------------------------------------------------------------------------
       
  1169 // CMuiuDynamicSettingsArray::GetItem()
       
  1170 // ----------------------------------------------------------------------------
       
  1171 //
       
  1172 CMuiuSettingBase* CMuiuDynamicSettingsArray::GetItem(
       
  1173     const TUid& aId,
       
  1174     const TBool aExcludeHidden ) const
       
  1175     {
       
  1176     InitDefaultSearch( aExcludeHidden );
       
  1177 
       
  1178     // Try to make the search, but if the search fails, allow caller
       
  1179     // to handle the result
       
  1180     TRAP_IGNORE( iFinder->StartSearchL( *iItemArray, aId ) );
       
  1181 
       
  1182     // Return the found item
       
  1183     return iFinder->FinderArray()->At( 0 ).iItem;
       
  1184     }
       
  1185 
       
  1186 // ----------------------------------------------------------------------------
       
  1187 // CMuiuDynamicSettingsArray::GetSubItem()
       
  1188 // ----------------------------------------------------------------------------
       
  1189 //
       
  1190 CMuiuSettingBase* CMuiuDynamicSettingsArray::GetSubItem(
       
  1191     const CMuiuSettingBase& aBaseItem,
       
  1192     const TUid& aId,
       
  1193     const TBool aExcludeHidden ) const
       
  1194     {
       
  1195     // Make sure the item has subitems
       
  1196     if ( ItemSubItemCheck( aBaseItem ) )
       
  1197         {
       
  1198         // Convert the item to link item
       
  1199         const CMuiuSettingsLink* link =
       
  1200             static_cast<const CMuiuSettingsLink*>( &aBaseItem );
       
  1201 
       
  1202         // Get item count
       
  1203         TInt count = link->iItemLinkArray ?
       
  1204             link->iItemLinkArray->Count() : KErrNotFound;
       
  1205 
       
  1206         // Find the item from the array
       
  1207         while ( --count >= 0)
       
  1208             {
       
  1209             CMuiuSettingBase* base = ( *link->iItemLinkArray )[count];
       
  1210 
       
  1211             if ( IsVisibleCheck( aBaseItem, aExcludeHidden ) &&
       
  1212                  base->iItemId == aId )
       
  1213                 {
       
  1214                 return base;
       
  1215                 }
       
  1216             }
       
  1217         }
       
  1218 
       
  1219     return NULL;
       
  1220     }
       
  1221 
       
  1222 // ----------------------------------------------------------------------------
       
  1223 // CMuiuDynamicSettingsArray::GetSubItem()
       
  1224 // ----------------------------------------------------------------------------
       
  1225 //
       
  1226 CMuiuSettingBase* CMuiuDynamicSettingsArray::GetSubItem(
       
  1227     const CMuiuSettingBase& aBaseItem,
       
  1228     const TInt aIndex,
       
  1229     const TBool aExcludeHidden ) const
       
  1230     {
       
  1231     CMuiuSettingBase* base = NULL;
       
  1232 
       
  1233     // Make sure the item has subitems
       
  1234     if ( ItemSubItemCheck( aBaseItem ) )
       
  1235         {
       
  1236         // Convert the item to link item
       
  1237         const CMuiuSettingsLink* link =
       
  1238             static_cast<const CMuiuSettingsLink*>( &aBaseItem );
       
  1239 
       
  1240         // Get the item count and make sure the required index is
       
  1241         // below the number of items
       
  1242         TInt count = link->iItemLinkArray ?
       
  1243             link->iItemLinkArray->Count() : KErrNotFound;
       
  1244         count = ( aIndex >= 0 && aIndex < count ) ? count : KErrNotFound;
       
  1245         TInt index = KErrNotFound;
       
  1246         TInt item = 0;
       
  1247 
       
  1248         for ( ; index != aIndex && item < count; item++ )
       
  1249             {
       
  1250             base = ( *link->iItemLinkArray )[item];
       
  1251 
       
  1252             if ( IsVisibleCheck( *base, aExcludeHidden ) )
       
  1253                 {
       
  1254                 index++;
       
  1255                 }
       
  1256             }
       
  1257 
       
  1258         // At the end of the items and still not found
       
  1259         if ( item == count && index != aIndex )
       
  1260             {
       
  1261             base = NULL;
       
  1262             }
       
  1263         }
       
  1264 
       
  1265     return base;
       
  1266     }
       
  1267 
       
  1268 // ----------------------------------------------------------------------------
       
  1269 // CMuiuDynamicSettingsDialog::GetSubItemIndex()
       
  1270 // ----------------------------------------------------------------------------
       
  1271 //
       
  1272 TInt CMuiuDynamicSettingsArray::GetSubItemIndex(
       
  1273     const CMuiuSettingsLink& aLinkItem,
       
  1274     const TUid& aId,
       
  1275     const TBool aExcludeHidden ) const
       
  1276     {
       
  1277     TBool found = EFalse;
       
  1278     TInt index = KErrNotFound;
       
  1279 
       
  1280     if ( aLinkItem.iItemLinkArray )
       
  1281         {
       
  1282         CMuiuSettingBase* subItem = NULL;
       
  1283 
       
  1284         const TInt items = aLinkItem.iItemLinkArray->Count();
       
  1285         TInt button = KErrNotFound;
       
  1286 
       
  1287         // Seek the item id and return its index
       
  1288         while ( !found && ++button < items )
       
  1289             {
       
  1290             subItem = ( *aLinkItem.iItemLinkArray )[button];
       
  1291 
       
  1292             // Ignore hidden items AND item is not hidden OR
       
  1293             // check all the items
       
  1294             if ( IsVisibleCheck( *subItem, aExcludeHidden ) )
       
  1295                 {
       
  1296                 ++index;
       
  1297 
       
  1298                 found = ( subItem->iItemId == aId );
       
  1299                 }
       
  1300             }
       
  1301         }
       
  1302 
       
  1303     return found ? index : KErrNotFound;
       
  1304     }
       
  1305 
       
  1306 // ----------------------------------------------------------------------------
       
  1307 // CMuiuDynamicSettingsDialog::GetSubItemIndex()
       
  1308 // ----------------------------------------------------------------------------
       
  1309 //
       
  1310 TInt CMuiuDynamicSettingsArray::GetSubItemIndex(
       
  1311     const CMuiuSettingsLink& aLinkItem,
       
  1312     const TInt aIndex,
       
  1313     const TBool aActualIndex ) const
       
  1314     {
       
  1315     TInt result = KErrNotFound;
       
  1316 
       
  1317     if ( aLinkItem.iItemLinkArray )
       
  1318         {
       
  1319         CMuiuSettingBase* radioButton = NULL;
       
  1320         TInt visibleCount = KErrNotFound;
       
  1321         TInt resourceCount = KErrNotFound;
       
  1322 
       
  1323         TInt items = aLinkItem.iItemLinkArray->Count();
       
  1324 
       
  1325         for ( TInt index = 0; result < 0 && index < items; index++ )
       
  1326             {
       
  1327             radioButton = ( *aLinkItem.iItemLinkArray )[index];
       
  1328 
       
  1329             resourceCount++;
       
  1330             if ( !IsHidden( *radioButton ) )
       
  1331                 {
       
  1332                 visibleCount++;
       
  1333                 }
       
  1334 
       
  1335             if ( aActualIndex )
       
  1336                 {
       
  1337                 if ( aIndex == visibleCount )
       
  1338                     {
       
  1339                     result = resourceCount;
       
  1340                     }
       
  1341                 }
       
  1342             else
       
  1343                 {
       
  1344                 if ( aIndex == resourceCount )
       
  1345                     {
       
  1346                     result = visibleCount;
       
  1347                     }
       
  1348                 }
       
  1349             }
       
  1350         }
       
  1351 
       
  1352     return result;
       
  1353     }
       
  1354 
       
  1355 // ----------------------------------------------------------------------------
       
  1356 // CMuiuDynamicSettingsArray::SearchResourceL()
       
  1357 // ----------------------------------------------------------------------------
       
  1358 //
       
  1359 void CMuiuDynamicSettingsArray::SearchResourceL(
       
  1360     const TInt aResourceId,
       
  1361     const TBool aExcludeHidden ) const
       
  1362     {
       
  1363     // When hiding all, search through all subfolders and allow the state
       
  1364     // change
       
  1365     TMuiuFlags search;
       
  1366     search.SetFlag( CMuiuDynamicSettingsItemFinder::EFinderSearchSubFolders );
       
  1367     search.SetFlag( CMuiuDynamicSettingsItemFinder::EFinderResourceSearch );
       
  1368     search.ChangeFlag(
       
  1369         CMuiuDynamicSettingsItemFinder::EFinderDoHideCheck, aExcludeHidden );
       
  1370     iFinder->SetSearchFlags( search );
       
  1371 
       
  1372     // Try to hide items and panic in any error
       
  1373     TRAPD( error, iFinder->StartSearchL( *iItemArray, aResourceId ) );
       
  1374     if ( error != KErrNone )
       
  1375         {
       
  1376         __ASSERT_DEBUG( EFalse,
       
  1377             User::Panic( KMuiuDynSettingsArrayPanic, error ) );
       
  1378         }
       
  1379     }
       
  1380 
       
  1381 // ----------------------------------------------------------------------------
       
  1382 // CMuiuDynamicSettingsArray::GetResource()
       
  1383 // ----------------------------------------------------------------------------
       
  1384 //
       
  1385 CMuiuDynFinderItemArray* CMuiuDynamicSettingsArray::GetResource(
       
  1386     const TInt aResourceId,
       
  1387     const TBool aExcludeHidden ) const
       
  1388     {
       
  1389     // Start the resource search
       
  1390     TRAP_IGNORE( SearchResourceL( aResourceId, aExcludeHidden ) );
       
  1391 
       
  1392     // Return the pointer to array
       
  1393     return iFinder->FinderArray();
       
  1394     }
       
  1395 
       
  1396 // ----------------------------------------------------------------------------
       
  1397 // CMuiuDynamicSettingsArray::GetResourceLC()
       
  1398 // ----------------------------------------------------------------------------
       
  1399 //
       
  1400 CMuiuDynFinderItemArray* CMuiuDynamicSettingsArray::GetResourceLC(
       
  1401     const TInt aResourceId,
       
  1402     const TBool aExcludeHidden ) const
       
  1403     {
       
  1404     // Start the resource search
       
  1405     SearchResourceL( aResourceId, aExcludeHidden );
       
  1406     TMuiuFlags search = iFinder->SearchFlags();
       
  1407     search.SetFlag( CMuiuDynamicSettingsItemFinder::EFinderMoveOwnership );
       
  1408     iFinder->SetSearchFlags( search );
       
  1409 
       
  1410     // Return the copy of the array
       
  1411     return iFinder->FinderArrayLC();
       
  1412     }
       
  1413 
       
  1414 // ----------------------------------------------------------------------------
       
  1415 // CMuiuDynamicSettingsArray::ItemSubArrayCheck()
       
  1416 // ----------------------------------------------------------------------------
       
  1417 //
       
  1418 TBool CMuiuDynamicSettingsArray::ItemSubArrayCheck(
       
  1419     const CMuiuSettingBase& aBaseItem ) const
       
  1420     {
       
  1421     // Check if the item type is menu array
       
  1422     return aBaseItem.Type() == EMuiuDynSetMenuArray;
       
  1423     }
       
  1424 
       
  1425 // ----------------------------------------------------------------------------
       
  1426 // CMuiuDynamicSettingsArray::ItemSubItemCheck()
       
  1427 // ----------------------------------------------------------------------------
       
  1428 //
       
  1429 TBool CMuiuDynamicSettingsArray::ItemSubItemCheck(
       
  1430     const CMuiuSettingBase& aBaseItem ) const
       
  1431     {
       
  1432     // if item is not any of the following types it cannot contain subitems
       
  1433     if ( aBaseItem.iItemType != EMuiuDynSetMenuArray &&
       
  1434          aBaseItem.iItemType != EMuiuDynSetRadioButtonArray &&
       
  1435          aBaseItem.iItemType != EMuiuDynSetCheckBoxArray &&
       
  1436          aBaseItem.iItemType != EMuiuDynSetUndefined &&
       
  1437          aBaseItem.iItemType != EMuiuDynSetItemMultiLine )
       
  1438         {
       
  1439         return EFalse;
       
  1440         }
       
  1441 
       
  1442     const CMuiuSettingsLink* link =
       
  1443         static_cast<const CMuiuSettingsLink*>( &aBaseItem );
       
  1444 
       
  1445     // If the item has an array and it contains items, return true
       
  1446     return ( link->iItemLinkArray != NULL &&
       
  1447              link->iItemLinkArray->Count() > 0 );
       
  1448     }
       
  1449 
       
  1450 // ----------------------------------------------------------------------------
       
  1451 // CMuiuDynamicSettingsArray::SetBetweenValues()
       
  1452 // ----------------------------------------------------------------------------
       
  1453 //
       
  1454 void CMuiuDynamicSettingsArray::SetBetweenValues(
       
  1455     TInt& aValue,
       
  1456     TInt aMin,
       
  1457     TInt aMax ) const
       
  1458     {
       
  1459     // Make a sanity check
       
  1460     if ( aMin > aMax )
       
  1461         {
       
  1462         // Swap the values
       
  1463         TInt temp = aMin;
       
  1464         aMin = aMax;
       
  1465         aMax = temp;
       
  1466         }
       
  1467 
       
  1468     // Make sure that we are above the minimum
       
  1469     if ( aValue < aMin )
       
  1470         {
       
  1471         aValue = aMin;
       
  1472         }
       
  1473 
       
  1474     // Make sure that we are below the maximum
       
  1475     if ( aValue > aMax )
       
  1476         {
       
  1477         aValue = aMax;
       
  1478         }
       
  1479     }
       
  1480 
       
  1481 // ----------------------------------------------------------------------------
       
  1482 // CMuiuDynamicSettingsArray::Refresh()
       
  1483 // ----------------------------------------------------------------------------
       
  1484 //
       
  1485 void CMuiuDynamicSettingsArray::Refresh()
       
  1486     {
       
  1487     if ( iArrayFlags.Flag( EMuiuDynArrayAllowRefresh ) )
       
  1488         {
       
  1489         UpdateActiveItemsCount();
       
  1490         TRAP_IGNORE( EventArrayChangedL( EMuiuDynArrayChanged ) );
       
  1491         }
       
  1492     }
       
  1493 
       
  1494 // ----------------------------------------------------------------------------
       
  1495 // CMuiuDynamicSettingsArray::UpdateActiveItemsCount()
       
  1496 // ----------------------------------------------------------------------------
       
  1497 //
       
  1498 void CMuiuDynamicSettingsArray::UpdateActiveItemsCount(
       
  1499     const TInt aNewCount )
       
  1500     {
       
  1501     // If count not provided, update it manually
       
  1502     if ( aNewCount == KErrNotFound )
       
  1503         {
       
  1504         iActiveCount = StackCountItems();
       
  1505         }
       
  1506     // Just update the count
       
  1507     else
       
  1508         {
       
  1509         iActiveCount = aNewCount;
       
  1510         }
       
  1511     }
       
  1512 
       
  1513 // ----------------------------------------------------------------------------
       
  1514 // CMuiuDynamicSettingsArray::HandleStackForwardL()
       
  1515 // ----------------------------------------------------------------------------
       
  1516 //
       
  1517 TMuiuStackResult CMuiuDynamicSettingsArray::HandleStackForwardL(
       
  1518     const TInt aIndex )
       
  1519     {
       
  1520     // If index is provided, append the resource to stack immediately
       
  1521     if ( aIndex != KErrNotFound )
       
  1522         {
       
  1523         TInt resource = iItemArray->At( aIndex )->iItemResourceId;
       
  1524 
       
  1525         if ( resource )
       
  1526             {
       
  1527             iResourceStack->AppendL( resource );
       
  1528             }
       
  1529         else
       
  1530             {
       
  1531             return EMuiuStackResultInvalid;
       
  1532             }
       
  1533         }
       
  1534     // Otherwise find the last submenu item in the array
       
  1535     else
       
  1536         {
       
  1537         TInt index = iItemArray->Count();
       
  1538 
       
  1539         while ( --index >= 0 )
       
  1540             {
       
  1541             // Check the item is menu item
       
  1542             if ( iItemArray->At( index )->iItemType == EMuiuDynSetMenuArray )
       
  1543                 {
       
  1544                 iResourceStack->AppendL(
       
  1545                     iItemArray->At( index )->iItemResourceId );
       
  1546                 index = EMuiuStackResultInvalid;
       
  1547                 }
       
  1548             }
       
  1549         }
       
  1550 
       
  1551     return HandleStackChangeL( ETrue );
       
  1552     }
       
  1553 
       
  1554 // ----------------------------------------------------------------------------
       
  1555 // CMuiuDynamicSettingsArray::HandleStackForwardL()
       
  1556 // ----------------------------------------------------------------------------
       
  1557 //
       
  1558 TMuiuStackResult CMuiuDynamicSettingsArray::HandleStackForwardL(
       
  1559     const TUid& aId )
       
  1560     {
       
  1561     TInt index = iItemArray->Count();
       
  1562 
       
  1563     // Search through the list
       
  1564     while ( --index >= 0 )
       
  1565         {
       
  1566         CMuiuSettingBase* base = iItemArray->At( index );
       
  1567 
       
  1568         // Check the item is menu item
       
  1569         if ( base->iItemId == aId &&
       
  1570              base->iItemType == EMuiuDynSetMenuArray )
       
  1571             {
       
  1572             iResourceStack->AppendL( base->iItemResourceId );
       
  1573             index = KErrNotFound;
       
  1574             }
       
  1575         else
       
  1576             {
       
  1577             return EMuiuStackResultInvalid;
       
  1578             }
       
  1579         }
       
  1580 
       
  1581     return HandleStackChangeL( ETrue );
       
  1582     }
       
  1583 
       
  1584 // ----------------------------------------------------------------------------
       
  1585 // CMuiuDynamicSettingsArray::HandleStackForwardL()
       
  1586 // ----------------------------------------------------------------------------
       
  1587 //
       
  1588 TMuiuStackResult CMuiuDynamicSettingsArray::HandleStackForwardL(
       
  1589     const CMuiuSettingBase& aBase )
       
  1590     {
       
  1591     // Make sure the item is subarray item
       
  1592     if ( ItemSubArrayCheck( aBase ) )
       
  1593         {
       
  1594         // Make sure the array exists and it contains items
       
  1595         const CMuiuSettingsLink* link =
       
  1596             static_cast<const CMuiuSettingsLink*>( &aBase );
       
  1597         __ASSERT_DEBUG( link->iItemLinkArray != NULL,
       
  1598             User::Panic( KMuiuDynSettingsArrayPanic, KErrNotFound ) );
       
  1599         const CMuiuSettingBase* nextItem = link->iItemLinkArray->At( 0 ) ;
       
  1600         __ASSERT_DEBUG( nextItem != NULL,
       
  1601             User::Panic( KMuiuDynSettingsArrayPanic, KErrNotFound ) );
       
  1602 
       
  1603         // new item has been found, check the resource is not same
       
  1604         __ASSERT_DEBUG( nextItem->iItemResourceId != StackActiveResource(),
       
  1605             User::Panic( KMuiuDynSettingsArrayPanic, KErrAlreadyExists ) );
       
  1606 
       
  1607         HandleStackChangeL( ETrue, nextItem->iItemResourceId );
       
  1608 
       
  1609         return EMuiuStackResultSubMenuOpen;
       
  1610         }
       
  1611 
       
  1612     return EMuiuStackResultOk;
       
  1613     }
       
  1614 
       
  1615 // ----------------------------------------------------------------------------
       
  1616 // CMuiuDynamicSettingsArray::HandleStackBackwardL()
       
  1617 // ----------------------------------------------------------------------------
       
  1618 //
       
  1619 TMuiuStackResult CMuiuDynamicSettingsArray::HandleStackBackwardL( TInt aCount )
       
  1620     {
       
  1621     // Remove the last item from stack number of times
       
  1622     while ( aCount-- && iResourceStack->Count() )
       
  1623         {
       
  1624         iResourceStack->Remove( iResourceStack->Count() - 1 );
       
  1625         }
       
  1626 
       
  1627     return HandleStackChangeL( EFalse );
       
  1628     }
       
  1629 
       
  1630 // ----------------------------------------------------------------------------
       
  1631 // CMuiuDynamicSettingsArray::HandleStackChangeL()
       
  1632 // ----------------------------------------------------------------------------
       
  1633 //
       
  1634 TMuiuStackResult CMuiuDynamicSettingsArray::HandleStackChangeL(
       
  1635     const TInt aForward,
       
  1636     const TInt aResourceId )
       
  1637     {
       
  1638     // If resource id not provided
       
  1639     if ( aResourceId != KErrNotFound )
       
  1640         {
       
  1641         iResourceStack->AppendL( aResourceId );
       
  1642         }
       
  1643 
       
  1644     // Update the active count
       
  1645     UpdateActiveItemsCount();
       
  1646 
       
  1647     // Inform of the array change
       
  1648     EventArrayChangedL(
       
  1649         aForward ? EMuiuDynArrayStackForward : EMuiuDynArrayStackBackward );
       
  1650 
       
  1651     return EMuiuStackResultOk;
       
  1652     }
       
  1653 
       
  1654 // ----------------------------------------------------------------------------
       
  1655 // CMuiuDynamicSettingsArray::StackCountItems()
       
  1656 // ----------------------------------------------------------------------------
       
  1657 //
       
  1658 TInt CMuiuDynamicSettingsArray::StackCountItems(
       
  1659     const TBool aExcludeHidden ) const
       
  1660     {
       
  1661     // Set the array finder to contain the current resource in array
       
  1662     GetResource( StackActiveResource(), aExcludeHidden );
       
  1663 
       
  1664     return iFinder->FinderArray()->Count();
       
  1665     }
       
  1666 
       
  1667 // ----------------------------------------------------------------------------
       
  1668 // CMuiuDynamicSettingsArray::StackActiveResource()
       
  1669 // ----------------------------------------------------------------------------
       
  1670 //
       
  1671 TInt CMuiuDynamicSettingsArray::StackActiveResource() const
       
  1672     {
       
  1673     return ( *iResourceStack )[iResourceStack->Count() - 1];
       
  1674     }
       
  1675 
       
  1676 // ----------------------------------------------------------------------------
       
  1677 // CMuiuDynamicSettingsArray::IsVisibleCheck()
       
  1678 // ----------------------------------------------------------------------------
       
  1679 //
       
  1680 TBool CMuiuDynamicSettingsArray::IsVisibleCheck(
       
  1681     const CMuiuSettingBase& aBaseItem,
       
  1682     const TBool aExcludeHidden ) const
       
  1683     {
       
  1684     return ( aExcludeHidden && !IsHidden( aBaseItem ) || !aExcludeHidden );
       
  1685     }
       
  1686 
       
  1687 //  End of File
       
  1688