|
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: Location Triggering Management Plugin view |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // System Include |
|
20 #include <barsread.h> // For TResourceReader |
|
21 #include <bautils.h> |
|
22 #include <StringLoader.h> |
|
23 #include <aknViewAppUi.h> |
|
24 #include <lbtmgmtpluginview.rsg> |
|
25 #include <avkon.rsg> |
|
26 #include <aknnotewrappers.h> // Error Notes |
|
27 #include <textresolver.h> // Text Resolver |
|
28 #include <hlplch.h> // Help |
|
29 #include <featmgr.h> // FeatureManager |
|
30 |
|
31 // User Include |
|
32 #include "locsettingsui.h" |
|
33 #include "locsettingsuiobserver.h" |
|
34 #include "lbtmgmtplugin.hrh" |
|
35 #include "lbtmgmtpluginview.h" |
|
36 #include "lbtmgmtplugincontainer.h" |
|
37 #include "lbtmgmtpluginengine.h" |
|
38 |
|
39 |
|
40 // ========================= MEMBER FUNCTIONS ================================ |
|
41 |
|
42 |
|
43 // --------------------------------------------------------------------------- |
|
44 // CLbtMgmtPluginView::CLbtMgmtPluginView |
|
45 // Overloaded Constructor |
|
46 // |
|
47 // --------------------------------------------------------------------------- |
|
48 // |
|
49 CLbtMgmtPluginView::CLbtMgmtPluginView( |
|
50 MLocSettingsUiObserver& aSettingsObsrv ) |
|
51 :iSettingsObserver( aSettingsObsrv ), |
|
52 iResourceLoader( *CCoeEnv::Static() ) |
|
53 { |
|
54 } |
|
55 |
|
56 // --------------------------------------------------------------------------- |
|
57 // CLbtMgmtPluginView::~CLbtMgmtPluginView |
|
58 // Destructor |
|
59 // |
|
60 // --------------------------------------------------------------------------- |
|
61 // |
|
62 CLbtMgmtPluginView::~CLbtMgmtPluginView() |
|
63 { |
|
64 // Close the resource loader |
|
65 iResourceLoader.Close(); |
|
66 } |
|
67 |
|
68 // --------------------------------------------------------------------------- |
|
69 // CLbtMgmtPluginView* CLbtMgmtPluginView::NewL |
|
70 // Creates new Location Trigger Management view. |
|
71 // |
|
72 // @param aSettingsObsrv Pointer to the Command Handler |
|
73 // @return CLbtMgmtPluginView* Reference to the application view |
|
74 // --------------------------------------------------------------------------- |
|
75 // |
|
76 CLbtMgmtPluginView* CLbtMgmtPluginView::NewL( |
|
77 MLocSettingsUiObserver& aSettingsObsrv ) |
|
78 { |
|
79 CLbtMgmtPluginView* self = |
|
80 CLbtMgmtPluginView::NewLC( aSettingsObsrv ); |
|
81 CleanupStack::Pop( self ); |
|
82 return self; |
|
83 } |
|
84 |
|
85 // --------------------------------------------------------------------------- |
|
86 // CLbtMgmtPluginView* CLbtMgmtPluginView::NewLC |
|
87 // Creates new Location Trigger Management view. |
|
88 // |
|
89 // @param aSettingsObsrv Pointer to the Command Handler |
|
90 // @return CLbtMgmtPluginView* Reference to the application view |
|
91 // --------------------------------------------------------------------------- |
|
92 // |
|
93 CLbtMgmtPluginView* CLbtMgmtPluginView::NewLC( |
|
94 MLocSettingsUiObserver& aSettingsObsrv ) |
|
95 { |
|
96 CLbtMgmtPluginView* self = |
|
97 new(ELeave) CLbtMgmtPluginView( aSettingsObsrv ); |
|
98 CleanupStack::PushL( self ); |
|
99 self->ConstructL(); |
|
100 return self; |
|
101 } |
|
102 |
|
103 // --------------------------------------------------------------------------- |
|
104 // void CLbtMgmtPluginView::ConstructL |
|
105 // Second Phase Constructor |
|
106 // |
|
107 // --------------------------------------------------------------------------- |
|
108 // |
|
109 void CLbtMgmtPluginView::ConstructL() |
|
110 { |
|
111 |
|
112 // Open the Resource File |
|
113 OpenLocalizedResourceFileL( KLbtMgmtViewResFileName, iResourceLoader ); |
|
114 |
|
115 // Call AknView's BaseConstrutL |
|
116 BaseConstructL( R_LBTMGMTPLUGIN_VIEW ); |
|
117 |
|
118 } |
|
119 |
|
120 // --------------------------------------------------------------------------- |
|
121 // void CLbtMgmtPluginView::CloseSettings |
|
122 // Close the Location Triggering Management Settings |
|
123 // |
|
124 // --------------------------------------------------------------------------- |
|
125 // |
|
126 void CLbtMgmtPluginView::CloseSettings() |
|
127 { |
|
128 // Stop displaying the menu bar, if its currently being displayed |
|
129 StopDisplayingMenuBar(); |
|
130 |
|
131 // Close all the active dialogs |
|
132 if( iEngine ) |
|
133 iEngine->Close(); |
|
134 } |
|
135 |
|
136 // --------------------------------------------------------------------------- |
|
137 // void CLbtMgmtPluginView::DoActivateL |
|
138 // |
|
139 // --------------------------------------------------------------------------- |
|
140 // |
|
141 void CLbtMgmtPluginView::DoActivateL( const TVwsViewId& /* PrevViewId*/, |
|
142 TUid /* aCustomMessageId*/, |
|
143 const TDesC8& /* aCustomMessage */) |
|
144 { |
|
145 // Destroy the existing container if it exists |
|
146 if( iContainer ) |
|
147 { |
|
148 AppUi()->RemoveFromViewStack( *this, iContainer ); |
|
149 delete iContainer; |
|
150 iContainer=NULL; |
|
151 } |
|
152 |
|
153 // Create the Location Triggering engine instance |
|
154 iEngine = CLbtMgmtPluginEngine::NewL( *this ); |
|
155 |
|
156 // Create new Container |
|
157 iContainer = CLbtMgmtPluginContainer::NewL( ClientRect(), |
|
158 *iEngine, |
|
159 *this ); |
|
160 iContainer->SetMopParent( this ); |
|
161 AppUi()->AddToViewStackL( *this, iContainer ); |
|
162 |
|
163 SetCba( R_LBTMGMTPLUGIN_CBA_CHANGE ); |
|
164 } |
|
165 |
|
166 // --------------------------------------------------------------------------- |
|
167 // void CLocationSystemUiView::DoDeactivate |
|
168 // |
|
169 // --------------------------------------------------------------------------- |
|
170 // |
|
171 void CLbtMgmtPluginView::DoDeactivate() |
|
172 { |
|
173 // Destroy Container |
|
174 AppUi()->RemoveFromViewStack( *this, iContainer ); |
|
175 delete iContainer; |
|
176 iContainer = NULL; |
|
177 |
|
178 // Delete the engine |
|
179 delete iEngine; |
|
180 iEngine = NULL; |
|
181 |
|
182 } |
|
183 |
|
184 // --------------------------------------------------------------------------- |
|
185 // TUid CLbtMgmtPluginView::Id |
|
186 // Returns the View Id. Should be chosen to reflect the Implementation UID |
|
187 // of the Plugin |
|
188 // |
|
189 // @return TUid The View Id |
|
190 // --------------------------------------------------------------------------- |
|
191 // |
|
192 TUid CLbtMgmtPluginView::Id() const |
|
193 { |
|
194 return TUid::Uid( KLbtMgmtPluginUID3 ); |
|
195 } |
|
196 |
|
197 // --------------------------------------------------------------------------- |
|
198 // void CLbtMgmtPluginView::HandleCommandL |
|
199 // |
|
200 // --------------------------------------------------------------------------- |
|
201 // |
|
202 void CLbtMgmtPluginView::HandleCommandL(TInt aCommand) |
|
203 { |
|
204 switch( aCommand ) |
|
205 { |
|
206 case ELbtMgmtChange: |
|
207 case ELbtMgmtMSKChange: |
|
208 { |
|
209 SettingsChangeL(aCommand); |
|
210 break; |
|
211 } |
|
212 case ELbtMgmtInfo: |
|
213 case ELbtMgmtMSKInfo: |
|
214 { |
|
215 iEngine->ShowInfoDialogL(); |
|
216 break; |
|
217 } |
|
218 case ELbtMgmtClearAll: |
|
219 { |
|
220 iEngine->ClearAllTriggersL(); |
|
221 iContainer->Update(); |
|
222 HandleCmdL(EListBoxItemFocused); |
|
223 break; |
|
224 } |
|
225 case EAknCmdHelp: |
|
226 { |
|
227 HlpLauncher::LaunchHelpApplicationL( iCoeEnv->WsSession(), |
|
228 AppUi()->AppHelpContextL()); |
|
229 break; |
|
230 } |
|
231 // Handle any plug-in specific internal commands here |
|
232 case EAknSoftkeyBack: |
|
233 { |
|
234 // The UI is intended to be closed. Pass the event |
|
235 // to the observer |
|
236 iSettingsObserver.SettingClosed( KErrNone ); |
|
237 break; |
|
238 } |
|
239 default: |
|
240 { |
|
241 // Un-handled commands are to be passed to the |
|
242 // App UI |
|
243 AppUi()->HandleCommandL( aCommand ); |
|
244 break; |
|
245 } |
|
246 } |
|
247 } |
|
248 |
|
249 // ----------------------------------------------------------------------------- |
|
250 // CLbtMgmtPluginView::DynInitMenuPaneL |
|
251 // ----------------------------------------------------------------------------- |
|
252 // |
|
253 void CLbtMgmtPluginView::DynInitMenuPaneL( TInt aResourceId, |
|
254 CEikMenuPane* aMenuPane ) |
|
255 { |
|
256 if ( aResourceId == R_LBTMGMTPLUGIN_MENU ) |
|
257 { |
|
258 User::LeaveIfNull( aMenuPane ); |
|
259 //Handle Help Feature |
|
260 |
|
261 //Context sensitive menu items |
|
262 if( CLbtMgmtPluginEngine::EActiveTriggers == iContainer->GetFocussedItem() ) |
|
263 { |
|
264 aMenuPane->SetItemDimmed( ELbtMgmtChange, ETrue ); |
|
265 if( iEngine->ActiveTriggers() ) |
|
266 { |
|
267 aMenuPane->SetItemDimmed( ELbtMgmtClearAll, EFalse ); |
|
268 aMenuPane->SetItemDimmed( ELbtMgmtInfo, EFalse ); |
|
269 } |
|
270 else |
|
271 { |
|
272 aMenuPane->SetItemDimmed( ELbtMgmtClearAll, ETrue ); |
|
273 aMenuPane->SetItemDimmed( ELbtMgmtInfo, ETrue ); |
|
274 } |
|
275 } |
|
276 else |
|
277 { |
|
278 aMenuPane->SetItemDimmed( ELbtMgmtChange, EFalse ); |
|
279 aMenuPane->SetItemDimmed( ELbtMgmtClearAll, ETrue ); |
|
280 aMenuPane->SetItemDimmed( ELbtMgmtInfo, ETrue ); |
|
281 } |
|
282 } |
|
283 } |
|
284 |
|
285 // ----------------------------------------------------------------------------- |
|
286 // CLbtMgmtPluginView::SetCba |
|
287 // ----------------------------------------------------------------------------- |
|
288 // |
|
289 void CLbtMgmtPluginView::SetCba( TInt aResourceId ) |
|
290 { |
|
291 if( Cba() ) |
|
292 { |
|
293 TRAP_IGNORE(Cba()->SetCommandSetL(aResourceId)); |
|
294 } |
|
295 Cba()->DrawDeferred(); |
|
296 } |
|
297 |
|
298 // --------------------------------------------------------------------------- |
|
299 // void CLbtMgmtPluginView::HandleCommandL |
|
300 // Inherited from MLbtMgmtPluginCmdHdlr |
|
301 // Handles Selection events from the container |
|
302 // |
|
303 // @param aCommand Command ID |
|
304 // --------------------------------------------------------------------------- |
|
305 // |
|
306 void CLbtMgmtPluginView::HandleCmdL( TLbtMgmtPluginCmd aCommand ) |
|
307 { |
|
308 switch( aCommand ) |
|
309 { |
|
310 // Handle any plug-in specific internal commands here |
|
311 case EListBoxItemSelected: |
|
312 { |
|
313 // Handle List Box Selected Event |
|
314 TRAPD( error, SettingsChangeL( ELbtMgmtMSKChange )); |
|
315 if( error ) |
|
316 { |
|
317 // Show Error Note |
|
318 CTextResolver* iTextResolver = CTextResolver::NewLC(*iCoeEnv); |
|
319 TPtrC buffer = iTextResolver->ResolveErrorString( error ); |
|
320 CAknErrorNote* errorNote = new ( ELeave )CAknErrorNote( ETrue ); |
|
321 TRAP_IGNORE( errorNote->ExecuteLD( buffer )); |
|
322 CleanupStack::PopAndDestroy( iTextResolver ); |
|
323 } |
|
324 break; |
|
325 } |
|
326 case EListBoxItemFocused: |
|
327 { |
|
328 if( CLbtMgmtPluginEngine::EActiveTriggers == iContainer->GetFocussedItem() ) |
|
329 { |
|
330 if( iEngine->ActiveTriggers() ) |
|
331 SetCba( R_LBTMGMTPLUGIN_CBA_INFO ); |
|
332 else |
|
333 SetCba( R_LBTMGMTPLUGIN_CBA_NOACTIVETRIGGERS ); |
|
334 } |
|
335 else |
|
336 SetCba( R_LBTMGMTPLUGIN_CBA_CHANGE ); |
|
337 break; |
|
338 } |
|
339 case EScreenSizeChanged: |
|
340 { |
|
341 if( iContainer ) |
|
342 { |
|
343 iContainer->SetRect( ClientRect()); |
|
344 } |
|
345 break; |
|
346 } |
|
347 default: |
|
348 { |
|
349 break; |
|
350 } |
|
351 } |
|
352 } |
|
353 |
|
354 // --------------------------------------------------------------------------- |
|
355 // Inherited from MLbtMgmtEngObserver |
|
356 // --------------------------------------------------------------------------- |
|
357 // |
|
358 void CLbtMgmtPluginView::HandleSettingsChangeEventL() |
|
359 { |
|
360 // Observer callback notifies that one/more of the settings values have |
|
361 // changed. Hence, need to refresh the container to show the latest |
|
362 // values |
|
363 if( iContainer ) |
|
364 { |
|
365 iContainer->DrawDeferred(); |
|
366 } |
|
367 |
|
368 // Handle any changes to the MSK configuration. |
|
369 HandleCmdL( EListBoxItemFocused ); |
|
370 } |
|
371 |
|
372 // ----------------------------------------------------------------------------- |
|
373 // CLbtMgmtPluginView::HandleHelpFeature |
|
374 // ----------------------------------------------------------------------------- |
|
375 // |
|
376 void CLbtMgmtPluginView::HandleHelpFeature( CEikMenuPane& aMenuPane ) const |
|
377 { |
|
378 if ( FeatureManager::FeatureSupported( KFeatureIdHelp )) |
|
379 { |
|
380 aMenuPane.SetItemDimmed( EAknCmdHelp, EFalse ); |
|
381 } |
|
382 else |
|
383 { |
|
384 aMenuPane.SetItemDimmed( EAknCmdHelp, ETrue ); |
|
385 } |
|
386 } |
|
387 |
|
388 |
|
389 // --------------------------------------------------------------------------- |
|
390 // Handle Settings Change Event |
|
391 // |
|
392 // @param aCmd Settings change command |
|
393 // --------------------------------------------------------------------------- |
|
394 // |
|
395 void CLbtMgmtPluginView::SettingsChangeL( TInt aCmd ) |
|
396 { |
|
397 if( !iContainer ) |
|
398 { |
|
399 // No container available. Nothing to do in this case. Hence, returning |
|
400 return; |
|
401 } |
|
402 CLbtMgmtPluginEngine::TSettingsList currentElement; |
|
403 currentElement = static_cast<CLbtMgmtPluginEngine::TSettingsList> |
|
404 ( iContainer->GetFocussedItem() ); |
|
405 |
|
406 // Switch based on the currently focussed element |
|
407 switch( currentElement ) |
|
408 { |
|
409 case CLbtMgmtPluginEngine::ETriggeringStatus: |
|
410 { |
|
411 // Different handling needed for Touch handling and Item selection |
|
412 // using the OK key. |
|
413 // Incase the User has selected the item using the OK key then |
|
414 // normal handling required |
|
415 // Incase the User has selected the item using touch selection |
|
416 // then the Trigger Status needs to be toggled |
|
417 if( ELbtMgmtChange == aCmd ) |
|
418 { |
|
419 iEngine->ChangeTiggerStatusL(); |
|
420 } |
|
421 else |
|
422 { |
|
423 iEngine->ToggleTiggerStatusL(); |
|
424 } |
|
425 iContainer->Update(); |
|
426 break; |
|
427 } |
|
428 case CLbtMgmtPluginEngine::EActiveTriggers: |
|
429 { |
|
430 // If condition is added for any pointer event from container |
|
431 if( iEngine->ActiveTriggers() ) |
|
432 iEngine->ShowInfoDialogL(); |
|
433 break; |
|
434 } |
|
435 default: |
|
436 { |
|
437 // Element not found |
|
438 User::Leave( KErrNotFound ); |
|
439 } |
|
440 } |
|
441 } |
|
442 |
|
443 // --------------------------------------------------------------------------- |
|
444 // void CLbtMgmtPluginView::OpenLocalizedResourceFileL |
|
445 // Opens the nearest localized resourcefile using aResourceLoader. |
|
446 // aResourceLoader should be opened only once before closing it. |
|
447 // Otherwise it will raise a panic. Therefore it is better to have |
|
448 // multiple resource loaders. |
|
449 // |
|
450 // @param aResourceFileName Drive and name of resource file in format |
|
451 // <path>:<rsc_file_name> |
|
452 // @param aResourceLoader Resource loader for the resource. The loader |
|
453 // must not be opened allready or it will raise |
|
454 // a panic. It is caller's responsibility to |
|
455 // close the resource loader after using the |
|
456 // resource. |
|
457 // --------------------------------------------------------------------------- |
|
458 // |
|
459 void CLbtMgmtPluginView::OpenLocalizedResourceFileL( |
|
460 const TDesC& aResourceFileName, |
|
461 RConeResourceLoader& aResourceLoader ) |
|
462 { |
|
463 RFs fsSession; |
|
464 User::LeaveIfError( fsSession.Connect()); |
|
465 |
|
466 TFileName* tmpName = new(ELeave) TFileName; |
|
467 CleanupStack::PushL( tmpName ); |
|
468 |
|
469 // Append the Resource Files Directory |
|
470 tmpName->Append( KDC_RESOURCE_FILES_DIR ); |
|
471 |
|
472 // Append the Ressource File Name |
|
473 tmpName->Append( aResourceFileName ); |
|
474 |
|
475 // Obtain the drive where the DLL is installed |
|
476 TFileName* dllDrive = new (ELeave) TFileName; |
|
477 CleanupStack::PushL( dllDrive ); |
|
478 Dll::FileName( *dllDrive ); |
|
479 |
|
480 // Obtain the Complete path for the Resource File |
|
481 TParse parse; |
|
482 User::LeaveIfError( parse.Set( *dllDrive, NULL, NULL ) ); |
|
483 User::LeaveIfError( parse.Set( parse.Drive(), tmpName, NULL ) ); |
|
484 TFileName* fileName = new(ELeave) TFileName; |
|
485 CleanupStack::PushL( fileName ); |
|
486 fileName->Append( parse.FullName() ); |
|
487 |
|
488 // Get language of resource file |
|
489 BaflUtils::NearestLanguageFile( fsSession, *fileName ); |
|
490 |
|
491 // Open resource file |
|
492 aResourceLoader.OpenL( *fileName ); |
|
493 |
|
494 // Pop all the fields |
|
495 CleanupStack::PopAndDestroy( fileName ); |
|
496 CleanupStack::PopAndDestroy( dllDrive ); |
|
497 CleanupStack::PopAndDestroy( tmpName ); |
|
498 |
|
499 //If leave occurs before this, close is called automatically when the thread exits. |
|
500 fsSession.Close(); |
|
501 } |