|
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 * Phonebook 2 names list control. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CPbk2SettingsListControl.h" |
|
22 #include "CPbk2NameOrderSettingItem.h" |
|
23 #include "CPbk2MemorySelectionSettingItem.h" |
|
24 #include "CPbk2PredictiveSearchSettingItem.h" |
|
25 #include "CPbk2DefaultSavingStorageSettingItem.h" |
|
26 #include "Pbk2UIControls.hrh" |
|
27 #include "CPbk2SettingsListState.h" |
|
28 #include "Phonebook2PrivateCRKeys.h" |
|
29 |
|
30 // From Phonebook 2 |
|
31 #include <Pbk2UIControls.rsg> |
|
32 #include <CPbk2UIExtensionManager.h> |
|
33 #include <MPbk2UIExtensionFactory.h> |
|
34 #include <MPbk2SettingsControlExtension.h> |
|
35 #include <CPbk2SortOrderManager.h> |
|
36 |
|
37 #include <StringLoader.h> |
|
38 #include <centralrepository.h> |
|
39 #include <featmgr.h> |
|
40 #include <AknFepInternalCRKeys.h> |
|
41 |
|
42 //Pbk2Debug |
|
43 #include "Pbk2Debug.h" |
|
44 |
|
45 |
|
46 // ================= MEMBER FUNCTIONS ======================= |
|
47 // ----------------------------------------------------------------------------- |
|
48 // CPbk2SettingsListControl::CPbk2SettingsListControl |
|
49 // ----------------------------------------------------------------------------- |
|
50 // |
|
51 CPbk2SettingsListControl::CPbk2SettingsListControl( |
|
52 CPbk2SortOrderManager& aSortOrderManager, |
|
53 MPbk2SettingsControlExtension& aControlExtension ) : |
|
54 iSortOrderManager( aSortOrderManager ), |
|
55 iControlExtension( aControlExtension ) |
|
56 { |
|
57 } |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // CPbk2SettingsListControl::~CPbk2SettingsListControl |
|
61 // ----------------------------------------------------------------------------- |
|
62 // |
|
63 CPbk2SettingsListControl::~CPbk2SettingsListControl() |
|
64 { |
|
65 delete iSettingListState; |
|
66 } |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // CPbk2SettingsListControl::NewL |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 EXPORT_C CPbk2SettingsListControl* CPbk2SettingsListControl::NewL( |
|
73 const CCoeControl* aContainer, |
|
74 CPbk2SortOrderManager& aSortOrderManager, |
|
75 MPbk2SettingsControlExtension& aControlExtension ) |
|
76 { |
|
77 CPbk2SettingsListControl* self = new (ELeave) CPbk2SettingsListControl( |
|
78 aSortOrderManager, aControlExtension ); |
|
79 CleanupStack::PushL( self ); |
|
80 self->ConstructL( aContainer ); |
|
81 CleanupStack::Pop( self ); |
|
82 return self; |
|
83 } |
|
84 |
|
85 // ----------------------------------------------------------------------------- |
|
86 // CPbk2SettingsListControl::CommitSettingsL |
|
87 // ----------------------------------------------------------------------------- |
|
88 // |
|
89 EXPORT_C void CPbk2SettingsListControl::CommitSettingsL() |
|
90 { |
|
91 StoreSettingsL(); |
|
92 } |
|
93 |
|
94 // ----------------------------------------------------------------------------- |
|
95 // CPbk2SettingsListControl::StoreSettings |
|
96 // ----------------------------------------------------------------------------- |
|
97 // |
|
98 void CPbk2SettingsListControl::StoreSettings() |
|
99 { |
|
100 TRAPD( err, StoreSettingsL() ); |
|
101 if ( err != KErrNone ) |
|
102 { |
|
103 iEikonEnv->HandleError( err ); |
|
104 } |
|
105 } |
|
106 |
|
107 // ----------------------------------------------------------------------------- |
|
108 // CPbk2SettingsListControl::SizeChanged |
|
109 // ----------------------------------------------------------------------------- |
|
110 // |
|
111 void CPbk2SettingsListControl::SizeChanged() |
|
112 { |
|
113 CAknSettingItemList::SizeChanged(); |
|
114 |
|
115 CEikListBox* listBox = ListBox(); |
|
116 if( listBox ) |
|
117 { |
|
118 listBox->SetRect( Rect() ); // Set container's rect to listbox |
|
119 } |
|
120 } |
|
121 |
|
122 // ----------------------------------------------------------------------------- |
|
123 // CPbk2SettingsListControl::EditItemL |
|
124 // ----------------------------------------------------------------------------- |
|
125 // |
|
126 void CPbk2SettingsListControl::EditItemL( TInt aIndex, TBool aCalledFromMenu ) |
|
127 { |
|
128 switch ( aIndex ) |
|
129 { |
|
130 case EPbk2SettingMemorySelection: |
|
131 { |
|
132 LaunchMemorySelectionSettingPageL(); |
|
133 this->StoreSettings(); |
|
134 break; |
|
135 } |
|
136 case EPbk2SettingPredictiveSearch: |
|
137 { |
|
138 // aCalledFromMenu = EFalse to make it in place, not show the popup |
|
139 CAknSettingItemList::EditItemL( aIndex, EFalse ); |
|
140 this->StoreSettings(); |
|
141 |
|
142 break; |
|
143 } |
|
144 case EPbk2SettingDefaultSavingStorage: //Fall through |
|
145 case EPbk2SettingNameOrder: //Fall through |
|
146 default: |
|
147 { |
|
148 CAknSettingItemList::EditItemL( aIndex, aCalledFromMenu ); |
|
149 this->StoreSettings(); |
|
150 break; |
|
151 } |
|
152 } |
|
153 } |
|
154 |
|
155 void CPbk2SettingsListControl::HandleResourceChange( TInt aType ) |
|
156 { |
|
157 ListBox()->HandleResourceChange( aType ); |
|
158 CAknSettingItemList::HandleResourceChange( aType ); |
|
159 } |
|
160 |
|
161 |
|
162 // ----------------------------------------------------------------------------- |
|
163 // CPbk2SettingsListControl::HandleListBoxEventL |
|
164 // ----------------------------------------------------------------------------- |
|
165 // |
|
166 void CPbk2SettingsListControl::HandleListBoxEventL(CEikListBox* aListBox, TListBoxEvent aEventType) |
|
167 { |
|
168 if( AknLayoutUtils::PenEnabled() ) |
|
169 { |
|
170 switch( aEventType ) |
|
171 { |
|
172 case EEventItemSingleClicked: //fall through |
|
173 case EEventEnterKeyPressed: |
|
174 { |
|
175 EditItemL( ListBox()->CurrentItemIndex(), ETrue ); |
|
176 break; |
|
177 } |
|
178 default : |
|
179 //ignore rest events |
|
180 break; |
|
181 } |
|
182 } |
|
183 } |
|
184 |
|
185 // ----------------------------------------------------------------------------- |
|
186 // CPbk2SettingsListControl::ConstructL |
|
187 // ----------------------------------------------------------------------------- |
|
188 // |
|
189 inline void CPbk2SettingsListControl::ConstructL( |
|
190 const CCoeControl* aContainer ) |
|
191 { |
|
192 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
193 ("CPbk2SettingsListControl::ConstructL(0x%x)"), |
|
194 aContainer); |
|
195 |
|
196 if ( !aContainer ) |
|
197 { |
|
198 User::Leave( KErrGeneral ); |
|
199 } |
|
200 |
|
201 // First set container |
|
202 SetContainerWindowL( *aContainer ); |
|
203 |
|
204 iSettingListState = CPbk2SettingsListState::NewL(); |
|
205 |
|
206 // Check language specific variation for name ordering item |
|
207 if ( ShowNameOrderingSettingL() ) |
|
208 { |
|
209 ConstructFromResourceL( R_PHONEBOOK2_SETTINGS_LIST ); |
|
210 } |
|
211 else |
|
212 { |
|
213 ConstructFromResourceL( R_PHONEBOOK2_SETTINGS_LIST_NO_NAME_ORDERING ); |
|
214 } |
|
215 |
|
216 iControlExtension.ModifySettingItemListL( *this ); |
|
217 // call this to make extension modifications visible |
|
218 HandleChangeInItemArrayOrVisibilityL(); |
|
219 |
|
220 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
221 ("CPbk2SettingsListControl::ConstructL end")); |
|
222 } |
|
223 |
|
224 // ----------------------------------------------------------------------------- |
|
225 // CPbk2SettingsListControl::CreateSettingItemL |
|
226 // ----------------------------------------------------------------------------- |
|
227 // |
|
228 CAknSettingItem* CPbk2SettingsListControl::CreateSettingItemL( TInt aSettingId ) |
|
229 { |
|
230 CAknSettingItem* settingItem = |
|
231 iControlExtension.CreateSettingItemL( aSettingId ); |
|
232 |
|
233 if ( !settingItem ) |
|
234 { |
|
235 switch ( aSettingId ) |
|
236 { |
|
237 case EPbk2SettingMemorySelection: |
|
238 { |
|
239 iSelectionSettingItem = |
|
240 new(ELeave) CPbk2MemorySelectionSettingItem( |
|
241 aSettingId, |
|
242 iSettingListState->SupportedStores(), |
|
243 iSettingListState->SelectionItemList() ); |
|
244 settingItem = iSelectionSettingItem; |
|
245 break; |
|
246 } |
|
247 case EPbk2SettingDefaultSavingStorage: |
|
248 { |
|
249 iDefaultSavingStorage = 0; |
|
250 iDefaultSavingStorageItem = |
|
251 new(ELeave) CPbk2DefaultSavingStorageSettingItem( |
|
252 aSettingId, iDefaultSavingStorage, |
|
253 iSettingListState->SupportedStores(), |
|
254 iSettingListState->SelectionItemList() ); |
|
255 settingItem = iDefaultSavingStorageItem; |
|
256 break; |
|
257 } |
|
258 case EPbk2SettingNameOrder: |
|
259 { |
|
260 CPbk2SortOrderManager::TPbk2NameDisplayOrder order = |
|
261 iSortOrderManager.NameDisplayOrder(); |
|
262 iDefaultNameDisplayOrder = TInt( order ); |
|
263 settingItem = new (ELeave) CPbk2NameOrderSettingItem( |
|
264 iSortOrderManager, aSettingId, iDefaultNameDisplayOrder ); |
|
265 break; |
|
266 } |
|
267 case EPbk2SettingPredictiveSearch: |
|
268 { |
|
269 if(FeatureManager::FeatureSupported(KFeatureIdFfContactsPredictiveSearch)) |
|
270 { |
|
271 TBool physicalKeyboardExist = PhysicalKeyboardExistL(); |
|
272 if ( physicalKeyboardExist ) |
|
273 { |
|
274 PredictiveSearchEnableInfoFromCenrepL(); |
|
275 iPredictiveSearchItem = new ( ELeave ) CPbk2PredictiveSearchSettingItem( aSettingId, iPredictiveSearchSettingsValue ); |
|
276 settingItem = iPredictiveSearchItem; |
|
277 } |
|
278 else // if no physical keyboard, make this settings invisible, |
|
279 // and reset cenrep for predictive search |
|
280 { |
|
281 DisablePredictiveSearchInCenrepL(); |
|
282 } |
|
283 } |
|
284 break; |
|
285 } |
|
286 default: |
|
287 { |
|
288 // Do nothing |
|
289 break; |
|
290 } |
|
291 } |
|
292 } |
|
293 |
|
294 return settingItem; |
|
295 } |
|
296 |
|
297 // ----------------------------------------------------------------------------- |
|
298 // CPbk2SettingsListControl::LaunchMemorySelectionSettingPageL |
|
299 // ----------------------------------------------------------------------------- |
|
300 // |
|
301 void CPbk2SettingsListControl::LaunchMemorySelectionSettingPageL() |
|
302 { |
|
303 //Store selection setting item list |
|
304 iSettingListState->StoreItemStateL(); |
|
305 |
|
306 TBool result( EFalse ); |
|
307 do |
|
308 { |
|
309 //Edit selection setting item |
|
310 //result is ETrue if OK pressed |
|
311 result = iSelectionSettingItem->EditItemL(); |
|
312 if ( result ) |
|
313 { |
|
314 //Is selection setting list changed by user |
|
315 //result is ETrue if it is changed |
|
316 result = iSettingListState->IsChanged(); |
|
317 if ( result ) |
|
318 { |
|
319 //Update default saving storage |
|
320 //result is ETrue if success |
|
321 result = !iDefaultSavingStorageItem->UpdateL(); |
|
322 DrawDeferred(); |
|
323 } |
|
324 } |
|
325 else |
|
326 { |
|
327 //restore selection setting item list |
|
328 iSettingListState->RestoreItemStateL(); |
|
329 iDefaultSavingStorageItem->RestoreStateL(); |
|
330 } |
|
331 }while( result ); |
|
332 } |
|
333 |
|
334 // ----------------------------------------------------------------------------- |
|
335 // CPbk2SettingsListControl::ShowNameOrderingSettingL |
|
336 // ----------------------------------------------------------------------------- |
|
337 // |
|
338 TBool CPbk2SettingsListControl::ShowNameOrderingSettingL() |
|
339 { |
|
340 // Language specific variation for name ordering setting item |
|
341 _LIT( KVisible, "1"); |
|
342 HBufC* nameOrderVisibilityBuf = |
|
343 StringLoader::LoadLC( R_QTN_PHOB_NAME_ORDERING_SETTINGS_VISIBILITY ); |
|
344 TBool result = ( nameOrderVisibilityBuf->Compare( KVisible ) == 0 ); |
|
345 CleanupStack::PopAndDestroy( nameOrderVisibilityBuf ); |
|
346 return result; |
|
347 } |
|
348 |
|
349 // ----------------------------------------------------------------------------- |
|
350 // CPbk2SettingsListControl::PredictiveSearchEnableInfoFromCenrepL |
|
351 // ----------------------------------------------------------------------------- |
|
352 // |
|
353 void CPbk2SettingsListControl::PredictiveSearchEnableInfoFromCenrepL() |
|
354 { |
|
355 CRepository* repository = CRepository::NewLC(TUid::Uid(KCRUidPhonebook)); |
|
356 |
|
357 TBool predictiveSearch = EFalse; |
|
358 TInt ret = KErrNone; |
|
359 |
|
360 ret = repository->Get( KPhonebookPredictiveSearchEnablerFlags, predictiveSearch ); |
|
361 |
|
362 if ( ret == KErrNotFound ) |
|
363 { |
|
364 predictiveSearch = EFalse; |
|
365 repository->Create(KPhonebookPredictiveSearchEnablerFlags, predictiveSearch ); |
|
366 } |
|
367 |
|
368 if ( predictiveSearch ) |
|
369 { |
|
370 iPredictiveSearchSettingsValue = ETrue; |
|
371 } |
|
372 else |
|
373 { |
|
374 iPredictiveSearchSettingsValue = EFalse; |
|
375 } |
|
376 |
|
377 CleanupStack::PopAndDestroy( repository ); |
|
378 } |
|
379 |
|
380 // ----------------------------------------------------------------------------- |
|
381 // CPbk2SettingsListControl::PhysicalKeyboardExistL |
|
382 // ----------------------------------------------------------------------------- |
|
383 // |
|
384 TBool CPbk2SettingsListControl::PhysicalKeyboardExistL() |
|
385 { |
|
386 TBool ret = ETrue; |
|
387 |
|
388 TInt physicalKeyboard = 0; |
|
389 CRepository* aknFepRepository = CRepository::NewL( KCRUidAknFep ); |
|
390 TInt err = aknFepRepository->Get( KAknFepPhysicalKeyboards, physicalKeyboard ); |
|
391 delete aknFepRepository; |
|
392 |
|
393 if ( err == KErrNone ) |
|
394 { |
|
395 ret = ( physicalKeyboard != 0 ) ? ETrue : EFalse; |
|
396 } |
|
397 return ret; |
|
398 } |
|
399 |
|
400 // ----------------------------------------------------------------------------- |
|
401 // CPbk2SettingsListControl::DisablePredictiveSearchInCenrepL |
|
402 // ----------------------------------------------------------------------------- |
|
403 // |
|
404 void CPbk2SettingsListControl::DisablePredictiveSearchInCenrepL() |
|
405 { |
|
406 TBool predictiveSearch = EFalse; |
|
407 CRepository* rep = CRepository::NewL(TUid::Uid(KCRUidPhonebook)); |
|
408 |
|
409 TInt err( rep->Set( KPhonebookPredictiveSearchEnablerFlags, predictiveSearch ) ); |
|
410 |
|
411 if ( err ) |
|
412 { |
|
413 rep->Create( KPhonebookPredictiveSearchEnablerFlags, predictiveSearch ); |
|
414 } |
|
415 |
|
416 delete rep; |
|
417 } |
|
418 // End of File |