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