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