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(), *iEngine, *this, |
|
158 this); |
|
159 iContainer->SetMopParent(this); |
|
160 AppUi()->AddToViewStackL(*this, iContainer); |
|
161 MenuBar()->SetContextMenuTitleResourceId(R_LBTMGMTPLUGIN_CONTEXTMENUBAR); |
|
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 ELbtMgmtShowCSMenu: |
|
207 if (CLbtMgmtPluginEngine::EActiveTriggers |
|
208 == iContainer->GetFocussedItem()) |
|
209 { |
|
210 iContainer->ShowContextMenuL(); |
|
211 } |
|
212 break; |
|
213 case ELbtMgmtChange: |
|
214 case ELbtMgmtMSKChange: |
|
215 { |
|
216 SettingsChangeL(aCommand); |
|
217 break; |
|
218 } |
|
219 case ELbtMgmtMSKInfo: |
|
220 break; |
|
221 case ELbtMgmtInfo: |
|
222 { |
|
223 iEngine->ShowInfoDialogL(); |
|
224 break; |
|
225 } |
|
226 case ELbtMgmtClearAll: |
|
227 { |
|
228 iEngine->ClearAllTriggersL(); |
|
229 iContainer->Update(); |
|
230 HandleCmdL(EListBoxItemFocused); |
|
231 break; |
|
232 } |
|
233 case EAknCmdHelp: |
|
234 { |
|
235 HlpLauncher::LaunchHelpApplicationL( iCoeEnv->WsSession(), |
|
236 AppUi()->AppHelpContextL()); |
|
237 break; |
|
238 } |
|
239 // Handle any plug-in specific internal commands here |
|
240 case EAknSoftkeyBack: |
|
241 { |
|
242 // The UI is intended to be closed. Pass the event |
|
243 // to the observer |
|
244 iSettingsObserver.SettingClosed( KErrNone ); |
|
245 break; |
|
246 } |
|
247 default: |
|
248 { |
|
249 // Un-handled commands are to be passed to the |
|
250 // App UI |
|
251 AppUi()->HandleCommandL(aCommand); |
|
252 break; |
|
253 } |
|
254 } |
|
255 } |
|
256 |
|
257 // ----------------------------------------------------------------------------- |
|
258 // CLbtMgmtPluginView::SetCba |
|
259 // ----------------------------------------------------------------------------- |
|
260 // |
|
261 void CLbtMgmtPluginView::SetCba( TInt aResourceId ) |
|
262 { |
|
263 if( Cba() ) |
|
264 { |
|
265 TRAP_IGNORE(Cba()->SetCommandSetL(aResourceId)); |
|
266 } |
|
267 Cba()->DrawDeferred(); |
|
268 } |
|
269 |
|
270 // --------------------------------------------------------------------------- |
|
271 // void CLbtMgmtPluginView::HandleCommandL |
|
272 // Inherited from MLbtMgmtPluginCmdHdlr |
|
273 // Handles Selection events from the container |
|
274 // |
|
275 // @param aCommand Command ID |
|
276 // --------------------------------------------------------------------------- |
|
277 // |
|
278 void CLbtMgmtPluginView::HandleCmdL( TLbtMgmtPluginCmd aCommand ) |
|
279 { |
|
280 switch( aCommand ) |
|
281 { |
|
282 // Handle any plug-in specific internal commands here |
|
283 case EListBoxItemSelected: |
|
284 { |
|
285 // Handle List Box Selected Event |
|
286 TRAPD( error, SettingsChangeL( ELbtMgmtMSKChange )); |
|
287 if( error ) |
|
288 { |
|
289 // Show Error Note |
|
290 CTextResolver* iTextResolver = CTextResolver::NewLC(*iCoeEnv); |
|
291 TPtrC buffer = iTextResolver->ResolveErrorString( error ); |
|
292 CAknErrorNote* errorNote = new ( ELeave )CAknErrorNote( ETrue ); |
|
293 TRAP_IGNORE( errorNote->ExecuteLD( buffer )); |
|
294 CleanupStack::PopAndDestroy( iTextResolver ); |
|
295 } |
|
296 break; |
|
297 } |
|
298 case EListBoxItemFocused: |
|
299 { |
|
300 if( CLbtMgmtPluginEngine::EActiveTriggers == iContainer->GetFocussedItem() ) |
|
301 { |
|
302 if( iEngine->ActiveTriggers() ) |
|
303 SetCba( R_LBTMGMTPLUGIN_CBA_INFO ); |
|
304 else |
|
305 SetCba( R_LBTMGMTPLUGIN_CBA_NOACTIVETRIGGERS ); |
|
306 } |
|
307 else |
|
308 SetCba( R_LBTMGMTPLUGIN_CBA_CHANGE ); |
|
309 break; |
|
310 } |
|
311 case EScreenSizeChanged: |
|
312 { |
|
313 if( iContainer ) |
|
314 { |
|
315 iContainer->SetRect( ClientRect()); |
|
316 } |
|
317 break; |
|
318 } |
|
319 default: |
|
320 { |
|
321 break; |
|
322 } |
|
323 } |
|
324 } |
|
325 |
|
326 // --------------------------------------------------------------------------- |
|
327 // Inherited from MLbtMgmtEngObserver |
|
328 // --------------------------------------------------------------------------- |
|
329 // |
|
330 void CLbtMgmtPluginView::HandleSettingsChangeEventL() |
|
331 { |
|
332 // Observer callback notifies that one/more of the settings values have |
|
333 // changed. Hence, need to refresh the container to show the latest |
|
334 // values |
|
335 if( iContainer ) |
|
336 { |
|
337 iContainer->DrawDeferred(); |
|
338 } |
|
339 |
|
340 // Handle any changes to the MSK configuration. |
|
341 HandleCmdL( EListBoxItemFocused ); |
|
342 } |
|
343 |
|
344 // ----------------------------------------------------------------------------- |
|
345 // CLbtMgmtPluginView::HandleHelpFeature |
|
346 // ----------------------------------------------------------------------------- |
|
347 // |
|
348 void CLbtMgmtPluginView::HandleHelpFeature( CEikMenuPane& aMenuPane ) const |
|
349 { |
|
350 if ( FeatureManager::FeatureSupported( KFeatureIdHelp )) |
|
351 { |
|
352 aMenuPane.SetItemDimmed( EAknCmdHelp, EFalse ); |
|
353 } |
|
354 else |
|
355 { |
|
356 aMenuPane.SetItemDimmed( EAknCmdHelp, ETrue ); |
|
357 } |
|
358 } |
|
359 |
|
360 |
|
361 // --------------------------------------------------------------------------- |
|
362 // Handle Settings Change Event |
|
363 // |
|
364 // @param aCmd Settings change command |
|
365 // --------------------------------------------------------------------------- |
|
366 // |
|
367 void CLbtMgmtPluginView::SettingsChangeL( TInt aCmd ) |
|
368 { |
|
369 if( !iContainer ) |
|
370 { |
|
371 // No container available. Nothing to do in this case. Hence, returning |
|
372 return; |
|
373 } |
|
374 CLbtMgmtPluginEngine::TSettingsList currentElement; |
|
375 currentElement = static_cast<CLbtMgmtPluginEngine::TSettingsList> |
|
376 ( iContainer->GetFocussedItem() ); |
|
377 |
|
378 // Switch based on the currently focussed element |
|
379 switch( currentElement ) |
|
380 { |
|
381 case CLbtMgmtPluginEngine::ETriggeringStatus: |
|
382 { |
|
383 // Different handling needed for Touch handling and Item selection |
|
384 // using the OK key. |
|
385 // Incase the User has selected the item using the OK key then |
|
386 // normal handling required |
|
387 // Incase the User has selected the item using touch selection |
|
388 // then the Trigger Status needs to be toggled |
|
389 if( ELbtMgmtChange == aCmd ) |
|
390 { |
|
391 iEngine->ChangeTiggerStatusL(); |
|
392 } |
|
393 else |
|
394 { |
|
395 iEngine->ToggleTiggerStatusL(); |
|
396 } |
|
397 iContainer->Update(); |
|
398 break; |
|
399 } |
|
400 case CLbtMgmtPluginEngine::EActiveTriggers: |
|
401 { |
|
402 // If condition is added for any pointer event from container |
|
403 break; |
|
404 } |
|
405 default: |
|
406 { |
|
407 // Element not found |
|
408 User::Leave( KErrNotFound ); |
|
409 } |
|
410 } |
|
411 } |
|
412 |
|
413 // --------------------------------------------------------------------------- |
|
414 // void CLbtMgmtPluginView::OpenLocalizedResourceFileL |
|
415 // Opens the nearest localized resourcefile using aResourceLoader. |
|
416 // aResourceLoader should be opened only once before closing it. |
|
417 // Otherwise it will raise a panic. Therefore it is better to have |
|
418 // multiple resource loaders. |
|
419 // |
|
420 // @param aResourceFileName Drive and name of resource file in format |
|
421 // <path>:<rsc_file_name> |
|
422 // @param aResourceLoader Resource loader for the resource. The loader |
|
423 // must not be opened allready or it will raise |
|
424 // a panic. It is caller's responsibility to |
|
425 // close the resource loader after using the |
|
426 // resource. |
|
427 // --------------------------------------------------------------------------- |
|
428 // |
|
429 void CLbtMgmtPluginView::OpenLocalizedResourceFileL( |
|
430 const TDesC& aResourceFileName, |
|
431 RConeResourceLoader& aResourceLoader ) |
|
432 { |
|
433 RFs fsSession; |
|
434 User::LeaveIfError( fsSession.Connect()); |
|
435 |
|
436 TFileName* tmpName = new(ELeave) TFileName; |
|
437 CleanupStack::PushL( tmpName ); |
|
438 |
|
439 // Append the Resource Files Directory |
|
440 tmpName->Append( KDC_RESOURCE_FILES_DIR ); |
|
441 |
|
442 // Append the Ressource File Name |
|
443 tmpName->Append( aResourceFileName ); |
|
444 |
|
445 // Obtain the drive where the DLL is installed |
|
446 TFileName* dllDrive = new (ELeave) TFileName; |
|
447 CleanupStack::PushL( dllDrive ); |
|
448 Dll::FileName( *dllDrive ); |
|
449 |
|
450 // Obtain the Complete path for the Resource File |
|
451 TParse parse; |
|
452 User::LeaveIfError( parse.Set( *dllDrive, NULL, NULL ) ); |
|
453 User::LeaveIfError( parse.Set( parse.Drive(), tmpName, NULL ) ); |
|
454 TFileName* fileName = new(ELeave) TFileName; |
|
455 CleanupStack::PushL( fileName ); |
|
456 fileName->Append( parse.FullName() ); |
|
457 |
|
458 // Get language of resource file |
|
459 BaflUtils::NearestLanguageFile( fsSession, *fileName ); |
|
460 |
|
461 // Open resource file |
|
462 aResourceLoader.OpenL( *fileName ); |
|
463 |
|
464 // Pop all the fields |
|
465 CleanupStack::PopAndDestroy( fileName ); |
|
466 CleanupStack::PopAndDestroy( dllDrive ); |
|
467 CleanupStack::PopAndDestroy( tmpName ); |
|
468 |
|
469 //If leave occurs before this, close is called automatically when the thread exits. |
|
470 fsSession.Close(); |
|
471 } |
|
472 |
|
473 // --------------------------------------------------------------------------- |
|
474 // CLbtMgmtPluginView :: GetLbtMgmtPluginEngine |
|
475 // |
|
476 // |
|
477 // --------------------------------------------------------------------------- |
|
478 // |
|
479 CLbtMgmtPluginEngine* CLbtMgmtPluginView::GetLbtMgmtPluginEngine() |
|
480 { |
|
481 return iEngine; |
|
482 } |
|