|
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 Settings list for Phonebook. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CPbkSettingsList.h" // This class |
|
22 #include "Cpbknameordersettingitem.h" |
|
23 #include <PbkView.hrh> |
|
24 #include <PbkView.rsg> |
|
25 #include <CPbkContactEngine.h> |
|
26 |
|
27 /// Unnamed namespace for local definitons |
|
28 namespace { |
|
29 |
|
30 #ifdef _DEBUG |
|
31 enum TPanicCode |
|
32 { |
|
33 EPanicPreCond_CreateSettingItemL, |
|
34 EPanicPreCond_SettingValue, |
|
35 EPanicPreCond_ChangeValue |
|
36 }; |
|
37 |
|
38 void Panic(TPanicCode aReason) |
|
39 { |
|
40 _LIT(KPanicText, "CPbkSettingsList"); |
|
41 User::Panic(KPanicText, aReason); |
|
42 } |
|
43 #endif // _DEBUG |
|
44 |
|
45 |
|
46 } // namespace |
|
47 |
|
48 |
|
49 |
|
50 // ================= MEMBER FUNCTIONS ======================= |
|
51 |
|
52 // CPbkSettingsList |
|
53 inline CPbkSettingsList::CPbkSettingsList(CPbkContactEngine& aEngine) |
|
54 : iEngine(aEngine) |
|
55 { |
|
56 } |
|
57 |
|
58 |
|
59 CPbkSettingsList* CPbkSettingsList::NewL(CPbkContactEngine& aEngine) |
|
60 { |
|
61 CPbkSettingsList* self = new(ELeave) CPbkSettingsList(aEngine); |
|
62 CleanupStack::PushL(self); |
|
63 self->ConstructL(); |
|
64 CleanupStack::Pop(); // self |
|
65 return self; |
|
66 } |
|
67 |
|
68 |
|
69 inline void CPbkSettingsList::ConstructL() |
|
70 { |
|
71 // Construct from resources |
|
72 ConstructFromResourceL(R_PBK_SETTINGS_LIST); |
|
73 } |
|
74 |
|
75 |
|
76 CPbkSettingsList::~CPbkSettingsList() |
|
77 { |
|
78 // iNameOrderSettingItem is deleted by the base class, since |
|
79 // all setting items belong to an array (owned by base class) |
|
80 // which is reseted at base class destructor |
|
81 } |
|
82 |
|
83 |
|
84 CAknSettingItem* CPbkSettingsList::CreateSettingItemL(TInt aSettingId) |
|
85 { |
|
86 __ASSERT_DEBUG(!iNameOrderSettingItem, |
|
87 Panic(EPanicPreCond_CreateSettingItemL)); |
|
88 |
|
89 CAknSettingItem* settingItem = NULL; |
|
90 |
|
91 switch (aSettingId) |
|
92 { |
|
93 case EPbkSettingNameOrder: |
|
94 { |
|
95 iDefaultNameOrderValue = iEngine.NameDisplayOrderL(); |
|
96 TBool useComma = !iEngine.NameSeparator().Eos(); |
|
97 |
|
98 // Map the Engine's NameOrder- and UseComma-values to |
|
99 // Settings-dialog's NameOrder-value. |
|
100 switch (iDefaultNameOrderValue) |
|
101 { |
|
102 case CPbkContactEngine::EPbkNameOrderLastNameFirstName: |
|
103 { |
|
104 if (useComma) |
|
105 { |
|
106 iDefaultNameOrderValue = |
|
107 EPbkSettingNameOrderLastSeparatorFirst; |
|
108 } |
|
109 else |
|
110 { |
|
111 iDefaultNameOrderValue = |
|
112 EPbkSettingNameOrderLastSpaceFirst; |
|
113 } |
|
114 break; |
|
115 } |
|
116 case CPbkContactEngine::EPbkNameOrderFirstNameLastName: |
|
117 { |
|
118 iDefaultNameOrderValue = |
|
119 EPbkSettingNameOrderFirstSpaceLast; |
|
120 break; |
|
121 } |
|
122 |
|
123 default: |
|
124 break; |
|
125 } |
|
126 |
|
127 settingItem = new (ELeave) CPbkNameOrderSettingItem(aSettingId, |
|
128 iDefaultNameOrderValue,iEngine); |
|
129 delete iNameOrderSettingItem; |
|
130 iNameOrderSettingItem = NULL; |
|
131 iNameOrderSettingItem = (CPbkNameOrderSettingItem*) settingItem; |
|
132 break; |
|
133 } |
|
134 default: |
|
135 { |
|
136 // Do nothing |
|
137 break; |
|
138 } |
|
139 } |
|
140 return settingItem; |
|
141 } |
|
142 |
|
143 TInt CPbkSettingsList::SettingValueL(TInt aSettingId) |
|
144 { |
|
145 __ASSERT_DEBUG(iNameOrderSettingItem, |
|
146 Panic(EPanicPreCond_SettingValue)); |
|
147 |
|
148 switch (aSettingId) |
|
149 { |
|
150 case EPbkSettingNameOrder: |
|
151 { |
|
152 iNameOrderSettingItem->StoreL(); |
|
153 return iNameOrderSettingItem->Value(); |
|
154 } |
|
155 default: |
|
156 { |
|
157 return KErrNotFound; |
|
158 } |
|
159 } |
|
160 } |
|
161 |
|
162 void CPbkSettingsList::ChangeValueL(TInt aSettingId) |
|
163 { |
|
164 __ASSERT_DEBUG(iNameOrderSettingItem, |
|
165 Panic(EPanicPreCond_ChangeValue)); |
|
166 |
|
167 switch (aSettingId) |
|
168 { |
|
169 case EPbkSettingNameOrder: |
|
170 { |
|
171 iNameOrderSettingItem->ChangeValueL(); |
|
172 LoadSettingsL(); |
|
173 ListBox()->DrawDeferred(); |
|
174 break; |
|
175 } |
|
176 default: |
|
177 { |
|
178 // Do nothing |
|
179 break; |
|
180 } |
|
181 } |
|
182 } |
|
183 |
|
184 void CPbkSettingsList::SizeChanged() |
|
185 { |
|
186 CAknSettingItemList::SizeChanged(); |
|
187 if (ListBox()) |
|
188 { |
|
189 ListBox()->SetRect(Rect()); |
|
190 } |
|
191 } |
|
192 |
|
193 // End of File |