messagingappbase/msgavkon/muiu_internal/settingsarray/src/MuiuSettingsArray.cpp
changeset 79 2981cb3aa489
equal deleted inserted replaced
25:84d9eb65b26f 79:2981cb3aa489
       
     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             CleanupStack::PushL( txt );
       
   115             flag = IsMessageSentStringL( txt );
       
   116             CleanupStack::PopAndDestroy( 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                 TResourceReader arrayReader;
       
   131                 env->CreateResourceReaderLC( arrayReader, array_id );
       
   132                 
       
   133                 CDesCArrayFlat* array = arrayReader.ReadDesCArrayL();
       
   134                 
       
   135                 if ( !flag && array )
       
   136                     {
       
   137                     item.iMuiuSettingsItemArray = array;
       
   138                     CleanupStack::PushL( array );
       
   139                     AppendL( item );
       
   140                     CleanupStack::Pop( array );
       
   141                     }
       
   142                 else
       
   143                     {
       
   144                     delete array;
       
   145                     }
       
   146                 
       
   147                 CleanupStack::PopAndDestroy();
       
   148                 }
       
   149             else
       
   150                 {
       
   151                 AppendL( item );
       
   152                 }
       
   153             }
       
   154         
       
   155         CleanupStack::PopAndDestroy(); //reader
       
   156         }
       
   157     
       
   158     iPasswordFill = EikResourceUtils::ReadTInt16L(
       
   159         R_MUIU_SETTINGS_DIALOG_PASSWORD_FILL, env );
       
   160     iCompulsoryText = env->AllocReadResourceL( R_MUIU_SETTINGS_DIALOG_COMPULSORY_FILL );
       
   161     }
       
   162 
       
   163 // ---------------------------------------------------------
       
   164 // CMuiuSettingsArray::~CMuiuSettingsArray
       
   165 // ---------------------------------------------------------
       
   166 //
       
   167 EXPORT_C CMuiuSettingsArray::~CMuiuSettingsArray()
       
   168     {
       
   169     delete iTempText;
       
   170     delete iCompulsoryText;
       
   171     for ( TInt loop = Count()-1; loop >= 0; loop--)
       
   172         {
       
   173         delete At( loop ).iMuiuSettingsItemArray;
       
   174         }
       
   175     delete iSettingPage;
       
   176     iResources.Close();
       
   177     }
       
   178 
       
   179 // ---------------------------------------------------------
       
   180 // CMuiuSettingsArray::EditItemL
       
   181 // ---------------------------------------------------------
       
   182 //
       
   183 EXPORT_C TBool CMuiuSettingsArray::EditItemL( TInt aIndex, TBool aEnterPressed )
       
   184     {
       
   185     TBool retValue = EFalse;
       
   186     switch ( At( aIndex ).iType )
       
   187         {
       
   188         case EMuiuSettingsSelectionList:
       
   189             retValue = HandleEditListBoxSettingsL( aIndex, aEnterPressed );
       
   190             break;
       
   191         case EMuiuSettingsEditableText:
       
   192             retValue = HandleEditTextSettingsL( aIndex );
       
   193             break;
       
   194         case EMuiuSettingsNumber:
       
   195             retValue = HandleEditNumberL( aIndex );
       
   196             break;
       
   197         case EMuiuSettingsPassword:
       
   198             retValue = HandleEditPasswordL( aIndex );
       
   199             break;
       
   200         case EMuiuSettingsScNumber:
       
   201             retValue = HandleEditScNumberL( aIndex );
       
   202             break;
       
   203         default:
       
   204             break;
       
   205         }
       
   206     return retValue;
       
   207     }
       
   208 
       
   209 // ---------------------------------------------------------
       
   210 // CMuiuSettingsArray::HandleEditListBoxSettingsL
       
   211 // ---------------------------------------------------------
       
   212 //
       
   213 TBool CMuiuSettingsArray::HandleEditListBoxSettingsL( TInt aIndex, TBool aEnterPressed )
       
   214     {
       
   215     TInt currentItem = At( aIndex ).iCurrentNumber;
       
   216     TBool langSpecificNumConv = At( aIndex ).iLangSpecificNumConv;
       
   217     TBool retValue = EFalse;
       
   218     
       
   219     if ( aEnterPressed && At( aIndex ).iMuiuSettingsItemArray->Count() == KTwoItems )
       
   220         {
       
   221         currentItem = !currentItem;
       
   222         At( aIndex ).iCurrentNumber = currentItem;
       
   223         At( aIndex ).iUserText.Copy( (*At( aIndex ).iMuiuSettingsItemArray)[currentItem] );
       
   224         retValue = ETrue;
       
   225         }
       
   226     else
       
   227         {
       
   228         const CDesCArrayFlat& origArray = (*At( aIndex ).iMuiuSettingsItemArray);
       
   229         const TInt count = origArray.Count();
       
   230         CDesCArrayFlat* tempArray = new (ELeave ) CDesCArrayFlat( KMuiuSettingsArrayGranularity );
       
   231         CleanupStack::PushL( tempArray );
       
   232         for ( TInt loop = 0; loop < count; loop++ )
       
   233             {
       
   234             HBufC* tempBuf = ( origArray )[loop].AllocL();
       
   235             CleanupStack::PushL( tempBuf );
       
   236             TPtr tempBufPtr = tempBuf->Des();
       
   237             if ( langSpecificNumConv )
       
   238                 {
       
   239                 AknTextUtils::DisplayTextLanguageSpecificNumberConversion( tempBufPtr );
       
   240                 }
       
   241             tempArray->AppendL( *tempBuf );
       
   242             CleanupStack::PopAndDestroy( tempBuf );
       
   243             }
       
   244         iSettingPage = new ( ELeave )CAknRadioButtonSettingPage( 
       
   245                              R_MUIU_SETTINGS_DIALOG_LISTBOX, currentItem, tempArray );
       
   246         iSettingPage->SetSettingTextL( At( aIndex ).iLabelText );
       
   247         if ( iSettingPage->ExecuteLD(CAknSettingPage::EUpdateWhenChanged) )
       
   248             {
       
   249             At( aIndex ).iCurrentNumber = currentItem;
       
   250             At( aIndex ).iUserText.Copy( (*At( aIndex ).iMuiuSettingsItemArray)[currentItem]  );
       
   251             retValue = ETrue;
       
   252             }
       
   253         CleanupStack::PopAndDestroy( tempArray ); 
       
   254         iSettingPage = NULL;
       
   255         }
       
   256     return retValue;
       
   257     }
       
   258 
       
   259 // ---------------------------------------------------------
       
   260 // CMuiuSettingsArray::HandleEditTextSettingsL
       
   261 // ---------------------------------------------------------
       
   262 //
       
   263 TBool CMuiuSettingsArray::HandleEditTextSettingsL( TInt aIndex )
       
   264     {
       
   265     TBuf<KMuiuMaxSettingsTextLength> textToEdit =
       
   266         At( aIndex ).iUserText.Left(At( aIndex ).iUserTextMaxLength );
       
   267     TBool retValue = EFalse;
       
   268     iSettingPage = new( ELeave )CAknTextSettingPage(R_MUIU_SETTINGS_DIALOG_TEXT, textToEdit );
       
   269     iSettingPage->SetSettingTextL( At( aIndex ).iLabelText );
       
   270     iSettingPage->ConstructL( );
       
   271     STATIC_CAST( CAknTextSettingPage*, iSettingPage)->TextControl()
       
   272         ->SetTextLimit( At( aIndex ).iUserTextMaxLength );
       
   273     
       
   274     if ( iSettingPage->ExecuteLD( CAknSettingPage::EUpdateWhenChanged ) )
       
   275         {
       
   276         At( aIndex ).iUserText.Copy( textToEdit );
       
   277         retValue = ETrue;
       
   278         }
       
   279     iSettingPage = NULL;
       
   280     return retValue;
       
   281     }
       
   282 
       
   283 // ---------------------------------------------------------
       
   284 // CMuiuSettingsArray::HandleEditNumberL
       
   285 // ---------------------------------------------------------
       
   286 //
       
   287 TBool CMuiuSettingsArray::HandleEditNumberL( TInt aIndex )
       
   288     {
       
   289     TInt numberToEdit = At( aIndex ).iCurrentNumber;
       
   290     TBool retValue = EFalse;
       
   291     iSettingPage = new( ELeave )CAknIntegerSettingPage( 
       
   292                    R_MUIU_SETTINGS_DIALOG_NUMBER, 
       
   293                    numberToEdit, 
       
   294                    CAknIntegerSettingPage::EInvalidValueNotOffered );
       
   295     iSettingPage->SetSettingTextL( At( aIndex ).iLabelText );
       
   296     
       
   297     iSettingPage->ConstructL();
       
   298     static_cast<CAknIntegerSettingPage*>(iSettingPage)->IntegerEditorControl()->
       
   299                  SetAknEditorNumericKeymap( EAknEditorPlainNumberModeKeymap );
       
   300     
       
   301     if ( iSettingPage->ExecuteLD(CAknSettingPage::EUpdateWhenChanged) )
       
   302         {
       
   303         At( aIndex ).iCurrentNumber = numberToEdit;
       
   304         At( aIndex ).iUserText.Num( numberToEdit );
       
   305         retValue = ETrue;
       
   306         }
       
   307     iSettingPage = NULL;
       
   308     return retValue;
       
   309     }
       
   310 
       
   311 // ---------------------------------------------------------
       
   312 // CMuiuSettingsArray::HandleEditScNumberL
       
   313 // ---------------------------------------------------------
       
   314 //
       
   315 TBool CMuiuSettingsArray::HandleEditScNumberL( TInt aIndex )
       
   316     {
       
   317     TBuf<KMuiuMaxSettingsTextLength> textToEdit = At( aIndex ).iUserText;
       
   318     TBool retValue = EFalse;
       
   319     if ( At( aIndex ).iLangSpecificNumConv )
       
   320         {
       
   321         AknTextUtils::DisplayTextLanguageSpecificNumberConversion( textToEdit );
       
   322         }
       
   323     iSettingPage = new( ELeave )CAknTextSettingPage( 
       
   324                    R_MUIU_SETTINGS_DIALOG_SC_NUMBER, textToEdit );
       
   325     iSettingPage->SetSettingTextL( At( aIndex ).iLabelText );
       
   326     
       
   327     if ( iSettingPage->ExecuteLD( CAknSettingPage::EUpdateWhenChanged ) )
       
   328         {
       
   329         AknTextUtils::ConvertDigitsTo( textToEdit , EDigitTypeWestern );
       
   330         At( aIndex ).iUserText.Copy( textToEdit );
       
   331         retValue = ETrue;
       
   332         }
       
   333     iSettingPage = NULL;
       
   334     return retValue;
       
   335     }
       
   336 
       
   337 // ---------------------------------------------------------
       
   338 // CMuiuSettingsArray::HandleEditPasswordL
       
   339 // ---------------------------------------------------------
       
   340 //
       
   341 TBool CMuiuSettingsArray::HandleEditPasswordL( TInt aIndex )
       
   342     {
       
   343     TBuf<KPaswordStrLength> newPassword = At( aIndex ).iUserText.Left( KValue );
       
   344     TBuf<KPaswordStrLength> oldPassword;
       
   345     oldPassword.Copy ( newPassword );
       
   346     TBool retValue = EFalse;
       
   347     
       
   348     iSettingPage = new( ELeave )CAknAlphaPasswordSettingPage(
       
   349         R_MUIU_SETTINGS_DIALOG_PASSWORD, newPassword, oldPassword );
       
   350     iSettingPage->SetSettingTextL( At( aIndex ).iLabelText );
       
   351     iSettingPage->ConstructL( );
       
   352     STATIC_CAST( CAknAlphaPasswordSettingPage*, iSettingPage )->AlphaPasswordEditor()
       
   353         ->SetMaxLength( At( aIndex ).iUserTextMaxLength );
       
   354     
       
   355     if ( iSettingPage->ExecuteLD(CAknSettingPage::EUpdateWhenChanged) )
       
   356         {
       
   357         At( aIndex ).iUserText.Copy( newPassword );
       
   358         retValue = ETrue;
       
   359         }
       
   360     iSettingPage = NULL;
       
   361     return retValue;
       
   362     }
       
   363 
       
   364 
       
   365 // ---------------------------------------------------------
       
   366 // CMuiuSettingsArray::MdcaCount
       
   367 // ---------------------------------------------------------
       
   368 //
       
   369 EXPORT_C TInt CMuiuSettingsArray::MdcaCount() const
       
   370     {
       
   371     return Count();
       
   372     }
       
   373 
       
   374 
       
   375 // ---------------------------------------------------------
       
   376 // CMuiuSettingsArray::MdcaPoint
       
   377 // ---------------------------------------------------------
       
   378 //
       
   379 EXPORT_C TPtrC CMuiuSettingsArray::MdcaPoint( TInt aIndex ) const
       
   380     {
       
   381     TPtr tempText = iTempText->Des();
       
   382     TBuf<KMuiuMaxSettingsTextLength> tempSettingText;
       
   383     tempSettingText.Zero();
       
   384     
       
   385     tempText.Zero();
       
   386     tempText.Append( KMuiuSpaceString );
       
   387     tempText.Append( KColumnListSeparator );
       
   388     tempText.Append( At( aIndex ).iLabelText );
       
   389     tempText.Append( KColumnListSeparator );
       
   390     tempText.Append( KColumnListSeparator );
       
   391     
       
   392     if ( At( aIndex ).iType == EMuiuSettingsSelectionList )
       
   393         {
       
   394         tempSettingText = At( aIndex ).iMuiuSettingsItemArray->MdcaPoint(
       
   395             At( aIndex ).iCurrentNumber ).Left( KMuiuSettingsArrayVisibleTextLength );
       
   396         }
       
   397     else if ( At( aIndex ).iType == EMuiuSettingsPassword )
       
   398         {
       
   399         TInt length = At( aIndex ).iUserText.Length();
       
   400         length = length > KMuiuSettingsArrayVisibleTextLength ?
       
   401         KMuiuSettingsArrayVisibleTextLength : length;
       
   402         if ( length > 0 )
       
   403             {
       
   404             TChar passFill = TChar( iPasswordFill );
       
   405             tempSettingText.AppendFill( passFill, length );
       
   406             }
       
   407         }
       
   408     else 
       
   409         {
       
   410         if ( At( aIndex ).iUserText.Length() )
       
   411             {
       
   412             tempSettingText = At( aIndex ).iUserText.Left( KMuiuSettingsArrayVisibleTextLength );
       
   413             }
       
   414         }
       
   415     
       
   416     if ( tempSettingText.Length() )
       
   417         {
       
   418         tempText.Append( tempSettingText );
       
   419         }
       
   420     else
       
   421         {
       
   422         if ( At( aIndex ).iCompulsory )
       
   423             {
       
   424             tempText.Append( *iCompulsoryText );
       
   425             }
       
   426         else
       
   427             {
       
   428             tempText.Append( KMuiuSpaceString );
       
   429             }
       
   430         }
       
   431     
       
   432     if ( At( aIndex ).iCompulsory )
       
   433         {
       
   434         tempText.Append( KMuiuSettingsArrayCompulsoryAdditionString );
       
   435         }
       
   436 
       
   437     if ( At( aIndex ).iLangSpecificNumConv )
       
   438         {
       
   439         AknTextUtils::DisplayTextLanguageSpecificNumberConversion( tempText );
       
   440         }
       
   441 
       
   442     return tempText;
       
   443     }
       
   444 
       
   445 // ---------------------------------------------------------
       
   446 // CMuiuSettingsArray::IsMessageSentStringL
       
   447 // ---------------------------------------------------------
       
   448 //
       
   449 TBool CMuiuSettingsArray::IsMessageSentStringL(HBufC* aString)
       
   450     {
       
   451     TInt flag = EFalse;
       
   452     HBufC* string = StringLoader::LoadLC( R_MUIU__MCE_SETTINGS_SMS_CONVERSION);
       
   453     if (aString->Compare(string->Des()) == 0)
       
   454         {
       
   455          TInt val = 0;
       
   456          TInt ret = RProperty::Get( KPSUidMuiu, KMuiuRemoveMsgSentSettings, val );
       
   457          if ( ret == KErrNone && val != 0 )
       
   458              {
       
   459              flag = ETrue;
       
   460              RProperty::Set( KPSUidMuiu, KMuiuRemoveMsgSentSettings, 0) ;
       
   461              }
       
   462          }
       
   463     CleanupStack::PopAndDestroy( string );
       
   464     return flag;
       
   465     }
       
   466 //  End of File