From e13c617a3b97b3707038c31cd18ef49686c36d3d Mon Sep 17 00:00:00 2001 From: thlo Date: Wed, 26 Dec 2012 21:58:29 +0100 Subject: Fixes and improvements of initial widget configuration. --- smarttv-client/Javascript/Config.js | 35 ++++++++++++++++++++++------------- smarttv-client/Javascript/Main.js | 10 ++++++---- smarttv-client/Javascript/Options.js | 8 +++++--- smarttv-client/Javascript/Server.js | 7 +++++++ 4 files changed, 40 insertions(+), 20 deletions(-) diff --git a/smarttv-client/Javascript/Config.js b/smarttv-client/Javascript/Config.js index b0742a4..ad0196f 100755 --- a/smarttv-client/Javascript/Config.js +++ b/smarttv-client/Javascript/Config.js @@ -3,7 +3,8 @@ var Config = { XHRObj : null, xmlDocument : null, serverUrl : "", // Will become the main URL for contacting the server - serverAddr : "192.168.1.122:8000", + serverAddr : "", + serverAddrDefault: "192.168.1.122:8000", format :"has", tgtBufferBitrate : 6000, // kbps totalBufferDuration : 30, // sec @@ -26,25 +27,27 @@ var Config = { Config.init = function () { var fileSystemObj = new FileSystem(); - + if (fileSystemObj.isValidCommonPath(curWidget.id) == 0){ - Display.showPopup ("First Launch of the Widget --> Launching Config Menu"); +// Display.showPopup ("First Launch of the Widget --> Launching Config Menu"); alert("First Launch of the Widget"); // should switch to the config screen here var res = fileSystemObj.createCommonDir(curWidget.id); if (res == true) { Config.firstLaunch = true; - -// Config.writeContext("192.168.1.122:8000"); + + Main.init(); + Main.changeState(4); return; } else { + Main.init(); Display.showPopup ("ERROR: Cannot create widget folder"); + Main.log("ERROR: Cannot create widget folder curWidget.id= " +curWidget.id); } return; } - else { Config.readContext(); } @@ -94,8 +97,6 @@ Config.updateContext = function (addr) { Config.readContext = function () { var fileSystemObj = new FileSystem(); -// Display.showPopup ("Reading Config file for curWidget.id= " + curWidget.id); - try { var fd = fileSystemObj.openCommonFile(Config.cfgFileName, "r"); @@ -109,23 +110,28 @@ Config.readContext = function () { Config.serverUrl = "http://" + Config.serverAddr; } else { - Display.showPopup ("WARNING: Error in Config File"); + Display.showPopup ("WARNING: Error in Config File. Try widget restart."); + // TODO: I should re-write the config file } } - fileSystemObj.closeCommonFile(fd); + fileSystemObj.closeCommonFile(fd); + } catch (e) { + Main.log("Config.readContext: Error while reading: e= " +e); var res = fileSystemObj.createCommonDir(curWidget.id); if (res == true) { - Display.showPopup ("*** Read Error and Widget Folder successfully created ***"); - alert("-------------- Error: res = true ------------------------"); + Main.log("Config.readContext: Widget Folder created"); + Display.showPopup ("Config Read Error: Try widget restart"); } else { - Display.showPopup ("*** Read Error and Widget Folder creation failed ***"); + Main.log("Config.readContext: Widget Folder creation failed"); + Display.showPopup ("Config Read Error: Try re-installing the widget"); alert("-------------- Error: res = false ------------------------"); } Config.firstLaunch = true; + Main.init(); Main.changeState(4); } }; @@ -171,16 +177,19 @@ Config.processConfig = function () { if (xmlResponse == null) { alert ("xml error"); Display.showPopup("Error in XML Config File"); + Main.log("Error in XML Config File"); return; } this.xmlDocument = xmlResponse.documentElement; if (!this.xmlDocument ) { alert("Failed to get valid Config XML"); Display.showPopup("Failed to get valid Config XML"); + Main.log("Failed to get valid Config XML"); return; } else { alert ("Paring config XML now"); + Main.log("Paring config XML now"); this.format = Config.getXmlString("format"); var res = Config.getXmlValue("tgtBufferBitrate"); if (res != 0) diff --git a/smarttv-client/Javascript/Main.js b/smarttv-client/Javascript/Main.js index ef92172..fa3c863 100755 --- a/smarttv-client/Javascript/Main.js +++ b/smarttv-client/Javascript/Main.js @@ -38,8 +38,6 @@ var Main = { }; Main.onLoad = function() { - -// Config.init("http://192.168.1.122:8000/widget.conf"); Network.init(); Display.init(); @@ -55,6 +53,7 @@ Main.onLoad = function() { }; // Called by Config, when done +// TODO: Send sendReadyEvent early and show a splash screen during startup Main.init = function () { alert("Main.init()"); if ( Player.init() && Audio.init() && Server.init() ) { @@ -77,7 +76,7 @@ Main.init = function () { document.getElementById("splashScreen").style.display="none"; - widgetAPI.sendReadyEvent(); + widgetAPI.sendReadyEvent(); } else { alert("Failed to initialise"); @@ -86,7 +85,10 @@ Main.init = function () { }; Main.log = function (msg) { - var XHRObj = new XMLHttpRequest(); + if (Config.serverUrl == "" ) + return; + + var XHRObj = new XMLHttpRequest(); XHRObj.open("POST", Config.serverUrl + "/log", true); XHRObj.send("CLOG: " + msg); }; diff --git a/smarttv-client/Javascript/Options.js b/smarttv-client/Javascript/Options.js index d60a9ff..11095c6 100755 --- a/smarttv-client/Javascript/Options.js +++ b/smarttv-client/Javascript/Options.js @@ -7,15 +7,15 @@ Options.init = function() { _g_ime.keySet = '12key'; this.imeBox = new IMEShell("widgetServerAddr", Options.onImeCreated, 'de'); - alert ("Options Initiated"); }; Options.onComplete = function () { - alert("Colpleted"); + alert("Completed"); }; Options.onEnter = function () { alert("Enter: " + document.getElementById("widgetServerAddr").value ); + Config.updateContext(document.getElementById("widgetServerAddr").value); document.getElementById('widgetServerAddr').blur(); @@ -38,6 +38,7 @@ Options.onBlue = function () { Options.onImeCreated = function(obj) { // _g_ime.keySet ("12key"); // obj.setKeySetFunc('12key'); + Main.log ("Options.onImeCreated()"); obj.setKeyFunc(tvKey.KEY_RETURN, function(keyCode) { widgetAPI.sendReturnEvent(); return false; } ); obj.setKeyFunc(tvKey.KEY_EXIT, function(keyCode) { widgetAPI.sendExitEvent(); return false; } ); @@ -46,7 +47,7 @@ Options.onImeCreated = function(obj) { obj.setWordBoxPos(18, 6); obj.setKeyFunc(tvKey.KEY_BLUE, Options.onBlue); - obj.setString(Config.serverAddr); + obj.setString(Config.serverAddrDefault); obj.setEnterFunc(Options.onEnter); if (obj.setMode("_num") == false) { @@ -60,6 +61,7 @@ Options.onImeCreated = function(obj) { Options.onReady = function () { document.getElementById('widgetServerAddr').focus(); + Main.log ("Options.onReady()"); alert ("KeySet= " + this.imeBox.getKeySet()); }; diff --git a/smarttv-client/Javascript/Server.js b/smarttv-client/Javascript/Server.js index 588906b..c64d320 100755 --- a/smarttv-client/Javascript/Server.js +++ b/smarttv-client/Javascript/Server.js @@ -60,6 +60,8 @@ Server.fetchVideoList = function(url) { Server.createVideoList = function() { alert ("creating Video list now"); + Main.log("creating Video list now"); + var splashElement = document.getElementById("splashStatus"); widgetAPI.putInnerHTML(splashElement, "Creating Video list now" ); @@ -96,6 +98,11 @@ Server.createVideoList = function() { { widgetAPI.putInnerHTML(splashElement, "Parsing ..."); var items = xmlElement.getElementsByTagName("item"); + if (items.length == 0) { + Display.showPopup("Something wrong. Response does not contain any item"); + Main.log("Something wrong. Response does not contain any item"); + + }; for (var index = 0; index < items.length; index++) { -- cgit v1.2.3