14 * Description: Location plugin implementation |
14 * Description: Location plugin implementation |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 |
18 |
19 #include "emailtrace.h" |
19 #include "cesmrlocationpluginimpl.h" |
|
20 #include "mesmrlocationpluginobserver.h" |
|
21 #include "cesmrurlparserplugin.h" |
|
22 |
20 #include <mnproviderfinder.h> |
23 #include <mnproviderfinder.h> |
21 #include <mnprovider.h> |
24 #include <mnprovider.h> |
22 //<cmail> |
25 #include <mnmapview.h> |
23 #include "mnmapview.h" |
26 #include <epos_cposlandmark.h> |
24 #include <EPos_CPosLandmark.h> |
27 #include <stringloader.h> |
25 #include <StringLoader.h> |
|
26 #include <esmrgui.rsg> |
28 #include <esmrgui.rsg> |
27 #include "cesmrurlparserplugin.h" |
|
28 //</cmail> |
|
29 #include <ct/rcpointerarray.h> |
29 #include <ct/rcpointerarray.h> |
30 |
30 #include <calentry.h> |
31 #include "cesmrlocationpluginimpl.h" |
31 |
32 #include "mesmrlocationpluginobserver.h" |
32 #include "emailtrace.h" |
33 |
33 |
|
34 // ======== LOCAL FUNCTIONS ======== |
|
35 |
|
36 namespace |
|
37 { |
|
38 /** |
|
39 * Converts vCal GEO value to landmark with coordinates |
|
40 * |
|
41 * @param aGeoValue coordinates |
|
42 * @return a landmark with coordinates |
|
43 */ |
|
44 CPosLandmark* CreateLandmarkL( const CCalGeoValue& aGeoValue ) |
|
45 { |
|
46 TReal lat; |
|
47 TReal lon; |
|
48 |
|
49 if( !aGeoValue.GetLatLong( lat, lon ) ) |
|
50 { |
|
51 User::Leave( KErrArgument ); |
|
52 } |
|
53 |
|
54 CPosLandmark* landmark = CPosLandmark::NewLC(); |
|
55 TLocality coordinate; |
|
56 coordinate.SetCoordinate( lat, lon ); |
|
57 landmark->SetPositionL( coordinate ); |
|
58 CleanupStack::Pop( landmark ); |
|
59 return landmark; |
|
60 } |
|
61 |
|
62 } |
34 // ======== MEMBER FUNCTIONS ======== |
63 // ======== MEMBER FUNCTIONS ======== |
35 |
64 |
36 // --------------------------------------------------------------------------- |
65 // --------------------------------------------------------------------------- |
37 // CESMRLocationPluginImpl::CESMRLocationPluginImpl |
66 // CESMRLocationPluginImpl::CESMRLocationPluginImpl |
38 // --------------------------------------------------------------------------- |
67 // --------------------------------------------------------------------------- |
39 // |
68 // |
40 CESMRLocationPluginImpl::CESMRLocationPluginImpl() |
69 CESMRLocationPluginImpl::CESMRLocationPluginImpl() |
41 : CESMRLocationPlugin( CActive::EPriorityStandard ) |
70 : CESMRLocationPlugin( CActive::EPriorityStandard ) |
42 { |
71 { |
43 FUNC_LOG; |
72 FUNC_LOG; |
44 } |
73 } |
45 |
74 |
46 // --------------------------------------------------------------------------- |
75 // --------------------------------------------------------------------------- |
52 FUNC_LOG; |
81 FUNC_LOG; |
53 // Find Map & Navigation provider |
82 // Find Map & Navigation provider |
54 RCPointerArray<CMnProvider> providers; |
83 RCPointerArray<CMnProvider> providers; |
55 CleanupClosePushL( providers ); |
84 CleanupClosePushL( providers ); |
56 MnProviderFinder::FindProvidersL( providers, |
85 MnProviderFinder::FindProvidersL( providers, |
57 CMnProvider::EServiceMapView |
86 CMnProvider::EServiceMapView |
58 | CMnProvider::EServiceNavigation |
87 | CMnProvider::EServiceNavigation ); |
59 | CMnProvider::EServiceGeocoding ); |
|
60 if ( providers.Count() == 0 ) |
88 if ( providers.Count() == 0 ) |
61 { |
89 { |
62 User::Leave( KErrNotSupported ); |
90 User::Leave( KErrNotSupported ); |
63 } |
91 } |
64 iProvider = providers[ 0 ]; |
92 iProvider = providers[ 0 ]; |
65 providers.Remove( 0 ); |
93 providers.Remove( 0 ); |
66 // PopAndDestroy provides from cleanupstack |
94 // PopAndDestroy provides from cleanupstack |
67 CleanupStack::PopAndDestroy( &providers ); |
95 CleanupStack::PopAndDestroy( &providers ); |
68 |
96 |
69 // Create Map & Navigation view |
97 // Create Map & Navigation view |
70 CreateMapViewL(); |
98 CreateMapViewL(); |
71 |
99 |
72 iUrlParser = CESMRUrlParserPlugin::NewL(); |
|
73 |
|
74 CActiveScheduler::Add( this ); |
100 CActiveScheduler::Add( this ); |
75 } |
101 } |
76 |
102 |
77 |
103 |
78 // --------------------------------------------------------------------------- |
104 // --------------------------------------------------------------------------- |
135 // CESMRLocationPluginImpl::SelectFromMapL |
161 // CESMRLocationPluginImpl::SelectFromMapL |
136 // From class MESMRLocationPlugin. |
162 // From class MESMRLocationPlugin. |
137 // --------------------------------------------------------------------------- |
163 // --------------------------------------------------------------------------- |
138 // |
164 // |
139 void CESMRLocationPluginImpl::SelectFromMapL( const TDesC& aSearchQuery, |
165 void CESMRLocationPluginImpl::SelectFromMapL( const TDesC& aSearchQuery, |
140 const TDesC& aLocationUrl ) |
166 const TDesC& aLocationUrl ) |
141 { |
167 { |
142 FUNC_LOG; |
168 FUNC_LOG; |
143 iLandMarks.ResetAndDestroy(); |
169 |
144 |
170 // Create landmark from location URL. TRAP errors because URL is optional. |
145 if ( IsActive() ) |
171 CPosLandmark* location = NULL; |
146 { |
172 TRAP_IGNORE( location = //codescanner::forgottoputptroncleanupstack |
147 User::Leave( KErrInUse ); |
173 UrlParserL().CreateLandmarkFromUrlL( aLocationUrl ) ) |
148 } |
174 |
149 |
175 SelectFromMapL( aSearchQuery, location ); |
150 CreateMapViewL(); |
176 } |
151 |
177 |
152 iMapView->ResetMapArea(); |
178 // --------------------------------------------------------------------------- |
153 |
179 // CESMRLocationPluginImpl::SelectFromMapL |
154 // Create landmark from location URL. TRAP errors because URL is optional. |
180 // From class MESMRLocationPlugin. |
155 CPosLandmark* location = NULL; |
181 // --------------------------------------------------------------------------- |
156 TRAP_IGNORE( location = //codescanner::forgottoputptroncleanupstack |
182 // |
157 iUrlParser->CreateLandmarkFromUrlL( aLocationUrl ) ) |
183 void CESMRLocationPluginImpl::SelectFromMapL( |
158 |
184 const TDesC& aSearchQuery, |
159 if ( location ) // Landmark created. Set search string as landmark name |
185 const CCalGeoValue* aGeoValue ) |
160 { |
186 { |
161 if ( aSearchQuery.Length() > 0 ) |
187 FUNC_LOG; |
162 { |
188 |
163 CleanupStack::PushL( location ); |
189 CPosLandmark* location = NULL; |
164 |
190 |
165 location->SetLandmarkNameL( aSearchQuery ); |
191 if ( aGeoValue ) |
166 |
192 { |
167 iLandMarks.AppendL( location ); |
193 location = CreateLandmarkL( *aGeoValue ); |
168 CleanupStack::Pop( location ); |
194 } |
169 |
195 |
170 iMapView->ResetLandmarksToShow(); |
196 SelectFromMapL( aSearchQuery, location ); |
171 iMapView->AddLandmarksToShowL( iLandMarks ); |
197 } |
172 } |
|
173 } |
|
174 else |
|
175 { |
|
176 // No location url provided, let's search from maps |
|
177 // with search string. It was agreed that search is done by |
|
178 // passing a landmark with search string as the name of the landmark |
|
179 // forward |
|
180 if ( aSearchQuery.Length() > 0 ) |
|
181 { |
|
182 location = CPosLandmark::NewLC(); |
|
183 location->SetLandmarkNameL( aSearchQuery ); |
|
184 |
|
185 iLandMarks.AppendL( location ); |
|
186 CleanupStack::Pop( location ); |
|
187 |
|
188 iMapView->ResetLandmarksToShow(); |
|
189 iMapView->AddLandmarksToShowL( iLandMarks ); |
|
190 } |
|
191 |
|
192 // Enable current location focus on map |
|
193 iMapView-> |
|
194 SetCurrentLocationOption( CMnMapView::ECurrentLocationEnabled ); |
|
195 } |
|
196 |
|
197 SetActive(); |
|
198 iMapView->SelectFromMapL( iStatus ); |
|
199 } |
|
200 |
198 |
201 // --------------------------------------------------------------------------- |
199 // --------------------------------------------------------------------------- |
202 // CESMRLocationPluginImpl::SearchFromMapL |
200 // CESMRLocationPluginImpl::SearchFromMapL |
203 // From class MESMRLocationPlugin. |
201 // From class MESMRLocationPlugin. |
204 // --------------------------------------------------------------------------- |
202 // --------------------------------------------------------------------------- |
205 // |
203 // |
206 void CESMRLocationPluginImpl::SearchFromMapL( const TDesC& aSearchQuery ) |
204 void CESMRLocationPluginImpl::SearchFromMapL( const TDesC& aSearchQuery ) |
207 { |
205 { |
208 FUNC_LOG; |
206 FUNC_LOG; |
209 iLandMarks.ResetAndDestroy(); |
207 iLandMarks.ResetAndDestroy(); |
210 |
208 |
211 CPosLandmark* location = CPosLandmark::NewLC(); |
209 CPosLandmark* location = CPosLandmark::NewLC(); |
212 location->SetLandmarkNameL( aSearchQuery ); |
210 location->SetLandmarkNameL( aSearchQuery ); |
213 |
211 |
214 iLandMarks.AppendL( location ); |
212 iLandMarks.AppendL( location ); |
215 CleanupStack::Pop( location ); |
213 CleanupStack::Pop( location ); |
216 |
214 |
217 iMapView->ResetLandmarksToShow(); |
215 iMapView->ResetLandmarksToShow(); |
218 iMapView->AddLandmarksToShowL( iLandMarks ); |
216 iMapView->AddLandmarksToShowL( iLandMarks ); |
219 iMapView->ShowMapL(); |
217 iMapView->ShowMapL(); |
220 } |
218 } |
221 |
219 |
222 // --------------------------------------------------------------------------- |
220 // --------------------------------------------------------------------------- |
223 // CESMRLocationPluginImpl::ShowOnMapL |
221 // CESMRLocationPluginImpl::ShowOnMapL |
224 // From class MESMRLocationPlugin. |
222 // From class MESMRLocationPlugin. |
225 // --------------------------------------------------------------------------- |
223 // --------------------------------------------------------------------------- |
226 // |
224 // |
227 void CESMRLocationPluginImpl::ShowOnMapL( const TDesC& aLocation, const TDesC& aLocationUrl ) |
225 void CESMRLocationPluginImpl::ShowOnMapL( const TDesC& aLocationUrl ) |
228 { |
226 { |
229 FUNC_LOG; |
227 FUNC_LOG; |
230 CreateMapViewL(); |
228 |
231 |
229 CPosLandmark* landmark = |
232 iMapView->ResetLandmarksToShow(); |
230 UrlParserL().CreateLandmarkFromUrlL( aLocationUrl ); |
233 RCPointerArray<CPosLandmark> landmarks; |
231 ShowLandmarkL( landmark ); |
234 CleanupClosePushL( landmarks ); |
232 } |
235 CPosLandmark* landmark = iUrlParser->CreateLandmarkFromUrlL( aLocationUrl ); |
233 |
236 landmark->SetLandmarkNameL(aLocation); |
234 // --------------------------------------------------------------------------- |
237 CleanupStack::PushL( landmark ); |
235 // CESMRLocationPluginImpl::ShowOnMapL |
238 landmarks.AppendL( landmark ); |
236 // From class MESMRLocationPlugin. |
239 CleanupStack::Pop( landmark ); |
237 // --------------------------------------------------------------------------- |
240 iMapView->AddLandmarksToShowL( landmarks ); |
238 // |
241 CleanupStack::PopAndDestroy( &landmarks ); |
239 void CESMRLocationPluginImpl::ShowOnMapL( const CCalGeoValue& aGeoValue ) |
242 iMapView->ShowMapL(); |
240 { |
243 } |
241 FUNC_LOG; |
|
242 |
|
243 CPosLandmark* landmark = CreateLandmarkL( aGeoValue ); |
|
244 ShowLandmarkL( landmark ); |
|
245 } |
244 |
246 |
245 // --------------------------------------------------------------------------- |
247 // --------------------------------------------------------------------------- |
246 // CESMRLocationPluginImpl::DoCancel |
248 // CESMRLocationPluginImpl::DoCancel |
247 // From class CActive. |
249 // From class CActive. |
248 // Cancels outstanding request to iMapView |
250 // Cancels outstanding request to iMapView |
278 FUNC_LOG; |
280 FUNC_LOG; |
279 if ( iStatus == KErrNone ) |
281 if ( iStatus == KErrNone ) |
280 { |
282 { |
281 CMnMapView::TSelectionResultType type; |
283 CMnMapView::TSelectionResultType type; |
282 type = iMapView->SelectionResultType(); |
284 type = iMapView->SelectionResultType(); |
283 |
285 |
284 if ( iObserver ) |
286 if ( iObserver ) |
285 { |
287 { |
286 switch ( type ) |
288 switch ( type ) |
287 { |
289 { |
288 case CMnMapView::ESelectionFreeLandmark: |
290 case CMnMapView::ESelectionFreeLandmark: |
289 { |
291 { |
290 // Read selection from map view, send result to observer |
292 // Read selection from map view, send result to observer |
291 CPosLandmark* landmark = |
293 CPosLandmark* landmark = |
292 iMapView->RetrieveSelectionResultL(); |
294 iMapView->RetrieveSelectionResultL(); |
293 iObserver->SelectFromMapCompleted( iStatus.Int(), |
295 iObserver->SelectFromMapCompleted( iStatus.Int(), |
294 landmark ); |
296 landmark ); |
295 break; |
297 break; |
296 } |
298 } |
297 case CMnMapView::ESelectionLandmarkIndex: |
299 case CMnMapView::ESelectionLandmarkIndex: |
298 { |
300 { |
299 TInt landmarkIndex = 0; |
301 TInt landmarkIndex = 0; |
300 iMapView->RetrieveSelectionResultL( landmarkIndex ); |
302 iMapView->RetrieveSelectionResultL( landmarkIndex ); |
301 |
303 |
302 if ( landmarkIndex < iLandMarks.Count() ) |
304 if ( landmarkIndex < iLandMarks.Count() ) |
303 { |
305 { |
304 iObserver->SelectFromMapCompleted( |
306 iObserver->SelectFromMapCompleted( |
305 iStatus.Int(), |
307 iStatus.Int(), |
306 iLandMarks[landmarkIndex] ); |
308 iLandMarks[landmarkIndex] ); |
307 iLandMarks.Remove( landmarkIndex ); |
309 iLandMarks.Remove( landmarkIndex ); |
308 } |
310 } |
309 else |
311 else |
310 { |
312 { |
324 { |
326 { |
325 // Notify error to observer |
327 // Notify error to observer |
326 iObserver->SelectFromMapCompleted( iStatus.Int(), NULL ); |
328 iObserver->SelectFromMapCompleted( iStatus.Int(), NULL ); |
327 } |
329 } |
328 |
330 |
329 // Close Map view |
331 // Close Map view |
330 delete iMapView; |
332 delete iMapView; |
331 iMapView = NULL; |
333 iMapView = NULL; |
332 } |
334 } |
333 |
335 |
334 // --------------------------------------------------------------------------- |
336 // --------------------------------------------------------------------------- |
335 // CESMRLocationPluginImpl::RunError |
337 // CESMRLocationPluginImpl::RunError |
336 // From class CActive. |
338 // From class CActive. |
337 // --------------------------------------------------------------------------- |
339 // --------------------------------------------------------------------------- |
338 // |
340 // |
339 TInt CESMRLocationPluginImpl::RunError( TInt aError ) |
341 TInt CESMRLocationPluginImpl::RunError( TInt aError ) |
340 { |
342 { |
341 FUNC_LOG; |
343 FUNC_LOG; |
342 // Notify error to observer |
344 // Notify error to observer |
343 if(iObserver) |
345 if(iObserver) |
344 { |
346 { |
345 iObserver->SelectFromMapCompleted( aError, NULL ); |
347 iObserver->SelectFromMapCompleted( aError, NULL ); |
346 } |
348 } |
347 |
349 |
348 // Close Map view |
350 // Close Map view |
349 delete iMapView; |
351 delete iMapView; |
350 iMapView = NULL; |
352 iMapView = NULL; |
351 |
353 |
352 return KErrNone; |
354 return KErrNone; |
353 } |
355 } |
354 |
356 |
355 // --------------------------------------------------------------------------- |
357 // --------------------------------------------------------------------------- |
356 // CESMRLocationPluginImpl::HandleServerAppExit |
358 // CESMRLocationPluginImpl::HandleServerAppExit |
357 // From class MAknServerAppExitObserver. |
359 // From class MAknServerAppExitObserver. |
358 // --------------------------------------------------------------------------- |
360 // --------------------------------------------------------------------------- |
359 // |
361 // |
360 void CESMRLocationPluginImpl::HandleServerAppExit( TInt aReason ) |
362 void CESMRLocationPluginImpl::HandleServerAppExit( TInt aReason ) |
361 { |
363 { |
362 FUNC_LOG; |
364 FUNC_LOG; |
363 Cancel(); |
365 Cancel(); |
364 |
366 |
365 if ( iObserver ) |
367 if ( iObserver ) |
366 { |
368 { |
367 // Notify observer that application has been closed without selection. |
369 // Notify observer that application has been closed without selection. |
368 iObserver->SelectFromMapCompleted( aReason, NULL ); |
370 iObserver->SelectFromMapCompleted( aReason, NULL ); |
369 } |
371 } |
370 |
372 |
371 delete iMapView; |
373 delete iMapView; |
372 iMapView = NULL; |
374 iMapView = NULL; |
373 } |
375 } |
374 |
376 |
|
377 // --------------------------------------------------------------------------- |
|
378 // CESMRLocationPluginImpl::ShowLandmarkL |
|
379 // --------------------------------------------------------------------------- |
|
380 // |
|
381 void CESMRLocationPluginImpl::SelectFromMapL( |
|
382 const TDesC& aSearchQuery, |
|
383 CPosLandmark* aLandmark ) |
|
384 { |
|
385 iLandMarks.ResetAndDestroy(); |
|
386 |
|
387 if ( IsActive() ) |
|
388 { |
|
389 User::Leave( KErrInUse ); |
|
390 } |
|
391 |
|
392 CreateMapViewL(); |
|
393 |
|
394 iMapView->ResetMapArea(); |
|
395 |
|
396 CPosLandmark* location = aLandmark; |
|
397 |
|
398 if ( location ) // Landmark created. Set search string as landmark name |
|
399 { |
|
400 if ( aSearchQuery.Length() > 0 ) |
|
401 { |
|
402 CleanupStack::PushL( location ); |
|
403 |
|
404 location->SetLandmarkNameL( aSearchQuery ); |
|
405 |
|
406 iLandMarks.AppendL( location ); |
|
407 CleanupStack::Pop( location ); |
|
408 |
|
409 iMapView->ResetLandmarksToShow(); |
|
410 iMapView->AddLandmarksToShowL( iLandMarks ); |
|
411 } |
|
412 } |
|
413 else |
|
414 { |
|
415 // No location url provided, let's search from maps |
|
416 // with search string. It was agreed that search is done by |
|
417 // passing a landmark with search string as the name of the landmark |
|
418 // forward |
|
419 if ( aSearchQuery.Length() > 0 ) |
|
420 { |
|
421 location = CPosLandmark::NewLC(); |
|
422 location->SetLandmarkNameL( aSearchQuery ); |
|
423 |
|
424 iLandMarks.AppendL( location ); |
|
425 CleanupStack::Pop( location ); |
|
426 |
|
427 iMapView->ResetLandmarksToShow(); |
|
428 iMapView->AddLandmarksToShowL( iLandMarks ); |
|
429 } |
|
430 |
|
431 // Enable current location focus on map |
|
432 iMapView-> |
|
433 SetCurrentLocationOption( CMnMapView::ECurrentLocationEnabled ); |
|
434 } |
|
435 |
|
436 SetActive(); |
|
437 iMapView->SelectFromMapL( iStatus ); |
|
438 } |
|
439 |
|
440 // --------------------------------------------------------------------------- |
|
441 // CESMRLocationPluginImpl::ShowLandmarkL |
|
442 // --------------------------------------------------------------------------- |
|
443 // |
|
444 void CESMRLocationPluginImpl::ShowLandmarkL( CPosLandmark* aLandmark ) |
|
445 { |
|
446 CreateMapViewL(); |
|
447 |
|
448 iMapView->ResetLandmarksToShow(); |
|
449 RCPointerArray<CPosLandmark> landmarks; |
|
450 CleanupClosePushL( landmarks ); |
|
451 CleanupStack::PushL( aLandmark ); |
|
452 landmarks.AppendL( aLandmark ); |
|
453 CleanupStack::Pop( aLandmark ); |
|
454 iMapView->AddLandmarksToShowL( landmarks ); |
|
455 CleanupStack::PopAndDestroy( &landmarks ); |
|
456 iMapView->ShowMapL(); |
|
457 } |
|
458 |
|
459 // --------------------------------------------------------------------------- |
|
460 // CESMRLocationPluginImpl::UrlParserL |
|
461 // --------------------------------------------------------------------------- |
|
462 // |
|
463 CESMRUrlParserPlugin& CESMRLocationPluginImpl::UrlParserL() |
|
464 { |
|
465 if ( !iUrlParser ) |
|
466 { |
|
467 iUrlParser = CESMRUrlParserPlugin::NewL(); |
|
468 } |
|
469 |
|
470 return *iUrlParser; |
|
471 } |
|
472 |
|
473 // EOF |