--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/org.symbian.tools.wrttools.doc.WebDeveloper/html/GUID-7C9CCFF3-A6E0-4593-8315-1A0EAAFD05AF.html Fri Mar 05 19:11:15 2010 -0800
@@ -0,0 +1,373 @@
+
+<!DOCTYPE html
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><meta name="copyright" content="(C) Copyright 2009"/><meta name="DC.rights.owner" content="(C) Copyright 2009"/><meta name="DC.Type" content="mobileconcept"/><meta name="DC.Title" content="SystemInfo Service API example"/><meta name="DC.Relation" scheme="URI" content="GUID-1D78998F-2A45-4100-AAD0-FCCAC300DBC1"/><meta name="DC.Relation" scheme="URI" content="GUID-7C69DDA4-16F1-4A8F-BDB2-4CB0015B4E81"/><meta name="DC.Relation" scheme="URI" content="GUID-65AAF569-D347-462B-B59A-9D7CA184AB9C"/><meta name="DC.Relation" scheme="URI" content="GUID-AEB26A58-1DE2-46CB-81EC-6DB3A477B7A3"/><meta name="DC.Format" content="XHTML"/><meta name="DC.Identifier" content="GUID-7C9CCFF3-A6E0-4593-8315-1A0EAAFD05AF"/><title>SystemInfo Service API example </title><script type="text/javascript">
+ function initPage() {}
+ </script><link href="../PRODUCT_PLUGIN/book.css" rel="stylesheet" type="text/css"/><link href="css/s60/style.css" rel="stylesheet" type="text/css" media="all"/></head><body onload="initPage();"><div class="body"><div class="contentLeft prTxt"><h1 class="pageHeading" id="GUID-7C9CCFF3-A6E0-4593-8315-1A0EAAFD05AF">SystemInfo Service API example</h1><div>
+<p/>
+<p>This section presents the full source code of a working sample widget
+for the <a href="GUID-E0ED671A-BBDA-4C07-828F-BD35782D9B36.html#GUID-E0ED671A-BBDA-4C07-828F-BD35782D9B36">SystemInfo
+Service</a>. You can download the <code>wgz</code> package for
+this widget from section <a href="GUID-775005BC-2FF8-45A9-BBA6-6CED6B5780A2.html#GUID-775005BC-2FF8-45A9-BBA6-6CED6B5780A2">Example widgets</a>.</p>
+<p>For general information about creating widgets, see section <a href="GUID-0E3095DB-03FF-4240-83F2-6D876AD2083A.html#GUID-0E3095DB-03FF-4240-83F2-6D876AD2083A">Widget component files</a>.</p>
+<p>For widget development and debugging purposes, this example writes its
+output to <code>c:\data\jslog_widget.log</code> using <code>console.info</code>.
+For instructions on how to enable logging in the Web browser for S60, see
+section <a href="GUID-B584CA90-543B-4AED-B134-A3A616259DB9.html#GUID-B584CA90-543B-4AED-B134-A3A616259DB9">JavaScript console</a>.</p>
+<div><h3>Info.plist</h3>
+<pre class="codeblock" id="GUID-7B7E64B5-53C1-441B-AC88-E22FCCA9257D"><?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Nokia//DTD PLIST 1.0//EN" "http://www.nokia.com/NOKIA_COM_1/DTDs/plist-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>DisplayName</key>
+ <string>SysInfoSample</string>
+ <key>Identifier</key>
+ <string>com.nokia.widget.sapi.sysinfo.sample</string>
+ <key>Version</key>
+ <string>1.0</string>
+ <key>MainHTML</key>
+ <string>sysinfo-sample.html</string>
+</dict>
+</plist></pre>
+</div>
+<div><h3>sysInfo-sample.html</h3>
+<pre class="codeblock" id="GUID-A3011DD3-5720-4704-8330-12BC1DE02DBD"><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+ <head>
+ <script type="text/javascript" src="js/common.js"></script>
+ <script type="text/javascript" src="js/sysinfo-sample.js"></script>
+ </head>
+ <body id='docBody' bgcolor="#ddeeff" onload="setup()" style=width:100%;height:100%;>
+ <form name="frm">
+ <h3>Sysinfo API Sample Widget</h3>
+ <input type="button" onclick="getSysInfo('img1')" value="GetSysInfo"><img id="img1" src="pic/blank.png" width="25" height="25" align="center"><br>
+ <input type="button" onclick="setSysInfo('img2')" value="SetSysInfo"><img id="img2" src="pic/blank.png" width="25" height="25" align="center"><br>
+ <input type="button" onclick="getSysInfoAsync('img3')" value="GetSysInfoAsync"><img id="img3" src="pic/blank.png" width="25" height="25" align="center"><br>
+ <input type="button" onclick="getNotification('img4')" value="GetNotification"><img id="img4" src="pic/blank.png" width="25" height="25" align="center"><br>
+ <input type="button" onclick="cancelGetSysInfoAsync('img5')" value="CancelGetSysInfoAsync"><img id="img5" src="pic/blank.png" width="25" height="25" align="center"><hr>
+ <div class='sysinfo' id='sysinfo' bgcolor="#ddeeff" style=width:100%;height:100%;overflow:auto></div>
+ </form>
+ </body>
+</html></pre>
+</div>
+<div><h3>common.js</h3>
+<pre class="codeblock" id="GUID-88C7ECB0-6656-4C16-9B9C-846E61F1AFF7">// common.js
+//
+// This file contains some utility functions
+
+// Check the error code and show the information to users
+function checkError(message, resultList, divId, imgId)
+{
+ var errCode = resultList.ErrorCode;
+ var msg = "";
+
+ if (errCode) {
+ msg = message + "<BR>" + "Failed Error: " + errCode + "<BR>";
+ if(resultList.ErrorMessage != undefined)
+ msg += "Error Message: " + resultList.ErrorMessage;
+ showIMG(imgId,"no");
+ } else {
+ showIMG(imgId,"yes");
+ }
+
+ //print error message
+ if(divId != null && divId != undefined)
+ document.getElementById(divId).innerHTML = msg;
+ console.info(msg);
+
+ return errCode;
+}
+
+// Build the message by reading a iteratorable list in a recursive manner
+function showIterableList(iterator)
+{
+ var msg = "";
+ try
+ {
+ iterator.reset();
+ var item;
+ while (( item = iterator.getNext()) != undefined ){
+ msg += showObject( item );
+ }
+ }
+ catch(e)
+ {
+ alert('<showIterableList> ' + e);
+ }
+ return msg;
+}
+
+// Build the message by reading a JS object in a recursive manner
+function showObject( obj )
+{
+ var txt = "";
+ try {
+ if ( typeof obj != 'object' )
+ return "" + obj + '<BR/>';
+ else {
+ for(var key in obj) {
+ txt += key + ":";
+ txt += showObject( obj[key] );
+ txt += '<BR/>';
+ }
+ txt += '<BR/>';
+ }
+ }
+ catch (e)
+ {
+ alert("showObject: " + e);
+ }
+ return txt;
+}
+
+// Show the image to indicate the test result
+function showIMG(imgId, isOK)
+{
+ if(imgId == null || imgId == undefined)
+ return;
+
+ if(isOK == "yes")
+ document.getElementById(imgId).src = "pic/yes.png";
+ else if(isOK == "no")
+ document.getElementById(imgId).src = "pic/no.png";
+ else
+ document.getElementById(imgId).src = "pic/blank.png";
+}
+
+// Show elements in object by using 'alert'
+function testObject(obj)
+{
+ var msg = "";
+ for(var key in obj) {
+ msg = msg + ":" + key + "=" + obj[key];
+ }
+ alert(msg);
+}
+
+// Test whether the input is numeric
+function IsNumeric(sText)
+{
+ var ValidChars = "0123456789.";
+ var IsNumber=true;
+ var Char;
+
+ for (i = 0; i < sText.length && IsNumber == true; i++)
+ {
+ Char = sText.charAt(i);
+ if (ValidChars.indexOf(Char) == -1)
+ {
+ IsNumber = false;
+ }
+ }
+ return IsNumber;
+}</pre>
+</div>
+<div><h3>sysInfo-sample.js</h3>
+<pre class="codeblock" id="GUID-1F051C8C-63E5-46EC-98F3-7138EF3C0A84">// sysinfo-sample.js
+//
+// In this sample system information will be listed and changed; The
+// notification will be send when the system info changes; Also,
+// async operation will be canceled.
+//
+
+//SAPI Error Codes
+// 0 - Success
+// 1000 - InvalidServiceArgument
+// 1001 - UnknownArgumentName
+// 1002 - BadArgumentType
+// 1003 - MissingArgument
+// 1004 - ServiceNotSupported
+// 1005 - ServiceInUse
+// 1006 - ServiceNotReady
+// 1007 - NoMemory
+// 1008 - HardwareNotAvailable
+// 1009 - ServerBusy
+// 1010 - EntryExists
+// 1011 - AccessDenied
+// 1012 - NotFound
+// 1013 - UnknownFormat
+// 1014 - GeneralError
+// 1015 - CancelSuccess
+// 1016 - ServiceTimedOut
+// 1017 - PathNotFound
+
+// Declare the service object
+var so;
+
+// imgid for callback1 function
+var imgid_callback1;
+
+// imgid for callback2 function
+var imgid_callback2;
+
+// imgid for callback3 function
+var imgid_callback3;
+
+// id of the div used to display information
+const DIV_ID = 'sysinfo';
+
+// Called from onload()
+function setup()
+{
+ try {
+ so = device.getServiceObject("Service.SysInfo", "ISysInfo");
+ console.info("setup: so: %s", so);
+ }
+ catch (e) {
+ alert('<setup> ' +e);
+ }
+}
+
+//Get SysInfo
+function getSysInfo(imgId)
+{
+ // get the entity
+ var entity = prompt("Please enter the Entry", "General");
+ var key = prompt("Please enter the Key", "VibraActive");
+ var criteria = new Object();
+ criteria.Entity = entity;
+ criteria.Key = key;
+
+ try {
+ var result = so.ISysInfo.GetInfo(criteria);
+ if(!checkError("ISysInfo::getSysInfo",result,DIV_ID,imgId)) {
+ document.getElementById(DIV_ID).innerHTML = showObject(result.ReturnValue);
+ }
+ }
+ catch (e) {
+ showIMG(imgId,"no");
+ alert ("getSysInfo: " + e);
+ }
+}
+
+//Set SysInfo
+function setSysInfo(imgId)
+{
+ // get the entity
+ var entity = prompt("Please enter the Entry", "General");
+ var key = prompt("Please enter the Key", "VibraActive");
+ var vals = prompt("Please enter the new Value", 0);
+
+ var systemData = new Object();
+ if(IsNumeric(vals)) {
+ systemData.Status = parseInt(vals);
+ } else {
+ systemData.StringData = vals;
+ }
+
+ var criteria = new Object();
+ criteria.Entity = entity;
+ criteria.Key = key;
+ criteria.SystemData = systemData;
+
+ try {
+ var result = so.ISysInfo.SetInfo(criteria);
+ checkError("ISysInfo::setSysInfo",result,DIV_ID,imgId);
+ }
+ catch (e) {
+ showIMG(imgId,"no");
+ alert ("setSysInfo: " + e);
+ }
+}
+
+//Get SysInfo
+function getSysInfoAsync(imgId)
+{
+ // get the entity
+ var entity = prompt("Please enter the Entry", "Network");
+ var key = prompt("Please enter the Key", "HomeNetwork");
+
+ var criteria = new Object();
+ criteria.Entity = entity;
+ criteria.Key = key;
+
+ try {
+ imgid_callback1 = imgId;
+ var result = so.ISysInfo.GetInfo(criteria, callback1);
+ if(!checkError("ISysInfo::getSysInfoAsync",result,DIV_ID,imgId))
+ showIMG(imgId, "");
+ }
+ catch (e) {
+ showIMG(imgId,"no");
+ alert ("getSysInfoAsync: " + e);
+ }
+}
+
+// set callback function for notification
+function getNotification(imgId)
+{
+ // get the entity
+ var entity = prompt("Please enter the Entry", "General");
+ var key = prompt("Please enter the Key", "VibraActive");
+
+ var criteria = new Object();
+ criteria.Entity = entity;
+ criteria.Key = key;
+
+ try {
+ imgid_callback2 = imgId;
+ var result = so.ISysInfo.GetNotification(criteria,callback2);
+ if(!checkError("ISysInfo::getNotification",result,DIV_ID,imgId))
+ showIMG(imgId, "");
+ }
+ catch (e) {
+ showIMG(imgId,"no");
+ alert ("setSysInfo: " + e);
+ }
+}
+
+//Ccancel SysInfo
+function cancelGetSysInfoAsync(imgId)
+{
+ // get the entity
+ var entity = prompt("Please enter the Entry", "Network");
+ var key = prompt("Please enter the Key", "HomeNetwork");
+
+ var criteria = new Object();
+ criteria.Entity = entity;
+ criteria.Key = key;
+
+ try {
+ imgid_callback3 = imgId;
+ var result = so.ISysInfo.GetInfo(criteria, callback3);
+ if(!checkError("ISysInfo::cancelGetSysInfoAsync",result,DIV_ID,imgId)){
+ var criteria2 = new Object();
+ criteria2.TransactionID = result.TransactionID;
+ var cresult = so.ISysInfo.Cancel(criteria2);
+ checkError("ISysInfo::cancelGetSysInfoAsync",cresult,DIV_ID,imgId);
+ }
+ }
+ catch (e) {
+ showIMG(imgId,"no");
+ alert ("cancelGetSysInfoAsync: " + e);
+ }
+}
+
+// This is the asynchronous callback handler
+function callback1(transId, eventCode, result)
+{
+ console.info("callback1: transId: %d eventCode: %d result.ErrorCode: %d", transId, eventCode, result.ErrorCode);
+ if(!checkError("callback1::getSysInfoAsync",result,DIV_ID,imgid_callback1)) {
+ document.getElementById(DIV_ID).innerHTML = showObject(result.ReturnValue);
+ }
+}
+
+// This is the asynchronous callback handler
+function callback2(transId, eventCode, result)
+{
+ console.info("callback2: transId: %d eventCode: %d result.ErrorCode: %d", transId, eventCode, result.ErrorCode);
+ if(!checkError("callback2::getNotification",result,DIV_ID,imgid_callback2)) {
+ document.getElementById(DIV_ID).innerHTML = "Got Notification!Following settings changed!\n" + showObject(result.ReturnValue);
+ }
+}
+
+// This is the asynchronous callback handler
+function callback3(transId, eventCode, result)
+{
+ console.info("callback3: transId: %d eventCode: %d result.ErrorCode: %d", transId, eventCode, result.ErrorCode);
+ if(!checkError("callback3::getNotification",result,DIV_ID,imgid_callback3)) {
+ document.getElementById(DIV_ID).innerHTML = showObject(result.ReturnValue);
+ }
+}</pre>
+</div>
+</div></div></div><div class="footer"><hr/><div class="copy">© Nokia 2009.</div></div></body></html>
\ No newline at end of file