1 /* |
|
2 * Copyright (c) 2002 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: Postioning Method Settings view class methods. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // System Include |
|
20 #include <aknViewAppUi.h> // AknViewAppUi |
|
21 #include <featmgr.h> // FeatureManager |
|
22 #include <eikmenup.h> // Menu pane |
|
23 #include <eikmenub.h> // Menu Bar |
|
24 #include <locpsysettingsuiview.rsg> // Resource File |
|
25 #include <avkon.rsg> |
|
26 #include <avkon.hrh> |
|
27 #include <hlplch.h> // Help |
|
28 #include <AknQueryDialog.h> // For Confirmation query |
|
29 |
|
30 // User Includes |
|
31 #include "locpsysettingsview.h" |
|
32 #include "locpsysettingscontainer.h" |
|
33 #include "locpsysettingsui.hrh" |
|
34 #include "locpsyappdebug.h" |
|
35 #include "locpsyeng.h" |
|
36 #include "locpsyinfo.h" |
|
37 #include "locpsysettings.h" |
|
38 #include "locpsyconfigclientimpl.h" |
|
39 #include "locpsycommandhandler.h" |
|
40 #include "locpsysettingsuiuid.hrh" |
|
41 |
|
42 // ================= MEMBER FUNCTIONS ======================= |
|
43 |
|
44 // ----------------------------------------------------------------------------- |
|
45 // CLocPsySettingsView::CLocPsySettingsView |
|
46 // C++ default constructor can NOT contain any code, that |
|
47 // might leave. |
|
48 // ----------------------------------------------------------------------------- |
|
49 CLocPsySettingsView::CLocPsySettingsView( MLocPsyCommandHandler& aCommandHandler ): |
|
50 iCommandHandler( aCommandHandler ) |
|
51 { |
|
52 } |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // CLocPsySettingsView::~CLocPsySettingsView |
|
56 // ----------------------------------------------------------------------------- |
|
57 CLocPsySettingsView::~CLocPsySettingsView() |
|
58 { |
|
59 if ( iContainer ) |
|
60 { |
|
61 AppUi()->RemoveFromViewStack( *this, iContainer ); |
|
62 } |
|
63 |
|
64 delete iContainer; |
|
65 |
|
66 FeatureManager::UnInitializeLib(); |
|
67 |
|
68 // Delete the Postioning Method Settings Engine |
|
69 delete iLocationEngine; |
|
70 |
|
71 // Close the Handle to the RPostionServer |
|
72 iPositionServer.Close(); |
|
73 } |
|
74 |
|
75 // ----------------------------------------------------------------------------- |
|
76 // CLocPsySettingsView::NewLC |
|
77 // Two-phased constructor. |
|
78 // ----------------------------------------------------------------------------- |
|
79 CLocPsySettingsView* CLocPsySettingsView::NewL( MLocPsyCommandHandler& aCommandHandler ) |
|
80 { |
|
81 CLocPsySettingsView* self = CLocPsySettingsView::NewLC( aCommandHandler ); |
|
82 CleanupStack::Pop(self); |
|
83 return self; |
|
84 } |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // CLocPsySettingsView::NewLC |
|
88 // Two-phased constructor. |
|
89 // ----------------------------------------------------------------------------- |
|
90 CLocPsySettingsView* CLocPsySettingsView::NewLC( MLocPsyCommandHandler& aCommandHandler ) |
|
91 { |
|
92 CLocPsySettingsView* self = new (ELeave) CLocPsySettingsView( aCommandHandler ); |
|
93 CleanupStack::PushL( self ); |
|
94 self->ConstructL(); |
|
95 return self; |
|
96 } |
|
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // CLocPsySettingsView::ConstructL |
|
100 // Symbian 2nd phase constructor can leave. |
|
101 // ----------------------------------------------------------------------------- |
|
102 void CLocPsySettingsView::ConstructL() |
|
103 { |
|
104 FeatureManager::InitializeLibL(); |
|
105 BaseConstructL( R_LOCATION_HOME_VIEW ); |
|
106 |
|
107 // Create the Postioning Method Settings Engine |
|
108 iLocationEngine = CLocPsyEng::NewL(); |
|
109 |
|
110 // Open a handle to the RPostionServer. This is required to determine |
|
111 // whether a PSY is currently enabled or disabled |
|
112 User::LeaveIfError( iPositionServer.Connect()); |
|
113 |
|
114 } |
|
115 |
|
116 // ----------------------------------------------------------------------------- |
|
117 // TUid CLocPsySettingsView::Id |
|
118 // ----------------------------------------------------------------------------- |
|
119 TUid CLocPsySettingsView::Id() const |
|
120 { |
|
121 return TUid::Uid( LOCPSYSETTINGSUI_UID3 ); |
|
122 } |
|
123 |
|
124 // ----------------------------------------------------------------------------- |
|
125 // CLocPsySettingsView::HandleCommandL |
|
126 // ----------------------------------------------------------------------------- |
|
127 void CLocPsySettingsView::HandleCommandL(TInt aCommand) |
|
128 { |
|
129 MLocPsySettings* psySettings = iLocationEngine->SettingsModel(); |
|
130 |
|
131 TInt listIndex = iContainer->SelectedRow(); |
|
132 |
|
133 switch ( aCommand ) |
|
134 { |
|
135 case ELocCmdEnablePsy: |
|
136 { |
|
137 TRAPD( err, psySettings->EnablePsyL( listIndex )); |
|
138 if ( err == KErrNone ) |
|
139 { |
|
140 iContainer->HandleMarkCommandL( EAknCmdMark ); |
|
141 } |
|
142 break; |
|
143 } |
|
144 case ELocCmdDisablePsy: |
|
145 { |
|
146 |
|
147 TBool popUpConfirmation = EFalse; |
|
148 |
|
149 // Obtain the PSY specific information |
|
150 CLocPsyInfo* info = NULL; |
|
151 TRAPD( error, info = psySettings->GetPsyL( listIndex )); |
|
152 if( error ) |
|
153 { |
|
154 // Unable to obtain PSY info. Don't continue with the operation |
|
155 break; |
|
156 } |
|
157 |
|
158 // Obtain the module status |
|
159 TPositionModuleStatus moduleStatus; |
|
160 error = iPositionServer.GetModuleStatus( moduleStatus, |
|
161 info->PsyId()); |
|
162 if( error ) |
|
163 { |
|
164 // Unable to obtain module status. Don't continue with the operation |
|
165 break; |
|
166 } |
|
167 |
|
168 // Set the popUpConfirmation flag if the PSY is being used |
|
169 if( TPositionModuleStatus::EDeviceActive == moduleStatus.DeviceStatus() || |
|
170 TPositionModuleStatus::EDeviceReady == moduleStatus.DeviceStatus() || |
|
171 TPositionModuleStatus::EDeviceInitialising == moduleStatus.DeviceStatus() || |
|
172 TPositionModuleStatus::EDeviceStandBy == moduleStatus.DeviceStatus()) |
|
173 { |
|
174 popUpConfirmation = ETrue; |
|
175 } |
|
176 |
|
177 |
|
178 if( popUpConfirmation ) |
|
179 { |
|
180 // The user should not be allowed to disable a PSY that is currently |
|
181 //being used. Hence, a confirmation dialog is popped up |
|
182 iConfirmationQuery = CAknQueryDialog::NewL(); |
|
183 TBool result = |
|
184 iConfirmationQuery->ExecuteLD( R_PSYDISABLE_CONFIG_QUERY ); |
|
185 iConfirmationQuery = NULL; |
|
186 if( !result ) |
|
187 { |
|
188 break; |
|
189 } |
|
190 } |
|
191 |
|
192 TRAPD( err, psySettings->DisablePsyL( listIndex )); |
|
193 if ( err == KErrNone ) |
|
194 { |
|
195 iContainer->HandleMarkCommandL( EAknCmdUnmark ); |
|
196 } |
|
197 break; |
|
198 } |
|
199 case ELocCmdConfigurePsy: |
|
200 { |
|
201 psySettings->ConfigurePsyL( listIndex, *this ); |
|
202 break; |
|
203 } |
|
204 case EAknCmdHelp: |
|
205 { |
|
206 HlpLauncher::LaunchHelpApplicationL( CEikonEnv::Static()->WsSession(), |
|
207 AppUi()->AppHelpContextL()); |
|
208 break; |
|
209 } |
|
210 case EAknSoftkeyBack: |
|
211 { |
|
212 iCommandHandler.HandleCommandL( EAknSoftkeyBack ); |
|
213 break; |
|
214 } |
|
215 case EAknSoftkeyExit: |
|
216 { |
|
217 AppUi()->HandleCommandL( EEikCmdExit ); |
|
218 break; |
|
219 } |
|
220 case ELocCmdNone: |
|
221 { |
|
222 break; |
|
223 } |
|
224 default: // EAknCmdHelp or other cmd |
|
225 { |
|
226 AppUi()->HandleCommandL( aCommand ); |
|
227 break; |
|
228 } |
|
229 } |
|
230 } |
|
231 |
|
232 // ----------------------------------------------------------------------------- |
|
233 // CLocPsySettingsView::ProcessCommandL |
|
234 // ----------------------------------------------------------------------------- |
|
235 void CLocPsySettingsView::ProcessCommandL( TInt aCommand ) |
|
236 { |
|
237 MenuBar()->SetContextMenuTitleResourceId(R_LOCATION_CONTEXT_MENUBAR_HOME_VIEW); |
|
238 // Close popup menu if open |
|
239 MenuBar()->StopDisplayingMenuBar(); |
|
240 // Call base class |
|
241 CAknView::ProcessCommandL( aCommand ); |
|
242 } |
|
243 |
|
244 // ----------------------------------------------------------------------------- |
|
245 // CLocPsySettingsView::DynInitMenuPaneL |
|
246 // ----------------------------------------------------------------------------- |
|
247 void CLocPsySettingsView::DynInitMenuPaneL( TInt aResourceId, |
|
248 CEikMenuPane* aMenuPane ) |
|
249 { |
|
250 if ( aResourceId == R_LOCATION_APP_MENU ) |
|
251 { |
|
252 User::LeaveIfNull( aMenuPane ); |
|
253 //Handle Help Fature |
|
254 HandleHelpFeature( *aMenuPane ); |
|
255 //Context sensitive menu items |
|
256 } |
|
257 else if ( aResourceId == R_LOCATION_HOME_VIEW_MENU ) |
|
258 { |
|
259 MLocPsySettings* psySettings = iLocationEngine->SettingsModel(); |
|
260 |
|
261 TInt listIndex = iContainer->SelectedRow(); |
|
262 if( listIndex >= 0 ) |
|
263 { |
|
264 TBool isPsyEnabled = psySettings->IsPsyEnabled( listIndex ); |
|
265 |
|
266 //Enable is present only if the current selected PSY is disabled. |
|
267 aMenuPane->SetItemDimmed( ELocCmdEnablePsy,isPsyEnabled ); |
|
268 |
|
269 //Disable is present only if the current selected PSY is enabled |
|
270 aMenuPane->SetItemDimmed( ELocCmdDisablePsy,!isPsyEnabled ); |
|
271 |
|
272 // Method setting is present only if the current selected PSY |
|
273 //is configurable. |
|
274 aMenuPane->SetItemDimmed( ELocCmdConfigurePsy, |
|
275 !psySettings->IsPsyConfigurable( listIndex )); |
|
276 } |
|
277 else |
|
278 { |
|
279 |
|
280 //Disable the menu items when there are no PSYS installed |
|
281 aMenuPane->SetItemDimmed( ELocCmdEnablePsy, ETrue ); |
|
282 aMenuPane->SetItemDimmed( ELocCmdDisablePsy, ETrue ); |
|
283 aMenuPane->SetItemDimmed( ELocCmdConfigurePsy, ETrue ); |
|
284 } |
|
285 } |
|
286 } |
|
287 |
|
288 // ----------------------------------------------------------------------------- |
|
289 // CLocPsySettingsView::NotifyL |
|
290 // ----------------------------------------------------------------------------- |
|
291 void CLocPsySettingsView::NotifyL() |
|
292 { |
|
293 MLocPsySettings* psySettings = iLocationEngine->SettingsModel(); |
|
294 |
|
295 if(!psySettings) |
|
296 return; |
|
297 |
|
298 // Disable the Middle soft Key if there are no PSYs |
|
299 if( psySettings && !psySettings->PSYCount()) |
|
300 { |
|
301 Cba()->SetCommandSetL( R_LOCATION_OPTIONS_EMPTY_BACK ); |
|
302 } |
|
303 else |
|
304 { |
|
305 MenuBar()->SetContextMenuTitleResourceId(R_LOCATION_CONTEXT_MENUBAR_HOME_VIEW); |
|
306 Cba()->SetCommandSetL( R_LOCATION_OPTIONS_SELECTION_BACK ); |
|
307 } |
|
308 |
|
309 // If the confirmation query is currently being displayed then check whether |
|
310 // its valid to continue to display the query. If not then dismiss the |
|
311 // query |
|
312 if( iConfirmationQuery ) |
|
313 { |
|
314 if( !iContainer ) |
|
315 { |
|
316 // The is no container. There is nothing to update. Just return |
|
317 return; |
|
318 } |
|
319 TInt listIndex = iContainer->SelectedRow(); |
|
320 |
|
321 // Obtain the PSY specific information |
|
322 CLocPsyInfo* info = NULL; |
|
323 TRAPD( error, info = psySettings->GetPsyL( listIndex )); |
|
324 if( !error ) |
|
325 { |
|
326 // Obtain the module status |
|
327 TPositionModuleStatus moduleStatus; |
|
328 error = iPositionServer.GetModuleStatus( moduleStatus, |
|
329 info->PsyId()); |
|
330 if( !error ) |
|
331 { |
|
332 if( TPositionModuleStatus::EDeviceDisabled == moduleStatus.DeviceStatus() || |
|
333 TPositionModuleStatus::EDeviceInactive == moduleStatus.DeviceStatus()) |
|
334 { |
|
335 // If the PSY for which the confirmation query is being displayed |
|
336 // is currently disabled then the query needs to be dismissed |
|
337 delete iConfirmationQuery; |
|
338 iConfirmationQuery = NULL; |
|
339 } |
|
340 } |
|
341 |
|
342 |
|
343 } |
|
344 } |
|
345 |
|
346 // Settings view implements the MLocEngObserver observer interface |
|
347 // which contains this leavable method. |
|
348 if ( iContainer ) |
|
349 { |
|
350 LOCAPPDEBUG("CLocPsySettingsView::NotifyL() container update called"); |
|
351 iContainer->UpdateL(); |
|
352 } |
|
353 } |
|
354 |
|
355 // ----------------------------------------------------------------------------- |
|
356 // CLocPsySettingsView::NotifyError |
|
357 // ----------------------------------------------------------------------------- |
|
358 void CLocPsySettingsView::NotifyError( TInt aErrorCode ) |
|
359 { |
|
360 LOCAPPDEBUG("CLocPsySettingsView::NotifyError() called"); |
|
361 if ( aErrorCode != KErrNone ) |
|
362 { |
|
363 CCoeEnv::Static()->HandleError( aErrorCode ); |
|
364 } |
|
365 } |
|
366 |
|
367 |
|
368 // ----------------------------------------------------------------------------- |
|
369 // CLocPsySettingsView::ProcessKeyEventL |
|
370 // ----------------------------------------------------------------------------- |
|
371 TBool CLocPsySettingsView::ProcessKeyEventL( const TKeyEvent& aKeyEvent, |
|
372 TEventCode aType ) |
|
373 { |
|
374 MLocPsySettings* psySettings = iLocationEngine->SettingsModel(); |
|
375 |
|
376 if(!psySettings) |
|
377 return EKeyWasNotConsumed; |
|
378 |
|
379 if( psySettings && !psySettings->PSYCount()) |
|
380 { |
|
381 return EKeyWasNotConsumed; |
|
382 } |
|
383 TInt listIndex = iContainer->SelectedRow(); |
|
384 |
|
385 // Popup the Menu when OK Selection key is pressed |
|
386 if ( aType == EEventKey && aKeyEvent.iCode == EKeyOK ) |
|
387 { |
|
388 //Check if the current positioning method is configurable or not |
|
389 //If yes then launch the context specific value |
|
390 //else toggle status of the current positioning method (changes for single click) |
|
391 if(!psySettings->IsPsyConfigurable( listIndex )) |
|
392 { |
|
393 if(!psySettings->IsPsyEnabled( listIndex )) |
|
394 { |
|
395 //Enable |
|
396 HandleCommandL(ELocCmdEnablePsy); |
|
397 } |
|
398 else |
|
399 { |
|
400 //disable |
|
401 HandleCommandL(ELocCmdDisablePsy); |
|
402 } |
|
403 } |
|
404 else |
|
405 { |
|
406 MenuBar()->TryDisplayContextMenuBarL(); |
|
407 } |
|
408 return EKeyWasConsumed; |
|
409 } |
|
410 return EKeyWasNotConsumed; |
|
411 } |
|
412 |
|
413 // ----------------------------------------------------------------------------- |
|
414 // CLocPsySettingsView::HandleServerAppExit |
|
415 // ----------------------------------------------------------------------------- |
|
416 void CLocPsySettingsView::HandleServerAppExit(TInt /*aReason*/) |
|
417 { |
|
418 MLocPsySettings* psySettings = iLocationEngine->SettingsModel(); |
|
419 |
|
420 /* Once the application exits the application handle in the Engine has to |
|
421 * be closed. Also this callback is triggered when the PSY configuration UI |
|
422 * is running but it has to be closed for some reason. For example, if |
|
423 * the PSY for which the configuration UI is running, is uninstalled then |
|
424 * the configuration application has to be closed. |
|
425 */ |
|
426 psySettings->ClosePsyConfigurationApp(); |
|
427 } |
|
428 |
|
429 // ----------------------------------------------------------------------------- |
|
430 // CLocPsySettingsView::HandleScreenSizeChange |
|
431 // ----------------------------------------------------------------------------- |
|
432 // |
|
433 void CLocPsySettingsView::HandleScreenSizeChange() |
|
434 { |
|
435 if( iContainer ) |
|
436 { |
|
437 iContainer->SetRect( ClientRect()); |
|
438 } |
|
439 } |
|
440 |
|
441 // ----------------------------------------------------------------------------- |
|
442 // CLocPsySettingsView::DoActivateL |
|
443 // ----------------------------------------------------------------------------- |
|
444 void CLocPsySettingsView::DoActivateL( |
|
445 const TVwsViewId& /*aPrevViewId*/,TUid /*aCustomMessageId*/, |
|
446 const TDesC8& /*aCustomMessage*/ ) |
|
447 { |
|
448 LOCAPPDEBUG("CLocPsySettingsView::DoActivateL() called"); |
|
449 if ( !iContainer ) |
|
450 { |
|
451 iLocationEngine->CreateModelL( ELocPsySettings ); |
|
452 MLocPsySettings* psySettings = iLocationEngine->SettingsModel(); |
|
453 psySettings->SetObserver(*this); |
|
454 iContainer = CLocPsySettingsContainer::NewL( this, |
|
455 this, |
|
456 this, |
|
457 psySettings, |
|
458 ClientRect()); |
|
459 AppUi()->AddToStackL( *this, iContainer ); |
|
460 } |
|
461 |
|
462 MLocPsySettings* psySettings = iLocationEngine->SettingsModel(); |
|
463 // Disable the Middle soft Key if there are no PSYs |
|
464 if( psySettings && !psySettings->PSYCount()) |
|
465 { |
|
466 Cba()->SetCommandSetL( R_LOCATION_OPTIONS_EMPTY_BACK ); |
|
467 } |
|
468 else |
|
469 { |
|
470 MenuBar()->SetContextMenuTitleResourceId(R_LOCATION_CONTEXT_MENUBAR_HOME_VIEW ); |
|
471 Cba()->SetCommandSetL( R_LOCATION_OPTIONS_SELECTION_BACK ); |
|
472 } |
|
473 } |
|
474 |
|
475 // ----------------------------------------------------------------------------- |
|
476 // CLocPsySettingsView::DoDeactivate |
|
477 // ----------------------------------------------------------------------------- |
|
478 void CLocPsySettingsView::DoDeactivate() |
|
479 { |
|
480 iLocationEngine->SettingsModel()->RemoveModelObserver(); |
|
481 iLocationEngine->RemoveModel( ELocPsySettings ); |
|
482 if ( iContainer ) |
|
483 { |
|
484 AppUi()->RemoveFromViewStack( *this, iContainer ); |
|
485 } |
|
486 delete iContainer; |
|
487 iContainer = NULL; |
|
488 } |
|
489 |
|
490 // ----------------------------------------------------------------------------- |
|
491 // CLocPsySettingsView::ActivateLocalViewL |
|
492 // ----------------------------------------------------------------------------- |
|
493 void CLocPsySettingsView::ActivateLocalViewL( TUid aViewId, |
|
494 TUid aCustomMessageId, const TDesC8& aCustomMessage ) |
|
495 { |
|
496 CAknViewAppUi* appui = AppUi(); |
|
497 appui->ActivateLocalViewL(aViewId, aCustomMessageId, aCustomMessage); |
|
498 } |
|
499 |
|
500 // ----------------------------------------------------------------------------- |
|
501 // CLocPsySettingsView::ActivateLocalViewL |
|
502 // ----------------------------------------------------------------------------- |
|
503 void CLocPsySettingsView::ActivateLocalViewL( TUid aViewId ) |
|
504 { |
|
505 TBuf8<1> customMessage; |
|
506 customMessage.Zero(); |
|
507 // Custom message Id value contains view id of caller |
|
508 ActivateLocalViewL( aViewId, Id(), customMessage ); |
|
509 } |
|
510 |
|
511 |
|
512 |
|
513 // ----------------------------------------------------------------------------- |
|
514 // CLocPsySettingsView::HandleHelpFeature |
|
515 // ----------------------------------------------------------------------------- |
|
516 void CLocPsySettingsView::HandleHelpFeature( CEikMenuPane& aMenuPane ) const |
|
517 { |
|
518 if ( FeatureManager::FeatureSupported( KFeatureIdHelp )) |
|
519 { |
|
520 aMenuPane.SetItemDimmed( EAknCmdHelp, EFalse ); |
|
521 } |
|
522 else |
|
523 { |
|
524 aMenuPane.SetItemDimmed( EAknCmdHelp, ETrue ); |
|
525 } |
|
526 } |
|