|
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 the License "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: Interface to Browser for handling embedded system info requests. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32std.h> |
|
21 #include <npupp.h> |
|
22 #include <string.h> |
|
23 #include <utf.h> |
|
24 #include <MProfileEngine.h> |
|
25 #include <MProfile.h> |
|
26 #include "SystemInfoPlugin.h" |
|
27 #include "NetworkObserver.h" |
|
28 #include "PowerObserver.h" |
|
29 #include "SystemInfoMisc.h" |
|
30 |
|
31 // CONSTANTS |
|
32 |
|
33 enum TIdentifiersNames |
|
34 { |
|
35 EIdChargeLevel, |
|
36 EIdOnChargeLevel, |
|
37 EIdChargerConnected, |
|
38 EIdOnChargerConnected, |
|
39 EIdSignalBars, |
|
40 EIdNetworkName, |
|
41 EIdNetworkRegistrationStatus, |
|
42 EIdOnNetworkRegistrationStatus, |
|
43 EIdLightMinIntensity, |
|
44 EIdLightMaxIntensity, |
|
45 EIdLightDefaultIntensity, |
|
46 EIdLightInfiniteDuration, |
|
47 EIdLightMaxDuration, |
|
48 EIdLightDefaultCycleTime, |
|
49 EIdLightTargetPrimaryDisplayAndKeyboard, |
|
50 EIdLightTargetSystem, |
|
51 EIdLightOn, |
|
52 EIdLightBlink, |
|
53 EIdLightOff, |
|
54 EIdVibraMinIntensity, |
|
55 EIdVibraMaxIntensity, |
|
56 EIdVibraMaxDuration, |
|
57 EIdVibraSettings, |
|
58 EIdStartVibra, |
|
59 EIdStopVibra, |
|
60 EIdBeep, |
|
61 EIdTotalRam, |
|
62 EIdFreeRam, |
|
63 EIdDriveList, |
|
64 EIdDriveSize, |
|
65 EIdDriveFree, |
|
66 EIdLanguage, |
|
67 EIdLast |
|
68 }; |
|
69 |
|
70 const NPUTF8 *systemInfoPluginIdentifierNames[EIdLast] = |
|
71 { |
|
72 "chargelevel", |
|
73 "onchargelevel", |
|
74 "chargerconnected", |
|
75 "onchargerconnected", |
|
76 "signalbars", |
|
77 "networkname", |
|
78 "networkregistrationstatus", |
|
79 "onnetworkregistrationstatus", |
|
80 "lightminintensity", |
|
81 "lightmaxintensity", |
|
82 "lightdefaultintensity", |
|
83 "lightinfiniteduration", |
|
84 "lightmaxduration", |
|
85 "lightdefaultcycletime", |
|
86 "lighttargetprimarydisplayandkeyboard", |
|
87 "lighttargetsystem", |
|
88 "lighton", |
|
89 "lightblink", |
|
90 "lightoff", |
|
91 "vibraminintensity", |
|
92 "vibramaxintensity", |
|
93 "vibramaxduration", |
|
94 "vibrasettings", |
|
95 "startvibra", |
|
96 "stopvibra", |
|
97 "beep", |
|
98 "totalram", |
|
99 "freeram", |
|
100 "drivelist", |
|
101 "drivesize", |
|
102 "drivefree", |
|
103 "language" |
|
104 }; |
|
105 |
|
106 const TBool IsMethod[EIdLast] = |
|
107 { |
|
108 EFalse, // "chargelevel" |
|
109 EFalse, // "onchargelevel" |
|
110 EFalse, // "chargerconnected" |
|
111 EFalse, // "onchargerconnected" |
|
112 EFalse, // "signalbars" |
|
113 EFalse, // "networkname" |
|
114 EFalse, // "networkregistrationstatus" |
|
115 EFalse, // "onnetworkregistrationstatus" |
|
116 EFalse, // "lightminintensity" |
|
117 EFalse, // "lightmaxintensity" |
|
118 EFalse, // "lightdefaultintensity" |
|
119 EFalse, // "lightinfiniteduration" |
|
120 EFalse, // "lightmaxduration" |
|
121 EFalse, // "lightdefaultcycletime" |
|
122 EFalse, // "lighttargetprimarydisplayandkeyboard" |
|
123 EFalse, // "lighttargetsystem" |
|
124 ETrue, // "lighton" |
|
125 ETrue, // "lightblink" |
|
126 ETrue, // "lightoff" |
|
127 EFalse, // "vibraminintensity" |
|
128 EFalse, // "vibramaxintensity" |
|
129 EFalse, // "vibramaxduration" |
|
130 EFalse, // "vibrasettings" |
|
131 ETrue, // "startvibra" |
|
132 ETrue, // "stopvibra" |
|
133 ETrue, // "beep" |
|
134 EFalse, // "totalram" |
|
135 EFalse, // "freeram" |
|
136 EFalse, // "drivelist" |
|
137 ETrue, // "drivesize" |
|
138 ETrue, // "drivefree" |
|
139 EFalse // "language" |
|
140 }; |
|
141 |
|
142 |
|
143 // ============================ MEMBER FUNCTIONS =============================== |
|
144 |
|
145 // ---------------------------------------------------------------------------- |
|
146 // CSystemInfoPlugin::CSystemInfoPlugin |
|
147 // C++ default constructor can NOT contain any code, that |
|
148 // might leave. |
|
149 // ---------------------------------------------------------------------------- |
|
150 CSystemInfoPlugin::CSystemInfoPlugin() |
|
151 { |
|
152 } |
|
153 |
|
154 // ---------------------------------------------------------------------------- |
|
155 // CSystemInfoPlugin::ConstructL |
|
156 // Symbian 2nd phase constructor can leave. |
|
157 // ---------------------------------------------------------------------------- |
|
158 void CSystemInfoPlugin::ConstructL() |
|
159 { |
|
160 iSystemInfoPluginIdentifiers = new (ELeave) NPIdentifier[EIdLast]; |
|
161 NPN_GetStringIdentifiers( systemInfoPluginIdentifierNames, EIdLast, |
|
162 iSystemInfoPluginIdentifiers ); |
|
163 iUid = RProcess().SecureId(); |
|
164 |
|
165 // need profile to determine silent mode for beep control |
|
166 iProfileEngine = CreateProfileEngineL(); |
|
167 |
|
168 // sysinfo feature class instances |
|
169 iPowerObserver = CPowerObserver::NewL( this ); |
|
170 iNetworkObserver = CNetworkObserver::NewL( this ); |
|
171 iSystemInfoMisc = CSystemInfoMisc::NewL(); |
|
172 } |
|
173 |
|
174 // ---------------------------------------------------------------------------- |
|
175 // CSystemInfoPlugin::NewL |
|
176 // Two-phased constructor. |
|
177 // ---------------------------------------------------------------------------- |
|
178 CSystemInfoPlugin* CSystemInfoPlugin::NewL() |
|
179 |
|
180 { |
|
181 CSystemInfoPlugin* self = new (ELeave) CSystemInfoPlugin; |
|
182 CleanupStack::PushL( self ); |
|
183 self->ConstructL(); |
|
184 CleanupStack::Pop( self ); |
|
185 return self; |
|
186 } |
|
187 |
|
188 // ---------------------------------------------------------------------------- |
|
189 // CSystemInfoPlugin::Destructor |
|
190 // ---------------------------------------------------------------------------- |
|
191 CSystemInfoPlugin::~CSystemInfoPlugin() |
|
192 { |
|
193 delete [] iSystemInfoPluginIdentifiers; |
|
194 |
|
195 if (iProfileEngine != NULL) |
|
196 { |
|
197 iProfileEngine->Release(); |
|
198 } |
|
199 // sysinfo feature class instances |
|
200 delete iPowerObserver; |
|
201 delete iNetworkObserver; |
|
202 delete iSystemInfoMisc; |
|
203 } |
|
204 |
|
205 // ---------------------------------------------------------------------------- |
|
206 // CSystemInfoPlugin::Deallocate |
|
207 // |
|
208 // ---------------------------------------------------------------------------- |
|
209 void CSystemInfoPlugin::Deallocate() |
|
210 { |
|
211 } |
|
212 |
|
213 // ---------------------------------------------------------------------------- |
|
214 // CSystemInfoPlugin::InvokeCallback |
|
215 // |
|
216 // ---------------------------------------------------------------------------- |
|
217 bool CSystemInfoPlugin::InvokeCallback( TDesC8& name, const NPVariant *args, uint32_t argCount ) |
|
218 { |
|
219 CSystemInfoPluginEcomMain* lSystemInfoPPluginEcomMain |
|
220 = (CSystemInfoPluginEcomMain*) Dll::Tls(); |
|
221 NPNetscapeFuncs* lNetscapeFuncs = lSystemInfoPPluginEcomMain->Funcs(); |
|
222 if ( lNetscapeFuncs && iInstanceHandle ) |
|
223 { |
|
224 void* value = 0; |
|
225 NPError npErr = lNetscapeFuncs->getvalue( iInstanceHandle, NPNVWindowNPObject, |
|
226 (void*)&value ); |
|
227 if ( npErr == NPERR_NO_ERROR ) |
|
228 { |
|
229 NPVariant resultVariant; |
|
230 VOID_TO_NPVARIANT( resultVariant ); |
|
231 NPIdentifier ident = NPN_GetStringIdentifier( (const NPUTF8 *)(name.Ptr()) ); |
|
232 return NPN_Invoke( iInstanceHandle, (NPObject*)value, ident, |
|
233 args, argCount, &resultVariant ); |
|
234 } |
|
235 } |
|
236 return false; |
|
237 } |
|
238 |
|
239 // ---------------------------------------------------------------------------- |
|
240 // CSystemInfoPlugin::HasMethod |
|
241 // |
|
242 // ---------------------------------------------------------------------------- |
|
243 bool CSystemInfoPlugin::HasMethod( NPIdentifier name ) |
|
244 { |
|
245 for (TInt i= 0; i < EIdLast; i++) |
|
246 { |
|
247 if ( name == iSystemInfoPluginIdentifiers[i] ) |
|
248 { |
|
249 return IsMethod[i]; |
|
250 } |
|
251 } |
|
252 return false; |
|
253 } |
|
254 |
|
255 // ---------------------------------------------------------------------------- |
|
256 // CSystemInfoPlugin::VariantToInt |
|
257 // |
|
258 // ---------------------------------------------------------------------------- |
|
259 void CSystemInfoPlugin::VariantToInt( NPVariant& v, TInt& i ) |
|
260 { |
|
261 if ( NPVARIANT_IS_INT32( v ) ) |
|
262 { |
|
263 i = NPVARIANT_TO_INT32( v ); |
|
264 } |
|
265 else if ( NPVARIANT_IS_DOUBLE( v ) ) |
|
266 { |
|
267 double d = NPVARIANT_TO_DOUBLE( v ); |
|
268 i = d; |
|
269 } |
|
270 // leave unchanged if some other type tag on variant |
|
271 } |
|
272 |
|
273 // ---------------------------------------------------------------------------- |
|
274 // CSystemInfoPlugin::Invoke |
|
275 // |
|
276 // ---------------------------------------------------------------------------- |
|
277 bool CSystemInfoPlugin::Invoke( NPIdentifier name, |
|
278 NPVariant* args, |
|
279 uint32_t argCount, |
|
280 NPVariant *result ) |
|
281 { |
|
282 bool ret = false; |
|
283 VOID_TO_NPVARIANT( *result ); |
|
284 |
|
285 if ( name == iSystemInfoPluginIdentifiers[EIdBeep] ) |
|
286 { |
|
287 // don't beep if profile is silent |
|
288 MProfile* profile = NULL; |
|
289 TRAPD( error, |
|
290 profile = iProfileEngine->ActiveProfileL() ); |
|
291 if ( KErrNone != error ) |
|
292 { |
|
293 return true; |
|
294 } |
|
295 if ( EFalse == profile->IsSilent() ) |
|
296 { |
|
297 TInt f = 440; // default 440 hertz |
|
298 TInt d = 500; // default 0.5 seconds (in milliseconds) |
|
299 if ( argCount > 0 ) VariantToInt( args[0], f ); |
|
300 if ( argCount > 1 ) VariantToInt( args[1], d ); |
|
301 // convert duration from milliseconds to microseconds, the |
|
302 // underlying functionality doesn't really handle microseconds |
|
303 // even though the interface specs it as microseconds |
|
304 d = d * 1000; |
|
305 // Note that d = 0 seems to mean "forever". Also, there |
|
306 // are max and min frequencies but they are not defined. |
|
307 // Below min there is silence, above max the equation |
|
308 // seems to be f = min( max_freq, f) |
|
309 iSystemInfoMisc->Beep( f, d ); |
|
310 } |
|
311 profile->Release(); |
|
312 ret = true; |
|
313 } |
|
314 else if ( name == iSystemInfoPluginIdentifiers[EIdLightOn] ) |
|
315 { |
|
316 TInt l = iSystemInfoMisc->LightTargetSystem(); |
|
317 TInt d = iSystemInfoMisc->LightInfiniteDuration(); |
|
318 TInt i = iSystemInfoMisc->LightDefaultIntensity(); |
|
319 TInt f = 1; |
|
320 if ( argCount > 0 ) VariantToInt( args[0], l ); |
|
321 if ( argCount > 1 ) VariantToInt( args[1], d ); |
|
322 if ( argCount > 2 ) VariantToInt( args[2], i ); |
|
323 if ( argCount > 3 ) VariantToInt( args[3], f ); |
|
324 iSystemInfoMisc->LightOn( l, d, i, f ); |
|
325 ret = true; |
|
326 } |
|
327 else if ( name == iSystemInfoPluginIdentifiers[EIdLightBlink] ) |
|
328 { |
|
329 TInt l = iSystemInfoMisc->LightTargetSystem(); |
|
330 TInt d = iSystemInfoMisc->LightInfiniteDuration(); |
|
331 TInt don = iSystemInfoMisc->LightDefaultCycleTime(); |
|
332 TInt doff = iSystemInfoMisc->LightDefaultCycleTime(); |
|
333 TInt i = iSystemInfoMisc->LightDefaultIntensity(); |
|
334 if ( argCount > 0 ) VariantToInt( args[0], l ); |
|
335 if ( argCount > 1 ) VariantToInt( args[1], d ); |
|
336 if ( argCount > 2 ) VariantToInt( args[2], don ); |
|
337 if ( argCount > 3 ) VariantToInt( args[3], doff ); |
|
338 if ( argCount > 4 ) VariantToInt( args[4], i ); |
|
339 iSystemInfoMisc->LightBlink( l, d, don, doff, i ); |
|
340 ret = true; |
|
341 } |
|
342 else if ( name == iSystemInfoPluginIdentifiers[EIdLightOff] ) |
|
343 { |
|
344 TInt l = iSystemInfoMisc->LightTargetSystem(); |
|
345 TInt d = iSystemInfoMisc->LightInfiniteDuration(); |
|
346 TInt f = 1; |
|
347 if ( argCount > 0 ) VariantToInt( args[0], l ); |
|
348 if ( argCount > 1 ) VariantToInt( args[1], d ); |
|
349 if ( argCount > 2 ) VariantToInt( args[2], f ); |
|
350 iSystemInfoMisc->LightOff( l, d, f ); |
|
351 ret = true; |
|
352 } |
|
353 else if ( name == iSystemInfoPluginIdentifiers[EIdStartVibra] ) |
|
354 { |
|
355 TInt d = iSystemInfoMisc->VibraMaxDuration(); |
|
356 TInt i = iSystemInfoMisc->VibraMaxIntensity(); |
|
357 if ( argCount > 0 ) VariantToInt( args[0], d ); |
|
358 if ( argCount > 1 ) VariantToInt( args[1], i ); |
|
359 iSystemInfoMisc->StartVibra( d, i ); |
|
360 ret = true; |
|
361 } |
|
362 else if ( name == iSystemInfoPluginIdentifiers[EIdStopVibra] ) |
|
363 { |
|
364 iSystemInfoMisc->StopVibra(); |
|
365 ret = true; |
|
366 } |
|
367 else if ( name == iSystemInfoPluginIdentifiers[EIdDriveSize] ) |
|
368 { |
|
369 TUint c = 0; |
|
370 if ( argCount > 0 && NPVARIANT_IS_STRING( args[0] ) ) |
|
371 { |
|
372 NPString nps = NPVARIANT_TO_STRING( args[0] ); |
|
373 if ( nps.UTF8Characters ) c = nps.UTF8Characters[0]; |
|
374 } |
|
375 if ( c > 0 ) |
|
376 { |
|
377 TChar drive( c ); |
|
378 TReal size = iSystemInfoMisc->DriveSize( drive ); |
|
379 DOUBLE_TO_NPVARIANT( size, *result ); |
|
380 ret = true; |
|
381 } |
|
382 } |
|
383 else if ( name == iSystemInfoPluginIdentifiers[EIdDriveFree] ) |
|
384 { |
|
385 TUint c = 0; |
|
386 if ( argCount > 0 && NPVARIANT_IS_STRING( args[0] ) ) |
|
387 { |
|
388 NPString nps = NPVARIANT_TO_STRING( args[0] ); |
|
389 if ( nps.UTF8Characters ) c = nps.UTF8Characters[0]; |
|
390 } |
|
391 if ( c > 0 ) |
|
392 { |
|
393 TChar drive( c ); |
|
394 TReal free = iSystemInfoMisc->DriveFree( drive ); |
|
395 DOUBLE_TO_NPVARIANT( free, *result ); |
|
396 ret = true; |
|
397 } |
|
398 } |
|
399 |
|
400 return ret; |
|
401 } |
|
402 |
|
403 // ---------------------------------------------------------------------------- |
|
404 // CSystemInfoPlugin::HasProperty |
|
405 // |
|
406 // ---------------------------------------------------------------------------- |
|
407 bool CSystemInfoPlugin::HasProperty (NPIdentifier name) |
|
408 { |
|
409 for ( TInt i= 0; i < EIdLast; i++ ) |
|
410 { |
|
411 if ( name == iSystemInfoPluginIdentifiers[i] ) |
|
412 { |
|
413 return !IsMethod[i]; |
|
414 } |
|
415 } |
|
416 return false; |
|
417 } |
|
418 |
|
419 |
|
420 // ---------------------------------------------------------------------------- |
|
421 // CSystemInfoPlugin::GetProperty |
|
422 // |
|
423 // ---------------------------------------------------------------------------- |
|
424 bool CSystemInfoPlugin::GetProperty( NPIdentifier name, NPVariant *variant ) |
|
425 { |
|
426 // default variant value maps to javascript undefined |
|
427 VOID_TO_NPVARIANT( *variant ); |
|
428 |
|
429 if ( name == iSystemInfoPluginIdentifiers[EIdChargeLevel] ) |
|
430 { |
|
431 INT32_TO_NPVARIANT( iPowerObserver->ChargeLevel(), *variant ); |
|
432 } |
|
433 else if ( name == iSystemInfoPluginIdentifiers[EIdChargerConnected] ) |
|
434 { |
|
435 INT32_TO_NPVARIANT( iPowerObserver->ChargerConnected(), *variant ); |
|
436 } |
|
437 else if ( name == iSystemInfoPluginIdentifiers[EIdSignalBars] ) |
|
438 { |
|
439 INT32_TO_NPVARIANT( iNetworkObserver->SignalBars(), *variant ); |
|
440 } |
|
441 else if ( name == iSystemInfoPluginIdentifiers[EIdNetworkRegistrationStatus] ) |
|
442 { |
|
443 INT32_TO_NPVARIANT( iNetworkObserver->RegistrationStatus(), *variant ); |
|
444 } |
|
445 else if ( name == iSystemInfoPluginIdentifiers[EIdNetworkName] ) |
|
446 { |
|
447 const TDesC& inBuf = iNetworkObserver->NetworkName(); |
|
448 HBufC8* outBuf = HBufC8::New( inBuf.Length() + 1 ); |
|
449 if ( outBuf ) |
|
450 { |
|
451 TPtr8 ptr( outBuf->Des() ); |
|
452 TInt ret = CnvUtfConverter::ConvertFromUnicodeToUtf8( ptr, inBuf ); |
|
453 DesToNpvariant(ptr, variant); |
|
454 delete outBuf; |
|
455 } |
|
456 } |
|
457 else if ( name == iSystemInfoPluginIdentifiers[EIdLightMinIntensity] ) |
|
458 { |
|
459 INT32_TO_NPVARIANT( iSystemInfoMisc->LightMinIntensity(), *variant ); |
|
460 } |
|
461 else if ( name == iSystemInfoPluginIdentifiers[EIdLightMaxIntensity] ) |
|
462 { |
|
463 INT32_TO_NPVARIANT( iSystemInfoMisc->LightMaxIntensity(), *variant ); |
|
464 } |
|
465 else if ( name == iSystemInfoPluginIdentifiers[EIdLightDefaultIntensity] ) |
|
466 { |
|
467 INT32_TO_NPVARIANT( iSystemInfoMisc->LightDefaultIntensity(), *variant ); |
|
468 } |
|
469 else if ( name == iSystemInfoPluginIdentifiers[EIdLightInfiniteDuration] ) |
|
470 { |
|
471 INT32_TO_NPVARIANT( iSystemInfoMisc->LightInfiniteDuration(), *variant ); |
|
472 } |
|
473 else if ( name == iSystemInfoPluginIdentifiers[EIdLightMaxDuration] ) |
|
474 { |
|
475 INT32_TO_NPVARIANT( iSystemInfoMisc->LightMaxDuration(), *variant ); |
|
476 } |
|
477 else if ( name == iSystemInfoPluginIdentifiers[EIdLightDefaultCycleTime] ) |
|
478 { |
|
479 INT32_TO_NPVARIANT( iSystemInfoMisc->LightDefaultCycleTime(), *variant ); |
|
480 } |
|
481 else if ( name == iSystemInfoPluginIdentifiers[EIdLightTargetPrimaryDisplayAndKeyboard] ) |
|
482 { |
|
483 INT32_TO_NPVARIANT( iSystemInfoMisc->LightTargetPrimaryDisplayAndKeyboard(), *variant ); |
|
484 } |
|
485 else if ( name == iSystemInfoPluginIdentifiers[EIdLightTargetSystem] ) |
|
486 { |
|
487 INT32_TO_NPVARIANT( iSystemInfoMisc->LightTargetSystem(), *variant ); |
|
488 } |
|
489 else if ( name == iSystemInfoPluginIdentifiers[EIdVibraMinIntensity] ) |
|
490 { |
|
491 INT32_TO_NPVARIANT( iSystemInfoMisc->VibraMinIntensity(), *variant ); |
|
492 } |
|
493 else if ( name == iSystemInfoPluginIdentifiers[EIdVibraMaxIntensity] ) |
|
494 { |
|
495 INT32_TO_NPVARIANT( iSystemInfoMisc->VibraMaxIntensity(), *variant ); |
|
496 } |
|
497 else if ( name == iSystemInfoPluginIdentifiers[EIdVibraMaxDuration] ) |
|
498 { |
|
499 INT32_TO_NPVARIANT( iSystemInfoMisc->VibraMaxDuration(), *variant ); |
|
500 } |
|
501 else if ( name == iSystemInfoPluginIdentifiers[EIdVibraSettings] ) |
|
502 { |
|
503 INT32_TO_NPVARIANT( iSystemInfoMisc->VibraSettings(), *variant ); |
|
504 } |
|
505 else if ( name == iSystemInfoPluginIdentifiers[EIdTotalRam] ) |
|
506 { |
|
507 INT32_TO_NPVARIANT( iSystemInfoMisc->TotalRam(), *variant ); |
|
508 } |
|
509 else if ( name == iSystemInfoPluginIdentifiers[EIdFreeRam] ) |
|
510 { |
|
511 INT32_TO_NPVARIANT( iSystemInfoMisc->FreeRam(), *variant ); |
|
512 } |
|
513 else if ( name == iSystemInfoPluginIdentifiers[EIdDriveList] ) |
|
514 { |
|
515 HBufC8* drives = HBufC8::New( KMaxDrives*2 ); |
|
516 if ( drives ) |
|
517 { |
|
518 TPtr8 ptr( drives->Des() ); |
|
519 iSystemInfoMisc->DriveList( ptr ); |
|
520 DesToNpvariant(ptr, variant); |
|
521 delete drives; |
|
522 } |
|
523 } |
|
524 else if ( name == iSystemInfoPluginIdentifiers[EIdLanguage] ) |
|
525 { |
|
526 TBuf<64> langCode; |
|
527 iSystemInfoMisc->Language( langCode ); |
|
528 HBufC8* outBuf = HBufC8::New( langCode.Length() + 1 ); |
|
529 if ( outBuf ) |
|
530 { |
|
531 TPtr8 ptr( outBuf->Des() ); |
|
532 ptr.SetLength( 0 ); |
|
533 // Note: the copy below goes from 16-bit to 8-bit by |
|
534 // dropping the high 8-bits. This will work since all |
|
535 // codes are made from 7-bit ASCII characters see |
|
536 // http://www.rfc-editor.org/rfc/rfc4646.txt section 7 |
|
537 // "Character Set Considerations". Also see |
|
538 // http://www.w3.org/International/questions/qa-lang-2or3 |
|
539 ptr.Copy( langCode ); |
|
540 ptr.ZeroTerminate(); |
|
541 DesToNpvariant( ptr, variant ); |
|
542 delete outBuf; |
|
543 } |
|
544 } |
|
545 else |
|
546 { |
|
547 return EFalse; |
|
548 } |
|
549 return ETrue; |
|
550 } |
|
551 |
|
552 // ---------------------------------------------------------------------------- |
|
553 // CSystemInfoPlugin::SetProperty |
|
554 // ---------------------------------------------------------------------------- |
|
555 bool CSystemInfoPlugin::SetPropertyL( NPIdentifier name, NPVariant *variant ) |
|
556 { |
|
557 // all writeable properties are names of callback functions |
|
558 HBufC8* pFunctionText = NULL; |
|
559 |
|
560 // anything but a string will result in nulling out the callback |
|
561 if ( NPVARIANT_IS_STRING( *variant ) ) |
|
562 { |
|
563 // canonicalize function name string: only fname (no args) and zero terminate |
|
564 NPString str = NPVARIANT_TO_STRING( *variant ); |
|
565 |
|
566 if ( (const TUint8 *)str.UTF8Characters ) |
|
567 { |
|
568 // allocate a copy |
|
569 TInt length = str.UTF8Length; |
|
570 pFunctionText = HBufC8::NewL( length+1 ); |
|
571 TPtr8 tptr = pFunctionText->Des(); |
|
572 tptr.Copy( (const TUint8 *)str.UTF8Characters, length ); |
|
573 |
|
574 //Remove any arguments passed in the with the function name |
|
575 TInt pos = pFunctionText->Locate(TChar('(')); |
|
576 if ( pos != KErrNotFound ) |
|
577 { |
|
578 length = pos; |
|
579 } |
|
580 tptr.SetLength(length); |
|
581 tptr.ZeroTerminate(); |
|
582 } |
|
583 } |
|
584 |
|
585 // NOTE: pFunctionText can be NULL |
|
586 |
|
587 if ( name == iSystemInfoPluginIdentifiers[EIdOnChargeLevel] ) |
|
588 { |
|
589 iPowerObserver->RequestNotificationL( CPowerObserver::EIdBatteryInfo, |
|
590 pFunctionText ); |
|
591 } |
|
592 else if ( name == iSystemInfoPluginIdentifiers[EIdOnChargerConnected] ) |
|
593 { |
|
594 iPowerObserver->RequestNotificationL( CPowerObserver::EIdIndicator, |
|
595 pFunctionText ); |
|
596 } |
|
597 else if ( name == iSystemInfoPluginIdentifiers[EIdOnNetworkRegistrationStatus] ) |
|
598 { |
|
599 iNetworkObserver->RequestNotificationL( CNetworkObserver::EIdRegistrationStatus, |
|
600 pFunctionText ); |
|
601 } |
|
602 else |
|
603 { |
|
604 delete pFunctionText; |
|
605 return EFalse; |
|
606 } |
|
607 return ETrue; |
|
608 } |
|
609 |
|
610 void CSystemInfoPlugin::DesToNpvariant(TPtr8& string, NPVariant*& variant) |
|
611 { |
|
612 char* newString = NULL; |
|
613 if (string.Length()) { |
|
614 newString = new char(string.Length()); |
|
615 } |
|
616 if (newString) { |
|
617 Mem::Copy(newString, string.Ptr(), string.Length()); |
|
618 STRINGN_TO_NPVARIANT(newString, string.Length(), *variant); |
|
619 } |
|
620 } |
|
621 |
|
622 |
|
623 |
|
624 // End of File |