ipsservices/ipssossettings/src/ipssetuibasearray.cpp
changeset 0 8466d47a6819
child 20 efd4f1afd43e
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: This file implements class CIpsSetUiBaseArray.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "emailtrace.h"
       
    20 #include <e32base.h>            // Base symbian include
       
    21 #include <gulutil.h>            // KColumnListSeparator
       
    22 #include <eikenv.h>             // CEikonEnv
       
    23 #include <eikrutil.h>           // EikResourceUtils
       
    24 #include <AknUtils.h>           // AknTextUtils
       
    25 
       
    26 #include <data_caging_path_literals.hrh>
       
    27 #include <ipssossettings.rsg>
       
    28 
       
    29 #include "ipssetutilsexception.h"
       
    30 #include "ipssetutilsconsts.h"
       
    31 #include "ipssetuifinder.h"
       
    32 #include "ipssetuiitembase.h"   
       
    33 #include "ipssetuiitemvalue.h"  
       
    34 #include "ipssetuiitemtext.h"   
       
    35 #include "ipssetuiitemlink.h"   
       
    36 #include "ipssetuiitemextlink.h"
       
    37 #include "ipssetuifinder.h"
       
    38 #include "ipssetutilspageids.hrh"
       
    39 #include "ipssetuibasearray.h"
       
    40 
       
    41 // This is added at the end of the compulsory setting item string
       
    42 _LIT( KIpsSetUiStrCompulsory, "\t*" );
       
    43 // The number of characters that can be shown in the screen
       
    44 const TInt KIpsSetUiVisibleTextLength = 30;
       
    45 //
       
    46 const TInt KIpsSetUiPasswordSecLength = 4;
       
    47 
       
    48 _LIT( KCharsToReplace, "\r\n\t\x2028\x2029" );
       
    49 
       
    50 // ============================ MEMBER FUNCTIONS ===============================
       
    51 
       
    52 // ----------------------------------------------------------------------------
       
    53 // CIpsSetUiBaseArray::CIpsSetUiBaseArray()
       
    54 // ----------------------------------------------------------------------------
       
    55 //
       
    56 CIpsSetUiBaseArray::CIpsSetUiBaseArray()
       
    57     :
       
    58     iFinder( NULL ),
       
    59     iItemArray( NULL ),
       
    60     iPasswordFill( 0x00 ),
       
    61     iActiveCount( 0 ),
       
    62     iError( KErrNone ),
       
    63     iEnv( CEikonEnv::Static() ) // faulty CS warning
       
    64     {
       
    65     FUNC_LOG;
       
    66     }
       
    67 
       
    68 // ----------------------------------------------------------------------------
       
    69 // CIpsSetUiBaseArray::~CIpsSetUiBaseArray()
       
    70 // ----------------------------------------------------------------------------
       
    71 //
       
    72 CIpsSetUiBaseArray::~CIpsSetUiBaseArray()
       
    73     {
       
    74     FUNC_LOG;
       
    75     CleanArrayItems();
       
    76 
       
    77     if ( iResourceStack )
       
    78         {
       
    79         iResourceStack->Reset();
       
    80         delete iResourceStack;
       
    81         iResourceStack = NULL;
       
    82         }
       
    83     delete iItemArray;
       
    84     delete iTempText;
       
    85     delete iFinder;
       
    86     }
       
    87 
       
    88 // ----------------------------------------------------------------------------
       
    89 // CIpsSetUiBaseArray::BaseConstructL()
       
    90 // ----------------------------------------------------------------------------
       
    91 //
       
    92 void CIpsSetUiBaseArray::BaseConstructL()
       
    93     {
       
    94     FUNC_LOG;
       
    95     // Prepare the arrays
       
    96     iItemArray = new ( ELeave ) CIpsSetUiBaseItemArray( KIpsSetUiArrayGranularity );
       
    97     iResourceStack = new ( ELeave ) RResourceStack( KIpsSetUiArrayGranularity );
       
    98     iFinder = CIpsSetUiFinder::NewL( *this );
       
    99     iArrayFlags.SetFlag( EIpsSetUiArrayAllowRefresh );
       
   100         
       
   101     // Prepare strings
       
   102     iTempText = HBufC::NewL( KIpsSetUiMaxSettingsTextLength );
       
   103     iPasswordFill = EikResourceUtils::ReadTInt16L( 
       
   104         R_IPS_SET_DIALOG_PASSWORD_FILL, iEnv );
       
   105     }
       
   106 
       
   107 // ----------------------------------------------------------------------------
       
   108 // CIpsSetUiBaseArray::BaseConstructL()
       
   109 // ----------------------------------------------------------------------------
       
   110 //
       
   111 void CIpsSetUiBaseArray::BaseConstructL(
       
   112     const TInt aResourceId )
       
   113     {
       
   114     FUNC_LOG;
       
   115     // Initialize the members
       
   116     BaseConstructL();
       
   117 
       
   118     // If resource provided add it into the setting array
       
   119     LoadSettingArrayFromResourceL( aResourceId );
       
   120 
       
   121     UpdateActiveItemsCount();
       
   122     }
       
   123 
       
   124 TInt CIpsSetUiBaseArray::GetLastResourceId( )
       
   125     {
       
   126     FUNC_LOG;
       
   127     TInt ret = KErrNotFound;
       
   128     if ( iResourceStack && iResourceStack->Count() > 0 )
       
   129         {
       
   130         ret = (*iResourceStack)[ iResourceStack->Count() -1 ];
       
   131         }
       
   132     return ret;
       
   133     }
       
   134 
       
   135 // ----------------------------------------------------------------------------
       
   136 // CIpsSetUiBaseArray::CleanArrayItems()
       
   137 // ----------------------------------------------------------------------------
       
   138 //
       
   139 void CIpsSetUiBaseArray::CleanArrayItems()
       
   140     {
       
   141     FUNC_LOG;
       
   142     if ( iItemArray )
       
   143         {
       
   144         // Search through all items in the array
       
   145         for ( TInt index = iItemArray->Count() - 1 ; index >= 0; index-- )
       
   146             {
       
   147             // Only certain type of items can contain subarrays
       
   148             CIpsSetUiItem* base = ( *iItemArray )[index];
       
   149             delete base;
       
   150             base = NULL;
       
   151             }
       
   152         }
       
   153     }
       
   154 
       
   155 // ----------------------------------------------------------------------------
       
   156 // CIpsSetUiBaseArray::CreateCustomItemToArrayLC()
       
   157 // ----------------------------------------------------------------------------
       
   158 //
       
   159 CIpsSetUiItem* CIpsSetUiBaseArray::CreateCustomItemToArrayLC(
       
   160     const TUid& /* aId */ )
       
   161     {
       
   162     FUNC_LOG;
       
   163     return NULL;
       
   164     }
       
   165 
       
   166 // ----------------------------------------------------------------------------
       
   167 // CIpsSetUiBaseArray::ListboxItemFillMultiLineLabel()
       
   168 // ----------------------------------------------------------------------------
       
   169 //
       
   170 void CIpsSetUiBaseArray::ListboxItemFillMultiLineLabel(
       
   171     const CIpsSetUiItem& aBaseItem,
       
   172     TIpsSetUtilsTextPlain& aText ) const
       
   173     {
       
   174     FUNC_LOG;
       
   175     aText = static_cast<const CIpsSetUiItemLink*>( 
       
   176         &aBaseItem )->iItemSettingText->Left( KIpsSetUiVisibleTextLength );
       
   177     }
       
   178 
       
   179 // ----------------------------------------------------------------------------
       
   180 // CIpsSetUiBaseArray::ListboxItemFillEditTextLabel()
       
   181 // ----------------------------------------------------------------------------
       
   182 //
       
   183 void CIpsSetUiBaseArray::ListboxItemFillEditTextLabel(
       
   184     const CIpsSetUiItem& aBaseItem,
       
   185     TIpsSetUtilsTextPlain& aText ) const
       
   186     {
       
   187     FUNC_LOG;
       
   188     aText.Copy( aBaseItem.Text().Left( KIpsSetUiVisibleTextLength ) );
       
   189     }
       
   190 
       
   191 // ----------------------------------------------------------------------------
       
   192 // CIpsSetUiBaseArray::ListboxItemFillEditValueLabel()
       
   193 // ----------------------------------------------------------------------------
       
   194 //
       
   195 void CIpsSetUiBaseArray::ListboxItemFillEditValueLabel(
       
   196     const CIpsSetUiItem& aBaseItem,
       
   197     TIpsSetUtilsTextPlain& aText ) const
       
   198     {
       
   199     FUNC_LOG;
       
   200     aText.Append( aBaseItem.Value() );
       
   201     aText.SetLength( KIpsSetUiVisibleTextLength );
       
   202     }
       
   203 
       
   204 // ----------------------------------------------------------------------------
       
   205 // CIpsSetUiBaseArray::ListboxItemFillEditTimeLabel()
       
   206 // ----------------------------------------------------------------------------
       
   207 //
       
   208 void CIpsSetUiBaseArray::ListboxItemFillEditTimeLabel(
       
   209     const CIpsSetUiItem& aBaseItem,
       
   210     TIpsSetUtilsTextPlain& aText ) const
       
   211     {
       
   212     FUNC_LOG;
       
   213     aText.Append( aBaseItem.Value() );
       
   214     aText.SetLength( KIpsSetUiVisibleTextLength );
       
   215     }
       
   216 
       
   217 // ----------------------------------------------------------------------------
       
   218 // CIpsSetUiBaseArray::ListboxUndefinedFillLabel()
       
   219 // ----------------------------------------------------------------------------
       
   220 //
       
   221 void CIpsSetUiBaseArray::ListboxUndefinedFillLabel(
       
   222     const CIpsSetUiItem& aBaseItem,
       
   223     TIpsSetUtilsTextPlain& aText ) const
       
   224     {
       
   225     FUNC_LOG;
       
   226     aText = static_cast<const CIpsSetUiItemLinkExt*>( 
       
   227         &aBaseItem )->iItemSettingText->Left( KIpsSetUiVisibleTextLength );
       
   228     }
       
   229 
       
   230 // ----------------------------------------------------------------------------
       
   231 // CIpsSetUiBaseArray::ListboxRadioButtonFillArrayLabel()
       
   232 // ----------------------------------------------------------------------------
       
   233 //
       
   234 void CIpsSetUiBaseArray::ListboxRadioButtonFillArrayLabel(
       
   235     const CIpsSetUiItem& aBaseItem,
       
   236     TIpsSetUtilsTextPlain& aText ) const
       
   237     {
       
   238     FUNC_LOG;
       
   239     aText = static_cast<const CIpsSetUiItemLinkExt*>( 
       
   240         &aBaseItem )->iItemSettingText->Left( KIpsSetUiVisibleTextLength );
       
   241     }
       
   242 
       
   243 // ----------------------------------------------------------------------------
       
   244 // CIpsSetUiBaseArray::ListboxCheckboxFillArrayLabel()
       
   245 // ----------------------------------------------------------------------------
       
   246 //
       
   247 void CIpsSetUiBaseArray::ListboxCheckboxFillArrayLabel(
       
   248     const CIpsSetUiItem& aBaseItem,
       
   249     TIpsSetUtilsTextPlain& aText ) const
       
   250     {
       
   251     FUNC_LOG;
       
   252     aText = static_cast<const CIpsSetUiItemLinkExt*>( 
       
   253         &aBaseItem )->iItemSettingText->Left( KIpsSetUiVisibleTextLength );
       
   254     }
       
   255 
       
   256 // ----------------------------------------------------------------------------
       
   257 // CIpsSetUiBaseArray::ListboxItemLabelFillL()
       
   258 // ----------------------------------------------------------------------------
       
   259 //
       
   260 TPtrC16 CIpsSetUiBaseArray::ListboxItemLabelFillL(
       
   261     CIpsSetUiItem& aBaseItem ) const
       
   262     {
       
   263     FUNC_LOG;
       
   264     // Get the type of the setting item
       
   265     TIpsSetUiSettingsType type = aBaseItem.iItemType;
       
   266     TIpsSetUtilsTextPlain tempSettingText;
       
   267     tempSettingText.Zero();
       
   268 
       
   269     switch ( type )
       
   270         {
       
   271         case EIpsSetUiItemMultiLine:
       
   272             ListboxItemFillMultiLineLabel( aBaseItem, tempSettingText );
       
   273             break;
       
   274 
       
   275         case EIpsSetUiUndefined:
       
   276             ListboxUndefinedFillLabel( aBaseItem, tempSettingText );
       
   277             break;
       
   278 
       
   279         case EIpsSetUiRadioButtonArray:
       
   280             ListboxRadioButtonFillArrayLabel( aBaseItem, tempSettingText );
       
   281             break;
       
   282 
       
   283         case EIpsSetUiCheckBoxArray:
       
   284             ListboxCheckboxFillArrayLabel( aBaseItem, tempSettingText );
       
   285             break;
       
   286 
       
   287         case EIpsSetUiItemText:
       
   288             ListboxItemFillEditTextLabel( aBaseItem, tempSettingText );
       
   289             break;
       
   290 
       
   291         case EIpsSetUiItemValue:
       
   292             ListboxItemFillEditValueLabel( aBaseItem, tempSettingText );
       
   293             break;
       
   294 
       
   295         case EIpsSetUiItemTime:
       
   296             ListboxItemFillEditTimeLabel( aBaseItem, tempSettingText );
       
   297             break;
       
   298 
       
   299         default:
       
   300             // Nothing to show, send empty text
       
   301             break;
       
   302         }
       
   303 
       
   304     // remove line feed from signature line's visible part
       
   305     if( aBaseItem.iItemId == TUid::Uid(EIpsSetUiMailboxSignature) || 
       
   306         aBaseItem.iItemId == TUid::Uid(EIpsSetUiMailboxMailboxName) )
       
   307         {
       
   308         AknTextUtils::ReplaceCharacters( tempSettingText, KCharsToReplace, ' ' );
       
   309         }
       
   310 
       
   311     // If the setting is marked as password, fill special character
       
   312     // instead of readable text
       
   313     TInt length = tempSettingText.Length();
       
   314     if ( length > 0 && aBaseItem.iItemFlags.Flag32( KIpsSetUiFlagPassword ) )
       
   315         {
       
   316         // Add special chars to all type characters in setting field
       
   317         TChar passFill = TChar( iPasswordFill );
       
   318         tempSettingText.Zero();
       
   319         tempSettingText.AppendFill( passFill, KIpsSetUiPasswordSecLength );
       
   320         }
       
   321 
       
   322     return tempSettingText;
       
   323     }
       
   324 
       
   325 /******************************************************************************
       
   326 
       
   327     Item property editors
       
   328 
       
   329 ******************************************************************************/
       
   330 
       
   331 // ----------------------------------------------------------------------------
       
   332 // CIpsSetUiBaseArray::SetItemText()
       
   333 // ----------------------------------------------------------------------------
       
   334 //
       
   335 void CIpsSetUiBaseArray::SetItemText(
       
   336     CIpsSetUiItem& aBaseItem,
       
   337     const TDesC& aText,
       
   338     const TBool aUpdate )
       
   339     {
       
   340     FUNC_LOG;
       
   341     switch ( aBaseItem.iItemType )
       
   342         {
       
   343         case EIpsSetUiItemValue:
       
   344             static_cast<CIpsSetUiItemValue*>( 
       
   345                 &aBaseItem )->iItemSettingText->Copy( aText );
       
   346             break;
       
   347 
       
   348         case EIpsSetUiRadioButtonArray:
       
   349         case EIpsSetUiCheckBoxArray:
       
   350             static_cast<CIpsSetUiItemLinkExt*>( 
       
   351                 &aBaseItem )->iItemSettingText->Copy( aText );
       
   352             break;
       
   353 
       
   354         default:
       
   355             aBaseItem.SetText( aText );
       
   356             break;
       
   357         }
       
   358 
       
   359     // Issue update when needed
       
   360     if ( aUpdate )
       
   361         {
       
   362         Refresh();
       
   363         }
       
   364     }
       
   365 
       
   366 // ----------------------------------------------------------------------------
       
   367 // CIpsSetUiBaseArray::ItemText()
       
   368 // ----------------------------------------------------------------------------
       
   369 //
       
   370 const TDesC& CIpsSetUiBaseArray::ItemText(
       
   371     CIpsSetUiItem& aBaseItem )
       
   372     {
       
   373     FUNC_LOG;
       
   374     switch ( aBaseItem.iItemType )
       
   375         {
       
   376         case EIpsSetUiItemValue:
       
   377             return *static_cast<CIpsSetUiItemValue*>( 
       
   378                 &aBaseItem )->iItemSettingText;
       
   379 
       
   380         case EIpsSetUiRadioButtonArray:
       
   381         case EIpsSetUiCheckBoxArray:
       
   382             return *static_cast<CIpsSetUiItemLinkExt*>( 
       
   383                 &aBaseItem )->iItemSettingText;
       
   384         }
       
   385 
       
   386     return aBaseItem.Text();
       
   387     }
       
   388 
       
   389 /******************************************************************************
       
   390 
       
   391     Base class function definitions
       
   392 
       
   393 ******************************************************************************/
       
   394 
       
   395 // ----------------------------------------------------------------------------
       
   396 // CIpsSetUiBaseArray::SearchDoError()
       
   397 // ----------------------------------------------------------------------------
       
   398 //
       
   399 TBool CIpsSetUiBaseArray::SearchDoError()
       
   400     {
       
   401     FUNC_LOG;
       
   402     return ETrue;
       
   403     }
       
   404 
       
   405 // ----------------------------------------------------------------------------
       
   406 // CIpsSetUiBaseArray::SearchDoContinuationCheck()
       
   407 // ----------------------------------------------------------------------------
       
   408 //
       
   409 TBool CIpsSetUiBaseArray::SearchDoContinuationCheck(
       
   410     const CIpsSetUiItem& /* aItem */,
       
   411     const TInt /* aIndex */ )
       
   412     {
       
   413     FUNC_LOG;
       
   414     return ETrue;
       
   415     }
       
   416 
       
   417 // ----------------------------------------------------------------------------
       
   418 // CIpsSetUiBaseArray::SearchDoItemCheck()
       
   419 // ----------------------------------------------------------------------------
       
   420 //
       
   421 TBool CIpsSetUiBaseArray::SearchDoItemCheck(
       
   422     CIpsSetUiItem& /* aItem */ )
       
   423     {
       
   424     FUNC_LOG;
       
   425     return ETrue;
       
   426     }
       
   427 
       
   428 // ----------------------------------------------------------------------------
       
   429 // CIpsSetUiBaseArray::MdcaCount()
       
   430 // ----------------------------------------------------------------------------
       
   431 //
       
   432 TInt CIpsSetUiBaseArray::MdcaCount() const
       
   433     {
       
   434     FUNC_LOG;
       
   435     return iActiveCount;
       
   436     }
       
   437 
       
   438 // ----------------------------------------------------------------------------
       
   439 // CIpsSetUiBaseArray::MdcaPoint()
       
   440 // ----------------------------------------------------------------------------
       
   441 //
       
   442 TPtrC16 CIpsSetUiBaseArray::MdcaPoint( TInt aIndex ) const
       
   443     {
       
   444     FUNC_LOG;
       
   445     // First search the currently active resource to array and check
       
   446     // the given index is in the current array
       
   447     IPS_ASSERT_DEBUG( aIndex < StackCountItems(), KErrOverflow, EBaseArray );
       
   448 
       
   449     // Temp text ptr
       
   450     TPtr tempText = iTempText->Des();
       
   451     
       
   452     // Do a sanity check for index and return null text if out of range
       
   453     if ( !iFinder || aIndex < 0 || aIndex >= StackCountItems())
       
   454         {       
       
   455         tempText.Zero();
       
   456         tempText.Append(KNullDesC);        
       
   457         return tempText;
       
   458         }
       
   459 
       
   460     // Search for item from the active array
       
   461     CIpsSetUiItem* setting = iFinder->FinderArray()->At( aIndex ).iItem;  // faulty CS warning
       
   462     IPS_ASSERT_DEBUG( setting , KErrNotFound, EBaseArray );
       
   463 
       
   464     // Prepare strings
       
   465     // Send custom event and if not used, prepare default
       
   466     if ( !EventCustomMdcaPoint( setting->iItemId, tempText ) )
       
   467         {
       
   468         // Initialize string
       
   469         tempText.Zero();
       
   470         tempText.Append( KIpsSetUiStrSpace );
       
   471         tempText.Append( KColumnListSeparator );
       
   472         tempText.Append( *setting->iItemLabel );
       
   473 
       
   474         // Submenus doesn't contain other information
       
   475         if ( !ItemSubArrayCheck( *setting ) )
       
   476             {
       
   477             tempText.Append( KColumnListSeparator );
       
   478             tempText.Append( KColumnListSeparator );
       
   479 
       
   480             TIpsSetUtilsTextPlain tempSettingText;
       
   481             // Try to add the text
       
   482             TRAP_IGNORE( tempSettingText =
       
   483                 ListboxItemLabelFillL( *setting ) );
       
   484 
       
   485             // Fill the setting text with string
       
   486             if ( tempSettingText.Length() )
       
   487                 {
       
   488                 tempText.Append( tempSettingText );
       
   489                 }
       
   490             else
       
   491                 {
       
   492                 tempText.Append( KIpsSetUiStrSpace );
       
   493                 }
       
   494 
       
   495             // Add the special string after compulsory fields
       
   496             if ( setting->iItemFlags.Flag32( KIpsSetUiFlagCompulsory ) )
       
   497                 {
       
   498                 tempText.Append( KIpsSetUiStrCompulsory );
       
   499                 }
       
   500 
       
   501             // Do the number conversion, if allowed
       
   502             if ( setting->iItemFlags.Flag32( KIpsSetUiFlagLangSpecificNumConv ) )
       
   503                 {
       
   504                 AknTextUtils::DisplayTextLanguageSpecificNumberConversion(
       
   505                     tempText );
       
   506                 }
       
   507             }
       
   508         }
       
   509 
       
   510     setting = NULL;
       
   511     return tempText;
       
   512     }
       
   513 
       
   514 /******************************************************************************
       
   515 
       
   516     Resource loading functions
       
   517 
       
   518 ******************************************************************************/
       
   519 
       
   520 // ----------------------------------------------------------------------------
       
   521 // CIpsSetUiBaseArray::LoadDynamicSettingItemL()
       
   522 // ----------------------------------------------------------------------------
       
   523 //
       
   524 void CIpsSetUiBaseArray::LoadDynamicSettingItemL(
       
   525     TResourceReader& aReader,
       
   526     CIpsSetUiItem& aBaseItem )
       
   527     {
       
   528     FUNC_LOG;
       
   529     // Read rest of the settings first
       
   530     // STRUCT IPS_SET_ITEM : LTEXT itemlabel
       
   531     HBufC* txt = aReader.ReadHBufCL();   // message text
       
   532 
       
   533     if ( txt )
       
   534         {
       
   535         aBaseItem.iItemLabel->Copy( *txt );
       
   536         }
       
   537 
       
   538     delete txt;
       
   539     txt = NULL;
       
   540 
       
   541     // STRUCT IPS_SET_ITEM : LLINK itemmaxlength
       
   542     TInt maxLength = aReader.ReadInt32();
       
   543 
       
   544     // STRUCT IPS_SET_ITEM : LONG itemflags
       
   545     aBaseItem.iItemFlags = MAKE_TUINT64( aReader.ReadInt32(), 0 );
       
   546 
       
   547     // STRUCT IPS_SET_ITEM : LLINK itemarray
       
   548     TInt linkResourceId = aReader.ReadInt32();
       
   549 
       
   550     // STRUCT IPS_SET_ITEM : WORD itemappereance
       
   551     TIpsSetUiSettingsType subtype =
       
   552         static_cast<TIpsSetUiSettingsType>( aReader.ReadInt16() );
       
   553 
       
   554     // Finally add the item to list
       
   555     HandleDynamicSettingsItemL(
       
   556         aBaseItem, maxLength, subtype, linkResourceId );
       
   557 
       
   558     // The basic data has been set, now init the userdata section
       
   559     InitUserData( aBaseItem );        
       
   560     }
       
   561 
       
   562 // ----------------------------------------------------------------------------
       
   563 // CIpsSetUiBaseArray::UpdateItemEditTextL()
       
   564 // ----------------------------------------------------------------------------
       
   565 //
       
   566 void CIpsSetUiBaseArray::UpdateItemEditTextL(
       
   567     CIpsSetUiItem& aBaseItem,
       
   568     const TInt aMaxLength )
       
   569     {
       
   570     FUNC_LOG;
       
   571     CIpsSetUiItemsEditText* text = 
       
   572         static_cast<CIpsSetUiItemsEditText*>( &aBaseItem );
       
   573     text->iItemMaxLength = aMaxLength;
       
   574     text = NULL;
       
   575     }
       
   576 
       
   577 // ----------------------------------------------------------------------------
       
   578 // CIpsSetUiBaseArray::UpdateItemEditValueL()
       
   579 // ----------------------------------------------------------------------------
       
   580 //
       
   581 void CIpsSetUiBaseArray::UpdateItemEditValueL(
       
   582     CIpsSetUiItem& aBaseItem,
       
   583     const TInt aMaxLength )
       
   584     {
       
   585     FUNC_LOG;
       
   586     CIpsSetUiItemValue* value = 
       
   587         static_cast<CIpsSetUiItemValue*>( &aBaseItem );
       
   588     value->iItemMaxLength = aMaxLength;
       
   589     value = NULL;
       
   590     }
       
   591 
       
   592 // ----------------------------------------------------------------------------
       
   593 // CIpsSetUiBaseArray::HandleDynamicSettingsItemL()
       
   594 // ----------------------------------------------------------------------------
       
   595 //
       
   596 void CIpsSetUiBaseArray::HandleDynamicSettingsItemL(
       
   597     CIpsSetUiItem& aBaseItem,
       
   598     const TInt aMaxLength,
       
   599     const TIpsSetUiSettingsType aSubType,
       
   600     const TInt aLinkResourceId )
       
   601     {
       
   602     FUNC_LOG;
       
   603     switch ( aBaseItem.Type() )
       
   604         {
       
   605         // Load dynamically linked items or submenus
       
   606         case EIpsSetUiMenuArray:
       
   607         case EIpsSetUiRadioButtonArray:
       
   608         case EIpsSetUiCheckBoxArray:
       
   609         case EIpsSetUiItemMultiLine:
       
   610             LoadDynamicSettingsItemLinkItemL(
       
   611                 aBaseItem, aSubType, aLinkResourceId );
       
   612             break;
       
   613 
       
   614         // Finish text item
       
   615         case EIpsSetUiItemText:
       
   616             UpdateItemEditTextL( aBaseItem, aMaxLength );
       
   617             break;
       
   618 
       
   619         // Finish number item
       
   620         case EIpsSetUiItemValue:
       
   621         case EIpsSetUiItemTime:
       
   622             UpdateItemEditValueL( aBaseItem, aMaxLength );
       
   623             break;
       
   624 
       
   625         // Other items are already finished
       
   626         case EIpsSetUiItemRadioButton:
       
   627         case EIpsSetUiItemCheckBox:
       
   628         default:
       
   629             break;
       
   630         }
       
   631     }
       
   632 
       
   633 // ----------------------------------------------------------------------------
       
   634 // CIpsSetUiBaseArray::CreateItemToArrayL()
       
   635 // ----------------------------------------------------------------------------
       
   636 //
       
   637 CIpsSetUiItem* CIpsSetUiBaseArray::CreateItemToArrayL(
       
   638     const TIpsSetUiSettingsType aType,
       
   639     const TUid& aId,
       
   640     CIpsSetUiBaseItemArray& aItemArray )
       
   641     {
       
   642     FUNC_LOG;
       
   643     CIpsSetUiItem* base = NULL;
       
   644 
       
   645     switch ( aType )
       
   646         {
       
   647         // Create array item
       
   648         case EIpsSetUiMenuArray:
       
   649             base = CIpsSetUiItemLink::NewLC();
       
   650             break;
       
   651 
       
   652         // Force manual item creation
       
   653         case EIpsSetUiUndefined:
       
   654             base = CreateCustomItemToArrayLC( aId );
       
   655             IPS_ASSERT_DEBUG( base , EUnidentifiedItem, EBaseArray );
       
   656             break;
       
   657 
       
   658         // Create radiobutton array item
       
   659         case EIpsSetUiRadioButtonArray:
       
   660         case EIpsSetUiCheckBoxArray:
       
   661         case EIpsSetUiItemMultiLine:
       
   662             base = CIpsSetUiItemLinkExt::NewLC();
       
   663             break;
       
   664 
       
   665         // Create edit text item
       
   666         case EIpsSetUiItemText:
       
   667             base = CIpsSetUiItemsEditText::NewLC();
       
   668             break;
       
   669 
       
   670         // Create edit number item
       
   671         case EIpsSetUiItemValue:
       
   672         case EIpsSetUiItemTime:
       
   673             base = CIpsSetUiItemValue::NewLC();
       
   674             break;
       
   675 
       
   676         // Create normal base item
       
   677         case EIpsSetUiItemRadioButton:
       
   678         case EIpsSetUiItemCheckBox:
       
   679         default:
       
   680             base = CIpsSetUiItem::NewLC();
       
   681             break;
       
   682         }
       
   683 
       
   684     // Add to array
       
   685     aItemArray.AppendL( base );
       
   686     CleanupStack::Pop( base );
       
   687 
       
   688     return base;
       
   689     }
       
   690 
       
   691 // ----------------------------------------------------------------------------
       
   692 // CIpsSetUiBaseArray::LoadDynamicSettingsItemLinkItemL()
       
   693 // ----------------------------------------------------------------------------
       
   694 //
       
   695 void CIpsSetUiBaseArray::LoadDynamicSettingsItemLinkItemL(
       
   696     CIpsSetUiItem& aBaseItem,
       
   697     const TIpsSetUiSettingsType aSubType,
       
   698     const TInt aLinkResourceId )
       
   699     {
       
   700     FUNC_LOG;
       
   701     // Prepare the item
       
   702     CIpsSetUiItemLink* linkItem = static_cast<CIpsSetUiItemLink*>( &aBaseItem );
       
   703     linkItem->iItemAppereance = aSubType;
       
   704     linkItem->iItemFlags.SetFlag32( KIpsSetUiFlagUpdateOnChange );
       
   705 
       
   706     // Start reading only if resource is provided
       
   707     if ( aLinkResourceId )
       
   708         {
       
   709         linkItem->iItemLinkArray =
       
   710             new ( ELeave ) CIpsSetUiBaseItemArray(
       
   711                 KIpsSetUiArrayGranularity );
       
   712 
       
   713         // Start loading the settings
       
   714         LoadSettingItemsToArrayL( aLinkResourceId, *linkItem->iItemLinkArray );
       
   715         }
       
   716 
       
   717     linkItem = NULL;
       
   718     }
       
   719 
       
   720 // ----------------------------------------------------------------------------
       
   721 // CIpsSetUiBaseArray::LoadSettingArrayFromResource()
       
   722 // ----------------------------------------------------------------------------
       
   723 //
       
   724 void CIpsSetUiBaseArray::LoadSettingArrayFromResourceL(
       
   725     const TInt aResourceId )
       
   726     {
       
   727     FUNC_LOG;
       
   728     // Start reading only if resource is provided
       
   729     if ( aResourceId )
       
   730         {
       
   731         iResourceStack->AppendL( aResourceId );
       
   732         const TInt items = iItemArray->Count();
       
   733 
       
   734         // Begin to read the items from the resource
       
   735         TInt count = LoadSettingItemsToArrayL( aResourceId, *iItemArray );
       
   736 
       
   737         // Update the item count
       
   738         UpdateActiveItemsCount( count );
       
   739         }
       
   740     }
       
   741 
       
   742 // ----------------------------------------------------------------------------
       
   743 // CIpsSetUiBaseArray::LoadSettingItemsToArrayL()
       
   744 // ----------------------------------------------------------------------------
       
   745 //
       
   746 TInt CIpsSetUiBaseArray::LoadSettingItemsToArrayL(
       
   747     const TInt aResourceId,
       
   748     CIpsSetUiBaseItemArray& aItemArray )
       
   749     {
       
   750     FUNC_LOG;
       
   751     // Define new read based on last item
       
   752     TResourceReader reader;
       
   753     iEnv->CreateResourceReaderLC(
       
   754         reader, aResourceId );
       
   755 
       
   756     // Get the count of items in resource
       
   757     TInt count = reader.ReadInt16();
       
   758     for ( TInt loop = 0; loop < count; loop++ )
       
   759         {
       
   760         // Read the settings from the resource
       
   761 
       
   762         // STRUCT IPS_SET_ITEM : WORD itemtype
       
   763         TIpsSetUiSettingsType type =
       
   764             static_cast<TIpsSetUiSettingsType>( reader.ReadInt16() );
       
   765 
       
   766         // STRUCT IPS_SET_ITEM : WORD itemid
       
   767         TUid id = TUid::Uid( reader.ReadInt16() );
       
   768 
       
   769         // Create the setting item
       
   770         CIpsSetUiItem* base =
       
   771             CreateItemToArrayL( type, id, aItemArray );
       
   772         base->iItemId = id;
       
   773         base->iItemType = type;
       
   774         base->iItemResourceId = aResourceId;
       
   775 
       
   776         // Start loading the item, based on item type
       
   777         LoadDynamicSettingItemL( reader, *base );
       
   778         base = NULL;
       
   779         }
       
   780 
       
   781     CleanupStack::PopAndDestroy(); // reader
       
   782 
       
   783     return count;
       
   784     }
       
   785 
       
   786 /******************************************************************************
       
   787 
       
   788     Item hide functions
       
   789 
       
   790 ******************************************************************************/
       
   791 
       
   792 // ----------------------------------------------------------------------------
       
   793 // CIpsSetUiBaseArray::IsHidden()
       
   794 // ----------------------------------------------------------------------------
       
   795 //
       
   796 TInt CIpsSetUiBaseArray::IsHidden( const TUid& aId ) const
       
   797     {
       
   798     FUNC_LOG;
       
   799     return IsHidden( *GetItem( aId ) );
       
   800     }
       
   801 
       
   802 // ----------------------------------------------------------------------------
       
   803 // CIpsSetUiBaseArray::IsHidden()
       
   804 // ----------------------------------------------------------------------------
       
   805 //
       
   806 TInt CIpsSetUiBaseArray::IsHidden(
       
   807     const CIpsSetUiItem& aItem ) const
       
   808     {
       
   809     FUNC_LOG;
       
   810     if ( aItem.iItemFlags.Flag32( KIpsSetUiFlagPermanentlyHidden ) )
       
   811         {
       
   812         return KErrNotSupported;
       
   813         }
       
   814     else if ( aItem.iItemFlags.Flag32( KIpsSetUiFlagHidden ) )
       
   815         {
       
   816         return KErrNotFound;
       
   817         }
       
   818     else
       
   819         {
       
   820         return KErrNone;
       
   821         }
       
   822     }
       
   823 
       
   824 // ----------------------------------------------------------------------------
       
   825 // CIpsSetUiBaseArray::IsHidden()
       
   826 // ----------------------------------------------------------------------------
       
   827 //
       
   828 TInt CIpsSetUiBaseArray::IsHidden( const TInt aIndex ) const
       
   829     {
       
   830     FUNC_LOG;
       
   831     return IsHidden( *GetItem( aIndex ) );
       
   832     }
       
   833 
       
   834 // ----------------------------------------------------------------------------
       
   835 // CIpsSetUiBaseArray::DoHideItems()
       
   836 // ----------------------------------------------------------------------------
       
   837 //
       
   838 void CIpsSetUiBaseArray::DoHideItems( const TBool aHide )
       
   839     {
       
   840     FUNC_LOG;
       
   841     // All items collected, set their flags hidden flags
       
   842     CIpsSetUiFinderArray& array = *iFinder->FinderArray();
       
   843     TInt item = array.Count();
       
   844     while ( --item >= 0 )
       
   845         {
       
   846         CIpsSetUiItem* base = array[item].iItem;
       
   847         if ( aHide )
       
   848             {
       
   849             base->iItemFlags.SetFlag32( KIpsSetUiFlagHidden );
       
   850             }
       
   851         else
       
   852             {
       
   853             base->iItemFlags.ClearFlag32( KIpsSetUiFlagHidden );
       
   854             }        
       
   855         }
       
   856     }
       
   857 
       
   858 // ----------------------------------------------------------------------------
       
   859 // CIpsSetUiBaseArray::SetHideItem()
       
   860 // ----------------------------------------------------------------------------
       
   861 //
       
   862 void CIpsSetUiBaseArray::SetHideItem(
       
   863     const TBool aHide,
       
   864     const TUid& aId,
       
   865     const TBool aUpdate )
       
   866     {
       
   867     FUNC_LOG;
       
   868     if ( aHide )
       
   869         {
       
   870         GetItem( aId )->iItemFlags.SetFlag32( KIpsSetUiFlagHidden );
       
   871         }
       
   872     else
       
   873         {
       
   874         GetItem( aId )->iItemFlags.ClearFlag32( KIpsSetUiFlagHidden );
       
   875         }    
       
   876 
       
   877     // Handle the array change
       
   878     if ( aUpdate )
       
   879         {
       
   880         Refresh();
       
   881         }
       
   882     }
       
   883     
       
   884 // ----------------------------------------------------------------------------
       
   885 // CIpsSetUiBaseArray::SetHideItem()
       
   886 // ----------------------------------------------------------------------------
       
   887 //
       
   888 void CIpsSetUiBaseArray::SetHideItem(
       
   889     const TBool aHide,
       
   890     CIpsSetUiItem& aItem,
       
   891     const TBool aUpdate )
       
   892     {
       
   893     FUNC_LOG;
       
   894     if ( aHide )
       
   895         {
       
   896         aItem.iItemFlags.SetFlag32( KIpsSetUiFlagHidden );
       
   897         }
       
   898     else
       
   899         {
       
   900         aItem.iItemFlags.ClearFlag32( KIpsSetUiFlagHidden );
       
   901         }    
       
   902 
       
   903     // Handle the array change
       
   904     if ( aUpdate )
       
   905         {
       
   906         Refresh();
       
   907         }
       
   908     }
       
   909     
       
   910 /******************************************************************************
       
   911 
       
   912     Item search functions
       
   913 
       
   914 ******************************************************************************/
       
   915 
       
   916 // ----------------------------------------------------------------------------
       
   917 // CIpsSetUiBaseArray::InitDefaultSearch()
       
   918 // ----------------------------------------------------------------------------
       
   919 //
       
   920 void CIpsSetUiBaseArray::InitDefaultSearch(
       
   921     const TBool aExcludeHidden ) const
       
   922     {
       
   923     FUNC_LOG;
       
   924     // In default search, subfolders are included and hidden items are not
       
   925     // included into the search
       
   926     TUint64 search = 0x00;
       
   927     search |= CIpsSetUiFinder::EFinderSearchSubFolders;
       
   928     if ( aExcludeHidden )
       
   929         {
       
   930         search |= CIpsSetUiFinder::EFinderDoHideCheck;
       
   931         }
       
   932     else
       
   933         {
       
   934         search &= CIpsSetUiFinder::EFinderDoHideCheck;
       
   935         }    
       
   936     iFinder->SetSearchFlags( search );
       
   937     }
       
   938 
       
   939 // ----------------------------------------------------------------------------
       
   940 // CIpsSetUiBaseArray::ItemIndex()
       
   941 // ----------------------------------------------------------------------------
       
   942 //
       
   943 TInt CIpsSetUiBaseArray::ItemIndex(
       
   944     const TUid& aId,
       
   945     const TBool aExcludeHidden ) const
       
   946     {
       
   947     FUNC_LOG;
       
   948     InitDefaultSearch( aExcludeHidden );
       
   949 
       
   950     // Try to make the search, but if the search fails, allow caller
       
   951     // to handle the result
       
   952     TRAP_IGNORE( iFinder->StartSearchL( *iItemArray, aId ) );
       
   953 
       
   954     TInt ret( KErrNotFound );
       
   955     if ( iFinder->FinderArray()->Count() )
       
   956         {
       
   957     // Return the found item
       
   958         ret = iFinder->FinderArray()->At( 0 ).iIndex;
       
   959         }
       
   960     return ret;
       
   961     }
       
   962 
       
   963 // ----------------------------------------------------------------------------
       
   964 // CIpsSetUiBaseArray::GetItem()
       
   965 // ----------------------------------------------------------------------------
       
   966 //
       
   967 CIpsSetUiItem* CIpsSetUiBaseArray::GetItem(
       
   968     const TInt aIndex,
       
   969     const TBool aExcludeHidden ) const
       
   970     {
       
   971     FUNC_LOG;
       
   972     // First search the currently active resource to array and check
       
   973     // the given index is in the current array
       
   974     TBool ok = aIndex < StackCountItems( aExcludeHidden );
       
   975     IPS_ASSERT_DEBUG( ok, KErrOverflow, EBaseArray );
       
   976     IPS_ASSERT_DEBUG( aIndex >= 0, KErrUnderflow, EBaseArray );
       
   977 
       
   978     // Return the found item
       
   979     return ok ? iFinder->FinderArray()->At( aIndex ).iItem : NULL; // CS warning
       
   980     }
       
   981 
       
   982 // ----------------------------------------------------------------------------
       
   983 // CIpsSetUiBaseArray::GetItem()
       
   984 // ----------------------------------------------------------------------------
       
   985 //
       
   986 CIpsSetUiItem* CIpsSetUiBaseArray::GetItem(
       
   987     const TUid& aId,
       
   988     const TBool aExcludeHidden ) const
       
   989     {
       
   990     FUNC_LOG;
       
   991     InitDefaultSearch( aExcludeHidden );
       
   992 
       
   993     // Try to make the search, but if the search fails, allow caller
       
   994     // to handle the result
       
   995     TRAP_IGNORE( iFinder->StartSearchL( *iItemArray, aId ) );
       
   996 
       
   997     // Return the found item
       
   998     return iFinder->FinderArray()->At( 0 ).iItem;
       
   999     }
       
  1000 
       
  1001 // ----------------------------------------------------------------------------
       
  1002 // CIpsSetUiBaseArray::GetSubItem()
       
  1003 // ----------------------------------------------------------------------------
       
  1004 //
       
  1005 CIpsSetUiItem* CIpsSetUiBaseArray::GetSubItem(
       
  1006     const CIpsSetUiItem& aBaseItem,
       
  1007     const TUid& aId,
       
  1008     const TBool aExcludeHidden ) const
       
  1009     {
       
  1010     FUNC_LOG;
       
  1011     // Make sure the item has subitems
       
  1012     if ( ItemSubItemCheck( aBaseItem ) )
       
  1013         {
       
  1014         // Convert the item to link item
       
  1015         const CIpsSetUiItemLink* link = 
       
  1016             static_cast<const CIpsSetUiItemLink*>( &aBaseItem );
       
  1017 
       
  1018         // Get item count
       
  1019         TInt count = link->iItemLinkArray ?
       
  1020             link->iItemLinkArray->Count() : KErrNotFound;
       
  1021 
       
  1022         // Find the item from the array
       
  1023         while ( --count >= 0)
       
  1024             {
       
  1025             CIpsSetUiItem* base = ( *link->iItemLinkArray )[count];
       
  1026 
       
  1027             if ( IsVisibleCheck( aBaseItem, aExcludeHidden ) &&
       
  1028                  base->iItemId == aId )
       
  1029                 {
       
  1030                 return base;
       
  1031                 }
       
  1032             }
       
  1033         }
       
  1034 
       
  1035     return NULL;
       
  1036     }
       
  1037 
       
  1038 // ----------------------------------------------------------------------------
       
  1039 // CIpsSetUiBaseArray::GetSubItem()
       
  1040 // ----------------------------------------------------------------------------
       
  1041 //
       
  1042 CIpsSetUiItem* CIpsSetUiBaseArray::GetSubItem(
       
  1043     const CIpsSetUiItem& aBaseItem,
       
  1044     const TInt aIndex,
       
  1045     const TBool aExcludeHidden ) const
       
  1046     {
       
  1047     FUNC_LOG;
       
  1048     CIpsSetUiItem* base = NULL;
       
  1049 
       
  1050     // Make sure the item has subitems
       
  1051     if ( ItemSubItemCheck( aBaseItem ) )
       
  1052         {
       
  1053         // Convert the item to link item
       
  1054         const CIpsSetUiItemLink* link = 
       
  1055             static_cast<const CIpsSetUiItemLink*>( &aBaseItem );
       
  1056 
       
  1057         // Get the item count and make sure the required index is
       
  1058         // below the number of items
       
  1059         TInt count = link->iItemLinkArray ?
       
  1060             link->iItemLinkArray->Count() : KErrNotFound;
       
  1061         count = ( aIndex >= 0 && aIndex < count ) ? count : KErrNotFound;
       
  1062         TInt index = KErrNotFound;
       
  1063         TInt item = 0;
       
  1064 
       
  1065         for ( ; index != aIndex && item < count; item++ )
       
  1066             {
       
  1067             base = ( *link->iItemLinkArray )[item];
       
  1068 
       
  1069             if ( IsVisibleCheck( *base, aExcludeHidden ) )
       
  1070                 {
       
  1071                 index++;
       
  1072                 }
       
  1073             }
       
  1074 
       
  1075         // At the end of the items and still not found
       
  1076         if ( item == count && index != aIndex )
       
  1077             {
       
  1078             base = NULL;
       
  1079             }
       
  1080         }
       
  1081 
       
  1082     return base;
       
  1083     }
       
  1084 
       
  1085 
       
  1086 // ----------------------------------------------------------------------------
       
  1087 // CIpsSetUiBaseArray::GetSubItemByType()
       
  1088 // ----------------------------------------------------------------------------
       
  1089 //
       
  1090 CIpsSetUiItem* CIpsSetUiBaseArray::GetSubItemByType(
       
  1091     const CIpsSetUiItem& aBaseItem,
       
  1092     const TInt aType ) const
       
  1093     {
       
  1094     FUNC_LOG;
       
  1095     CIpsSetUiItem* base = NULL;
       
  1096 
       
  1097     // Make sure the item has subitems
       
  1098     if ( ItemSubItemCheck( aBaseItem ) )
       
  1099         {
       
  1100         // Convert the item to link item
       
  1101         const CIpsSetUiItemLink* link = 
       
  1102             static_cast<const CIpsSetUiItemLink*>( &aBaseItem );
       
  1103 
       
  1104         // Get the item count and make sure the required index is
       
  1105         // below the number of items
       
  1106         TInt count = link->iItemLinkArray ?
       
  1107             link->iItemLinkArray->Count() : KErrNotFound;
       
  1108 
       
  1109         for ( TInt item = 0 ; !base && item < count; item++ )
       
  1110             {
       
  1111             base = ( *link->iItemLinkArray )[item];
       
  1112             base = ( base && base->Type() == aType ) ? base : NULL;                
       
  1113             }
       
  1114         }
       
  1115 
       
  1116     return base;
       
  1117     }
       
  1118     
       
  1119 // ----------------------------------------------------------------------------
       
  1120 // CIpsSetUiBaseArray::GetSubItemIndex()
       
  1121 // ----------------------------------------------------------------------------
       
  1122 //
       
  1123 TInt CIpsSetUiBaseArray::GetSubItemIndex(
       
  1124     const CIpsSetUiItemLink& aLinkItem,
       
  1125     const TUid& aId,
       
  1126     const TBool aExcludeHidden ) const
       
  1127     {
       
  1128     FUNC_LOG;
       
  1129     TBool found = EFalse;
       
  1130     TInt index = KErrNotFound;
       
  1131 
       
  1132     if ( aLinkItem.iItemLinkArray )
       
  1133         {
       
  1134         CIpsSetUiItem* subItem = NULL;
       
  1135 
       
  1136         const TInt items = aLinkItem.iItemLinkArray->Count();
       
  1137         TInt button = KErrNotFound;
       
  1138 
       
  1139         // Seek the item id and return its index
       
  1140         while ( !found && ++button < items )
       
  1141             {
       
  1142             subItem = ( *aLinkItem.iItemLinkArray )[button];
       
  1143 
       
  1144             // Ignore hidden items AND item is not hidden OR
       
  1145             // check all the items
       
  1146             if ( IsVisibleCheck( *subItem, aExcludeHidden ) )
       
  1147                 {
       
  1148                 ++index;
       
  1149 
       
  1150                 found = ( subItem->iItemId == aId );
       
  1151                 }
       
  1152             }
       
  1153         }
       
  1154 
       
  1155     return found ? index : KErrNotFound;
       
  1156     }
       
  1157 
       
  1158 // ----------------------------------------------------------------------------
       
  1159 // CIpsSetUiBaseArray::GetSubItemIndex()
       
  1160 // ----------------------------------------------------------------------------
       
  1161 //
       
  1162 TInt CIpsSetUiBaseArray::GetSubItemIndex(
       
  1163     const CIpsSetUiItemLink& aLinkItem,
       
  1164     const TInt aIndex,
       
  1165     const TBool aActualIndex ) const
       
  1166     {
       
  1167     FUNC_LOG;
       
  1168     TInt result = KErrNotFound;
       
  1169 
       
  1170     if ( aLinkItem.iItemLinkArray )
       
  1171         {
       
  1172         CIpsSetUiItem* radioButton = NULL;
       
  1173         TInt visibleCount = KErrNotFound;
       
  1174         TInt resourceCount = KErrNotFound;
       
  1175 
       
  1176         TInt items = aLinkItem.iItemLinkArray->Count();
       
  1177 
       
  1178         for ( TInt index = 0; result < 0 && index < items; index++ )
       
  1179             {
       
  1180             radioButton = ( *aLinkItem.iItemLinkArray )[index];
       
  1181 
       
  1182             resourceCount++;
       
  1183             if ( !IsHidden( *radioButton ) )
       
  1184                 {
       
  1185                 visibleCount++;
       
  1186                 }
       
  1187 
       
  1188             if ( aActualIndex )
       
  1189                 {
       
  1190                 if ( aIndex == visibleCount )
       
  1191                     {
       
  1192                     result = resourceCount;
       
  1193                     }
       
  1194                 }
       
  1195             else
       
  1196                 {
       
  1197                 if ( aIndex == resourceCount )
       
  1198                     {
       
  1199                     result = visibleCount;
       
  1200                     }
       
  1201                 }
       
  1202             }
       
  1203         }
       
  1204 
       
  1205     return result;
       
  1206     }
       
  1207 
       
  1208 // ----------------------------------------------------------------------------
       
  1209 // CIpsSetUiBaseArray::SearchResourceL()
       
  1210 // ----------------------------------------------------------------------------
       
  1211 //
       
  1212 void CIpsSetUiBaseArray::SearchResourceL(
       
  1213     const TInt aResourceId,
       
  1214     const TBool aExcludeHidden ) const
       
  1215     {
       
  1216     FUNC_LOG;
       
  1217     // When hiding all, search through all subfolders and allow the state
       
  1218     // change
       
  1219     TUint64 search = 0x00;
       
  1220     search |= CIpsSetUiFinder::EFinderSearchSubFolders;
       
  1221     search |= CIpsSetUiFinder::EFinderResourceSearch;
       
  1222     if ( aExcludeHidden )
       
  1223         {
       
  1224         search |= CIpsSetUiFinder::EFinderDoHideCheck;
       
  1225         }
       
  1226     else
       
  1227         {
       
  1228         search &= ~CIpsSetUiFinder::EFinderDoHideCheck;
       
  1229         }    
       
  1230     iFinder->SetSearchFlags( search );
       
  1231 
       
  1232     // Try to hide items and panic in any error
       
  1233     TRAPD( error, iFinder->StartSearchL( *iItemArray, aResourceId ) );
       
  1234     if ( error != KErrNone )
       
  1235         {
       
  1236         IPS_ASSERT_DEBUG( EFalse, error, EBaseArray );
       
  1237         }
       
  1238     }
       
  1239 
       
  1240 // ----------------------------------------------------------------------------
       
  1241 // CIpsSetUiBaseArray::GetResource()
       
  1242 // ----------------------------------------------------------------------------
       
  1243 //
       
  1244 CIpsSetUiFinderArray* CIpsSetUiBaseArray::GetResourceL(
       
  1245     const TInt aResourceId,
       
  1246     const TBool aExcludeHidden ) const
       
  1247     {
       
  1248     FUNC_LOG;
       
  1249     // Start the resource search
       
  1250     SearchResourceL( aResourceId, aExcludeHidden );
       
  1251 
       
  1252     // Return the pointer to array
       
  1253     return iFinder->FinderArray();
       
  1254     }
       
  1255 
       
  1256 // ----------------------------------------------------------------------------
       
  1257 // CIpsSetUiBaseArray::GetResourceLC()
       
  1258 // ----------------------------------------------------------------------------
       
  1259 //
       
  1260 CIpsSetUiFinderArray* CIpsSetUiBaseArray::GetResourceLC(
       
  1261     const TInt aResourceId,
       
  1262     const TBool aExcludeHidden ) const
       
  1263     {
       
  1264     FUNC_LOG;
       
  1265     // Start the resource search
       
  1266     SearchResourceL( aResourceId, aExcludeHidden );
       
  1267     TUint64 search = iFinder->SearchFlags();
       
  1268     search |= CIpsSetUiFinder::EFinderMoveOwnership;
       
  1269     iFinder->SetSearchFlags( search );
       
  1270 
       
  1271     // Return the copy of the array
       
  1272     return iFinder->FinderArrayLC();
       
  1273     }
       
  1274 
       
  1275 // ----------------------------------------------------------------------------
       
  1276 // CIpsSetUiBaseArray::ItemSubArrayCheck()
       
  1277 // ----------------------------------------------------------------------------
       
  1278 //
       
  1279 TBool CIpsSetUiBaseArray::ItemSubArrayCheck(
       
  1280     const CIpsSetUiItem& aBaseItem ) const
       
  1281     {
       
  1282     FUNC_LOG;
       
  1283     // Check if the item type is menu array
       
  1284     return aBaseItem.Type() == EIpsSetUiMenuArray;
       
  1285     }
       
  1286 
       
  1287 // ----------------------------------------------------------------------------
       
  1288 // CIpsSetUiBaseArray::ItemSubItemCheck()
       
  1289 // ----------------------------------------------------------------------------
       
  1290 //
       
  1291 TBool CIpsSetUiBaseArray::ItemSubItemCheck(
       
  1292     const CIpsSetUiItem& aBaseItem ) const
       
  1293     {
       
  1294     FUNC_LOG;
       
  1295     // if item is not any of the following types it cannot contain subitems
       
  1296     if ( aBaseItem.iItemType != EIpsSetUiMenuArray &&
       
  1297          aBaseItem.iItemType != EIpsSetUiRadioButtonArray &&
       
  1298          aBaseItem.iItemType != EIpsSetUiCheckBoxArray &&
       
  1299          aBaseItem.iItemType != EIpsSetUiUndefined &&
       
  1300          aBaseItem.iItemType != EIpsSetUiItemMultiLine )
       
  1301         {
       
  1302         return EFalse;
       
  1303         }
       
  1304 
       
  1305     const CIpsSetUiItemLink* link = 
       
  1306         static_cast<const CIpsSetUiItemLink*>( &aBaseItem );
       
  1307 
       
  1308     // If the item has an array and it contains items, return true
       
  1309     return ( link->iItemLinkArray &&
       
  1310              link->iItemLinkArray->Count() > 0 );
       
  1311     }
       
  1312 
       
  1313 // ----------------------------------------------------------------------------
       
  1314 // CIpsSetUiBaseArray::SetBetweenValues()
       
  1315 // ----------------------------------------------------------------------------
       
  1316 //
       
  1317 void CIpsSetUiBaseArray::SetBetweenValues(
       
  1318     TInt& aValue,
       
  1319     TInt aMin,
       
  1320     TInt aMax ) const
       
  1321     {
       
  1322     FUNC_LOG;
       
  1323     // Make a sanity check
       
  1324     if ( aMin > aMax )
       
  1325         {
       
  1326         // Swap the values
       
  1327         TInt temp = aMin;
       
  1328         aMin = aMax;
       
  1329         aMax = temp;
       
  1330         }
       
  1331 
       
  1332     // Make sure that we are above the minimum
       
  1333     if ( aValue < aMin )
       
  1334         {
       
  1335         aValue = aMin;
       
  1336         }
       
  1337 
       
  1338     // Make sure that we are below the maximum
       
  1339     if ( aValue > aMax )
       
  1340         {
       
  1341         aValue = aMax;
       
  1342         }
       
  1343     }
       
  1344 
       
  1345 // ----------------------------------------------------------------------------
       
  1346 // CIpsSetUiBaseArray::Refresh()
       
  1347 // ----------------------------------------------------------------------------
       
  1348 //
       
  1349 void CIpsSetUiBaseArray::Refresh()
       
  1350     {
       
  1351     FUNC_LOG;
       
  1352     TRAP_IGNORE( RefreshL() );
       
  1353     }
       
  1354     
       
  1355 // ----------------------------------------------------------------------------
       
  1356 // CIpsSetUiBaseArray::RefreshL()
       
  1357 // ----------------------------------------------------------------------------
       
  1358 //
       
  1359 void CIpsSetUiBaseArray::RefreshL()
       
  1360     {
       
  1361     FUNC_LOG;
       
  1362     if ( iArrayFlags.Flag( EIpsSetUiArrayAllowRefresh ) )
       
  1363         {        
       
  1364         UpdateActiveItemsCount();
       
  1365         EventArrayChangedL( EIpsSetUiArrayChanged );
       
  1366         }
       
  1367     }
       
  1368 
       
  1369 // ----------------------------------------------------------------------------
       
  1370 // CIpsSetUiBaseArray::UpdateActiveItemsCount()
       
  1371 // ----------------------------------------------------------------------------
       
  1372 //
       
  1373 void CIpsSetUiBaseArray::UpdateActiveItemsCount(
       
  1374     const TInt aNewCount )
       
  1375     {
       
  1376     FUNC_LOG;
       
  1377     // If count not provided, update it manually
       
  1378     if ( aNewCount == KErrNotFound )
       
  1379         {
       
  1380         iActiveCount = StackCountItems();
       
  1381         }
       
  1382     // Just update the count
       
  1383     else
       
  1384         {
       
  1385         iActiveCount = aNewCount;
       
  1386         }
       
  1387     }
       
  1388 
       
  1389 // ----------------------------------------------------------------------------
       
  1390 // CIpsSetUiBaseArray::HandleStackForwardL()
       
  1391 // ----------------------------------------------------------------------------
       
  1392 //
       
  1393 TIpsSetUiStackResult CIpsSetUiBaseArray::HandleStackForwardL(
       
  1394     const CIpsSetUiItem& aBase )
       
  1395     {
       
  1396     FUNC_LOG;
       
  1397     // Make sure the item is subarray item
       
  1398     if ( ItemSubArrayCheck( aBase ) )
       
  1399         {
       
  1400         // Make sure the array exists and it contains items
       
  1401         const CIpsSetUiItemLink* link = 
       
  1402             static_cast<const CIpsSetUiItemLink*>( &aBase );
       
  1403         IPS_ASSERT_DEBUG( link->iItemLinkArray ,
       
  1404             ENullPointer, EBaseArray );
       
  1405         const CIpsSetUiItem* nextItem = link->iItemLinkArray->At( 0 ) ;
       
  1406         IPS_ASSERT_DEBUG( nextItem , ENullPointer, EBaseArray );
       
  1407 
       
  1408         // new item has been found, check the resource is not same
       
  1409         IPS_ASSERT_DEBUG( nextItem->iItemResourceId != StackActiveResource(),
       
  1410             KErrNotFound, EBaseArray );
       
  1411 
       
  1412         HandleStackChangeL( ETrue, nextItem->iItemResourceId );
       
  1413 
       
  1414         return EIpsSetUiStackResultSubMenuOpen;
       
  1415         }
       
  1416 
       
  1417     return EIpsSetUiStackResultOk;
       
  1418     }
       
  1419 
       
  1420 // ----------------------------------------------------------------------------
       
  1421 // CIpsSetUiBaseArray::HandleStackBackwardL()
       
  1422 // ----------------------------------------------------------------------------
       
  1423 //
       
  1424 TIpsSetUiStackResult CIpsSetUiBaseArray::HandleStackBackwardL( TInt aCount )
       
  1425     {
       
  1426     FUNC_LOG;
       
  1427     // Remove the last item from stack number of times
       
  1428     while ( aCount-- && iResourceStack->Count() )
       
  1429         {
       
  1430         iResourceStack->Remove( iResourceStack->Count() - 1 );
       
  1431         }
       
  1432 
       
  1433     return HandleStackChangeL( EFalse );
       
  1434     }
       
  1435 
       
  1436 // ----------------------------------------------------------------------------
       
  1437 // CIpsSetUiBaseArray::HandleStackChangeL()
       
  1438 // ----------------------------------------------------------------------------
       
  1439 //
       
  1440 TIpsSetUiStackResult CIpsSetUiBaseArray::HandleStackChangeL(
       
  1441     const TInt aForward,
       
  1442     const TInt aResourceId )
       
  1443     {
       
  1444     FUNC_LOG;
       
  1445     // If resource id not provided
       
  1446     if ( aResourceId != KErrNotFound )
       
  1447         {
       
  1448         iResourceStack->AppendL( aResourceId );
       
  1449         }
       
  1450 
       
  1451     // Update the active count
       
  1452     UpdateActiveItemsCount();
       
  1453 
       
  1454     // Inform of the array change
       
  1455     EventArrayChangedL(
       
  1456         aForward ? EIpsSetUiArrayStackForward : EIpsSetUiArrayStackBackward );
       
  1457 
       
  1458     return EIpsSetUiStackResultOk;
       
  1459     }
       
  1460 
       
  1461 // ----------------------------------------------------------------------------
       
  1462 // CIpsSetUiBaseArray::StackCountItems()
       
  1463 // ----------------------------------------------------------------------------
       
  1464 //
       
  1465 TInt CIpsSetUiBaseArray::StackCountItems(
       
  1466     const TBool aExcludeHidden ) const
       
  1467     {
       
  1468     FUNC_LOG;
       
  1469     // Set the array finder to contain the current resource in array
       
  1470     TRAP_IGNORE ( GetResourceL( StackActiveResource(), aExcludeHidden ) );
       
  1471 
       
  1472     return iFinder->FinderArray()->Count();
       
  1473     }
       
  1474 
       
  1475 // ----------------------------------------------------------------------------
       
  1476 // CIpsSetUiBaseArray::StackActiveResource()
       
  1477 // ----------------------------------------------------------------------------
       
  1478 //
       
  1479 TInt CIpsSetUiBaseArray::StackActiveResource() const
       
  1480     {
       
  1481     FUNC_LOG;
       
  1482     return ( *iResourceStack )[iResourceStack->Count() - 1];
       
  1483     }
       
  1484 
       
  1485 // ----------------------------------------------------------------------------
       
  1486 // CIpsSetUiBaseArray::IsVisibleCheck()
       
  1487 // ----------------------------------------------------------------------------
       
  1488 //
       
  1489 TBool CIpsSetUiBaseArray::IsVisibleCheck(
       
  1490     const CIpsSetUiItem& aBaseItem,
       
  1491     const TBool aExcludeHidden ) const
       
  1492     {
       
  1493     FUNC_LOG;
       
  1494     return ( aExcludeHidden && !IsHidden( aBaseItem ) || !aExcludeHidden );
       
  1495     }
       
  1496 
       
  1497 //  End of File
       
  1498