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