phonebookui/Phonebook/View/src/Cpbknameordersettingitem.cpp
changeset 0 e686773b3f54
child 21 9da50d567e3c
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     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 *       Provides methods for Name Order settings item.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "Cpbknameordersettingitem.h"   // This class
       
    22 #include <CPbkContactEngine.h>
       
    23 #include <StringLoader.h>
       
    24 #include <PbkView.rsg>
       
    25 
       
    26 #include <PbkView.hrh>
       
    27 #include "PbkViewUtils.h"
       
    28 
       
    29 /// Unnamed namespace for local definitions
       
    30 namespace {
       
    31 
       
    32 void AppendEnumeratedItemL( TInt aResourceId, 
       
    33     TInt aEnumeration,
       
    34     CArrayPtr<CAknEnumeratedText>& aEnumeratedArray )
       
    35     {
       
    36     HBufC* lastSpaceFirst = StringLoader::LoadLC( aResourceId );
       
    37     CAknEnumeratedText* enumeratedText = new( ELeave ) CAknEnumeratedText( 
       
    38         aEnumeration, 
       
    39         lastSpaceFirst );
       
    40     CleanupStack::Pop( lastSpaceFirst );
       
    41     CleanupStack::PushL( enumeratedText );
       
    42     aEnumeratedArray.AppendL( enumeratedText );
       
    43     CleanupStack::Pop( enumeratedText );
       
    44     }
       
    45     
       
    46 void AppendEnumeratedStringItemL( TInt aResourceId, 
       
    47     TInt aEnumeration,
       
    48     const TDesC& aString,
       
    49     CArrayPtr<CAknEnumeratedText>& aEnumeratedArray )
       
    50     {
       
    51     HBufC* lastSpaceFirst = StringLoader::LoadLC( aResourceId, aString );
       
    52     CAknEnumeratedText* enumeratedText = new( ELeave ) CAknEnumeratedText( 
       
    53         aEnumeration, 
       
    54         lastSpaceFirst );
       
    55     CleanupStack::Pop( lastSpaceFirst );
       
    56     CleanupStack::PushL( enumeratedText );
       
    57     aEnumeratedArray.AppendL( enumeratedText );
       
    58     CleanupStack::Pop( enumeratedText );
       
    59     }
       
    60 }
       
    61 
       
    62 
       
    63 // ================= MEMBER FUNCTIONS =======================
       
    64 
       
    65 // CPbkNameOrderSettingItem
       
    66 
       
    67 CPbkNameOrderSettingItem::CPbkNameOrderSettingItem
       
    68 		(TInt aResourceId, TInt& aValue, CPbkContactEngine& aEngine)
       
    69 		: CAknEnumeratedTextPopupSettingItem(aResourceId, aValue),
       
    70 		 iEngine(aEngine)
       
    71     {    
       
    72     }
       
    73 
       
    74 TInt CPbkNameOrderSettingItem::Value()
       
    75     {
       
    76 	return ExternalValue();
       
    77     }
       
    78 
       
    79 void CPbkNameOrderSettingItem::ChangeValueL()
       
    80 	{
       
    81 	// First get the current value
       
    82 	LoadL();
       
    83 	TInt value = InternalValue();
       
    84 	
       
    85 	// Then change it...
       
    86 	if (value == CPbkContactEngine::EPbkNameOrderLastNameFirstName)
       
    87 		{
       
    88 		value = CPbkContactEngine::EPbkNameOrderFirstNameLastName;
       
    89 		}
       
    90 	else
       
    91 		{
       
    92 		value = CPbkContactEngine::EPbkNameOrderLastNameFirstName;
       
    93 		}
       
    94 
       
    95 	// ...and set it
       
    96 	SetInternalValue(value);
       
    97 	StoreL();
       
    98 	}
       
    99 
       
   100 void CPbkNameOrderSettingItem::CompleteConstructionL()
       
   101     {
       
   102     CAknEnumeratedTextPopupSettingItem::CompleteConstructionL();
       
   103     
       
   104     // get reference from the base class to texts that are showed in
       
   105     // settings item list
       
   106     CArrayPtr<CAknEnumeratedText>* enumeratedTexts = EnumeratedTextArray();
       
   107     // get reference from the base class to texts that are showed in
       
   108     // the pop up. In this case these are same as enumerated texts
       
   109     CArrayPtr<HBufC>* poppedTexts = PoppedUpTextArray();
       
   110     
       
   111     // Append items to enumerated array
       
   112     
       
   113     // Last name First name item
       
   114     AppendEnumeratedItemL( 
       
   115         R_QTN_PHOB_SET_NAMES_LAST_SPACE_FIRST, 
       
   116         EPbkSettingNameOrderLastSpaceFirst,
       
   117         *enumeratedTexts );
       
   118 
       
   119     TBuf<1> sepChar;
       
   120     sepChar.Append(PbkViewUtils::ResolveNameOrderSeparatorL(iEngine));
       
   121     AppendEnumeratedStringItemL(
       
   122         R_QTN_PHOB_SET_NAMES_LAST_SEPARATOR_FIRST,
       
   123         EPbkSettingNameOrderLastSeparatorFirst,
       
   124         sepChar,
       
   125         *enumeratedTexts );
       
   126 
       
   127     AppendEnumeratedItemL( 
       
   128         R_QTN_PHOB_SET_NAMES_FIRST_SPACE_LAST, 
       
   129         EPbkSettingNameOrderFirstSpaceLast,
       
   130         *enumeratedTexts );
       
   131 
       
   132     // Append items to the poppedup array in the same order as in enumerated
       
   133     // array
       
   134     const TInt count = enumeratedTexts->Count();
       
   135     for ( TInt i = 0; i < count; ++i )
       
   136         {
       
   137         HBufC* text = enumeratedTexts->At( i )->Value()->AllocLC();
       
   138         poppedTexts->AppendL( text );
       
   139         CleanupStack::Pop( text );
       
   140         }
       
   141     }
       
   142 
       
   143 //  End of File