|
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: Active object class that makes asycn request to launch the map |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDES |
|
20 #include <calencontext.h> |
|
21 #include <StringLoader.h> |
|
22 #include <calentry.h> |
|
23 #include <aknnotewrappers.h> |
|
24 #include <mnmapview.h> |
|
25 #include <lbsposition.h> |
|
26 #include <EPos_CPosLmDatabaseManager.h> |
|
27 #include <EPos_CPosLandmarkDatabase.h> |
|
28 #include <EPos_HPosLmDatabaseInfo.h> |
|
29 #include <EPos_Landmarks.h> |
|
30 #include <e32math.h> |
|
31 #include <caleninstanceid.h> // TCalenInstanceId |
|
32 |
|
33 //debug |
|
34 #include "calendarui_debug.h" |
|
35 #include "calenlocationactiveselector.h" |
|
36 #include "calenglobaldata.h" |
|
37 |
|
38 // ---------------------------------------------------------------------------- |
|
39 // CCalenLocationActiveSelector::NewL |
|
40 // NewL function |
|
41 // (other items were commented in a header). |
|
42 // ---------------------------------------------------------------------------- |
|
43 // |
|
44 CCalenLocationActiveSelector* CCalenLocationActiveSelector::NewL(MCalenSelectionObserver& aObserver, |
|
45 MAknServerAppExitObserver& aExitObserver, |
|
46 CCalenGlobalData& aGlobalData) |
|
47 { |
|
48 TRACE_ENTRY_POINT; |
|
49 |
|
50 CCalenLocationActiveSelector* self = new(ELeave) CCalenLocationActiveSelector( aObserver, |
|
51 aExitObserver, |
|
52 aGlobalData); |
|
53 CleanupStack::PushL( self ); |
|
54 self->ConstructL(); |
|
55 CleanupStack::Pop( self ); |
|
56 |
|
57 TRACE_EXIT_POINT; |
|
58 return self; |
|
59 } |
|
60 |
|
61 // ---------------------------------------------------------------------------- |
|
62 // CCalenLocationActiveSelector::CCalenLocationActiveSelector |
|
63 // C++ constructor |
|
64 // (other items were commented in a header). |
|
65 // ---------------------------------------------------------------------------- |
|
66 // |
|
67 CCalenLocationActiveSelector::CCalenLocationActiveSelector( MCalenSelectionObserver& aObserver, |
|
68 MAknServerAppExitObserver& aExitObserver, |
|
69 CCalenGlobalData& aGlobalData) |
|
70 : CActive( CActive::EPriorityStandard ), |
|
71 iObserver( aObserver ), |
|
72 iExitObserver(aExitObserver), |
|
73 iGlobalData(aGlobalData) |
|
74 { |
|
75 TRACE_ENTRY_POINT; |
|
76 |
|
77 CActiveScheduler::Add( this ); |
|
78 |
|
79 TRACE_EXIT_POINT; |
|
80 } |
|
81 |
|
82 // ---------------------------------------------------------------------------- |
|
83 // CCalenLocationActiveSelector::ConstructL |
|
84 // Second Phace constructor |
|
85 // (other items were commented in a header). |
|
86 // ---------------------------------------------------------------------------- |
|
87 // |
|
88 void CCalenLocationActiveSelector::ConstructL() |
|
89 { |
|
90 TRACE_ENTRY_POINT; |
|
91 |
|
92 |
|
93 TRACE_EXIT_POINT; |
|
94 } |
|
95 // ---------------------------------------------------------------------------- |
|
96 // CCalenLocationActiveSelector::~CCalenLocationActiveSelector |
|
97 // Destructor |
|
98 // (other items were commented in a header). |
|
99 // ---------------------------------------------------------------------------- |
|
100 // |
|
101 CCalenLocationActiveSelector::~CCalenLocationActiveSelector() |
|
102 { |
|
103 Cancel(); |
|
104 ReleaseLandmarkResources(); |
|
105 } |
|
106 |
|
107 // ---------------------------------------------------------------------------- |
|
108 // CCalenLocationActiveSelector::SelectL |
|
109 // Initiates selection operation |
|
110 // (other items were commented in a header). |
|
111 // ---------------------------------------------------------------------------- |
|
112 // |
|
113 void CCalenLocationActiveSelector::SelectL( CMnProvider& aProvider, |
|
114 TPosition& aPosition, |
|
115 TBool /*isLaunchedFromEditors*/) |
|
116 { |
|
117 if ( IsActive() ) |
|
118 { |
|
119 // avoid two simultaneous selection requests |
|
120 User::Leave( KErrInUse ); |
|
121 } |
|
122 |
|
123 // create connection |
|
124 iMapView = CMnMapView::NewChainedL( aProvider ); |
|
125 _LIT(text, "Select Meeting Location"); |
|
126 iMapView->SetCustomRequestTextL(text); |
|
127 |
|
128 iMapView->SetExitObserverL(iExitObserver); |
|
129 |
|
130 // Set the current location coordinates |
|
131 TReal latitude = aPosition.Latitude(); |
|
132 TReal longitude = aPosition.Longitude(); |
|
133 TCoordinate currentPoint(latitude, longitude); |
|
134 iMapView->SetMapAreaL(currentPoint,100000); |
|
135 iMapView->SetCurrentLocationOption(CMnMapView::ECurrentLocationShowAlways); |
|
136 |
|
137 // Start the request |
|
138 iMapView->SelectFromMapL( iStatus ); |
|
139 SetActive(); |
|
140 } |
|
141 |
|
142 // ---------------------------------------------------------------------------- |
|
143 // CCalenLocationActiveSelector::SelectL |
|
144 // Initiates selection operation |
|
145 // (other items were commented in a header). |
|
146 // ---------------------------------------------------------------------------- |
|
147 // |
|
148 void CCalenLocationActiveSelector::SelectL( CMnProvider& aProvider, |
|
149 CPosLandmark* aLandmarkToShow) |
|
150 { |
|
151 if ( IsActive() ) |
|
152 { |
|
153 // avoid two simultaneous selection requests |
|
154 User::Leave( KErrInUse ); |
|
155 } |
|
156 |
|
157 // create connection |
|
158 iMapView = CMnMapView::NewChainedL( aProvider ); |
|
159 _LIT(text, "Select Meeting Location"); |
|
160 iMapView->SetCustomRequestTextL(text); |
|
161 iMapView->SetExitObserverL(iExitObserver); |
|
162 if(aLandmarkToShow) |
|
163 { |
|
164 // Add available landmarks |
|
165 RPointerArray<CPosLandmark> landmarks; |
|
166 landmarks.Append(aLandmarkToShow); |
|
167 iMapView->AddLandmarksToShowL(landmarks); |
|
168 } |
|
169 |
|
170 // Start the request |
|
171 iMapView->SelectFromMapL( iStatus ); |
|
172 SetActive(); |
|
173 } |
|
174 |
|
175 // ---------------------------------------------------------------------------- |
|
176 // CCalenLocationActiveSelector::RetrieveAndAddLandMarksL |
|
177 // Reads all landmarks from all the available databases in the system |
|
178 // (other items were commented in a header). |
|
179 // ---------------------------------------------------------------------------- |
|
180 // |
|
181 void CCalenLocationActiveSelector::RetrieveAndAddLandMarksL(CMnMapView* aMapView, |
|
182 TBool isLaunchedFromEditors) |
|
183 { |
|
184 RPointerArray<CPosLandmark> landmarks; |
|
185 CPosLmDatabaseManager* dbManager = CPosLmDatabaseManager::NewL(); |
|
186 CleanupStack::PushL( dbManager ); |
|
187 |
|
188 // Get a list of databases |
|
189 RPointerArray<HPosLmDatabaseInfo> dbInfoList; |
|
190 dbManager->ListDatabasesL( dbInfoList ); |
|
191 |
|
192 for ( TInt i = 0; i < dbInfoList.Count(); ++i ) |
|
193 { |
|
194 HPosLmDatabaseInfo* dbInfo = dbInfoList[i]; |
|
195 |
|
196 // Get information about the database |
|
197 TPtrC uri = dbInfo->DatabaseUri(); |
|
198 CPosLandmarkDatabase* db = CPosLandmarkDatabase::OpenL(uri); |
|
199 CleanupStack::PushL( db ); |
|
200 |
|
201 if(db->IsInitializingNeeded()) |
|
202 { |
|
203 db->InitializeL(); |
|
204 } |
|
205 // Create an iterator for iterating the landmarks in the database |
|
206 CPosLmItemIterator* iter = db->LandmarkIteratorL(); |
|
207 CleanupStack::PushL( iter ); |
|
208 |
|
209 // Read each landmark in the database and do something. |
|
210 TPosLmItemId lmID = KPosLmNullItemId; |
|
211 while ( ( lmID = iter->NextL() ) != KPosLmNullItemId ) |
|
212 { |
|
213 CPosLandmark* lm = db->ReadLandmarkLC( lmID ); |
|
214 CleanupStack::Pop(); |
|
215 // Add landmark into array |
|
216 landmarks.Append(lm); |
|
217 } |
|
218 // Close the iterator and the database handle. |
|
219 CleanupStack::PopAndDestroy( iter ); |
|
220 CleanupStack::PopAndDestroy( db ); |
|
221 } |
|
222 |
|
223 // Destroy list |
|
224 dbInfoList.ResetAndDestroy(); |
|
225 |
|
226 CleanupStack::PopAndDestroy( dbManager ); |
|
227 |
|
228 // Append the landmark from context if any |
|
229 MCalenContext& context = iGlobalData.Context(); |
|
230 CPosLandmark* landmark = context.GetLandMark(); |
|
231 //TBool isCtxtLmAdded = EFalse; |
|
232 if(landmark) |
|
233 { |
|
234 TPosition position; |
|
235 landmark->GetPosition(position); |
|
236 if(Math::IsNaN(position.Latitude())) |
|
237 { |
|
238 //landmarks.Append(landmark); |
|
239 //isCtxtLmAdded = ETrue; |
|
240 } |
|
241 } |
|
242 else if( !isLaunchedFromEditors ) // If launched frm day view or event viewer |
|
243 { |
|
244 // Get the entry |
|
245 TCalLocalUid instanceId = context.InstanceId().iEntryLocalUid; |
|
246 CCalEntry* entry = iGlobalData.EntryViewL(context.InstanceId().iColId)->FetchL(instanceId); |
|
247 if(entry) |
|
248 { |
|
249 CleanupStack::PushL( entry ); |
|
250 CCalGeoValue* geoValue = entry->GeoValueL(); |
|
251 if(!geoValue) |
|
252 { |
|
253 TPtrC location = entry->LocationL(); |
|
254 if(location.Length()) |
|
255 { |
|
256 /* CPosLandmark* landmark = CPosLandmark::NewL(); |
|
257 landmark->SetLandmarkNameL(location); |
|
258 landmarks.Append(landmark);*/ |
|
259 } |
|
260 } |
|
261 else |
|
262 { |
|
263 delete geoValue; |
|
264 } |
|
265 CleanupStack::PopAndDestroy( entry ); |
|
266 } |
|
267 } |
|
268 |
|
269 // Add landmarks to show |
|
270 aMapView->AddLandmarksToShowL(landmarks); |
|
271 |
|
272 // Delete landmark pointers |
|
273 context.ResetLandMark(); |
|
274 landmarks.ResetAndDestroy(); |
|
275 } |
|
276 |
|
277 // ---------------------------------------------------------------------------- |
|
278 // CCalenLocationActiveSelector::RunL |
|
279 // RunL method to handle the user selection |
|
280 // (other items were commented in a header). |
|
281 // ---------------------------------------------------------------------------- |
|
282 // |
|
283 void CCalenLocationActiveSelector::RunL() |
|
284 { |
|
285 // request is completed, inform observer |
|
286 iObserver.HandleSelectionCompletedL( *iMapView, iStatus.Int() ); |
|
287 } |
|
288 |
|
289 // ---------------------------------------------------------------------------- |
|
290 // CCalenLocationActiveSelector::RunError |
|
291 // Function to handle any errors in async request |
|
292 // (other items were commented in a header). |
|
293 // ---------------------------------------------------------------------------- |
|
294 // |
|
295 TInt CCalenLocationActiveSelector::RunError( TInt /*aError*/ ) |
|
296 { |
|
297 Reset(); |
|
298 return KErrNone; |
|
299 } |
|
300 |
|
301 // ---------------------------------------------------------------------------- |
|
302 // CCalenLocationActiveSelector::DoCancel |
|
303 // Cancel method to handle the user selection |
|
304 // (other items were commented in a header). |
|
305 // ---------------------------------------------------------------------------- |
|
306 // |
|
307 void CCalenLocationActiveSelector::DoCancel() |
|
308 { |
|
309 if ( IsActive() && iMapView ) |
|
310 { |
|
311 iMapView->Cancel(); |
|
312 } |
|
313 Reset(); |
|
314 } |
|
315 |
|
316 // ---------------------------------------------------------------------------- |
|
317 // CCalenLocationActiveSelector::Reset |
|
318 // Disconnects from provider, when operation is completed |
|
319 // (other items were commented in a header). |
|
320 // ---------------------------------------------------------------------------- |
|
321 // |
|
322 void CCalenLocationActiveSelector::Reset() |
|
323 { |
|
324 if(iMapView) |
|
325 { |
|
326 iMapView->ResetLandmarksToShow(); |
|
327 delete iMapView; |
|
328 iMapView = NULL; |
|
329 } |
|
330 ReleaseLandmarkResources(); |
|
331 } |
|
332 |
|
333 // END OF FILE |