1 /* |
|
2 * Copyright (c) 2005 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 UI plugin to the Location System |
|
15 * UI engine |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // System Include |
|
21 #include <aknViewAppUi.h> |
|
22 #include <barsread.h> // For TResourceReader |
|
23 #include <bautils.h> |
|
24 #include <StringLoader.h> |
|
25 #include <locpsysettingsuiview.rsg> |
|
26 #include <eikmenub.h> // Menu Bar |
|
27 |
|
28 |
|
29 // User Includes |
|
30 #include "locpsysettingsui.h" |
|
31 #include "locsettingsuiobserver.h" |
|
32 #include "locsettingsuiparams.h" |
|
33 #include "locpsysettingsview.h" |
|
34 |
|
35 |
|
36 // --------------------------------------------------------------------------- |
|
37 // CLocPsySettingsUi::CLocPsySettingsUi |
|
38 // C++ default constructor. |
|
39 // --------------------------------------------------------------------------- |
|
40 CLocPsySettingsUi::CLocPsySettingsUi( MLocSettingsUiObserver& aSettingsUiObserver, |
|
41 CAknViewAppUi& aAppUi ) |
|
42 :CLocSettingsUi( aSettingsUiObserver, aAppUi ), |
|
43 iResourceLoader( *CCoeEnv::Static()) |
|
44 { |
|
45 } |
|
46 |
|
47 // --------------------------------------------------------------------------- |
|
48 // CLocPsySettingsUi::~CLocPsySettingsUi |
|
49 // Destructor. |
|
50 // --------------------------------------------------------------------------- |
|
51 CLocPsySettingsUi::~CLocPsySettingsUi() |
|
52 { |
|
53 // Close the Resource loader |
|
54 iResourceLoader.Close(); |
|
55 } |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 // CLocPsySettingsUi* CLocPsySettingsUi::NewL |
|
59 // Symbian OS two-phased constructor |
|
60 // |
|
61 // @return CLocPsySettingsUi* Reference to the Settings UI object |
|
62 // --------------------------------------------------------------------------- |
|
63 CLocPsySettingsUi* CLocPsySettingsUi::NewL( TAny* aParams ) |
|
64 { |
|
65 CLocSettingsUiParams* param = reinterpret_cast<CLocSettingsUiParams *>(aParams); |
|
66 MLocSettingsUiObserver& observer = param->SettingsUiObserver(); |
|
67 CAknViewAppUi& appUi = param->AppUi(); |
|
68 CLocPsySettingsUi* self = new ( ELeave )CLocPsySettingsUi( observer, |
|
69 appUi ); |
|
70 CleanupStack::PushL( self ); |
|
71 self->ConstructL(); |
|
72 CleanupStack::Pop( self ); |
|
73 return self; |
|
74 } |
|
75 |
|
76 // --------------------------------------------------------------------------- |
|
77 // void CLocPsySettingsUi::ConstructL |
|
78 // Second phase constructor. |
|
79 // --------------------------------------------------------------------------- |
|
80 void CLocPsySettingsUi::ConstructL() |
|
81 { |
|
82 |
|
83 // Open the Resource file for the plugin |
|
84 OpenLocalizedResourceFileL( KPosSettingsUiResFileName, |
|
85 iResourceLoader ); |
|
86 |
|
87 // Create the Position Method Settings UI View |
|
88 iView = CLocPsySettingsView::NewL( *this ); |
|
89 |
|
90 // Transferring the view's control to AppUi |
|
91 iAppUi.AddViewL( iView ); |
|
92 |
|
93 // Obtaining the View Id for reference |
|
94 iViewId = iView->Id(); |
|
95 |
|
96 } |
|
97 |
|
98 // --------------------------------------------------------------------------- |
|
99 // void CLocPsySettingsUi::LaunchL |
|
100 // Inherited from CLocSettingsUi |
|
101 // Launches the Settings UI |
|
102 // |
|
103 // @param aUiLaunchParams Flags that define specific configuration of |
|
104 // if the Settings UI, that the user of the API |
|
105 // wants to launch. |
|
106 // --------------------------------------------------------------------------- |
|
107 void CLocPsySettingsUi::LaunchL( TInt /* aUiLaunchParams */) |
|
108 { |
|
109 // Activate self |
|
110 iAppUi.ActivateLocalViewL( iViewId ); |
|
111 } |
|
112 |
|
113 // --------------------------------------------------------------------------- |
|
114 // void CLocPsySettingsUi::Close |
|
115 // Inherited from CLocSettingsUi |
|
116 // Closes the running Settings UI prematurely. |
|
117 // --------------------------------------------------------------------------- |
|
118 void CLocPsySettingsUi::Close() |
|
119 { |
|
120 // Close the Menubar if it's being displayed |
|
121 iView->StopDisplayingMenuBar(); |
|
122 } |
|
123 |
|
124 // --------------------------------------------------------------------------- |
|
125 // void CLocPsySettingsUi::GetCaptionL |
|
126 // Inherited from CLocSettingsUi |
|
127 // Method for getting caption of this plugin. This should be the |
|
128 // localized name of the settings view to be shown in parent view. |
|
129 // |
|
130 // @param aCaption pointer to Caption variable |
|
131 // --------------------------------------------------------------------------- |
|
132 void CLocPsySettingsUi::GetCaptionL( TDes& aCaption ) const |
|
133 { |
|
134 HBufC* caption = StringLoader::LoadL( R_POSSETTINGSUI_CAPTION ); |
|
135 aCaption.Copy( *caption ); |
|
136 delete caption; |
|
137 } |
|
138 |
|
139 // --------------------------------------------------------------------------- |
|
140 // TInt CLocPsySettingsUi::GetPriority |
|
141 // Inherited from CLocSettingsUi |
|
142 // Returns the priority of the UI module. |
|
143 // |
|
144 // @return Priority of the Settings UI |
|
145 // --------------------------------------------------------------------------- |
|
146 TInt CLocPsySettingsUi::GetPriority() |
|
147 { |
|
148 // As defined by the Location System UI UI specification, the PSY settings |
|
149 // plug-in should be inserted at the first level |
|
150 const TInt KPsyPluginPriority = 0x00000001; |
|
151 return KPsyPluginPriority; |
|
152 } |
|
153 |
|
154 // --------------------------------------------------------------------------- |
|
155 // void CLocPsySettingsUi::HandleCommandL |
|
156 // Inherited from MCommandHandler |
|
157 // Handles commands from the views |
|
158 // |
|
159 // @param aCommand Command ID |
|
160 // --------------------------------------------------------------------------- |
|
161 void CLocPsySettingsUi::HandleCommandL( TInt aCommand ) |
|
162 { |
|
163 switch ( aCommand ) |
|
164 { |
|
165 // Handle any plug-in specific internal commands here |
|
166 case EAknSoftkeyBack: |
|
167 { |
|
168 // The UI is intended to be closed. Pass the event |
|
169 // to the observer |
|
170 iSettingsUiObserver.SettingClosed( KErrNone ); |
|
171 break; |
|
172 } |
|
173 default: |
|
174 { |
|
175 // Un-handled commands are to be passed to the |
|
176 // App UI |
|
177 iAppUi.HandleCommandL( aCommand ); |
|
178 break; |
|
179 } |
|
180 } |
|
181 } |
|
182 |
|
183 // --------------------------------------------------------------------------- |
|
184 // void CLocPsySettingsUi::OpenLocalizedResourceFileL |
|
185 // Opens the nearest localized resourcefile using aResourceLoader. |
|
186 // aResourceLoader should be opened only once before closing it. |
|
187 // Otherwise it will raise a panic. Therefore it is better to have |
|
188 // multiple resource loaders. |
|
189 // |
|
190 // @param aResourceFileName Drive and name of resource file in format |
|
191 // <path>:<rsc_file_name> |
|
192 // @param aResourceLoader Resource loader for the resource. The loader |
|
193 // must not be opened allready or it will raise |
|
194 // a panic. It is caller's responsibility to |
|
195 // close the resource loader after using the |
|
196 // resource. |
|
197 // --------------------------------------------------------------------------- |
|
198 void CLocPsySettingsUi::OpenLocalizedResourceFileL( const TDesC& aResourceFileName, |
|
199 RConeResourceLoader& aResourceLoader ) |
|
200 { |
|
201 RFs fsSession; |
|
202 User::LeaveIfError( fsSession.Connect()); |
|
203 |
|
204 // Add the RFs session to the CleanupStack |
|
205 CleanupClosePushL( fsSession ); |
|
206 |
|
207 TFileName* tmpName = new(ELeave) TFileName; |
|
208 CleanupStack::PushL( tmpName ); |
|
209 |
|
210 // Append the Resource Files Directory |
|
211 tmpName->Append( KDC_RESOURCE_FILES_DIR ); |
|
212 |
|
213 // Append the Ressource File Name |
|
214 tmpName->Append( aResourceFileName ); |
|
215 |
|
216 |
|
217 // Obtain the drive where the DLL is installed |
|
218 TFileName* dllDrive = new (ELeave) TFileName; |
|
219 CleanupStack::PushL( dllDrive ); |
|
220 Dll::FileName( *dllDrive ); |
|
221 |
|
222 // Obtain the Complete path for the Resource File |
|
223 TParse parse; |
|
224 User::LeaveIfError( parse.Set( *dllDrive, NULL, NULL ) ); |
|
225 User::LeaveIfError( parse.Set( parse.Drive(), tmpName, NULL ) ); |
|
226 TFileName* fileName = new(ELeave) TFileName; |
|
227 CleanupStack::PushL( fileName ); |
|
228 fileName->Append( parse.FullName()); |
|
229 |
|
230 // Get language of resource file |
|
231 BaflUtils::NearestLanguageFile( fsSession, *fileName ); |
|
232 |
|
233 // Open resource file |
|
234 aResourceLoader.OpenL( *fileName ); |
|
235 |
|
236 // Pop all the fields |
|
237 CleanupStack::PopAndDestroy( fileName ); |
|
238 CleanupStack::PopAndDestroy( dllDrive ); |
|
239 CleanupStack::PopAndDestroy( tmpName ); |
|
240 |
|
241 //If leave occurs before this, close is called automatically |
|
242 // from by the CleanupStack |
|
243 CleanupStack::PopAndDestroy(); // fsSession |
|
244 } |
|