phonebookui/Phonebook2/UIControls/src/CPbk2NameOrderSettingItem.cpp
changeset 0 e686773b3f54
child 21 9da50d567e3c
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2002-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: 
       
    15 *       Provides methods for Name Order settings item.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CPbk2NameOrderSettingItem.h"   // This class
       
    22 
       
    23 #include <Pbk2UIControls.rsg>
       
    24 #include <CPbk2SortOrderManager.h>
       
    25 #include <StringLoader.h>
       
    26 
       
    27 /// Unnamed namespace for local definitions
       
    28 namespace {
       
    29 
       
    30 /// Append enumerated text items to array
       
    31 void AppendEnumeratedItemL( TInt aResourceId, 
       
    32     CPbk2SortOrderManager::TPbk2NameDisplayOrder aEnumeration,
       
    33     CArrayPtr<CAknEnumeratedText>& aEnumeratedArray )
       
    34     {
       
    35     HBufC* lastSpaceFirst = StringLoader::LoadLC( aResourceId );
       
    36     CAknEnumeratedText* enumeratedText = new( ELeave ) CAknEnumeratedText( 
       
    37         aEnumeration, 
       
    38         lastSpaceFirst );
       
    39     CleanupStack::Pop( lastSpaceFirst );
       
    40     CleanupStack::PushL( enumeratedText );
       
    41     aEnumeratedArray.AppendL( enumeratedText );
       
    42     CleanupStack::Pop( enumeratedText );
       
    43     }
       
    44 }
       
    45 // ================= MEMBER FUNCTIONS =======================
       
    46 
       
    47 // CPbk2NameOrderSettingItem
       
    48 
       
    49 CPbk2NameOrderSettingItem::CPbk2NameOrderSettingItem(
       
    50         CPbk2SortOrderManager& aSortOrderManager, 
       
    51         TInt aResourceId, 
       
    52         TInt& aValue) : 
       
    53     CAknEnumeratedTextPopupSettingItem(aResourceId, aValue),
       
    54     iSortOrderManager(aSortOrderManager)
       
    55     {
       
    56     }
       
    57 
       
    58 TInt CPbk2NameOrderSettingItem::Value()
       
    59     {
       
    60 	return ExternalValue();
       
    61     }
       
    62 
       
    63 // ---------------------------------------------------------------------------
       
    64 // From class CAknEnumeratedTextPopupSettingItem
       
    65 // CPbk2NameOrderSettingItem::CompleteConstructionL
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 void CPbk2NameOrderSettingItem::CompleteConstructionL()
       
    69     {
       
    70     CAknEnumeratedTextPopupSettingItem::CompleteConstructionL();
       
    71     
       
    72     // get reference from the base class to texts that are showed in
       
    73     // settings item list
       
    74     CArrayPtr<CAknEnumeratedText>* enumeratedTexts = EnumeratedTextArray();
       
    75     // get reference from the base class to texts that are showed in
       
    76     // the pop up. In this case these are same as enumerated texts
       
    77     CArrayPtr<HBufC>* poppedTexts = PoppedUpTextArray();
       
    78     
       
    79     // Append items to enumerated array in the same order 
       
    80     // as enumerations in TPbk2NameDisplayOrder
       
    81     AppendEnumeratedItemL( 
       
    82         R_QTN_PHOB_SET_NAMES_LAST_SPACE_FIRST, 
       
    83         CPbk2SortOrderManager::EPbk2NameDisplayOrderLastNameFirstName,
       
    84         *enumeratedTexts );
       
    85     
       
    86     HBufC* lastSeparatorFirst = StringLoader::LoadLC( 
       
    87         R_QTN_PHOB_SET_NAMES_LAST_SEPARATOR_FIRST, 
       
    88         Separator() );
       
    89     CAknEnumeratedText* enumeratedText = new( ELeave ) CAknEnumeratedText( 
       
    90         CPbk2SortOrderManager::EPbk2NameDisplayOrderLastNameSeparatorFirstName, 
       
    91         lastSeparatorFirst );
       
    92     CleanupStack::Pop( lastSeparatorFirst );
       
    93     CleanupStack::PushL( enumeratedText );
       
    94     enumeratedTexts->AppendL( enumeratedText );
       
    95     CleanupStack::Pop( enumeratedText ); 
       
    96     
       
    97     AppendEnumeratedItemL( 
       
    98         R_QTN_PHOB_SET_NAMES_FIRST_SPACE_LAST, 
       
    99         CPbk2SortOrderManager::EPbk2NameDisplayOrderFirstNameLastName,
       
   100         *enumeratedTexts );
       
   101     
       
   102     // Append items to the poppedup array in the same order as in enumerated
       
   103     // array
       
   104     const TInt count = enumeratedTexts->Count();
       
   105     for ( TInt i = 0; i < count; ++i )
       
   106         {
       
   107         HBufC* text = enumeratedTexts->At( i )->Value()->AllocLC();
       
   108         poppedTexts->AppendL( text );
       
   109         CleanupStack::Pop( text );
       
   110         }
       
   111     }
       
   112 
       
   113 // ---------------------------------------------------------------------------
       
   114 // From class CAknEnumeratedTextPopupSettingItem
       
   115 // CPbk2NameOrderSettingItem::StoreL
       
   116 // ---------------------------------------------------------------------------
       
   117 //    
       
   118 void CPbk2NameOrderSettingItem::StoreL()
       
   119     {
       
   120     CAknEnumeratedTextPopupSettingItem::StoreL();
       
   121     
       
   122     CPbk2SortOrderManager::TPbk2NameDisplayOrder selectedOrder( 
       
   123         static_cast<CPbk2SortOrderManager::TPbk2NameDisplayOrder>( 
       
   124             Value() ) );
       
   125     
       
   126     if ( selectedOrder == 
       
   127          CPbk2SortOrderManager::EPbk2NameDisplayOrderLastNameSeparatorFirstName )
       
   128         {                           
       
   129         iSortOrderManager.SetNameDisplayOrderL( selectedOrder, Separator() );
       
   130         }
       
   131     else
       
   132         {
       
   133         iSortOrderManager.SetNameDisplayOrderL( selectedOrder );
       
   134         }
       
   135     }
       
   136 
       
   137 // ---------------------------------------------------------------------------
       
   138 // From class CAknEnumeratedTextPopupSettingItem
       
   139 // CPbk2NameOrderSettingItem::IsSeparatorSpace
       
   140 // ---------------------------------------------------------------------------
       
   141 //    
       
   142 TPtrC CPbk2NameOrderSettingItem::Separator()
       
   143     {
       
   144     // Retrieve current separator. If it's space then use the language
       
   145     // specific default separator.
       
   146     TPtrC separator( iSortOrderManager.CurrentSeparator() );
       
   147     if ( separator.Length() > 0 && TChar(separator[0]).IsSpace() )
       
   148         {
       
   149         separator.Set( iSortOrderManager.DefaultSeparator() );
       
   150         }
       
   151     return separator;
       
   152     }
       
   153 //  End of File