/* * OperaWidget.js * -------------- * Javascript wrapper file for Opera widgets being ported to Nokia WRT * * Emulates the special functionality provided by the Opera Widget environment * References to the widget object need to be changed to operaWidget to access functionality, * as the Nokia WRT widget object cannot be extended. * * Licensed under the BSD License. * Originally developed by Metropolia Media Works / Andrew Wharton * Supported by Forum Nokia * version: 1.0 * -------------- */ var operaWidget = { // Widget API attributes //"identifier": Supported by Nokia WRT "originURL": null, // initialised after object is created "widgetMode": "widget", // Widget API methods //"openURL": Supported by Nokia WRT //"preferenceForKey": Supported by Nokia WRT //"setPreferenceForKey": Supported by Nokia WRT //"getAttention": No similar functinality "showNotification": showNotification, // Callback functions //"onshow": supported by Nokia WRT //"onhide": supported by Nokia WRT // Methods "show": show, "hide": hide } // initialise the originURL attribute getOriginURL(); // function to initialise the value for the originURL function getOriginURL() { // create the variable to hold the identifier used for comparison, and the obtained path to the widget var identifier = widget.identifier; var widgetPath = null; // get the service object to obtains var so = device.getServiceObject("Service.AppManager", "IAppManager"); // create a criteria object and populate it with the required information var criteria = new Object(); criteria.Type = "Application"; // gets information about all apps, regardless of type // get a list of applications var result = so.IAppManager.GetList(criteria); // while an AppUid has not been identified, go through the returned list of application, // checking if the filename a the end of the path is the same as the identifier of the widget. // 1. get the path of the first widget in the list // 2. get the file name from the path, which is the same as the identifier of the widget // 3. check if the filename is the same as the identifier // 4. if it is not the same, go to the next application in the list // 5. if it is the same, get the Uid of the app and store it into the AppUid variable // the loop will continue until the Application is found and the Uid stored, breaking the loop // place the iterator at the beginning result.ReturnValue.reset(); while(widgetPath == null) { // get the first item from the iterator var item; item = result.ReturnValue.getNext(); // get the path of the current app in the list var path = item.Path; // split the path, store to an array and take the 4th item in the array var pathArray = new Array(); pathArray = path.split("\\"); // get the identifier part of the array var extractedIdentifier = pathArray[3]; // 4th item in the array is the same as the identifier //compare the filename and the identifier if(extractedIdentifier == identifier) { widgetPath = item.Path; // breaks the while loop when the items match } } // store the path to the operaWidget.originURL slot operaWidget.originURL = widgetPath; } /* * Method Implementations * ---------------------- * - showNotification * - show * - hide */ /* * showNotification * ---------------- * shows a notification to the user in the form of an alert. The callback is not supported */ function showNotification(notification, callback) { alert(notification); } /* * show * ---- * Brings the Widget to the foreground * Works by getting a list of the installed apps and * iterating through it until a it finds itself, then uses the Uid to open itself. * */ function show() { // create the variable to hold the identifier used for comparison, and the obtained path to the widget var identifier = widget.identifier; var widgetUid = null; // get the service object to obtains var so = device.getServiceObject("Service.AppManager", "IAppManager"); // create a criteria object and populate it with the required information var criteria = new Object(); criteria.Type = "Application"; // gets information about all apps, regardless of type // get a list of applications var result = so.IAppManager.GetList(criteria); // while an widgetUid has not been identified, go through the returned list of application, // checking if the filename a the end of the path is the same as the identifier of the widget. // 1. get the path of the first widget in the list // 2. get the file name from the path, which is the same as the identifier of the widget // 3. check if the filename is the same as the identifier // 4. if it is not the same, go to the next application in the list // 5. if it is the same, get the Uid of the app and store it into the AppUid variable // the loop will continue until the Application is found and the Uid stored, breaking the loop // place the iterator at the beginning result.ReturnValue.reset(); while(widgetUid == null) { // get the first item from the iterator var item; item = result.ReturnValue.getNext(); // get the path of the current app in the list var path = item.Path; // split the path, store to an array and take the 4th item in the array var pathArray = new Array(); pathArray = path.split("\\"); // need to escape the forward slash character // get the identifier part of the array var extractedIdentifier = pathArray[3]; // 4th item in the array is the same as the identifier //compare the filename and the identifier if(extractedIdentifier == identifier) { widgetUidHex = item.Uid - 0; // convert the Uid string to a number widgetUid = widgetUidHex; // breaks out of the while loop when the items match } } // open the widget based on it's Uid widget.openApplication(widgetUid); } /* * hide * ---- * Brings the HomeScreen to the foreground, which on S60 3rd edition FP2 and S60 5th edition devices * has a UID of 0x102750F0 ref. http://wiki.forum.nokia.com/index.php/How_to_send_a_Web_Runtime_widget_to_background */ function hide() { widget.openApplication(0x102750F0); }