|
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: Category settings implementation for LandmarksUi |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CLmkAppCategorySettingsImpl.h" |
|
21 #include "LmkListProviderFactory.h" |
|
22 #include "CLmkLmItemListProvider.h" |
|
23 #include "CLmkUiItemBase.h" |
|
24 #include "CLmkDbUtils.h" |
|
25 #include "CLmkUiUtils.h" |
|
26 #include "LmkConsts.h" |
|
27 #include "LmkNotes.h" |
|
28 #include <lmkui.rsg> |
|
29 #include <eiktxlbx.h> |
|
30 #include <EPos_CPosLandmarkCategory.h> |
|
31 #include <EPos_CPosLmCategoryManager.h> |
|
32 #include <EPos_CPosLandmarkCategory.h> |
|
33 #include <AknWaitDialog.h> |
|
34 #include <EPos_CPosLandmarkDatabase.h> |
|
35 #include <EPos_CPosLandmark.h> |
|
36 #include <EPos_TPosLmSortPref.h> |
|
37 #include <EPos_CPosLmItemIterator.h> |
|
38 #include <lmkerrors.h> |
|
39 |
|
40 |
|
41 // CONSTANTS |
|
42 /// Unnamed namespace for local definitions |
|
43 namespace { |
|
44 |
|
45 #if defined(_DEBUG) |
|
46 |
|
47 _LIT( KPanicMsg, "CLmkAppCategorySettingsImpl" ); |
|
48 |
|
49 void Panic( TPanicCode aReason ) |
|
50 { |
|
51 User::Panic( KPanicMsg, aReason ); |
|
52 } |
|
53 #endif |
|
54 |
|
55 } // namespace |
|
56 // ============================ MEMBER FUNCTIONS =============================== |
|
57 |
|
58 // ----------------------------------------------------------------------------- |
|
59 // CLmkAppCategorySettingsImpl::CLmkAppCategorySettingsImpl |
|
60 // C++ default constructor can NOT contain any code, that |
|
61 // might leave. |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 CLmkAppCategorySettingsImpl::CLmkAppCategorySettingsImpl( |
|
65 CPosLandmarkDatabase& aDb, |
|
66 CLmkSender& aSender, |
|
67 TBool aFindBox ) |
|
68 : CLmkAppLmItemSelectorImpl( aDb, aSender, aFindBox ) |
|
69 { |
|
70 } |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // CLmkAppCategorySettingsImpl::ConstructL |
|
74 // Symbian 2nd phase constructor can leave. |
|
75 // ----------------------------------------------------------------------------- |
|
76 // |
|
77 void CLmkAppCategorySettingsImpl::ConstructL() |
|
78 { |
|
79 CLmkAppLmItemSelectorImpl::BaseConstructL(); |
|
80 iBuffer = HBufC::NewL( KMaxCategoryNameFieldLen ); |
|
81 } |
|
82 |
|
83 // ----------------------------------------------------------------------------- |
|
84 // CLmkAppCategorySettingsImpl::NewL |
|
85 // Two-phased constructor. |
|
86 // ----------------------------------------------------------------------------- |
|
87 // |
|
88 EXPORT_C CLmkAppCategorySettingsImpl* CLmkAppCategorySettingsImpl::NewL( |
|
89 CPosLandmarkDatabase& aDb, |
|
90 CLmkSender& aSender, |
|
91 TBool aFindBox ) |
|
92 { |
|
93 CLmkAppCategorySettingsImpl* self = |
|
94 new( ELeave ) CLmkAppCategorySettingsImpl( aDb, aSender, aFindBox ); |
|
95 |
|
96 CleanupStack::PushL( self ); |
|
97 self->ConstructL(); |
|
98 CleanupStack::Pop(); |
|
99 |
|
100 return self; |
|
101 } |
|
102 |
|
103 // ----------------------------------------------------------------------------- |
|
104 // CLmkAppCategorySettingsImpl::~CLmkAppCategorySettingsImpl |
|
105 // ----------------------------------------------------------------------------- |
|
106 // |
|
107 CLmkAppCategorySettingsImpl::~CLmkAppCategorySettingsImpl() |
|
108 { |
|
109 if ( iWaitNote ) |
|
110 { |
|
111 TRAPD( err, iWaitNote->ProcessFinishedL() ); |
|
112 if (err != KErrNone) |
|
113 { |
|
114 delete iWaitNote; |
|
115 iWaitNote = NULL; |
|
116 } |
|
117 } |
|
118 delete iBuffer; |
|
119 } |
|
120 |
|
121 // ----------------------------------------------------------------------------- |
|
122 // CLmkAppCategorySettingsImpl::SetupListProviderL |
|
123 // ----------------------------------------------------------------------------- |
|
124 // |
|
125 void CLmkAppCategorySettingsImpl::SetupListProviderL() |
|
126 { |
|
127 if ( !iListProvider ) |
|
128 { |
|
129 iListProvider = |
|
130 LmkListProviderFactory::CreateProviderL( iDb, ECategorySelector, |
|
131 ELmkShowExtendedCategories ); |
|
132 iListProvider->AddObserverL( *this ); |
|
133 iListProvider->InitializeL(); |
|
134 } |
|
135 } |
|
136 |
|
137 // ----------------------------------------------------------------------------- |
|
138 // CLmkAppCategorySettingsImpl::ListProvider |
|
139 // ----------------------------------------------------------------------------- |
|
140 // |
|
141 const CLmkListProviderBase& CLmkAppCategorySettingsImpl::ListProvider() const |
|
142 { |
|
143 __ASSERT_DEBUG( iListProvider, Panic( KLmkPanicNullMember ) ); |
|
144 return *iListProvider; |
|
145 } |
|
146 |
|
147 // ----------------------------------------------------------------------------- |
|
148 // CLmkAppCategorySettingsImpl::ProcessCommandL |
|
149 // ----------------------------------------------------------------------------- |
|
150 // |
|
151 void CLmkAppCategorySettingsImpl::ProcessCommandL( TInt aCommandId ) |
|
152 { |
|
153 switch ( aCommandId ) |
|
154 { |
|
155 case ELmkCmdNewCategory: |
|
156 { |
|
157 NewCategoryCmdL(); |
|
158 break; |
|
159 } |
|
160 case ELmkCmdChangeIcon: |
|
161 { |
|
162 ChangeIconCmdL(); |
|
163 break; |
|
164 } |
|
165 case ELmkCmdRenameCat: |
|
166 { |
|
167 RenameCategoryCmdL(); |
|
168 break; |
|
169 } |
|
170 case ELmkCmdDeleteCat: |
|
171 { |
|
172 DeleteCategoryCmdL(); |
|
173 break; |
|
174 } |
|
175 default: |
|
176 { |
|
177 // leave command handling to others |
|
178 break; |
|
179 } |
|
180 } |
|
181 } |
|
182 |
|
183 // ----------------------------------------------------------------------------- |
|
184 // CLmkAppCategorySettingsImpl::HandleOperationL |
|
185 // ----------------------------------------------------------------------------- |
|
186 // |
|
187 void CLmkAppCategorySettingsImpl::HandleOperationL( |
|
188 TOperationTypes aType, |
|
189 TReal32 /*aProgress*/, |
|
190 TInt aStatus ) |
|
191 { |
|
192 if ( aType == EDeleteCategories ) |
|
193 { |
|
194 if ( aStatus != KPosLmOperationNotComplete && iWaitNote ) |
|
195 { |
|
196 iWaitNote->ProcessFinishedL(); |
|
197 iWaitNote = NULL; |
|
198 } |
|
199 } |
|
200 } |
|
201 |
|
202 // ----------------------------------------------------------------------------- |
|
203 // CLmkAppCategorySettingsImpl::ChangeIconL |
|
204 // ----------------------------------------------------------------------------- |
|
205 // |
|
206 void CLmkAppCategorySettingsImpl::ChangeIconL( |
|
207 TPosLmItemId aId, |
|
208 TInt aIconIndex, |
|
209 TInt aMaskIndex) |
|
210 { |
|
211 TFileName* iconFile = CLmkUiUtils::LmkUiIconFileLC(); |
|
212 iDbUtils->ChangeIconL( iDb, aId, ELmkItemTypeCategory, |
|
213 *iconFile, aIconIndex, aMaskIndex); |
|
214 CleanupStack::PopAndDestroy();//iconFile |
|
215 } |
|
216 |
|
217 // ----------------------------------------------------------------------------- |
|
218 // CLmkAppCategorySettingsImpl::ChangeIconsL |
|
219 // ----------------------------------------------------------------------------- |
|
220 // |
|
221 void CLmkAppCategorySettingsImpl::ChangeIconsL( |
|
222 RArray<TPosLmItemId>& aIdArray, |
|
223 TInt aIconIndex, |
|
224 TInt aMaskIndex) |
|
225 { |
|
226 TFileName* iconFile = CLmkUiUtils::LmkUiIconFileLC(); |
|
227 iDbUtils->ChangeIconsL( aIdArray, ELmkItemTypeCategory, |
|
228 *iconFile, aIconIndex, aMaskIndex); |
|
229 CleanupStack::PopAndDestroy();//iconFile |
|
230 } |
|
231 |
|
232 // ----------------------------------------------------------------------------- |
|
233 // CLmkAppCategorySettingsImpl::NewCategoryCmdL |
|
234 // ----------------------------------------------------------------------------- |
|
235 // |
|
236 void CLmkAppCategorySettingsImpl::NewCategoryCmdL() |
|
237 { |
|
238 TPtr catName( iBuffer->Des() ); |
|
239 catName.Zero(); |
|
240 CPosLandmarkCategory* newCategory = CPosLandmarkCategory::NewLC(); |
|
241 |
|
242 while( LmkNotes::CategoryNameQueryL( catName, R_LMK_CATEGORY_NAME_QUERY ) ) |
|
243 { |
|
244 newCategory->SetCategoryNameL( catName ); |
|
245 TRAPD( err, iDbUtils->AddCategoryL( *newCategory, iDb ) ); |
|
246 if( err == KErrNone ) |
|
247 { |
|
248 iNewListBoxItemAdded = ETrue; |
|
249 break; |
|
250 } |
|
251 else if ( err == KErrAlreadyExists ) |
|
252 { |
|
253 LmkNotes::InformationNoteL( iEnv,R_LMK_CATEGORY_NAME_EXISTS_NOTE ); |
|
254 } |
|
255 else |
|
256 { |
|
257 User::LeaveIfError( err ); // other error cases |
|
258 break; // exit while loop if no error |
|
259 } |
|
260 } |
|
261 CleanupStack::PopAndDestroy(); // newCategory |
|
262 } |
|
263 |
|
264 // ----------------------------------------------------------------------------- |
|
265 // CLmkAppCategorySettingsImpl::RenameCategoryCmdL |
|
266 // ----------------------------------------------------------------------------- |
|
267 // |
|
268 void CLmkAppCategorySettingsImpl::RenameCategoryCmdL() |
|
269 { |
|
270 __ASSERT_DEBUG( iListProvider, Panic( KLmkPanicNullMember ) ); |
|
271 TInt index = iListBox->CurrentItemIndex(); |
|
272 CLmkUiItemBase* item = |
|
273 iListProvider->ItemAtL( index ); |
|
274 CleanupStack::PushL( item ); |
|
275 |
|
276 TPtr catName( iBuffer->Des() ); |
|
277 catName.Zero(); |
|
278 catName.Append( item->Text() ); |
|
279 |
|
280 while( LmkNotes::CategoryNameQueryL( catName, R_LMK_CATEGORY_NAME_QUERY ) ) |
|
281 { |
|
282 TRAPD( err, |
|
283 iDbUtils->RenameCategoryL( catName, SelectedIdL(), iDb ) ); |
|
284 if ( err == KErrAlreadyExists ) |
|
285 { |
|
286 LmkNotes::InformationNoteL( iEnv, R_LMK_CATEGORY_NAME_EXISTS_NOTE ); |
|
287 } |
|
288 else if ( err == KErrNone) |
|
289 { |
|
290 iNewListBoxItemAdded = ETrue; |
|
291 break; |
|
292 } |
|
293 else |
|
294 { |
|
295 User::LeaveIfError( err ); // other error cases |
|
296 break; // exit while loop if no error |
|
297 } |
|
298 } |
|
299 |
|
300 CleanupStack::PopAndDestroy(); //item |
|
301 } |
|
302 |
|
303 // ----------------------------------------------------------------------------- |
|
304 // CLmkAppCategorySettingsImpl::IsGlobalCategory |
|
305 // ----------------------------------------------------------------------------- |
|
306 // |
|
307 EXPORT_C TBool CLmkAppCategorySettingsImpl::IsPredefinedCategoryL() |
|
308 { |
|
309 |
|
310 TBool isGlobalCategory = EFalse; |
|
311 |
|
312 RArray<TPosLmItemId>& markedItemIds = MarkedItemIdsL(); |
|
313 TInt markedCount = markedItemIds.Count(); |
|
314 |
|
315 if (markedCount) |
|
316 { |
|
317 CPosLmCategoryManager* categoryMgr = CPosLmCategoryManager::NewL( iDb ); |
|
318 CleanupStack::PushL( categoryMgr ); |
|
319 |
|
320 for(TInt i =0; i < markedCount; i++) |
|
321 { |
|
322 if(!isGlobalCategory) |
|
323 { |
|
324 CPosLandmarkCategory* category = categoryMgr->ReadCategoryLC(markedItemIds[i]); |
|
325 if (category->GlobalCategory() != KPosLmNullGlobalCategory) |
|
326 { |
|
327 isGlobalCategory = ETrue; |
|
328 } |
|
329 CleanupStack::PopAndDestroy(1); //category |
|
330 } |
|
331 } |
|
332 CleanupStack::PopAndDestroy(1); //categoryMgr |
|
333 } |
|
334 else |
|
335 { |
|
336 TPosLmItemId categoryId = SelectedIdL(); |
|
337 CPosLmCategoryManager* categoryMgr = CPosLmCategoryManager::NewL( iDb ); |
|
338 |
|
339 CleanupStack::PushL( categoryMgr ); |
|
340 CPosLandmarkCategory* category = categoryMgr->ReadCategoryLC( categoryId ); |
|
341 |
|
342 // Check for Global category |
|
343 if (category->GlobalCategory() != KPosLmNullGlobalCategory) |
|
344 { |
|
345 isGlobalCategory = ETrue; |
|
346 } |
|
347 |
|
348 CleanupStack::PopAndDestroy( 2 ); //category, categoryMgr |
|
349 } |
|
350 return isGlobalCategory; |
|
351 } |
|
352 // ----------------------------------------------------------------------------- |
|
353 // CLmkAppCategorySettingsImpl::DeleteCategoryCmdL |
|
354 // ----------------------------------------------------------------------------- |
|
355 // |
|
356 void CLmkAppCategorySettingsImpl::DeleteCategoryCmdL() |
|
357 { |
|
358 RArray<TPosLmItemId>& markedItemIds = MarkedItemIdsL(); |
|
359 TInt markedCount = markedItemIds.Count(); |
|
360 |
|
361 if(IsPredefinedCategoryL()) |
|
362 return; |
|
363 |
|
364 if ( markedCount ) |
|
365 { |
|
366 if ( LmkNotes::CategoryConfirmationQueryL( iEnv, markedCount ) ) |
|
367 { |
|
368 StoreIdTobeFocussedAfterDeletion( markedItemIds ); |
|
369 iDeletionHelper.StoreListInformation( *iListBox, ETrue ); |
|
370 iDbUtils->DeleteCategoriesL( markedItemIds ); |
|
371 // wait note |
|
372 iWaitNote = new( ELeave ) CAknWaitDialog( NULL, ETrue ); |
|
373 if ( !iWaitNote->ExecuteLD( R_LMK_DELETING_WAIT_NOTE ) ) |
|
374 { |
|
375 //making iWaitNote null, since framework destroys waitnote |
|
376 //dialog on pressing cancel. |
|
377 iWaitNote = NULL; |
|
378 iDbUtils->CancelLmOperation(); |
|
379 } |
|
380 } |
|
381 |
|
382 } |
|
383 else |
|
384 { |
|
385 // One item only |
|
386 RArray<TPosLmItemId> categoryIdArray( 1 ); |
|
387 CleanupClosePushL( categoryIdArray ); |
|
388 User::LeaveIfError( categoryIdArray.Append( SelectedIdL() ) ); |
|
389 if ( LmkNotes::CategoryConfirmationQueryL( iEnv, 1 ) ) |
|
390 { |
|
391 iDeletionHelper.StoreListInformation( *iListBox, EFalse ); |
|
392 iDbUtils->DeleteCategoriesL( categoryIdArray ); |
|
393 } |
|
394 CleanupStack::PopAndDestroy( 1 ); // categoryIdArray |
|
395 |
|
396 } |
|
397 } |
|
398 |
|
399 // ----------------------------------------------------------------------------- |
|
400 // CLmkAppCategorySettingsImpl::HandleEventListReadyL |
|
401 // ----------------------------------------------------------------------------- |
|
402 // |
|
403 TBool CLmkAppCategorySettingsImpl::HandleEventListReadyL() |
|
404 { |
|
405 // Possibly user-initiated delete finished --> if yes, update the list: |
|
406 TBool retVal; |
|
407 if( iNewListBoxItemAdded ) |
|
408 { |
|
409 TPosLmItemId lmkItemId = iDbUtils->CategoryIdL(iDb, *iBuffer); |
|
410 TInt listboxIndex = LmItemListProvider().SelectedIndex(lmkItemId); |
|
411 if ( listboxIndex == KLmkInValidIndex ) |
|
412 { |
|
413 retVal = EFalse; |
|
414 return retVal; |
|
415 } |
|
416 /* This line is added to hold the current before changing |
|
417 * the selection with the new one. |
|
418 */ |
|
419 iListBox->HandleItemAdditionL(); |
|
420 iListBox->SetCurrentItemIndex( listboxIndex ); |
|
421 UpdateMarkIndexAfterAdditionL( listboxIndex ); |
|
422 iListBox->DrawDeferred(); |
|
423 iNewListBoxItemAdded = EFalse; |
|
424 retVal = ETrue; |
|
425 } |
|
426 else |
|
427 { |
|
428 retVal = iDeletionHelper.UpdateListIfDeleteHappenedL(); |
|
429 if( retVal ) |
|
430 { |
|
431 //delete has been performed, reset the focus. |
|
432 SetFocusToItemAfterDeletionOfMarkedItems(); |
|
433 } |
|
434 iListBox->DrawDeferred(); |
|
435 } |
|
436 return retVal; |
|
437 } |
|
438 // ----------------------------------------------------------------------------- |
|
439 // CLmkAppCategorySettingsImpl::HandleLmCreated |
|
440 // ----------------------------------------------------------------------------- |
|
441 // |
|
442 void CLmkAppCategorySettingsImpl::HandleLmCreated(TPosLmItemId aNewLmkItemId) |
|
443 { |
|
444 iNewLmkItemId = aNewLmkItemId; |
|
445 iNewListBoxItemAdded = ETrue; |
|
446 } |
|
447 // End of File |