|
1 /* |
|
2 * Copyright (c) 2007 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: BatIndicatorPanePlugin plugin implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32property.h> // RPropert |
|
21 #include <batindpaneplugin.rsg> // BatIndicatorPanePlugin resources |
|
22 #include <StringLoader.h> // Stringloader |
|
23 #include <psmclient.h> |
|
24 #include <psmsettings.h> |
|
25 #include <hwrmpowerstatesdkpskeys.h> |
|
26 #include <data_caging_path_literals.hrh> // KDC_ECOM_RESOURCE_DIR |
|
27 #include <centralrepository.h> |
|
28 #include "batindicatorpanepluginimpl.h" |
|
29 #include "batindpanepluginprivatecrkeys.h" |
|
30 #include "bsutil.h" |
|
31 #include "trace.h" |
|
32 |
|
33 // CONSTANTS |
|
34 _LIT( KIndicatorResourceFile,"z:batindpaneplugin.rsc" ); |
|
35 |
|
36 |
|
37 // ======== MEMBER FUNCTIONS ======== |
|
38 |
|
39 // --------------------------------------------------------------------------- |
|
40 // Two-phased constructor. |
|
41 // --------------------------------------------------------------------------- |
|
42 // |
|
43 CBatIndicatorPanePluginImpl* CBatIndicatorPanePluginImpl::NewL( ) |
|
44 { |
|
45 FUNC_LOG |
|
46 |
|
47 CBatIndicatorPanePluginImpl* self = new( ELeave ) CBatIndicatorPanePluginImpl( ); |
|
48 CleanupStack::PushL( self ); |
|
49 self->ConstructL(); |
|
50 CleanupStack::Pop( self ); |
|
51 return self; |
|
52 } |
|
53 |
|
54 // --------------------------------------------------------------------------- |
|
55 // Destructor |
|
56 // --------------------------------------------------------------------------- |
|
57 // |
|
58 CBatIndicatorPanePluginImpl::~CBatIndicatorPanePluginImpl() |
|
59 { |
|
60 FUNC_LOG |
|
61 |
|
62 delete iContentText; |
|
63 delete iPsmClient; |
|
64 delete iBatteryStateUtil; |
|
65 delete iPopupControl; |
|
66 delete iLinkText; |
|
67 iResourceLoader.Close(); |
|
68 } |
|
69 |
|
70 // --------------------------------------------------------------------------- |
|
71 // From MEikCommandObserver |
|
72 // --------------------------------------------------------------------------- |
|
73 // |
|
74 void CBatIndicatorPanePluginImpl::ProcessCommandL( TInt aCommandId ) |
|
75 { |
|
76 FUNC_LOG |
|
77 |
|
78 if( aCommandId == ELinkFirst ) |
|
79 { |
|
80 SetPowerSaveModeEnabled(); |
|
81 } |
|
82 } |
|
83 |
|
84 // --------------------------------------------------------------------------- |
|
85 // CBatIndicatorPanePluginImpl::CBatIndicatorPanePluginImpl |
|
86 // C++ default constructor can NOT contain any code, that |
|
87 // might leave. |
|
88 // --------------------------------------------------------------------------- |
|
89 // |
|
90 CBatIndicatorPanePluginImpl::CBatIndicatorPanePluginImpl( ): |
|
91 iResourceLoader( *CEikonEnv::Static() ), |
|
92 iBatIndPanePluginFeatures( 0 ) |
|
93 { |
|
94 FUNC_LOG |
|
95 } |
|
96 |
|
97 // --------------------------------------------------------------------------- |
|
98 // CBatIndicatorPanePluginImpl::ConstructL |
|
99 // Symbian 2nd phase constructor can leave. |
|
100 // --------------------------------------------------------------------------- |
|
101 // |
|
102 void CBatIndicatorPanePluginImpl::ConstructL( ) |
|
103 { |
|
104 FUNC_LOG |
|
105 // Create PSM client |
|
106 iPsmClient = CPsmClient::NewL( *this ); |
|
107 |
|
108 GetFeatures(); |
|
109 |
|
110 // Create Battery State Utilities |
|
111 if( !Supported( KBatIndPanePluginLinkOnly ) ) |
|
112 { |
|
113 iBatteryStateUtil = CBSUtil::NewL(); |
|
114 } |
|
115 |
|
116 // Read resource strings |
|
117 TParse* fp = new( ELeave ) TParse(); |
|
118 CleanupStack::PushL( fp ); |
|
119 fp->Set( KIndicatorResourceFile, &KDC_ECOM_RESOURCE_DIR , NULL ); |
|
120 TFileName filename = fp->FullName(); |
|
121 iResourceLoader.OpenL( filename ); |
|
122 CleanupStack::PopAndDestroy( fp ); |
|
123 } |
|
124 |
|
125 // --------------------------------------------------------------------------- |
|
126 // Shows soft notification. |
|
127 // --------------------------------------------------------------------------- |
|
128 // |
|
129 void CBatIndicatorPanePluginImpl::ShowPreviewPopupL( ) |
|
130 { |
|
131 FUNC_LOG |
|
132 |
|
133 delete iPopupControl; |
|
134 iPopupControl = NULL; |
|
135 |
|
136 if( iContentText ) |
|
137 { |
|
138 iPopupControl = CBatteryPopupControl::NewL( *iContentText, |
|
139 *iLinkText ); |
|
140 } |
|
141 else |
|
142 { |
|
143 iPopupControl = CBatteryPopupControl::NewL( KNullDesC, |
|
144 *iLinkText ); |
|
145 } |
|
146 |
|
147 iPopupControl->SetCommandObserver( *this ); |
|
148 // Launch |
|
149 iPopupControl->ShowPopUpL(); |
|
150 |
|
151 delete iContentText; |
|
152 iContentText = NULL; |
|
153 |
|
154 delete iLinkText; |
|
155 iLinkText = NULL; |
|
156 } |
|
157 |
|
158 // --------------------------------------------------------------------------- |
|
159 // Enables or disables power save mode. |
|
160 // --------------------------------------------------------------------------- |
|
161 // |
|
162 void CBatIndicatorPanePluginImpl::SetPowerSaveModeEnabled( ) |
|
163 { |
|
164 FUNC_LOG |
|
165 // Get PSM state |
|
166 TInt mode; |
|
167 TInt err = iPsmClient->PsmSettings().GetCurrentMode( mode ); |
|
168 |
|
169 if ( err == KErrNone ) |
|
170 { |
|
171 if( mode == EPsmsrvModeNormal || |
|
172 mode == EPsmsrvPartialMode ) |
|
173 { |
|
174 iPsmClient->ChangePowerSaveMode( EPsmsrvModePowerSave ); |
|
175 } |
|
176 else |
|
177 { |
|
178 iPsmClient->ChangePowerSaveMode( EPsmsrvModeNormal ); |
|
179 } |
|
180 } |
|
181 } |
|
182 |
|
183 // --------------------------------------------------------------------------- |
|
184 // From CAknIndicatorPlugin |
|
185 // --------------------------------------------------------------------------- |
|
186 // |
|
187 void CBatIndicatorPanePluginImpl::HandleIndicatorTapL( const TInt /*aUid*/ ) |
|
188 { |
|
189 FUNC_LOG |
|
190 |
|
191 delete iContentText; |
|
192 iContentText = NULL; |
|
193 |
|
194 delete iLinkText; |
|
195 iLinkText = NULL; |
|
196 |
|
197 TInt err = KErrNone; |
|
198 |
|
199 if ( iBatteryStateUtil ) |
|
200 { |
|
201 TInt batteryStatus; |
|
202 err = RProperty::Get( KPSUidHWRMPowerState, KHWRMBatteryStatus, batteryStatus ); |
|
203 |
|
204 if( !err && batteryStatus == EBatteryStatusLow ) |
|
205 { |
|
206 iContentText = StringLoader::LoadL( R_QTN_BATTERY_LOW_PREVIEW_POPUP ); |
|
207 } |
|
208 else |
|
209 { |
|
210 TUint8 batteryCapacity = iBatteryStateUtil->GetBatteryCapacity(); |
|
211 |
|
212 iContentText = StringLoader::LoadL( R_QTN_BATTERY_STATUS_POPUP, |
|
213 batteryCapacity ); |
|
214 } |
|
215 } |
|
216 |
|
217 // Get PSM state |
|
218 TInt mode; |
|
219 TBool psmActive = EFalse; |
|
220 err = iPsmClient->PsmSettings().GetCurrentMode( mode ); |
|
221 |
|
222 if ( err == KErrNone ) |
|
223 { |
|
224 psmActive = ( mode == EPsmsrvModePowerSave ); |
|
225 } |
|
226 |
|
227 if ( psmActive ) |
|
228 { |
|
229 iLinkText = StringLoader::LoadL( R_QTN_DEACTIVATE_POWER_SAVING ); |
|
230 } |
|
231 else |
|
232 { |
|
233 iLinkText = StringLoader::LoadL( R_QTN_ACTIVATE_POWER_SAVING ); |
|
234 } |
|
235 ShowPreviewPopupL(); |
|
236 } |
|
237 |
|
238 // ---------------------------------------------------------------------------- |
|
239 // CBatIndicatorPanePluginImpl::GetFeatures() |
|
240 // ---------------------------------------------------------------------------- |
|
241 // |
|
242 void CBatIndicatorPanePluginImpl::GetFeatures( ) |
|
243 { |
|
244 FUNC_LOG |
|
245 |
|
246 CRepository* repository = NULL; |
|
247 |
|
248 TRAPD( err, repository = CRepository::NewL( KCRUidBatIndPanePluginConf ) ); |
|
249 |
|
250 if ( err == KErrNone ) |
|
251 { |
|
252 err = repository->Get( KBatIndPanePlugin, iBatIndPanePluginFeatures ); |
|
253 |
|
254 if ( err != KErrNone || iBatIndPanePluginFeatures < 0 ) // ERROR |
|
255 { |
|
256 INFO_1( "CBatIndicatorPanePluginImpl::GetFeatures - Reading features err %d", err ) |
|
257 iBatIndPanePluginFeatures = 0; |
|
258 } |
|
259 } |
|
260 else |
|
261 { |
|
262 INFO_1( "CBatIndicatorPanePluginImpl::GetFeatures: open KCRUidBatIndPanePluginConf failed, err=%d", err ) |
|
263 } |
|
264 delete repository; |
|
265 } |
|
266 |
|
267 // ---------------------------------------------------------------------------- |
|
268 // CBatIndicatorPanePluginImpl::Supported() |
|
269 // ---------------------------------------------------------------------------- |
|
270 // |
|
271 TInt CBatIndicatorPanePluginImpl::Supported( TInt aFeatureId ) |
|
272 { |
|
273 FUNC_LOG |
|
274 return aFeatureId & iBatIndPanePluginFeatures; |
|
275 } |
|
276 // --------------------------------------------------------------------------- |
|
277 // From MPsmClientObserver |
|
278 // --------------------------------------------------------------------------- |
|
279 // |
|
280 void CBatIndicatorPanePluginImpl::PowerSaveModeChanged( const TPsmsrvMode /*aMode*/ ) |
|
281 { |
|
282 FUNC_LOG |
|
283 } |
|
284 |
|
285 // --------------------------------------------------------------------------- |
|
286 // From MPsmClientObserver |
|
287 // --------------------------------------------------------------------------- |
|
288 // |
|
289 void CBatIndicatorPanePluginImpl::PowerSaveModeChangeError( const TInt /*aError*/ ) |
|
290 { |
|
291 FUNC_LOG |
|
292 } |
|
293 // End of File |