|
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: Provides blid main view class methods. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <blid.rsg> |
|
21 #include <EPos_CPosLandmarkDatabase.h> |
|
22 #include <eikmenub.h> // CEikMenuBar |
|
23 #include <avkon.hrh> |
|
24 #include <aknViewAppUi.h> |
|
25 #include <AknQueryDialog.h> |
|
26 #include <StringLoader.h> |
|
27 #include <AknsConstants.h> |
|
28 #include "Blid.hrh" |
|
29 #include "CBlidSavedWayptsContainer.h" |
|
30 #include "CBlidEng.h" |
|
31 #include "CBlidDocument.h" |
|
32 #include "MBlidLocation.h" |
|
33 #include "CBlidAppUi.h" |
|
34 #include "CBlidSavedWayptsView.h" |
|
35 #include "aknlists.h" |
|
36 #include "CLmkEditorDlg.h" |
|
37 #include "bliduiconsts.h" |
|
38 |
|
39 |
|
40 //CONSTANTS |
|
41 enum TPanicCode |
|
42 { |
|
43 KBlidNullPointer = 1 |
|
44 }; |
|
45 |
|
46 |
|
47 // ================= MEMBER FUNCTIONS ======================= |
|
48 // ---------------------------------------------------------------------------- |
|
49 // CBlidSavedWayptsView::NewLC |
|
50 // Two-phased constructor. |
|
51 // ---------------------------------------------------------------------------- |
|
52 // |
|
53 CBlidSavedWayptsView* CBlidSavedWayptsView::NewLC( MKeyProcessor& aKeyProcessor ) |
|
54 { |
|
55 CBlidSavedWayptsView* self = new (ELeave) CBlidSavedWayptsView(aKeyProcessor); |
|
56 CleanupStack::PushL( self ); |
|
57 self->ConstructL(); |
|
58 return self; |
|
59 } |
|
60 // ---------------------------------------------------------------------------- |
|
61 // CBlidSavedWayptsView::CBlidSavedWayptsView |
|
62 // C++ default constructor can NOT contain any code, that |
|
63 // might leave. |
|
64 // ---------------------------------------------------------------------------- |
|
65 // |
|
66 CBlidSavedWayptsView::CBlidSavedWayptsView( MKeyProcessor& aKeyProcessor ): |
|
67 CBlidBaseView( aKeyProcessor ) |
|
68 { |
|
69 } |
|
70 |
|
71 // ---------------------------------------------------------------------------- |
|
72 // CBlidSavedWayptsView::ConstructL(const TRect& aRect) |
|
73 // Symbian 2nd phase constructor can leave. |
|
74 // ---------------------------------------------------------------------------- |
|
75 // |
|
76 void CBlidSavedWayptsView::ConstructL() |
|
77 { |
|
78 BaseConstructL( R_BLID_SAVEDWAYPTS_VIEW ); |
|
79 |
|
80 iSettings = iEngine->SettingsModel(); |
|
81 __ASSERT_DEBUG(iSettings, |
|
82 User::Panic(_L("CBlidSavedWayptsView"), |
|
83 KBlidNullPointer)); |
|
84 } |
|
85 |
|
86 // ---------------------------------------------------------------------------- |
|
87 // CBlidMainView::~CBlidSavedWayptsView |
|
88 // ---------------------------------------------------------------------------- |
|
89 // |
|
90 CBlidSavedWayptsView::~CBlidSavedWayptsView() |
|
91 { |
|
92 if ( iContainer ) |
|
93 { |
|
94 static_cast<CBlidAppUi*>(AppUi())->RemoveFromViewStack( *this, iContainer ); |
|
95 } |
|
96 |
|
97 delete iContainer; |
|
98 } |
|
99 |
|
100 // --------------------------------------------------------- |
|
101 // CBlidSavedWayptsView::NotifyL |
|
102 // --------------------------------------------------------- |
|
103 // |
|
104 void CBlidSavedWayptsView::NotifyL( const TBool aOnlineMode ) |
|
105 { |
|
106 if( iContainer ) |
|
107 { |
|
108 iContainer->UpdateL(); |
|
109 } |
|
110 CBlidBaseView::NotifyL( aOnlineMode ); |
|
111 } |
|
112 |
|
113 // ---------------------------------------------------------------------------- |
|
114 // TUid CBlidSavedWayptsView::Id |
|
115 // ---------------------------------------------------------------------------- |
|
116 // |
|
117 TUid CBlidSavedWayptsView::Id() const |
|
118 { |
|
119 return TUid::Uid(EBlidSavedWayptsView); |
|
120 } |
|
121 |
|
122 // ---------------------------------------------------------------------------- |
|
123 // CBlidSavedWayptsView::HandleCommandL |
|
124 // ---------------------------------------------------------------------------- |
|
125 // |
|
126 void CBlidSavedWayptsView::HandleCommandL(TInt aCommand) |
|
127 { |
|
128 iContainer-> HandleMarkCommandL( aCommand ); |
|
129 |
|
130 switch ( aCommand ) |
|
131 { |
|
132 case EAknSoftkeyBack: |
|
133 { |
|
134 static_cast<CBlidAppUi*>(AppUi())->ActivateLocalViewL( iPreviousViewid.iViewUid ); |
|
135 break; |
|
136 } |
|
137 case EBlidCmdRenameWaypt: |
|
138 { |
|
139 if(RenameWaypointL()) |
|
140 { |
|
141 static_cast<CBlidDocument*>(AppUi()->Document())->SaveL(); |
|
142 } |
|
143 break; |
|
144 } |
|
145 case EBlidCmdDeleteWaypt: |
|
146 { |
|
147 HandleWaypointsDeletionL(); |
|
148 break; |
|
149 } |
|
150 default: |
|
151 { |
|
152 static_cast<CBlidAppUi*>(AppUi())->HandleCommandL( aCommand ); |
|
153 break; |
|
154 } |
|
155 } // switch |
|
156 |
|
157 if( iContainer ) |
|
158 { |
|
159 iContainer->UpdateL(); |
|
160 } |
|
161 } |
|
162 |
|
163 // ---------------------------------------------------------------------------- |
|
164 // CBlidSavedWayptsView::DoActivateL |
|
165 // ---------------------------------------------------------------------------- |
|
166 // |
|
167 void CBlidSavedWayptsView::DoActivateL( |
|
168 const TVwsViewId& aPrevViewId,TUid /*aCustomMessageId*/, |
|
169 const TDesC8& /*aCustomMessage*/) |
|
170 { |
|
171 #ifdef _DEBUG |
|
172 RDebug::Print(_L("CBlidSavedWayptsView::DoActivateL() called")); |
|
173 #endif |
|
174 |
|
175 if ( !iContainer ) |
|
176 { |
|
177 iContainer = CBlidSavedWayptsContainer::NewL(*this, this, ClientRect(), |
|
178 iLocation, iSettings,iRouter, *this); |
|
179 static_cast<CBlidAppUi*>(AppUi())->AddToStackL( *this, iContainer ); |
|
180 iLocation->SetObserver(*this, EBlidSavedWayptsView); |
|
181 if(!iMSKVisible) |
|
182 { |
|
183 SetMSKVisible(); |
|
184 } |
|
185 MenuBar()->SetContextMenuTitleResourceId(R_BLID_SAVEDWAYPTS_VIEW_OK_MENUBAR); |
|
186 |
|
187 #ifdef RD_SCALABLE_UI_V2 |
|
188 iContainer->SetListBoxObserver(this); |
|
189 #endif // RD_SCALABLE_UI_V2 |
|
190 } |
|
191 iPreviousViewid = aPrevViewId; |
|
192 } |
|
193 |
|
194 // ---------------------------------------------------------------------------- |
|
195 // CBlidSavedWayptsView::DoDeactivate |
|
196 // ---------------------------------------------------------------------------- |
|
197 // |
|
198 void CBlidSavedWayptsView::DoDeactivate() |
|
199 { |
|
200 if ( iContainer ) |
|
201 { |
|
202 static_cast<CBlidAppUi*>(AppUi())->RemoveFromViewStack( *this, iContainer ); |
|
203 } |
|
204 delete iContainer; |
|
205 iContainer = NULL; |
|
206 } |
|
207 |
|
208 // --------------------------------------------------------- |
|
209 // CBlidSavedWayptsView::DynInitMenuPaneL |
|
210 // --------------------------------------------------------- |
|
211 // |
|
212 void CBlidSavedWayptsView::DynInitMenuPaneL( |
|
213 TInt aResourceId, CEikMenuPane* aMenuPane ) |
|
214 { |
|
215 AknSelectionService::HandleMarkableListDynInitMenuPane(aResourceId, |
|
216 aMenuPane, |
|
217 iContainer->iListBox); |
|
218 switch(aResourceId) |
|
219 { |
|
220 case R_BLID_SAVEDWAYPTS_VIEW_OK_MENU: |
|
221 case R_BLID_SAVEDWAYPTS_MENU: |
|
222 { |
|
223 if( iRouter->Count() <= 0 ) |
|
224 { |
|
225 aMenuPane->SetItemDimmed( EBlidCmdRenameWaypt, ETrue ); |
|
226 aMenuPane->SetItemDimmed( EBlidCmdDeleteWaypt, ETrue ); |
|
227 } |
|
228 |
|
229 const CArrayFix<TInt>& indexes = *iContainer->iListBox->SelectionIndexes(); |
|
230 if(indexes.Count() != 0) |
|
231 { |
|
232 aMenuPane->SetItemDimmed( EBlidCmdRenameWaypt, ETrue ); |
|
233 } |
|
234 |
|
235 break; |
|
236 } |
|
237 default: |
|
238 { |
|
239 break; |
|
240 } |
|
241 } |
|
242 } |
|
243 |
|
244 // ---------------------------------------------------------------------------- |
|
245 // CBlidSavedWayptsView::RenameWaypointL() |
|
246 // ---------------------------------------------------------------------------- |
|
247 // |
|
248 TBool CBlidSavedWayptsView::RenameWaypointL() |
|
249 { |
|
250 TInt index(0); |
|
251 TBuf<KBlidWaypointNameMaxLen> textData; |
|
252 index = iContainer->SelectedRow(); |
|
253 TNamedCoordinate currentWaypoint; |
|
254 if(index < iRouter->Count() && index >= 0) |
|
255 { |
|
256 currentWaypoint = iRouter->At(index); |
|
257 } |
|
258 HBufC* waypointName = currentWaypoint.Name(); |
|
259 textData = waypointName->Des(); |
|
260 TInt errorCode(KErrNone); |
|
261 TBool returnValue(ETrue); |
|
262 TInt removedIndex; |
|
263 |
|
264 do |
|
265 { |
|
266 if(errorCode != KErrNone) |
|
267 { |
|
268 delete waypointName; |
|
269 return EFalse; |
|
270 } |
|
271 CAknTextQueryDialog* dlg = new(ELeave) CAknTextQueryDialog(textData, |
|
272 CAknQueryDialog::ENoTone); |
|
273 |
|
274 if (!dlg->ExecuteLD(R_BLID_WAYPOINT_QUERY) || |
|
275 (waypointName->Compare(textData) == 0 ) ) |
|
276 { |
|
277 delete waypointName; |
|
278 return EFalse; |
|
279 } |
|
280 |
|
281 }while( CheckIfExistL( textData, errorCode, removedIndex ) ); |
|
282 |
|
283 delete waypointName; |
|
284 |
|
285 if ( index == KErrCancel ) |
|
286 { |
|
287 return EFalse; |
|
288 } |
|
289 |
|
290 TInt retVal(KErrNone); |
|
291 if ( index >=0 ) |
|
292 { |
|
293 //Check if CheckIfExistL has removed a waypoint below index |
|
294 if((removedIndex != -1 ) && |
|
295 (removedIndex < index) ) |
|
296 { |
|
297 --index; |
|
298 } |
|
299 |
|
300 |
|
301 retVal = iRouter->RemoveL( index ); |
|
302 if(retVal == KErrDiskFull) |
|
303 { |
|
304 returnValue = EFalse; |
|
305 BlidNotes::OutOfMemoryNoteL(); |
|
306 } |
|
307 } |
|
308 |
|
309 if(retVal == KErrNone) |
|
310 { |
|
311 TNamedCoordinate* waypoint = new(ELeave)TNamedCoordinate(); |
|
312 CleanupStack::PushL( waypoint ); |
|
313 waypoint->SetName( textData ); |
|
314 TPosition position = iLocation->GetCurrentPosition(); |
|
315 waypoint->SetCoordinate( position.Latitude(), |
|
316 position.Longitude(), |
|
317 position.Altitude() ); |
|
318 position.SetHorizontalAccuracy(position.HorizontalAccuracy()); |
|
319 waypoint->SetAccuracy(position.HorizontalAccuracy()); |
|
320 //iRouter takes waypoint's ownership |
|
321 TInt retVal = iRouter->AppendL( waypoint, ETrue ); |
|
322 if(retVal == KErrDiskFull) |
|
323 { |
|
324 returnValue = EFalse; |
|
325 BlidNotes::OutOfMemoryNoteL(); |
|
326 } |
|
327 CleanupStack::Pop(); //waypoint |
|
328 // Set the actual index of renamed wp |
|
329 retVal = iRouter->FindWaypointIndex( waypoint ); |
|
330 if( retVal != KErrNotFound ) |
|
331 { |
|
332 iContainer->iListBox->SetCurrentItemIndex(retVal); |
|
333 } |
|
334 } |
|
335 return returnValue; |
|
336 } |
|
337 |
|
338 // ---------------------------------------------------------------------------- |
|
339 // CBlidSavedWayptsView::DeleteWaypointL() |
|
340 // ---------------------------------------------------------------------------- |
|
341 // |
|
342 TBool CBlidSavedWayptsView::DeleteWaypointL(TInt aIndex) |
|
343 { |
|
344 if ( aIndex == KErrCancel ) |
|
345 { |
|
346 return EFalse; |
|
347 } |
|
348 |
|
349 if ( aIndex >=0 ) |
|
350 { |
|
351 TInt retVal = iRouter->RemoveL( aIndex ); |
|
352 if(retVal == KErrDiskFull) |
|
353 { |
|
354 BlidNotes::OutOfMemoryNoteL(); |
|
355 return EFalse; |
|
356 } |
|
357 if(iRouter->Count() <= 0) |
|
358 { |
|
359 SetMSKNotVisible(); |
|
360 } |
|
361 } |
|
362 return ETrue; |
|
363 } |
|
364 |
|
365 |
|
366 // ---------------------------------------------------------------------------- |
|
367 // CBlidSavedWayptsView::DeleteWaypointsL() |
|
368 // ---------------------------------------------------------------------------- |
|
369 // |
|
370 TBool CBlidSavedWayptsView::DeleteWaypointsL(const CArrayFix<TInt>& aIndexes) |
|
371 { |
|
372 const TInt count( aIndexes.Count() ); |
|
373 TBool retVal = 0; |
|
374 TBool deleteOpRetVal(ETrue); |
|
375 |
|
376 if(count == 1) |
|
377 { |
|
378 TInt index = aIndexes.At( 0 ); |
|
379 TDesC* name = iRouter->At( index ).Name(); |
|
380 CleanupStack::PushL(name); |
|
381 HBufC* buffer = StringLoader::LoadL(R_BLID_QUERY_DELETE_WAYPOINT, |
|
382 (*name), |
|
383 iCoeEnv); |
|
384 CAknQueryDialog* dlg = CAknQueryDialog::NewL(); |
|
385 CleanupStack::PushL(dlg); |
|
386 dlg->SetPromptL(buffer->Des()); |
|
387 retVal = dlg->ExecuteLD(R_BLID_CONFIRMATION_QUERY); |
|
388 if( retVal ) |
|
389 { |
|
390 deleteOpRetVal = DeleteWaypointL(index); |
|
391 } |
|
392 else |
|
393 { |
|
394 deleteOpRetVal = EFalse; |
|
395 } |
|
396 CleanupStack::Pop(2); |
|
397 delete buffer; |
|
398 delete name; |
|
399 if((iRouter->Count() != 0) && (index == iRouter->Count())) |
|
400 { |
|
401 iContainer->iListBox->SetCurrentItemIndex(index-1); |
|
402 } |
|
403 } |
|
404 else |
|
405 { |
|
406 HBufC* buffer = StringLoader::LoadL(R_BLID_QUERY_DELETE_WAYPOINTS, |
|
407 count, |
|
408 iCoeEnv); |
|
409 CleanupStack::PushL(buffer); |
|
410 CAknQueryDialog* dlg = CAknQueryDialog::NewL(); |
|
411 CleanupStack::PushL(dlg); |
|
412 dlg->SetPromptL(buffer->Des()); |
|
413 retVal = dlg->ExecuteLD(R_BLID_CONFIRMATION_QUERY); |
|
414 if( retVal ) |
|
415 { |
|
416 TInt markedArray[KMaxNumberOfWaypoints] = {0}; |
|
417 |
|
418 for ( TInt i(0 ); i < count; ++i ) |
|
419 { |
|
420 TInt ix = aIndexes.At( i ); |
|
421 markedArray[ix] = 1; |
|
422 } |
|
423 TInt waypointCount = iRouter->Count(); |
|
424 for( TInt i= waypointCount-1; i >= 0; --i ) |
|
425 { |
|
426 if(markedArray[i]) |
|
427 { |
|
428 deleteOpRetVal = DeleteWaypointL(i); |
|
429 if(!deleteOpRetVal) |
|
430 { |
|
431 break; |
|
432 } |
|
433 } |
|
434 } |
|
435 } |
|
436 else |
|
437 { |
|
438 deleteOpRetVal = EFalse; |
|
439 } |
|
440 CleanupStack::Pop(2); // buffer, dlg |
|
441 delete buffer; |
|
442 TInt index = iContainer->iListBox->CurrentItemIndex(); |
|
443 if( (iRouter->Count()!=0) && (index == -1) ) |
|
444 { |
|
445 iContainer->iListBox->SetCurrentItemIndex(iRouter->Count() - 1); |
|
446 } |
|
447 } |
|
448 return deleteOpRetVal; |
|
449 } |
|
450 |
|
451 // ---------------------------------------------------------------------------- |
|
452 // CBlidSavedWayptsView::HandleWaypointsDeletionL() |
|
453 // ---------------------------------------------------------------------------- |
|
454 // |
|
455 void CBlidSavedWayptsView::HandleWaypointsDeletionL() |
|
456 { |
|
457 const CArrayFix<TInt>& indexes = *iContainer->iListBox->SelectionIndexes(); |
|
458 TBool retVal(ETrue); |
|
459 if (indexes.Count() == 0) |
|
460 { |
|
461 TInt index(0); |
|
462 index = iContainer->SelectedRow(); |
|
463 |
|
464 TDesC* name; |
|
465 if( index < 0 ) |
|
466 { |
|
467 return; |
|
468 } |
|
469 name = iRouter->At( index ).Name(); |
|
470 CleanupStack::PushL(name); |
|
471 HBufC* buffer = StringLoader::LoadL(R_BLID_QUERY_DELETE_WAYPOINT, |
|
472 (*name), |
|
473 iCoeEnv); |
|
474 CleanupStack::PushL(buffer); |
|
475 CAknQueryDialog* dlg = CAknQueryDialog::NewL(); |
|
476 CleanupStack::PushL(dlg); |
|
477 dlg->SetPromptL(buffer->Des()); |
|
478 if( dlg->ExecuteLD(R_BLID_CONFIRMATION_QUERY) ) |
|
479 { |
|
480 retVal = DeleteWaypointL(index); |
|
481 } |
|
482 else |
|
483 { |
|
484 retVal = EFalse; |
|
485 } |
|
486 CleanupStack::Pop(3); // buffer, dlg, name |
|
487 delete buffer; |
|
488 delete name; |
|
489 if((iRouter->Count()!=0) && (index == iRouter->Count())) |
|
490 { |
|
491 iContainer->iListBox->SetCurrentItemIndex(index-1); |
|
492 } |
|
493 } |
|
494 else |
|
495 { |
|
496 retVal = DeleteWaypointsL(indexes); |
|
497 if( retVal ) |
|
498 { |
|
499 iContainer->iListBox->ClearSelection(); |
|
500 } |
|
501 } |
|
502 if(retVal) |
|
503 { |
|
504 static_cast<CBlidDocument*>(AppUi()->Document())->SaveL(); |
|
505 } |
|
506 } |
|
507 |
|
508 |
|
509 #ifdef RD_SCALABLE_UI_V2 |
|
510 // --------------------------------------------------------------------------- |
|
511 // CBlidSavedWayptsView::HandleListBoxSelectionL |
|
512 // --------------------------------------------------------------------------- |
|
513 // |
|
514 void CBlidSavedWayptsView::HandleListBoxSelectionL() |
|
515 { |
|
516 MenuBar()->TryDisplayContextMenuBarL(); |
|
517 } |
|
518 #endif // RD_SCALABLE_UI_V2 |
|
519 // End of File |