|
1 /* |
|
2 * Copyright (c) 2005 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: LandmarksUi Content File - |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 // INCLUDE FILES |
|
24 #include <e32def.h> |
|
25 #include <avkon.hrh> |
|
26 #include <aknViewAppUi.h> |
|
27 #include <AknsUtils.h> |
|
28 #include <StringLoader.h> |
|
29 #include <aknnotewrappers.h> |
|
30 #include <eikmenup.h> |
|
31 #include <EPos_CPosLandmarkDatabase.h> |
|
32 #include <lmuirefapp.rsg> |
|
33 #include "lmuirefapp.hrh" |
|
34 #include "CLmkLandmarkSelectorDlg.h" |
|
35 #include "CLmkCategorySelectorDlg.h" |
|
36 #include "LmUiRefAppDocument.h" |
|
37 #include "LmUiRefAppContainer.h" |
|
38 #include "LmUiRefAppUi.h" |
|
39 #include "LmUiRefAppView.h" |
|
40 #include "CLmkEditorDlg.h" |
|
41 #include "TLmkItemIdDbCombiInfo.h" //For multi db support, combiinfo struct |
|
42 |
|
43 #define LMK_PARAMS (CLmkEditorDlg::ELmkOnlyName | CLmkEditorDlg::ELmkCategory | CLmkEditorDlg::ELmkStreet | CLmkEditorDlg::ELmkCity | CLmkEditorDlg::ELmkLatitude| CLmkEditorDlg::ELmkLongitude) |
|
44 |
|
45 #define LMK_PARAMS_DEFAULT CLmkEditorDlg::ELmkAll |
|
46 |
|
47 // ================= MEMBER FUNCTIONS ======================= |
|
48 //------------------------------------------------------------------------- |
|
49 // CLmUiRefAppView::NewLC |
|
50 // Two-phased constructor. |
|
51 //------------------------------------------------------------------------- |
|
52 // |
|
53 CLmUiRefAppView* CLmUiRefAppView::NewLC() |
|
54 { |
|
55 CLmUiRefAppView* self = |
|
56 new( ELeave ) CLmUiRefAppView(); |
|
57 CleanupStack::PushL( self ); |
|
58 self->ConstructL(); |
|
59 return self; |
|
60 } |
|
61 |
|
62 //--------------------------------------------------------------------------- |
|
63 // CLmUiRefAppView::CLmUiRefAppView |
|
64 // C++ default constructor can NOT contain any code, that |
|
65 // might leave. |
|
66 //--------------------------------------------------------------------------- |
|
67 // |
|
68 CLmUiRefAppView::CLmUiRefAppView() |
|
69 { |
|
70 } |
|
71 |
|
72 // -------------------------------------------------------------------------- |
|
73 // CLmUiRefAppView::ConstructL |
|
74 // Symbian 2nd phase constructor can leave. |
|
75 // -------------------------------------------------------------------------- |
|
76 // |
|
77 void CLmUiRefAppView::ConstructL() |
|
78 { |
|
79 BaseConstructL(R_LMUIREFAPP_VIEW); |
|
80 } |
|
81 |
|
82 // -------------------------------------------------------------------------- |
|
83 // CLmUiRefAppView::~CLmUiRefAppView |
|
84 // ------------------------------------------------------------------------ |
|
85 // |
|
86 CLmUiRefAppView::~CLmUiRefAppView() |
|
87 { |
|
88 if ( iContainer ) |
|
89 { |
|
90 AppUi()->RemoveFromViewStack( *this, iContainer ); |
|
91 } |
|
92 delete iContainer; |
|
93 } |
|
94 |
|
95 // -------------------------------------------------------------------------- |
|
96 // TUid CLmUiRefAppView::Id |
|
97 // -------------------------------------------------------------------------- |
|
98 // |
|
99 TUid CLmUiRefAppView::Id() const |
|
100 { |
|
101 return TUid::Uid(ELmUiRefAppView); |
|
102 } |
|
103 |
|
104 // -------------------------------------------------------------------------- |
|
105 // CLmUiRefAppView::HandleCommandL |
|
106 // -------------------------------------------------------------------------- |
|
107 // |
|
108 void CLmUiRefAppView::HandleCommandL( TInt aCommand ) |
|
109 { |
|
110 switch ( aCommand ) |
|
111 { |
|
112 // these all are same: exit |
|
113 case EAknSoftkeyExit: |
|
114 case EAknSoftkeyBack: |
|
115 { |
|
116 AppUi()->HandleCommandL(EEikCmdExit); |
|
117 break; |
|
118 } |
|
119 case ELmUiRefAppCmdDeleteLm: |
|
120 { |
|
121 if (IsLmDbEmptyL()) |
|
122 { |
|
123 // Display some Error Note here |
|
124 iContainer->DrawNow(); |
|
125 return; |
|
126 } |
|
127 if (LaunchLandmarksDialogL() == 0) |
|
128 { |
|
129 // If Selector is cancelled, return to MAIN view |
|
130 iContainer->DrawNow(); |
|
131 return; |
|
132 } |
|
133 // Display Note |
|
134 CEikonEnv* env = CEikonEnv::Static(); |
|
135 HBufC* noteText = NULL; |
|
136 noteText |
|
137 = StringLoader::LoadLC( R_LMUIREFAPP_DELETE_LANDMARK, env ); |
|
138 CAknQueryDialog* query = |
|
139 new( ELeave ) CAknQueryDialog( *noteText ); |
|
140 TInt ret = query->ExecuteLD( R_LMUIREFAPP_QUERY); |
|
141 if (!(ret)) |
|
142 { |
|
143 CleanupStack::PopAndDestroy(noteText); //noteText |
|
144 iContainer->DrawNow(); |
|
145 return; |
|
146 } |
|
147 TPosLmItemId delLmItem = SelectedItem(); |
|
148 ilDb->RemoveLandmarkL(delLmItem); |
|
149 delete ilDb; |
|
150 CleanupStack::PopAndDestroy(noteText); //noteText |
|
151 break; |
|
152 } |
|
153 case ELmUiRefAppCmdNewLm : |
|
154 { |
|
155 //if to be used later on or commented because of an Error. |
|
156 NewLmCmdL(); |
|
157 break; |
|
158 } |
|
159 case ELmUiRefAppCmdViewLm: |
|
160 { |
|
161 /* Launch LM Selector only when Landmarks |
|
162 * Database has any entries |
|
163 */ |
|
164 if (IsLmDbEmptyL()) |
|
165 { |
|
166 // Display some Error Note here |
|
167 iContainer->DrawNow(); |
|
168 return; |
|
169 } |
|
170 if (LaunchLandmarksDialogL() == 0) |
|
171 { |
|
172 // If Selector is cancelled, return to MAIN view |
|
173 iContainer->DrawNow(); |
|
174 return; |
|
175 } |
|
176 |
|
177 CLmkEditorDlg::TLmkEditorParams editParams; |
|
178 editParams.iAttributes = CLmkEditorDlg::ELmkAll; |
|
179 editParams.iEditorMode = CLmkEditorDlg::ELmkViewer; |
|
180 TPosLmItemId lmItem = SelectedItem(); |
|
181 CLmkEditorDlg *dlg = CLmkEditorDlg::NewL(*ilDb, |
|
182 lmItem, |
|
183 editParams); |
|
184 dlg->ExecuteLD(); |
|
185 iContainer->DrawNow(); |
|
186 delete ilDb; |
|
187 break; |
|
188 } |
|
189 |
|
190 case ELmUiRefAppCmdEditLm: |
|
191 { |
|
192 if (IsLmDbEmptyL()) |
|
193 { |
|
194 // Display some Error Note here |
|
195 iContainer->DrawNow(); |
|
196 return; |
|
197 } |
|
198 if (LaunchLandmarksDialogL() == 0) |
|
199 { |
|
200 // If Selector is cancelled, return to MAIN view |
|
201 iContainer->DrawNow(); |
|
202 return; |
|
203 } |
|
204 CPosLandmark* landmarkedi = NULL; |
|
205 ExecuteLmEditorL(landmarkedi, *ilDb); |
|
206 // Refresh |
|
207 iContainer->DrawNow(); |
|
208 delete ilDb; |
|
209 break; |
|
210 } |
|
211 case ELmUiRefAppCmdMultiLmSelector: |
|
212 { |
|
213 if ( IsLmDbEmptyL() ) |
|
214 { |
|
215 // Display some Error Note here |
|
216 iContainer->DrawNow(); |
|
217 return; |
|
218 } |
|
219 |
|
220 if ( LaunchMultiLandmarkSelectorDialogL() == 0 ) |
|
221 { |
|
222 // If Selector is cancelled, return to MAIN view |
|
223 iContainer->DrawNow(); |
|
224 return; |
|
225 } |
|
226 break; |
|
227 } |
|
228 case ELmUiRefAppCmdMultiCatSelector: |
|
229 { |
|
230 if ( IsLmDbEmptyL() ) |
|
231 { |
|
232 // Display some Error Note here |
|
233 iContainer->DrawNow(); |
|
234 return; |
|
235 } |
|
236 |
|
237 if ( LaunchMultiCategorySelectorDialogL() == 0 ) |
|
238 { |
|
239 // If Selector is cancelled, return to MAIN view |
|
240 iContainer->DrawNow(); |
|
241 return; |
|
242 } |
|
243 break; |
|
244 } |
|
245 case ELmUiRefAppCmdSingleCatSelector: |
|
246 { |
|
247 if ( IsLmDbEmptyL() ) |
|
248 { |
|
249 // Display some Error Note here |
|
250 iContainer->DrawNow(); |
|
251 return; |
|
252 } |
|
253 |
|
254 if ( LaunchSingleCategoeyDialogL() == 0 ) |
|
255 { |
|
256 // If Selector is cancelled, return to MAIN view |
|
257 iContainer->DrawNow(); |
|
258 return; |
|
259 } |
|
260 // Refresh view if needed |
|
261 iContainer->DrawNow(); |
|
262 delete ilDb; |
|
263 break; |
|
264 } |
|
265 default: |
|
266 break; |
|
267 } |
|
268 } |
|
269 |
|
270 // -------------------------------------------------------------------------- |
|
271 // CLmUiRefAppView::NewLmCmdL() |
|
272 // -------------------------------------------------------------------------- |
|
273 // |
|
274 void CLmUiRefAppView::NewLmCmdL() |
|
275 { |
|
276 CPosLandmark* landmark = CPosLandmark::NewL(); |
|
277 CleanupStack::PushL( landmark ); |
|
278 CLmUiRefAppUi* lmUiAppUi = static_cast<CLmUiRefAppUi*>( ViewAppUi() ); |
|
279 CPosLandmarkDatabase& iaDb = (lmUiAppUi->Document().LmDb()); |
|
280 ExecuteLmEditorL( landmark, iaDb ); |
|
281 CleanupStack::PopAndDestroy( landmark ); |
|
282 } |
|
283 |
|
284 // ----------------------------------------------------------------------------- |
|
285 // CLmUiRefAppView::ExecuteLmEditorL() |
|
286 // ----------------------------------------------------------------------------- |
|
287 void CLmUiRefAppView::ExecuteLmEditorL( |
|
288 CPosLandmark* aLandmark, CPosLandmarkDatabase& aDb) |
|
289 { |
|
290 CLmkEditorDlg::TLmkEditorParams editParams; |
|
291 editParams.iAttributes = LMK_PARAMS_DEFAULT; |
|
292 editParams.iEditorMode = CLmkEditorDlg::ELmkEditor; |
|
293 TPosLmItemId lmItem = SelectedItem(); |
|
294 if (aLandmark) |
|
295 { |
|
296 CLmkEditorDlg *dlg = CLmkEditorDlg::NewL(aDb, *aLandmark, editParams); |
|
297 dlg->ExecuteLD(); |
|
298 } |
|
299 else |
|
300 { |
|
301 CLmkEditorDlg *dlg = CLmkEditorDlg::NewL(aDb, lmItem, editParams); |
|
302 dlg->ExecuteLD(); |
|
303 } |
|
304 } |
|
305 |
|
306 // -------------------------------------------------------------------------- |
|
307 // CLmUiRefAppView::DoActivateL |
|
308 // -------------------------------------------------------------------------- |
|
309 // |
|
310 void CLmUiRefAppView::DoActivateL( |
|
311 const TVwsViewId& /*aPrevViewId*/, |
|
312 TUid /*aCustomMessageId*/, |
|
313 const TDesC8& /*aCustomMessage*/ ) |
|
314 { |
|
315 if ( !iContainer ) |
|
316 { |
|
317 iContainer = CLmUiRefAppContainer::NewL(this, ClientRect() ); |
|
318 AppUi()->AddToStackL( *this, iContainer ); |
|
319 } |
|
320 } |
|
321 |
|
322 // -------------------------------------------------------------------------- |
|
323 // CLmUiRefAppView::DoDeactivate |
|
324 // -------------------------------------------------------------------------- |
|
325 // |
|
326 void CLmUiRefAppView::DoDeactivate() |
|
327 { |
|
328 if ( iContainer ) |
|
329 { |
|
330 AppUi()->RemoveFromViewStack( *this, iContainer ); |
|
331 } |
|
332 delete iContainer; |
|
333 iContainer = NULL; |
|
334 } |
|
335 |
|
336 // -------------------------------------------------------------------------- |
|
337 // CLmUiRefAppView::LaunchLandmarksDialogL() |
|
338 // -------------------------------------------------------------------------- |
|
339 // |
|
340 TInt CLmUiRefAppView::LaunchLandmarksDialogL() |
|
341 { |
|
342 // Launch LMK Selector |
|
343 iLmkSelectDlg = CLmkLandmarkSelectorDlg::NewL(); |
|
344 iLmkSelectDlg->SetMopParent(this); |
|
345 TLmkItemIdDbCombiInfo selItem; |
|
346 TInt retVal = iLmkSelectDlg->ExecuteLD( selItem ); |
|
347 if (retVal !=0) |
|
348 { |
|
349 iSelectedItem = selItem.GetItemId(); |
|
350 ilDb = selItem.GetLmDb(); |
|
351 } |
|
352 return retVal; |
|
353 } |
|
354 |
|
355 // -------------------------------------------------------------------------- |
|
356 // CLmUiRefAppView::ViewAppUi() |
|
357 // -------------------------------------------------------------------------- |
|
358 // |
|
359 CAknViewAppUi* CLmUiRefAppView::ViewAppUi() |
|
360 { |
|
361 return static_cast<CAknViewAppUi*>( iAvkonAppUi ); |
|
362 } |
|
363 |
|
364 // -------------------------------------------------------------------------- |
|
365 // CLmUiRefAppView::SelectedItem() |
|
366 // -------------------------------------------------------------------------- |
|
367 // |
|
368 TPosLmItemId CLmUiRefAppView::SelectedItem() const |
|
369 { |
|
370 return iSelectedItem; |
|
371 } |
|
372 |
|
373 // -------------------------------------------------------------------------- |
|
374 // CLmUiRefAppView::IsLmDbEmptyL() |
|
375 // -------------------------------------------------------------------------- |
|
376 // |
|
377 TBool CLmUiRefAppView::IsLmDbEmptyL() |
|
378 { |
|
379 CPosLmItemIterator* itemIterator = NULL;CLmUiRefAppUi* lmUiAppUi = static_cast<CLmUiRefAppUi*>( ViewAppUi() ); |
|
380 CPosLandmarkDatabase& iaDb = lmUiAppUi->Document().LmDb(); |
|
381 |
|
382 itemIterator = iaDb.LandmarkIteratorL(); |
|
383 |
|
384 CleanupStack::PushL(itemIterator); |
|
385 itemIterator->Reset(); |
|
386 TUint nrOfItems = itemIterator->NumOfItemsL(); |
|
387 CleanupStack::PopAndDestroy(itemIterator); |
|
388 if (nrOfItems == 0) |
|
389 { |
|
390 return ETrue; |
|
391 } |
|
392 return EFalse; |
|
393 } |
|
394 |
|
395 // --------------------------------------------------------- |
|
396 // CLmkByLmView::DynInitMenuPaneL |
|
397 // --------------------------------------------------------- |
|
398 // |
|
399 void CLmUiRefAppView::DynInitMenuPaneL( |
|
400 TInt aResourceId, |
|
401 CEikMenuPane* aMenuPane ) |
|
402 { |
|
403 switch ( aResourceId ) |
|
404 { |
|
405 case R_LMUIREFAPP_MENU1: |
|
406 { |
|
407 if (IsLmDbEmptyL()) |
|
408 { |
|
409 // Show NEW LM Menu Item |
|
410 aMenuPane->SetItemDimmed( ELmUiRefAppCmdEditLm, ETrue ); |
|
411 aMenuPane->SetItemDimmed( ELmUiRefAppCmdViewLm, ETrue ); |
|
412 aMenuPane->SetItemDimmed( ELmUiRefAppCmdDeleteLm, ETrue ); |
|
413 } |
|
414 break; |
|
415 } |
|
416 default: |
|
417 { |
|
418 break; |
|
419 } |
|
420 } |
|
421 } |
|
422 // -------------------------------------------------------------------------- |
|
423 // CLmUiRefAppView::LaunchMultiLandmarkSelectorDialogL() |
|
424 // -------------------------------------------------------------------------- |
|
425 // |
|
426 TInt CLmUiRefAppView::LaunchMultiLandmarkSelectorDialogL() |
|
427 { |
|
428 // Launch LMK Selector |
|
429 iLmkSelectDlg = CLmkLandmarkSelectorDlg::NewL(); |
|
430 iLmkSelectDlg->SetMopParent(this); |
|
431 RArray<TLmkItemIdDbCombiInfo> selItemArray; |
|
432 TInt retVal = iLmkSelectDlg->ExecuteLD( selItemArray ); |
|
433 TInt count = selItemArray.Count(); |
|
434 if ( count > 0 ) |
|
435 { |
|
436 CPosLandmarkDatabase* pDb = selItemArray[0].GetLmDb(); |
|
437 delete( pDb ); |
|
438 } |
|
439 selItemArray.Close(); |
|
440 return retVal; |
|
441 } |
|
442 |
|
443 //-------------------------------------------------------------------------- |
|
444 // CLmUiRefAppView::LaunchLandmarksDialogL() |
|
445 // -------------------------------------------------------------------------- |
|
446 // |
|
447 TInt CLmUiRefAppView::LaunchMultiCategorySelectorDialogL() |
|
448 { |
|
449 // Launch multiple Category Selector |
|
450 iCategorySelectDlg = CLmkCategorySelectorDlg::NewL(); |
|
451 iCategorySelectDlg->SetMopParent(this); |
|
452 RArray<TLmkItemIdDbCombiInfo> selItemArray; |
|
453 TInt retVal = iCategorySelectDlg->ExecuteLD( selItemArray ); |
|
454 TInt count = selItemArray.Count(); |
|
455 if ( count > 0 ) |
|
456 { |
|
457 CPosLandmarkDatabase* pDb = selItemArray[0].GetLmDb(); |
|
458 delete( pDb ); |
|
459 } |
|
460 selItemArray.Close(); |
|
461 return retVal; |
|
462 } |
|
463 |
|
464 // -------------------------------------------------------------------------- |
|
465 // CLmUiRefAppView::LaunchSingleCategoeyDialogL() |
|
466 // -------------------------------------------------------------------------- |
|
467 // |
|
468 TInt CLmUiRefAppView::LaunchSingleCategoeyDialogL() |
|
469 { |
|
470 // Launch single category selector |
|
471 iCategorySelectDlg = CLmkCategorySelectorDlg::NewL(); |
|
472 iCategorySelectDlg->SetMopParent(this); |
|
473 TLmkItemIdDbCombiInfo selItem; |
|
474 TInt retVal = iCategorySelectDlg->ExecuteLD( selItem ); |
|
475 if (retVal !=0) |
|
476 { |
|
477 iSelectedItem = selItem.GetItemId(); |
|
478 ilDb = selItem.GetLmDb(); |
|
479 } |
|
480 return retVal; |
|
481 } |
|
482 |
|
483 |
|
484 // End of File |