messagingappbase/msgavkon/muiu_internal/settingsarray/src/MuiuSettingsArray.cpp
changeset 0 72b543305e3a
child 9 1d7827e39b52
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 *     Text and listbox settings
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 // INCLUDE FILES
       
    23 #include <coemain.h>
       
    24 #include <data_caging_path_literals.hrh> // KDC_RESOURCE_FILES_DIR
       
    25 #include <eikrutil.h>
       
    26 #include <aknsettingpage.h>
       
    27 #include <aknradiobuttonsettingpage.h>
       
    28 #include <aknpasswordsettingpage.h>
       
    29 #include <akntextsettingpage.h>
       
    30 #include <muiu_internal.rsg>
       
    31 #include "MuiuSettingsArray.h"
       
    32 
       
    33 // CONSTANTS
       
    34 const TInt KMuiuSettingsArrayGranularity    = 4;
       
    35 const TInt KMuiuSettingsArrayVisibleTextLength = 30;
       
    36 const TInt KPaswordStrLength = 32;
       
    37 const TInt KTwoItems    = 2;
       
    38 const TInt KValue = 32;
       
    39 _LIT(KMuiuSpaceString, " ");
       
    40 // this is added at the end of the compulsory setting item string
       
    41 _LIT(KMuiuSettingsArrayCompulsoryAdditionString, "\t*"); 
       
    42 _LIT(KDirAndMuiuResFileName,"muiu_internal.rsc");
       
    43 
       
    44 
       
    45 
       
    46 
       
    47 
       
    48 // ============================ MEMBER FUNCTIONS ===============================
       
    49 
       
    50 
       
    51 // ---------------------------------------------------------
       
    52 // CMuiuSettingsArray::NewL
       
    53 // ---------------------------------------------------------
       
    54 //
       
    55 EXPORT_C CMuiuSettingsArray* CMuiuSettingsArray::NewL( TInt aResourceId )
       
    56     {
       
    57     CMuiuSettingsArray* self = new (ELeave) CMuiuSettingsArray();
       
    58     CleanupStack::PushL( self );
       
    59     self->ConstructL( aResourceId );
       
    60     CleanupStack::Pop( self ); // self
       
    61     return self;
       
    62     }
       
    63 
       
    64 // ---------------------------------------------------------
       
    65 // CMuiuSettingsArray::CMuiuSettingsArray
       
    66 // ---------------------------------------------------------
       
    67 //
       
    68 EXPORT_C CMuiuSettingsArray::CMuiuSettingsArray()
       
    69 : CArrayFixFlat<TMuiuSettingsItem> ( KMuiuSettingsArrayGranularity ),
       
    70 iResources( *CCoeEnv::Static() )
       
    71     {
       
    72     }
       
    73 
       
    74 // ---------------------------------------------------------
       
    75 // CMuiuSettingsArray::ConstructL
       
    76 // ---------------------------------------------------------
       
    77 //
       
    78 EXPORT_C void CMuiuSettingsArray::ConstructL( TInt aResourceId )
       
    79     {
       
    80     TParse parse;
       
    81 
       
    82     CEikonEnv* env = CEikonEnv::Static();
       
    83     if ( !env )
       
    84         {
       
    85         User::Leave( KErrGeneral );
       
    86         }
       
    87     parse.Set( KDirAndMuiuResFileName, &KDC_RESOURCE_FILES_DIR, NULL ); 
       
    88     TFileName fileName( parse.FullName() );
       
    89 
       
    90     iResources.OpenL( fileName );
       
    91 
       
    92     iTempText = HBufC::NewL( KMuiuMaxSettingsTextLength );
       
    93     
       
    94     if ( aResourceId )
       
    95         {
       
    96         TResourceReader reader;
       
    97         env->CreateResourceReaderLC( reader, aResourceId );
       
    98         
       
    99         const TInt count = reader.ReadInt16();
       
   100         for ( TInt loop = 0; loop < count; loop++ )
       
   101             {
       
   102             TMuiuSettingsItem item;
       
   103             item.iLangSpecificNumConv = ETrue;
       
   104             item.iCurrentNumber = 0;
       
   105             item.iMuiuSettingsItemArray = 0;
       
   106             item.iType = EMuiuSettingsUnknown;
       
   107             HBufC* txt = reader.ReadHBufCL();   // message text
       
   108             item.iLabelText.Copy( *txt );
       
   109             delete txt;
       
   110             
       
   111             const TMuiuSettingsType type = ( TMuiuSettingsType ) reader.ReadInt16();
       
   112             item.iType = type;
       
   113             const TInt maxLength = reader.ReadInt16();
       
   114             item.iUserTextMaxLength = maxLength < KMuiuMaxSettingsTextLength ?
       
   115                                       maxLength : KMuiuMaxSettingsTextLength;
       
   116             
       
   117             item.iCompulsory = reader.ReadInt8() != EMuiuSettingsCompulsoryNo;
       
   118             
       
   119             const TInt array_id = reader.ReadInt32();
       
   120             
       
   121             if ( type == EMuiuSettingsSelectionList && array_id )
       
   122                 {
       
   123                 CDesCArrayFlat* array = 
       
   124                                 new( ELeave ) CDesCArrayFlat( KMuiuSettingsArrayGranularity );
       
   125                 CleanupStack::PushL( array );
       
   126                 TResourceReader reader2;
       
   127                 env->CreateResourceReaderLC( reader2, array_id );
       
   128                 
       
   129                 const TInt count = reader2.ReadInt16();
       
   130                 for ( TInt loop = 0; loop < count; loop++ )
       
   131                     {
       
   132                     HBufC* txt = reader2.ReadHBufCL();
       
   133                     CleanupStack::PushL( txt );
       
   134                     array->AppendL( *txt );
       
   135                     CleanupStack::PopAndDestroy(); // txt
       
   136                     }
       
   137                 CleanupStack::PopAndDestroy(); //reader2
       
   138                 item.iMuiuSettingsItemArray = array;
       
   139                 AppendL( item );
       
   140                 CleanupStack::Pop( array ); //array
       
   141                 }
       
   142             else
       
   143                 {
       
   144                 AppendL( item );
       
   145                 }
       
   146             }
       
   147         
       
   148         CleanupStack::PopAndDestroy(); //reader
       
   149         }
       
   150     
       
   151     iPasswordFill = EikResourceUtils::ReadTInt16L(
       
   152         R_MUIU_SETTINGS_DIALOG_PASSWORD_FILL, env );
       
   153     iCompulsoryText = env->AllocReadResourceL( R_MUIU_SETTINGS_DIALOG_COMPULSORY_FILL );
       
   154     }
       
   155 
       
   156 // ---------------------------------------------------------
       
   157 // CMuiuSettingsArray::~CMuiuSettingsArray
       
   158 // ---------------------------------------------------------
       
   159 //
       
   160 EXPORT_C CMuiuSettingsArray::~CMuiuSettingsArray()
       
   161     {
       
   162     delete iTempText;
       
   163     delete iCompulsoryText;
       
   164     for ( TInt loop = Count()-1; loop >= 0; loop--)
       
   165         {
       
   166         delete At( loop ).iMuiuSettingsItemArray;
       
   167         }
       
   168     delete iSettingPage;
       
   169     iResources.Close();
       
   170     }
       
   171 
       
   172 // ---------------------------------------------------------
       
   173 // CMuiuSettingsArray::EditItemL
       
   174 // ---------------------------------------------------------
       
   175 //
       
   176 EXPORT_C TBool CMuiuSettingsArray::EditItemL( TInt aIndex, TBool aEnterPressed )
       
   177     {
       
   178     TBool retValue = EFalse;
       
   179     switch ( At( aIndex ).iType )
       
   180         {
       
   181         case EMuiuSettingsSelectionList:
       
   182             retValue = HandleEditListBoxSettingsL( aIndex, aEnterPressed );
       
   183             break;
       
   184         case EMuiuSettingsEditableText:
       
   185             retValue = HandleEditTextSettingsL( aIndex );
       
   186             break;
       
   187         case EMuiuSettingsNumber:
       
   188             retValue = HandleEditNumberL( aIndex );
       
   189             break;
       
   190         case EMuiuSettingsPassword:
       
   191             retValue = HandleEditPasswordL( aIndex );
       
   192             break;
       
   193         case EMuiuSettingsScNumber:
       
   194             retValue = HandleEditScNumberL( aIndex );
       
   195             break;
       
   196         default:
       
   197             break;
       
   198         }
       
   199     return retValue;
       
   200     }
       
   201 
       
   202 // ---------------------------------------------------------
       
   203 // CMuiuSettingsArray::HandleEditListBoxSettingsL
       
   204 // ---------------------------------------------------------
       
   205 //
       
   206 TBool CMuiuSettingsArray::HandleEditListBoxSettingsL( TInt aIndex, TBool aEnterPressed )
       
   207     {
       
   208     TInt currentItem = At( aIndex ).iCurrentNumber;
       
   209     TBool langSpecificNumConv = At( aIndex ).iLangSpecificNumConv;
       
   210     TBool retValue = EFalse;
       
   211     
       
   212     if ( aEnterPressed && At( aIndex ).iMuiuSettingsItemArray->Count() == KTwoItems )
       
   213         {
       
   214         currentItem = !currentItem;
       
   215         At( aIndex ).iCurrentNumber = currentItem;
       
   216         At( aIndex ).iUserText.Copy( (*At( aIndex ).iMuiuSettingsItemArray)[currentItem] );
       
   217         retValue = ETrue;
       
   218         }
       
   219     else
       
   220         {
       
   221         const CDesCArrayFlat& origArray = (*At( aIndex ).iMuiuSettingsItemArray);
       
   222         const TInt count = origArray.Count();
       
   223         CDesCArrayFlat* tempArray = new (ELeave ) CDesCArrayFlat( KMuiuSettingsArrayGranularity );
       
   224         CleanupStack::PushL( tempArray );
       
   225         for ( TInt loop = 0; loop < count; loop++ )
       
   226             {
       
   227             HBufC* tempBuf = ( origArray )[loop].AllocL();
       
   228             CleanupStack::PushL( tempBuf );
       
   229             TPtr tempBufPtr = tempBuf->Des();
       
   230             if ( langSpecificNumConv )
       
   231                 {
       
   232                 AknTextUtils::DisplayTextLanguageSpecificNumberConversion( tempBufPtr );
       
   233                 }
       
   234             tempArray->AppendL( *tempBuf );
       
   235             CleanupStack::PopAndDestroy( tempBuf );
       
   236             }
       
   237         iSettingPage = new ( ELeave )CAknRadioButtonSettingPage( 
       
   238                              R_MUIU_SETTINGS_DIALOG_LISTBOX, currentItem, tempArray );
       
   239         iSettingPage->SetSettingTextL( At( aIndex ).iLabelText );
       
   240         if ( iSettingPage->ExecuteLD(CAknSettingPage::EUpdateWhenChanged) )
       
   241             {
       
   242             At( aIndex ).iCurrentNumber = currentItem;
       
   243             At( aIndex ).iUserText.Copy( (*At( aIndex ).iMuiuSettingsItemArray)[currentItem]  );
       
   244             retValue = ETrue;
       
   245             }
       
   246         CleanupStack::PopAndDestroy( tempArray ); 
       
   247         iSettingPage = NULL;
       
   248         }
       
   249     return retValue;
       
   250     }
       
   251 
       
   252 // ---------------------------------------------------------
       
   253 // CMuiuSettingsArray::HandleEditTextSettingsL
       
   254 // ---------------------------------------------------------
       
   255 //
       
   256 TBool CMuiuSettingsArray::HandleEditTextSettingsL( TInt aIndex )
       
   257     {
       
   258     TBuf<KMuiuMaxSettingsTextLength> textToEdit =
       
   259         At( aIndex ).iUserText.Left(At( aIndex ).iUserTextMaxLength );
       
   260     TBool retValue = EFalse;
       
   261     iSettingPage = new( ELeave )CAknTextSettingPage(R_MUIU_SETTINGS_DIALOG_TEXT, textToEdit );
       
   262     iSettingPage->SetSettingTextL( At( aIndex ).iLabelText );
       
   263     iSettingPage->ConstructL( );
       
   264     STATIC_CAST( CAknTextSettingPage*, iSettingPage)->TextControl()
       
   265         ->SetTextLimit( At( aIndex ).iUserTextMaxLength );
       
   266     
       
   267     if ( iSettingPage->ExecuteLD( CAknSettingPage::EUpdateWhenChanged ) )
       
   268         {
       
   269         At( aIndex ).iUserText.Copy( textToEdit );
       
   270         retValue = ETrue;
       
   271         }
       
   272     iSettingPage = NULL;
       
   273     return retValue;
       
   274     }
       
   275 
       
   276 // ---------------------------------------------------------
       
   277 // CMuiuSettingsArray::HandleEditNumberL
       
   278 // ---------------------------------------------------------
       
   279 //
       
   280 TBool CMuiuSettingsArray::HandleEditNumberL( TInt aIndex )
       
   281     {
       
   282     TInt numberToEdit = At( aIndex ).iCurrentNumber;
       
   283     TBool retValue = EFalse;
       
   284     iSettingPage = new( ELeave )CAknIntegerSettingPage( 
       
   285                    R_MUIU_SETTINGS_DIALOG_NUMBER, 
       
   286                    numberToEdit, 
       
   287                    CAknIntegerSettingPage::EInvalidValueNotOffered );
       
   288     iSettingPage->SetSettingTextL( At( aIndex ).iLabelText );
       
   289     
       
   290     iSettingPage->ConstructL();
       
   291     static_cast<CAknIntegerSettingPage*>(iSettingPage)->IntegerEditorControl()->
       
   292                  SetAknEditorNumericKeymap( EAknEditorPlainNumberModeKeymap );
       
   293     
       
   294     if ( iSettingPage->ExecuteLD(CAknSettingPage::EUpdateWhenChanged) )
       
   295         {
       
   296         At( aIndex ).iCurrentNumber = numberToEdit;
       
   297         At( aIndex ).iUserText.Num( numberToEdit );
       
   298         retValue = ETrue;
       
   299         }
       
   300     iSettingPage = NULL;
       
   301     return retValue;
       
   302     }
       
   303 
       
   304 // ---------------------------------------------------------
       
   305 // CMuiuSettingsArray::HandleEditScNumberL
       
   306 // ---------------------------------------------------------
       
   307 //
       
   308 TBool CMuiuSettingsArray::HandleEditScNumberL( TInt aIndex )
       
   309     {
       
   310     TBuf<KMuiuMaxSettingsTextLength> textToEdit = At( aIndex ).iUserText;
       
   311     TBool retValue = EFalse;
       
   312     if ( At( aIndex ).iLangSpecificNumConv )
       
   313         {
       
   314         AknTextUtils::DisplayTextLanguageSpecificNumberConversion( textToEdit );
       
   315         }
       
   316     iSettingPage = new( ELeave )CAknTextSettingPage( 
       
   317                    R_MUIU_SETTINGS_DIALOG_SC_NUMBER, textToEdit );
       
   318     iSettingPage->SetSettingTextL( At( aIndex ).iLabelText );
       
   319     
       
   320     if ( iSettingPage->ExecuteLD( CAknSettingPage::EUpdateWhenChanged ) )
       
   321         {
       
   322         AknTextUtils::ConvertDigitsTo( textToEdit , EDigitTypeWestern );
       
   323         At( aIndex ).iUserText.Copy( textToEdit );
       
   324         retValue = ETrue;
       
   325         }
       
   326     iSettingPage = NULL;
       
   327     return retValue;
       
   328     }
       
   329 
       
   330 // ---------------------------------------------------------
       
   331 // CMuiuSettingsArray::HandleEditPasswordL
       
   332 // ---------------------------------------------------------
       
   333 //
       
   334 TBool CMuiuSettingsArray::HandleEditPasswordL( TInt aIndex )
       
   335     {
       
   336     TBuf<KPaswordStrLength> newPassword = At( aIndex ).iUserText.Left( KValue );
       
   337     TBuf<KPaswordStrLength> oldPassword;
       
   338     oldPassword.Copy ( newPassword );
       
   339     TBool retValue = EFalse;
       
   340     
       
   341     iSettingPage = new( ELeave )CAknAlphaPasswordSettingPage(
       
   342         R_MUIU_SETTINGS_DIALOG_PASSWORD, newPassword, oldPassword );
       
   343     iSettingPage->SetSettingTextL( At( aIndex ).iLabelText );
       
   344     iSettingPage->ConstructL( );
       
   345     STATIC_CAST( CAknAlphaPasswordSettingPage*, iSettingPage )->AlphaPasswordEditor()
       
   346         ->SetMaxLength( At( aIndex ).iUserTextMaxLength );
       
   347     
       
   348     if ( iSettingPage->ExecuteLD(CAknSettingPage::EUpdateWhenChanged) )
       
   349         {
       
   350         At( aIndex ).iUserText.Copy( newPassword );
       
   351         retValue = ETrue;
       
   352         }
       
   353     iSettingPage = NULL;
       
   354     return retValue;
       
   355     }
       
   356 
       
   357 
       
   358 // ---------------------------------------------------------
       
   359 // CMuiuSettingsArray::MdcaCount
       
   360 // ---------------------------------------------------------
       
   361 //
       
   362 EXPORT_C TInt CMuiuSettingsArray::MdcaCount() const
       
   363     {
       
   364     return Count();
       
   365     }
       
   366 
       
   367 
       
   368 // ---------------------------------------------------------
       
   369 // CMuiuSettingsArray::MdcaPoint
       
   370 // ---------------------------------------------------------
       
   371 //
       
   372 EXPORT_C TPtrC CMuiuSettingsArray::MdcaPoint( TInt aIndex ) const
       
   373     {
       
   374     TPtr tempText = iTempText->Des();
       
   375     TBuf<KMuiuMaxSettingsTextLength> tempSettingText;
       
   376     tempSettingText.Zero();
       
   377     
       
   378     tempText.Zero();
       
   379     tempText.Append( KMuiuSpaceString );
       
   380     tempText.Append( KColumnListSeparator );
       
   381     tempText.Append( At( aIndex ).iLabelText );
       
   382     tempText.Append( KColumnListSeparator );
       
   383     tempText.Append( KColumnListSeparator );
       
   384     
       
   385     if ( At( aIndex ).iType == EMuiuSettingsSelectionList )
       
   386         {
       
   387         tempSettingText = At( aIndex ).iMuiuSettingsItemArray->MdcaPoint(
       
   388             At( aIndex ).iCurrentNumber ).Left( KMuiuSettingsArrayVisibleTextLength );
       
   389         }
       
   390     else if ( At( aIndex ).iType == EMuiuSettingsPassword )
       
   391         {
       
   392         TInt length = At( aIndex ).iUserText.Length();
       
   393         length = length > KMuiuSettingsArrayVisibleTextLength ?
       
   394         KMuiuSettingsArrayVisibleTextLength : length;
       
   395         if ( length > 0 )
       
   396             {
       
   397             TChar passFill = TChar( iPasswordFill );
       
   398             tempSettingText.AppendFill( passFill, length );
       
   399             }
       
   400         }
       
   401     else 
       
   402         {
       
   403         if ( At( aIndex ).iUserText.Length() )
       
   404             {
       
   405             tempSettingText = At( aIndex ).iUserText.Left( KMuiuSettingsArrayVisibleTextLength );
       
   406             }
       
   407         }
       
   408     
       
   409     if ( tempSettingText.Length() )
       
   410         {
       
   411         tempText.Append( tempSettingText );
       
   412         }
       
   413     else
       
   414         {
       
   415         if ( At( aIndex ).iCompulsory )
       
   416             {
       
   417             tempText.Append( *iCompulsoryText );
       
   418             }
       
   419         else
       
   420             {
       
   421             tempText.Append( KMuiuSpaceString );
       
   422             }
       
   423         }
       
   424     
       
   425     if ( At( aIndex ).iCompulsory )
       
   426         {
       
   427         tempText.Append( KMuiuSettingsArrayCompulsoryAdditionString );
       
   428         }
       
   429 
       
   430     if ( At( aIndex ).iLangSpecificNumConv )
       
   431         {
       
   432         AknTextUtils::DisplayTextLanguageSpecificNumberConversion( tempText );
       
   433         }
       
   434 
       
   435     return tempText;
       
   436     }
       
   437 
       
   438 //  End of File