|
1 /* |
|
2 * Copyright (c) 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: Controller class for location UI behavior |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 //debug |
|
21 #include "calendarui_debug.h" |
|
22 |
|
23 #include "calenlocationui.h" |
|
24 #include "calencontroller.h" |
|
25 #include <calencommands.hrh> |
|
26 #include "calenlocationactiveselector.h" |
|
27 #include "calenglobaldata.h" |
|
28 #include "calenlocationutil.h" |
|
29 #include <Calendar.rsg> |
|
30 #include <calencommonui.rsg> |
|
31 #include <calentry.h> |
|
32 #include <CalenInterimUtils2.h> |
|
33 #include <aknnotewrappers.h> |
|
34 #include <aknselectionlist.h> |
|
35 #include <aknPopup.h> |
|
36 #include <aknlists.h> |
|
37 #include <StringLoader.h> |
|
38 #include <sysutil.h> |
|
39 #include <eikenv.h> |
|
40 #include <mnmapview.h> |
|
41 #include <mnproviderfinder.h> |
|
42 #include <EPos_CPosLandmark.h> |
|
43 #include <lbsposition.h> |
|
44 #include <e32math.h> |
|
45 #include <calencontext.h> |
|
46 |
|
47 // CONSTANTS and MACROS |
|
48 _LIT(KComma, ","); |
|
49 _LIT(KNokiaVendorName, "Nokia gate5 GmbH"); |
|
50 const TInt KCalenMaxTextEditorLength(160); |
|
51 |
|
52 // ---------------------------------------------------------------------------- |
|
53 // CCalenLocationUi::NewL |
|
54 // First stage construction |
|
55 // (other items were commented in a header). |
|
56 // ---------------------------------------------------------------------------- |
|
57 // |
|
58 CCalenLocationUi* CCalenLocationUi::NewL( CCalenController& aController ) |
|
59 { |
|
60 TRACE_ENTRY_POINT; |
|
61 |
|
62 CCalenLocationUi* self = new(ELeave) CCalenLocationUi( aController ); |
|
63 CleanupStack::PushL( self ); |
|
64 self->ConstructL(); |
|
65 CleanupStack::Pop( self ); |
|
66 |
|
67 TRACE_EXIT_POINT; |
|
68 return self; |
|
69 } |
|
70 |
|
71 // ---------------------------------------------------------------------------- |
|
72 // CCalenLocationUi::~CCalenLocationUi |
|
73 // Destructor |
|
74 // (other items were commented in a header). |
|
75 // ---------------------------------------------------------------------------- |
|
76 // |
|
77 CCalenLocationUi::~CCalenLocationUi() |
|
78 { |
|
79 TRACE_ENTRY_POINT; |
|
80 if(iLocationSelector) |
|
81 { |
|
82 delete iLocationSelector; |
|
83 } |
|
84 |
|
85 if(iCurrLocAcquisition) |
|
86 { |
|
87 delete iCurrLocAcquisition; |
|
88 } |
|
89 |
|
90 if( iGlobalData ) |
|
91 { |
|
92 iGlobalData->Release(); |
|
93 } |
|
94 |
|
95 if(iLocationText) |
|
96 { |
|
97 delete iLocationText; |
|
98 iLocationText = NULL; |
|
99 } |
|
100 |
|
101 TRACE_EXIT_POINT; |
|
102 } |
|
103 |
|
104 // ---------------------------------------------------------------------------- |
|
105 // CCalenLocationUi::CCalenLocationUi |
|
106 // Constructor |
|
107 // (other items were commented in a header). |
|
108 // ---------------------------------------------------------------------------- |
|
109 // |
|
110 CCalenLocationUi::CCalenLocationUi( CCalenController& aController ) |
|
111 : iController( aController ) |
|
112 { |
|
113 TRACE_ENTRY_POINT; |
|
114 TRACE_EXIT_POINT; |
|
115 } |
|
116 |
|
117 // ---------------------------------------------------------------------------- |
|
118 // CCalenLocationUi::ConstructL |
|
119 // Second stage construction |
|
120 // (other items were commented in a header). |
|
121 // ---------------------------------------------------------------------------- |
|
122 // |
|
123 void CCalenLocationUi::ConstructL() |
|
124 { |
|
125 TRACE_ENTRY_POINT; |
|
126 |
|
127 isCurrLocAvailable = EFalse; |
|
128 iGlobalData = CCalenGlobalData::InstanceL(); |
|
129 iLocationSelector = CCalenLocationActiveSelector::NewL( *this, *this, *iGlobalData); |
|
130 |
|
131 RArray<TCalenNotification> notificationArray; |
|
132 notificationArray.Append( ECalenNotifyEntryClosed ); |
|
133 notificationArray.Append( ECalenNotifyInstanceSaved ); |
|
134 notificationArray.Append( ECalenNotifyDialogClosed ); |
|
135 notificationArray.Append( ECalenNotifyMapClosed ); |
|
136 notificationArray.Append( ECalenNotifyCancelMapLaunch ); |
|
137 notificationArray.Append( ECalenNotifyEntrySaved ); |
|
138 notificationArray.Append( ECalenNotifyEntryDeleted ); |
|
139 |
|
140 iController.RegisterForNotificationsL(this, notificationArray); |
|
141 notificationArray.Reset(); |
|
142 TRACE_EXIT_POINT; |
|
143 } |
|
144 |
|
145 // ---------------------------------------------------------------------------- |
|
146 // CCalenLocationUi::HandleActionUiCommandL |
|
147 // Handles action ui commands |
|
148 // (other items were commented in a header). |
|
149 // ---------------------------------------------------------------------------- |
|
150 // |
|
151 TBool CCalenLocationUi::HandleCommandL( const TCalenCommand& aCommand ) |
|
152 { |
|
153 TRACE_ENTRY_POINT; |
|
154 |
|
155 if(isRequestPending) |
|
156 { |
|
157 // Already one request is being processed, |
|
158 // Ignore this new request |
|
159 return EFalse; |
|
160 } |
|
161 |
|
162 TBool continueCommand(EFalse); |
|
163 TInt command = aCommand.Command(); |
|
164 switch ( command ) |
|
165 { |
|
166 case ECalenGetLocationAndSave: |
|
167 isGetLocationAndSave = ETrue; |
|
168 LaunchMapL(); |
|
169 break; |
|
170 case ECalenGetLocation: |
|
171 LaunchMapL(); |
|
172 break; |
|
173 case ECalenShowLocation: |
|
174 ShowLocationOnMapL(); |
|
175 break; |
|
176 case ECalenGetLocationAndReplace: |
|
177 isGetLocationAndSave = ETrue; |
|
178 isReplaceLocation = ETrue; |
|
179 LaunchMapL(); |
|
180 break; |
|
181 case ECalenShowLocationQuery: |
|
182 { |
|
183 TInt userResponse = ShowDefineLocationQuery(); |
|
184 if(userResponse) |
|
185 { |
|
186 isGetLocationAndSave = ETrue; |
|
187 LaunchMapL(); |
|
188 } |
|
189 else |
|
190 { |
|
191 iController.BroadcastNotification(ECalenNotifyMapClosed); |
|
192 } |
|
193 } |
|
194 break; |
|
195 default: |
|
196 break; |
|
197 } |
|
198 |
|
199 TRACE_EXIT_POINT; |
|
200 return continueCommand; |
|
201 } |
|
202 |
|
203 // ---------------------------------------------------------------------------- |
|
204 // CCalenLocationUi::CalenCommandHandlerExtensionL |
|
205 // |
|
206 // ---------------------------------------------------------------------------- |
|
207 // |
|
208 TAny* CCalenLocationUi::CalenCommandHandlerExtensionL( TUid /*aExtensionUid*/ ) |
|
209 { |
|
210 TRACE_ENTRY_POINT; |
|
211 TRACE_EXIT_POINT; |
|
212 return NULL; |
|
213 } |
|
214 |
|
215 // ---------------------------------------------------------------------------- |
|
216 // CCalenLocationUi::HandleNotification |
|
217 // Handle notifications |
|
218 // (other items were commented in a header). |
|
219 // ---------------------------------------------------------------------------- |
|
220 // |
|
221 void CCalenLocationUi::HandleNotification(const TCalenNotification aNotification ) |
|
222 { |
|
223 TRACE_ENTRY_POINT; |
|
224 MCalenContext& context = iGlobalData->Context(); |
|
225 |
|
226 switch( aNotification ) |
|
227 { |
|
228 case ECalenNotifyEntryClosed: // issued when new entry dialog is cancelled |
|
229 case ECalenNotifyEntrySaved: |
|
230 case ECalenNotifyInstanceSaved: |
|
231 case ECalenNotifyDialogClosed: |
|
232 case ECalenNotifyEntryDeleted: |
|
233 { |
|
234 if(isRequestPending) |
|
235 { |
|
236 iCurrLocAcquisition->CancelRequest(); |
|
237 delete iCurrLocAcquisition; |
|
238 iController.BroadcastNotification(ECalenNotifyMapClosed); |
|
239 } |
|
240 // Delete the landmark object from context |
|
241 context.ResetLandMark(); |
|
242 } |
|
243 break; |
|
244 case ECalenNotifyMapClosed: |
|
245 // Repopulate the current view |
|
246 if(isGetLocationAndSave) |
|
247 { |
|
248 isGetLocationAndSave = EFalse; |
|
249 PIM_TRAPD_HANDLE(iController.IssueCommandL( ECalenStartActiveStep )); |
|
250 } |
|
251 break; |
|
252 case ECalenNotifyCancelMapLaunch: |
|
253 { |
|
254 // Cancel any pending async requests |
|
255 iLocationSelector->DoCancel(); |
|
256 if(iProvider) |
|
257 { |
|
258 delete iProvider; |
|
259 iProvider = NULL; |
|
260 } |
|
261 } |
|
262 break; |
|
263 } |
|
264 |
|
265 TRACE_EXIT_POINT; |
|
266 } |
|
267 |
|
268 // ----------------------------------------------------------------------------- |
|
269 // CCalenLocationUi::RequestCurrenLocationL |
|
270 // It issues asyn request to get the coordinates for current location |
|
271 // (other items were commented in a header). |
|
272 // ----------------------------------------------------------------------------- |
|
273 // |
|
274 void CCalenLocationUi::RequestCurrenLocationL() |
|
275 { |
|
276 TRACE_ENTRY_POINT; |
|
277 |
|
278 iCurrLocAcquisition = CCalenCurrentLocationAcquisition::NewL( *this); |
|
279 isRequestPending = ETrue; |
|
280 iCurrLocAcquisition->RequestL(); |
|
281 |
|
282 TRACE_EXIT_POINT; |
|
283 } |
|
284 |
|
285 // ----------------------------------------------------------------------------- |
|
286 // CCalenLocationUi::NotifyCurrentLocationL |
|
287 // Callback which gets called when async request is complete. |
|
288 // (other items were commented in a header). |
|
289 // ----------------------------------------------------------------------------- |
|
290 // |
|
291 void CCalenLocationUi::NotifyCurrentLocationL() |
|
292 { |
|
293 TRACE_ENTRY_POINT; |
|
294 |
|
295 // Asyn request complete, now get the coordinates of current location |
|
296 TPosition currPosition = iCurrLocAcquisition->CurrentPosition(); |
|
297 delete iCurrLocAcquisition; |
|
298 iCurrPosition = currPosition; |
|
299 isCurrLocAvailable = ETrue; |
|
300 isRequestPending = EFalse; |
|
301 LaunchMapL(currPosition); |
|
302 |
|
303 TRACE_EXIT_POINT; |
|
304 } |
|
305 |
|
306 // ----------------------------------------------------------------------------- |
|
307 // CCalenLocationUi::NotifyCurrentLocationL |
|
308 // Callback function that gets called if there is any error |
|
309 // while fetching coordinates for current location |
|
310 // (other items were commented in a header). |
|
311 // ----------------------------------------------------------------------------- |
|
312 // |
|
313 void CCalenLocationUi::NotifyErrorL(const TInt /* errorCode */) |
|
314 { |
|
315 TRACE_ENTRY_POINT; |
|
316 |
|
317 delete iCurrLocAcquisition; |
|
318 isRequestPending = EFalse; |
|
319 |
|
320 // Error occurred, launch the map with default values |
|
321 LaunchMapL(); |
|
322 |
|
323 TRACE_EXIT_POINT; |
|
324 } |
|
325 |
|
326 // ---------------------------------------------------------------------------- |
|
327 // CCalenLocationUi::LaunchMapL |
|
328 // Launches Map with coords of current location |
|
329 // for the user to select the event location |
|
330 // (other items were commented in a header). |
|
331 // ---------------------------------------------------------------------------- |
|
332 // |
|
333 void CCalenLocationUi::LaunchMapL(TPosition& aPosition) |
|
334 { |
|
335 TRACE_ENTRY_POINT; |
|
336 |
|
337 const CMnProvider::TServices neededServices = CMnProvider::EServiceNavigation | |
|
338 CMnProvider::EServiceMapView ; |
|
339 iProvider = GetFirstProviderL(neededServices); |
|
340 iLocationSelector->SelectL( *iProvider, aPosition, !isGetLocationAndSave ); |
|
341 |
|
342 TRACE_EXIT_POINT; |
|
343 } |
|
344 |
|
345 // ---------------------------------------------------------------------------- |
|
346 // CCalenLocationUi::LaunchMapL |
|
347 // Launches Map with default coords for the user to select the event location |
|
348 // (other items were commented in a header). |
|
349 // ---------------------------------------------------------------------------- |
|
350 // |
|
351 void CCalenLocationUi::LaunchMapL() |
|
352 { |
|
353 TRACE_ENTRY_POINT; |
|
354 |
|
355 const CMnProvider::TServices neededServices = CMnProvider::EServiceNavigation | |
|
356 CMnProvider::EServiceMapView ; |
|
357 iProvider = GetFirstProviderL(neededServices); |
|
358 MCalenContext& context = iGlobalData->Context(); |
|
359 CPosLandmark* landmark = context.GetLandMark(); |
|
360 if(landmark) |
|
361 { |
|
362 { |
|
363 // entry has proepr geovalues, launch the map with that location at the centre |
|
364 iLocationSelector->SelectL( *iProvider, landmark ); |
|
365 } |
|
366 |
|
367 context.ResetLandMark(); |
|
368 } |
|
369 else if(isGetLocationAndSave) // If issued from Day view or event viewer |
|
370 { |
|
371 // Get the entry |
|
372 TCalLocalUid instanceId = context.InstanceId().iEntryLocalUid; |
|
373 CCalEntry* entry = iGlobalData->EntryViewL(context.InstanceId().iColId)->FetchL(instanceId); |
|
374 if(entry) |
|
375 { |
|
376 CleanupStack::PushL( entry ); |
|
377 CCalGeoValue* geoValue = entry->GeoValueL(); |
|
378 TPtrC location = entry->LocationL(); |
|
379 if(geoValue) |
|
380 { |
|
381 // entry has proepr geovalues, launch the map with that location at the centre |
|
382 TReal latitude; |
|
383 TReal longitude; |
|
384 geoValue->GetLatLong(latitude, longitude); |
|
385 TPosition position; |
|
386 position.SetCoordinate(latitude, longitude); |
|
387 CPosLandmark* landmarkToShow = CPosLandmark::NewL(); |
|
388 //TPtrC location = entry->LocationL(); |
|
389 landmarkToShow->SetLandmarkNameL(location); |
|
390 landmarkToShow->SetPositionL(position); |
|
391 delete geoValue; |
|
392 iLocationSelector->SelectL( *iProvider, landmarkToShow ); |
|
393 delete landmarkToShow; |
|
394 } |
|
395 else if(location.Length()) |
|
396 { |
|
397 // Add dummy landmark, so that Maps search box will get filled |
|
398 CPosLandmark* landmarkToShow = CPosLandmark::NewL(); |
|
399 landmarkToShow->SetLandmarkNameL(location); |
|
400 iLocationSelector->SelectL( *iProvider, landmarkToShow ); |
|
401 delete landmarkToShow; |
|
402 } |
|
403 else{ |
|
404 iLocationSelector->SelectL( *iProvider, NULL ); |
|
405 } |
|
406 CleanupStack::PopAndDestroy( entry ); |
|
407 } |
|
408 } |
|
409 else |
|
410 { |
|
411 iLocationSelector->SelectL( *iProvider, NULL ); |
|
412 } |
|
413 |
|
414 TRACE_EXIT_POINT; |
|
415 } |
|
416 |
|
417 // ---------------------------------------------------------------------------- |
|
418 // CCalenLocationUi::ShowLocationOnMapL |
|
419 // Launches Map for the user to show the event location |
|
420 // (other items were commented in a header). |
|
421 // ---------------------------------------------------------------------------- |
|
422 // |
|
423 void CCalenLocationUi::ShowLocationOnMapL() |
|
424 { |
|
425 TRACE_ENTRY_POINT; |
|
426 |
|
427 const CMnProvider::TServices neededServices = CMnProvider::EServiceMapView ; |
|
428 iProvider = GetFirstProviderL(neededServices); |
|
429 |
|
430 iMapView = CMnMapView::NewChainedL( *iProvider ); |
|
431 iMapView->SetExitObserverL(*this); |
|
432 |
|
433 // Get the entry |
|
434 MCalenContext& context = iGlobalData->Context(); |
|
435 CPosLandmark* landmark = context.GetLandMark(); |
|
436 RPointerArray<CPosLandmark> landmarks; |
|
437 |
|
438 if(landmark) |
|
439 { |
|
440 landmarks.Append(landmark); |
|
441 iMapView->AddLandmarksToShowL(landmarks); |
|
442 context.ResetLandMark(); |
|
443 } |
|
444 else |
|
445 { |
|
446 TCalLocalUid instanceId = context.InstanceId().iEntryLocalUid; |
|
447 CCalEntry* entry = iGlobalData->EntryViewL(context.InstanceId().iColId)->FetchL(instanceId); |
|
448 if(entry) |
|
449 { |
|
450 CleanupStack::PushL( entry ); |
|
451 CCalGeoValue* geoValue = entry->GeoValueL(); |
|
452 if(geoValue) |
|
453 { |
|
454 TReal latitude; |
|
455 TReal longitude; |
|
456 geoValue->GetLatLong(latitude, longitude); |
|
457 TPosition position; |
|
458 position.SetCoordinate(latitude, longitude); |
|
459 CPosLandmark* landmarkToShow = CPosLandmark::NewL(); |
|
460 TPtrC location = entry->LocationL(); |
|
461 landmarkToShow->SetLandmarkNameL(location); |
|
462 landmarkToShow->SetPositionL(position); |
|
463 landmarks.Append(landmarkToShow); |
|
464 iMapView->AddLandmarksToShowL(landmarks); |
|
465 delete landmarkToShow; |
|
466 delete geoValue; |
|
467 } |
|
468 CleanupStack::PopAndDestroy( entry ); |
|
469 } |
|
470 } |
|
471 _LIT(text, "Meeting Location"); |
|
472 |
|
473 // start request |
|
474 iMapView->SetCustomRequestTextL(text); |
|
475 iMapView->ShowMapL(); |
|
476 |
|
477 TRACE_EXIT_POINT; |
|
478 } |
|
479 |
|
480 // ---------------------------------------------------------------------------- |
|
481 // CCalenLocationUi::HandleSelectionCompletedL |
|
482 // Handles user selection for the event location on the map |
|
483 // (other items were commented in a header). |
|
484 // ---------------------------------------------------------------------------- |
|
485 // |
|
486 void CCalenLocationUi::HandleSelectionCompletedL( CMnMapView& aMapView, TInt aError ) |
|
487 { |
|
488 TRACE_ENTRY_POINT; |
|
489 |
|
490 // Forcefully broadcast app foreground notification, so that |
|
491 // ECalenMapState would be current state |
|
492 iController.BroadcastNotification(ECalenNotifyAppForegrounded); |
|
493 |
|
494 // selection is done, analyze error code first... |
|
495 if ( !aError ) |
|
496 { |
|
497 // retrieve result |
|
498 switch ( aMapView.SelectionResultType() ) |
|
499 { |
|
500 case CMnMapView::ESelectionFreeLandmark: |
|
501 { |
|
502 // retrieve result landmark as free-location landmark |
|
503 CPosLandmark* landmark = aMapView.RetrieveSelectionResultL(); |
|
504 TPtrC name; |
|
505 TBuf<3 * KCalenMaxTextEditorLength> landmarkname; |
|
506 // Get the location name if available |
|
507 TPtrC locationName; |
|
508 if( landmark->IsPositionFieldAvailable( EPositionFieldLocationName ) ) |
|
509 { |
|
510 landmark->GetPositionField( EPositionFieldLocationName, locationName ); |
|
511 landmarkname.Append(locationName); |
|
512 } |
|
513 // Get the street name if available |
|
514 TPtrC street; |
|
515 if( landmark->IsPositionFieldAvailable( EPositionFieldStreet ) ) |
|
516 { |
|
517 if(landmarkname.Length()) |
|
518 { |
|
519 // Append comma before we add this field |
|
520 landmarkname.Append(KComma); |
|
521 } |
|
522 landmark->GetPositionField( EPositionFieldStreet, street ); |
|
523 landmarkname.Append(street); |
|
524 } |
|
525 // Get the city name if available |
|
526 TPtrC city; |
|
527 if( landmark->IsPositionFieldAvailable( EPositionFieldCity ) ) |
|
528 { |
|
529 if(landmarkname.Length()) |
|
530 { |
|
531 // Append comma before we add this field |
|
532 landmarkname.Append(KComma); |
|
533 } |
|
534 landmark->GetPositionField( EPositionFieldCity, city ); |
|
535 landmarkname.Append(city); |
|
536 } |
|
537 // Get the state name if available |
|
538 TPtrC state; |
|
539 if( landmark->IsPositionFieldAvailable( EPositionFieldState ) ) |
|
540 { |
|
541 if(landmarkname.Length()) |
|
542 { |
|
543 // Append comma before we add this field |
|
544 landmarkname.Append(KComma); |
|
545 } |
|
546 landmark->GetPositionField( EPositionFieldState, state ); |
|
547 landmarkname.Append(state); |
|
548 } |
|
549 // Get the country name if available |
|
550 TPtrC country; |
|
551 if( landmark->IsPositionFieldAvailable( EPositionFieldCountry ) ) |
|
552 { |
|
553 if(landmarkname.Length()) |
|
554 { |
|
555 // Append comma before we add this field |
|
556 landmarkname.Append(KComma); |
|
557 } |
|
558 landmark->GetPositionField( EPositionFieldCountry, country ); |
|
559 landmarkname.Append(country); |
|
560 } |
|
561 |
|
562 if(landmarkname.Length() > KCalenMaxTextEditorLength ) |
|
563 { |
|
564 // Truncate the location details to fit to its max length |
|
565 TBuf<KCalenMaxTextEditorLength> truncLocationInfo; |
|
566 |
|
567 truncLocationInfo.Append(landmarkname.Left(KCalenMaxTextEditorLength)); |
|
568 landmark->SetLandmarkNameL(truncLocationInfo); |
|
569 } |
|
570 else |
|
571 { |
|
572 landmark->SetLandmarkNameL(landmarkname); |
|
573 } |
|
574 |
|
575 iLocationSelector->Reset(); |
|
576 delete iProvider; |
|
577 iProvider = NULL; |
|
578 if(!landmarkname.Length()) |
|
579 { |
|
580 // User has selected a landmark that does'nt have any name identified |
|
581 // hence, return without saving the landmark |
|
582 delete landmark; |
|
583 iController.BroadcastNotification(ECalenNotifyMapClosed); |
|
584 return; |
|
585 } |
|
586 if(isGetLocationAndSave) |
|
587 { |
|
588 StoreLocationInfoL(landmark); |
|
589 delete landmark; |
|
590 } |
|
591 else |
|
592 { |
|
593 // Get the context |
|
594 MCalenContext& context = iGlobalData->Context(); |
|
595 context.SetLandMark(landmark); |
|
596 } |
|
597 iController.BroadcastNotification(ECalenNotifyMapClosed); |
|
598 } |
|
599 break; |
|
600 |
|
601 default: |
|
602 break; |
|
603 } |
|
604 } |
|
605 else if( aError == -3 ) // If user has pressed back without selecting any locaiton on map, then |
|
606 { // cleanup everything. Not doing here is causing maps crash when coming back without selecting any location |
|
607 iLocationSelector->Reset(); |
|
608 delete iProvider; |
|
609 iProvider = NULL; |
|
610 // Issue Map Closed notification |
|
611 iController.BroadcastNotification(ECalenNotifyMapClosed); |
|
612 } |
|
613 |
|
614 TRACE_EXIT_POINT; |
|
615 } |
|
616 |
|
617 // ---------------------------------------------------------------------------- |
|
618 // CCalenLocationUi::HandleServerAppExit |
|
619 // Handle the exit of a connected server app. |
|
620 // (other items were commented in a header). |
|
621 // ---------------------------------------------------------------------------- |
|
622 // |
|
623 void CCalenLocationUi::HandleServerAppExit(TInt aReason ) |
|
624 { |
|
625 TRACE_ENTRY_POINT; |
|
626 |
|
627 if(!iMapView) |
|
628 { |
|
629 iLocationSelector->Reset(); |
|
630 delete iProvider; |
|
631 iProvider = NULL; |
|
632 // Issue Map Closed notification |
|
633 iController.BroadcastNotification(ECalenNotifyMapClosed); |
|
634 } |
|
635 else{ |
|
636 |
|
637 // Remove the observer |
|
638 iMapView->RemoveExitObserver(); |
|
639 iMapView->ResetLandmarksToShow(); |
|
640 |
|
641 // Cleanup |
|
642 delete iMapView; |
|
643 iMapView = NULL; |
|
644 delete iProvider; |
|
645 iProvider = NULL; |
|
646 // Issue Map Closed notification |
|
647 iController.BroadcastNotification(ECalenNotifyMapClosed); |
|
648 } |
|
649 |
|
650 if((aReason == EAknCmdExit) || (aReason == EAknSoftkeyExit)|| (aReason == -15)) /* if user presses END key, then terminate calendar application |
|
651 * -15 is checked because aReason will be -15 when END key is pressed while maps is being launched and launching is above 60% complete. |
|
652 * If END key is pressed before 60% of completion, Calendar is not getting any notification from map. Hence, Calendar will |
|
653 * be sent to background but not exited */ |
|
654 { |
|
655 // User has pressed red button on maps, fake exit calendar |
|
656 TRAP_IGNORE(iController.IssueCommandL(EAknSoftkeyExit)); |
|
657 } |
|
658 |
|
659 TRACE_EXIT_POINT; |
|
660 } |
|
661 |
|
662 // ---------------------------------------------------------------------------- |
|
663 // CCalenLocationUi::GetFirstProviderL |
|
664 // Returns the Map provider available in the system |
|
665 // (other items were commented in a header). |
|
666 // ---------------------------------------------------------------------------- |
|
667 // |
|
668 CMnProvider* CCalenLocationUi::GetFirstProviderL( CMnProvider::TServices aServicesNeeded ) |
|
669 { |
|
670 TRACE_ENTRY_POINT; |
|
671 |
|
672 RPointerArray<CMnProvider> providers; |
|
673 MnProviderFinder::FindProvidersL( providers, aServicesNeeded ); |
|
674 |
|
675 TInt count = providers.Count(); |
|
676 CMnProvider* nokiaProvider = NULL; |
|
677 |
|
678 for(TInt i = 0; i < count; i++) |
|
679 { |
|
680 TPtrC vendorName; |
|
681 providers[i]->GetVendorName(vendorName); |
|
682 if(vendorName.Compare(KNokiaVendorName) == 0) |
|
683 { |
|
684 // Found provider for Nokia maps |
|
685 nokiaProvider = providers[i]; |
|
686 providers.Remove(i); |
|
687 break; |
|
688 } |
|
689 } |
|
690 providers.ResetAndDestroy(); |
|
691 return nokiaProvider; |
|
692 |
|
693 TRACE_EXIT_POINT; |
|
694 } |
|
695 |
|
696 // ---------------------------------------------------------------------------- |
|
697 // CCalenLocationUi::ShowLocationReplaceNotice |
|
698 // Function to query user whether to replace or keep existing location details |
|
699 // (other items were commented in a header). |
|
700 // ---------------------------------------------------------------------------- |
|
701 // |
|
702 TInt CCalenLocationUi::ShowLocationReplaceNoticeL(TPtrC aLocaitonName) |
|
703 { |
|
704 TRACE_ENTRY_POINT; |
|
705 |
|
706 CAknQueryDialog *dialog = CAknQueryDialog::NewL( ); |
|
707 CleanupStack::PushL( dialog ); |
|
708 TInt resID = R_CALEN_QTN_REPLACE_LOCATION; |
|
709 |
|
710 TBuf<KCalenMaxTextEditorLength> location; |
|
711 TChar quote = '"'; |
|
712 location.Append(quote); |
|
713 location.Append(aLocaitonName); |
|
714 location.Append(quote); |
|
715 |
|
716 HBufC* prompt = StringLoader::LoadL( resID, location, CEikonEnv::Static() ); |
|
717 CleanupStack::PushL( prompt ); |
|
718 dialog->SetPromptL( *prompt ); |
|
719 CleanupStack::PopAndDestroy( prompt ); |
|
720 |
|
721 CleanupStack::Pop( dialog ); |
|
722 |
|
723 return dialog->ExecuteLD( R_CALEN_LOCATION_REPLACE_NOTE ); |
|
724 |
|
725 TRACE_EXIT_POINT; |
|
726 } |
|
727 |
|
728 // ---------------------------------------------------------------------------- |
|
729 // CCalenLocationUi::ShowAddressUpdatedNoticeL |
|
730 // Displays "Address Updated" transient notice |
|
731 // (other items were commented in a header). |
|
732 // ---------------------------------------------------------------------------- |
|
733 // |
|
734 void CCalenLocationUi::ShowAddressUpdatedNoticeL() |
|
735 { |
|
736 HBufC* buf = StringLoader::LoadLC( R_CALEN_QTN_ADDRESS_UPDATED, CEikonEnv::Static() ); |
|
737 CAknConfirmationNote* dialog = new( ELeave ) CAknConfirmationNote(); |
|
738 dialog->ExecuteLD(*buf); |
|
739 CleanupStack::PopAndDestroy( buf ); |
|
740 } |
|
741 |
|
742 // ----------------------------------------------------------------------------- |
|
743 // CCalenLocationUi::ShowDefineLocationQuery |
|
744 // Queries user to validate the location frm maps or not |
|
745 // ----------------------------------------------------------------------------- |
|
746 // |
|
747 TInt CCalenLocationUi::ShowDefineLocationQuery() |
|
748 { |
|
749 TRACE_ENTRY_POINT; |
|
750 |
|
751 CAknQueryDialog *dialog = CAknQueryDialog::NewL( ); |
|
752 CleanupStack::PushL( dialog ); |
|
753 TInt resID = R_CALEN_QTN_DEFINE_LOCATION_NOTE; |
|
754 |
|
755 HBufC* prompt; |
|
756 prompt = StringLoader::LoadLC( resID, CEikonEnv::Static() ); |
|
757 |
|
758 dialog->SetPromptL( *prompt ); |
|
759 CleanupStack::PopAndDestroy( prompt ); |
|
760 |
|
761 CleanupStack::Pop( dialog ); |
|
762 return dialog->ExecuteLD( R_CALEN_DEFINE_LOCATION_NOTE ); |
|
763 |
|
764 TRACE_EXIT_POINT; |
|
765 } |
|
766 |
|
767 // ---------------------------------------------------------------------------- |
|
768 // CCalenLocationUi::ShowLocationReplaceNotice |
|
769 // Stores the locaiton details of currently focusses entry in Day/Event Viewer |
|
770 // into Agenda Server |
|
771 // (other items were commented in a header). |
|
772 // ---------------------------------------------------------------------------- |
|
773 // |
|
774 void CCalenLocationUi::StoreLocationInfoL(CPosLandmark* landmark) |
|
775 { |
|
776 TRACE_ENTRY_POINT; |
|
777 |
|
778 MCalenContext& context = iGlobalData->Context(); |
|
779 // Get the entry |
|
780 TCalLocalUid instanceId = context.InstanceId().iEntryLocalUid; |
|
781 CCalEntry* entry = iGlobalData->EntryViewL()->FetchL(instanceId); |
|
782 |
|
783 TPtrC existingLocationInfo = entry->LocationL(); |
|
784 TBuf<2*KCalenMaxTextEditorLength> locationInfo; |
|
785 TPtrC landmarkname; |
|
786 landmark->GetLandmarkName(landmarkname); |
|
787 CCalGeoValue* entryGeoValue = entry->GeoValueL(); |
|
788 if(entryGeoValue || isReplaceLocation) |
|
789 { |
|
790 isReplaceLocation = EFalse; |
|
791 // Query user to replace |
|
792 TInt userResponse = ShowLocationReplaceNoticeL(landmarkname); |
|
793 if(!userResponse) |
|
794 { |
|
795 delete entryGeoValue; |
|
796 delete entry; |
|
797 return; |
|
798 } |
|
799 else |
|
800 { |
|
801 locationInfo.Append(landmarkname); |
|
802 delete entryGeoValue; |
|
803 } |
|
804 } |
|
805 else if(existingLocationInfo.Length() && !isReplaceLocation) |
|
806 { |
|
807 RPointerArray<HBufC> locationStrings; |
|
808 HBufC* oldLocation = HBufC::NewL(KCalenMaxTextEditorLength); |
|
809 oldLocation->Des().Copy(existingLocationInfo); |
|
810 |
|
811 HBufC* oldNewLocation = HBufC::NewL(KCalenMaxTextEditorLength); |
|
812 TBuf<2*KCalenMaxTextEditorLength> combLocation; |
|
813 combLocation.Append(existingLocationInfo); |
|
814 combLocation.Append(KComma); |
|
815 combLocation.Append(landmarkname); |
|
816 oldNewLocation->Des().Copy(combLocation.Left(KCalenMaxTextEditorLength)); |
|
817 |
|
818 HBufC* newLocation = HBufC::NewL(KCalenMaxTextEditorLength); |
|
819 newLocation->Des().Copy(landmarkname); |
|
820 |
|
821 locationStrings.Append(oldNewLocation); |
|
822 locationStrings.Append(newLocation); |
|
823 locationStrings.Append(oldLocation); |
|
824 TInt userResponse = CCalenLocationUtil::ShowLocationAppendOrReplaceL(locationStrings); |
|
825 locationStrings.ResetAndDestroy(); |
|
826 if(userResponse == KErrCancel) |
|
827 { |
|
828 delete entry; |
|
829 return; |
|
830 } |
|
831 switch(userResponse) |
|
832 { |
|
833 case 0: |
|
834 { |
|
835 locationInfo.Append(combLocation.Left(KCalenMaxTextEditorLength)); |
|
836 } |
|
837 break; |
|
838 case 1: |
|
839 { |
|
840 locationInfo.Append(landmarkname); |
|
841 } |
|
842 break; |
|
843 case 2: |
|
844 { |
|
845 locationInfo.Append(existingLocationInfo); |
|
846 } |
|
847 break; |
|
848 default: |
|
849 break; |
|
850 } |
|
851 } |
|
852 else // for isReplaceLocation |
|
853 { |
|
854 locationInfo.Append(landmarkname); |
|
855 } |
|
856 TPtrC landmarkDesc; |
|
857 landmark->GetLandmarkDescription(landmarkDesc); |
|
858 if(landmarkDesc.Size()) |
|
859 { |
|
860 locationInfo.Append(KComma); |
|
861 locationInfo.Append(landmarkDesc); |
|
862 } |
|
863 |
|
864 // Get the geo coordinates |
|
865 TLocality position; |
|
866 landmark->GetPosition(position); |
|
867 CCalGeoValue* geoValue = CCalGeoValue::NewL(); |
|
868 geoValue->SetLatLongL(position.Latitude(), position.Longitude()); |
|
869 |
|
870 // Get the context |
|
871 entry->SetLocationL(locationInfo); |
|
872 entry->SetGeoValueL(*geoValue); |
|
873 delete geoValue; |
|
874 |
|
875 if(existingLocationInfo.Length()) |
|
876 { |
|
877 ShowAddressUpdatedNoticeL(); |
|
878 } |
|
879 // Save entry into Agenda server |
|
880 CCalenInterimUtils2::StoreL( *(iGlobalData->EntryViewL()), *entry, ETrue ); |
|
881 delete entry; |
|
882 |
|
883 TRACE_EXIT_POINT; |
|
884 } |
|
885 |
|
886 // End Of File |