1 /* |
|
2 * Copyright (c) 2006 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 interface for obtaining Location updates |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // System Includes |
|
20 #include <StringLoader.h> // StringLoader |
|
21 #include <simpsyui.rsg> |
|
22 #include <aknnotedialog.h> |
|
23 #include <AknQueryDialog.h> |
|
24 |
|
25 // User Includes |
|
26 #include "simpsyuiao.h" |
|
27 |
|
28 // Constant Defintions |
|
29 const TInt KFormatStringLength = 200; |
|
30 const TInt KFormatCharacterWidth = 10; |
|
31 const TInt KPositionDataGranularity = 6; |
|
32 const TInt KFormatDecimalNumbers = 4; |
|
33 |
|
34 _LIT( KTabulator, "\t" ); |
|
35 _LIT( KSimPsyConfiguratorName, "SimPsyConfigurator"); |
|
36 |
|
37 // --------------------------------------------------------------------------- |
|
38 // Private Constructor |
|
39 // --------------------------------------------------------------------------- |
|
40 // |
|
41 CSimPsyUiAO::CSimPsyUiAO( MSimPsyAOObserver& aObserver ) |
|
42 :CActive( EPriorityStandard ), |
|
43 iObserver( aObserver ) |
|
44 { |
|
45 } |
|
46 |
|
47 // --------------------------------------------------------------------------- |
|
48 // Destructor |
|
49 // --------------------------------------------------------------------------- |
|
50 // |
|
51 CSimPsyUiAO::~CSimPsyUiAO() |
|
52 { |
|
53 Cancel(); |
|
54 } |
|
55 |
|
56 // --------------------------------------------------------------------------- |
|
57 // CSimPsyUiAO* CSimPsyUiAO::NewL |
|
58 // Static Two phase contructor that instantiates the CSimPsyUiAO |
|
59 // |
|
60 // @param aObserver Observer to the Active object |
|
61 // @return CSimPsyUiAO* Reference to the object created |
|
62 // --------------------------------------------------------------------------- |
|
63 // |
|
64 CSimPsyUiAO* CSimPsyUiAO::NewL( MSimPsyAOObserver& aObserver ) |
|
65 { |
|
66 CSimPsyUiAO* self = new ( ELeave ) CSimPsyUiAO( aObserver ); |
|
67 CleanupStack::PushL( self ); |
|
68 self->ConstructL(); |
|
69 CleanupStack::Pop( self ); |
|
70 |
|
71 return self; |
|
72 } |
|
73 |
|
74 // --------------------------------------------------------------------------- |
|
75 // void CSimPsyUiAO::ConstructL |
|
76 // Second phase of the two phase constructor |
|
77 // --------------------------------------------------------------------------- |
|
78 // |
|
79 void CSimPsyUiAO::ConstructL() |
|
80 { |
|
81 CActiveScheduler::Add( this ); |
|
82 } |
|
83 |
|
84 // --------------------------------------------------------------------------- |
|
85 // void CSimPsyUiAO::Initialize |
|
86 // Obtains the current Location information using the Location |
|
87 // Acquisition API. The function call is asynchronous and the |
|
88 // notification regarding the completion of the operation is |
|
89 // provided through the MSimPsyAOObserver object |
|
90 // |
|
91 // --------------------------------------------------------------------------- |
|
92 // |
|
93 void CSimPsyUiAO::GetCurrentLocationL() |
|
94 { |
|
95 |
|
96 // Leave if there is an outstanding Location request |
|
97 if( IsActive()) |
|
98 { |
|
99 User::Leave( KErrInUse ); |
|
100 } |
|
101 |
|
102 TPositionModuleId KUidSimulationPsy = { 0x101f7a81 }; |
|
103 TBuf<KFormatStringLength> buf; |
|
104 |
|
105 // Initialize the Location Server session |
|
106 TInt error = iPositionServer.Connect(); |
|
107 if ( KErrNone != error ) |
|
108 { |
|
109 // Show error to the user and break |
|
110 HBufC* formatString = StringLoader::LoadL( R_SIMPSYUI_SERV_CONNECT_ERR ); |
|
111 StringLoader::Format( buf, *formatString,0, error ); |
|
112 delete formatString; |
|
113 ShowErrorL(buf); |
|
114 User::Leave( KErrCouldNotConnect ); |
|
115 } |
|
116 |
|
117 // Get current Location using the SimulationPSY module |
|
118 error = iPositioner.Open( iPositionServer, KUidSimulationPsy ); |
|
119 |
|
120 // The opening of a subsession failed |
|
121 if ( KErrNone != error ) |
|
122 { |
|
123 // Show error to the user and return |
|
124 iPositionServer.Close(); |
|
125 HBufC* formatString = StringLoader::LoadL( R_SIMPSYUI_PSY_OPEN_ERR ); |
|
126 StringLoader::Format( buf, *formatString,0, error ); |
|
127 delete formatString; |
|
128 ShowErrorL(buf); |
|
129 User::Leave( KErrAbort ); |
|
130 } |
|
131 |
|
132 // Set Requestor information |
|
133 error = iPositioner.SetRequestor( CRequestor::ERequestorService, |
|
134 CRequestor::EFormatApplication, |
|
135 KSimPsyConfiguratorName ); |
|
136 // The requestor could not be set |
|
137 if ( KErrNone != error ) |
|
138 { |
|
139 // Show error to the user and return |
|
140 iPositioner.Close(); |
|
141 iPositionServer.Close(); |
|
142 HBufC* formatString = StringLoader::LoadL( R_SIMPSYUI_SETTING_REQUESTOR_ERR ); |
|
143 StringLoader::Format( buf, *formatString,0, error ); |
|
144 delete formatString; |
|
145 ShowErrorL(buf); |
|
146 User::Leave( KErrAbort ); |
|
147 } |
|
148 |
|
149 iPositioner.NotifyPositionUpdate( iPositionInfo, iStatus ); |
|
150 SetActive(); |
|
151 } |
|
152 |
|
153 // --------------------------------------------------------------------------- |
|
154 // void CSimPsyUiAO::CancelLocationRequest |
|
155 // Cancels any outstanding Location request |
|
156 // --------------------------------------------------------------------------- |
|
157 // |
|
158 void CSimPsyUiAO::CancelLocationRequest() |
|
159 { |
|
160 Cancel(); |
|
161 } |
|
162 |
|
163 // --------------------------------------------------------------------------- |
|
164 // void CSimPsyUiAO::DisplayCurrentLocation |
|
165 // Displays the current Location |
|
166 // --------------------------------------------------------------------------- |
|
167 // |
|
168 void CSimPsyUiAO::DisplayCurrentLocationL() |
|
169 { |
|
170 TPosition pos; |
|
171 iPositionInfo.GetPosition( pos ); |
|
172 TInt dummy = 0; |
|
173 HBufC* formatString = NULL; |
|
174 CAknListQueryDialog* dlg = new( ELeave ) CAknListQueryDialog( &dummy ); |
|
175 dlg->PrepareLC( R_SIMPSYUI_LOCATION_DIALOG ); |
|
176 |
|
177 TReal64 latitude = pos.Latitude(); |
|
178 TReal64 longitude = pos.Longitude(); |
|
179 TReal32 altitude = pos.Altitude(); |
|
180 TReal32 hAccuracy = pos.HorizontalAccuracy(); |
|
181 TReal32 vAccuracy = pos.VerticalAccuracy(); |
|
182 |
|
183 TRealFormat formatter( KFormatCharacterWidth,KFormatDecimalNumbers ); |
|
184 TBuf<KFormatStringLength> buf; |
|
185 CDesCArrayFlat* locData = |
|
186 new( ELeave ) CDesCArrayFlat( KPositionDataGranularity ); |
|
187 CleanupStack::PushL( locData ); |
|
188 |
|
189 buf.Zero(); |
|
190 formatString = StringLoader::LoadL( R_SIMPSYUI_LOCATION_INFO_LATITUDE ); |
|
191 buf.Copy(*formatString); |
|
192 delete formatString; |
|
193 buf.Append( KTabulator ); |
|
194 buf.AppendNum( latitude, formatter ); |
|
195 locData->AppendL( buf ); |
|
196 |
|
197 buf.Zero(); |
|
198 formatString = StringLoader::LoadL( R_SIMPSYUI_LOCATION_INFO_LONGITUDE ); |
|
199 buf.Copy(*formatString); |
|
200 delete formatString; |
|
201 buf.Append( KTabulator ); |
|
202 buf.AppendNum( longitude, formatter ); |
|
203 locData->AppendL( buf ); |
|
204 |
|
205 buf.Zero(); |
|
206 formatString = StringLoader::LoadL( R_SIMPSYUI_LOCATION_INFO_ALTITUDE ); |
|
207 buf.Copy(*formatString); |
|
208 delete formatString; |
|
209 buf.Append( KTabulator ); |
|
210 buf.AppendNum( altitude, formatter ); |
|
211 locData->AppendL( buf ); |
|
212 |
|
213 buf.Zero(); |
|
214 formatString = StringLoader::LoadL( R_SIMPSYUI_LOCATION_INFO_HORZ_ACCURACY ); |
|
215 buf.Copy(*formatString); |
|
216 delete formatString; |
|
217 buf.Append( KTabulator ); |
|
218 buf.AppendNum( hAccuracy, formatter ); |
|
219 locData->AppendL( buf ); |
|
220 |
|
221 buf.Zero(); |
|
222 formatString = StringLoader::LoadL( R_SIMPSYUI_LOCATION_INFO_VERT_ACCURACY ); |
|
223 buf.Copy(*formatString); |
|
224 delete formatString; |
|
225 buf.Append( KTabulator ); |
|
226 buf.AppendNum( vAccuracy, formatter ); |
|
227 locData->AppendL( buf ); |
|
228 |
|
229 CleanupStack::Pop( locData ); |
|
230 dlg->SetItemTextArray( locData ); |
|
231 dlg->SetOwnershipType( ELbmOwnsItemArray ); |
|
232 |
|
233 dlg->RunLD(); |
|
234 } |
|
235 |
|
236 |
|
237 // --------------------------------------------------------------------------- |
|
238 // void CSimPsyUiAO::RunL |
|
239 // Inherited from CActive |
|
240 // --------------------------------------------------------------------------- |
|
241 // |
|
242 void CSimPsyUiAO::RunL() |
|
243 { |
|
244 switch( iStatus.Int()) |
|
245 { |
|
246 case KErrNone: |
|
247 { |
|
248 // Close the server sessions |
|
249 iPositioner.Close(); |
|
250 iPositionServer.Close(); |
|
251 iObserver.NotifyLocationRequestCompletedL(); |
|
252 break; |
|
253 } |
|
254 case KErrCancel: |
|
255 { |
|
256 // There is no need of closing the sessions incase of Cancel since |
|
257 // the sessions are closed as a part of DoCancel |
|
258 break; |
|
259 } |
|
260 default: |
|
261 { |
|
262 // Close the server sessions |
|
263 iPositioner.Close(); |
|
264 iPositionServer.Close(); |
|
265 TBuf<KFormatStringLength> buf; |
|
266 // Display Error Code and Break |
|
267 HBufC* formatString = StringLoader::LoadL( R_SIMPSYUI_GET_LOCATION_ERR ); |
|
268 StringLoader::Format( buf, *formatString,0, iStatus.Int() ); |
|
269 delete formatString; |
|
270 ShowErrorL(buf); |
|
271 break; |
|
272 } |
|
273 } |
|
274 |
|
275 } |
|
276 |
|
277 // --------------------------------------------------------------------------- |
|
278 // void CSimPsyUiAO::DoCancel |
|
279 // Inherited from CActive |
|
280 // --------------------------------------------------------------------------- |
|
281 // |
|
282 void CSimPsyUiAO::DoCancel() |
|
283 { |
|
284 iPositioner.CancelRequest( EPositionerNotifyPositionUpdate ); |
|
285 // Close the server sessions |
|
286 iPositioner.Close(); |
|
287 iPositionServer.Close(); |
|
288 } |
|
289 |
|
290 // --------------------------------------------------------------------------- |
|
291 // void CSimPsyUiAO::ShowErrorL |
|
292 // Displays error note |
|
293 // |
|
294 // @param aErrorText Error text |
|
295 // --------------------------------------------------------------------------- |
|
296 // |
|
297 void CSimPsyUiAO::ShowErrorL(const TDesC& aErrorText) |
|
298 { |
|
299 CAknNoteDialog* note = new( ELeave ) CAknNoteDialog( CAknNoteDialog::EErrorTone, |
|
300 CAknNoteDialog::ENoTimeout ); |
|
301 CleanupStack::PushL( note ); |
|
302 note->SetTextWrapping( ETrue ); |
|
303 note->PrepareLC( R_SIMPSYUI_ERROR_NOTE ); |
|
304 note->SetTextL( aErrorText ); |
|
305 CleanupStack::Pop( note ); |
|
306 note->RunLD(); |
|
307 return; |
|
308 } |
|