From eb44d51a9fdfc9be5a9b069b5bf5f45d93262504 Mon Sep 17 00:00:00 2001 From: thlo Date: Wed, 1 May 2013 18:21:27 +0200 Subject: Widget v0.94 isNew indicator delete YT URLs Notification, when a recording is started / stopped Notification, when a timer is added / deleted HTTP based configuration. --- smarttv-client/Javascript/Buttons.js | 11 +++- smarttv-client/Javascript/Comm.js | 63 ++++++++++++++++++---- smarttv-client/Javascript/Config.js | 18 +++---- smarttv-client/Javascript/Data.js | 69 +++++++++++++++++++++--- smarttv-client/Javascript/Display.js | 32 +++++------ smarttv-client/Javascript/Main.js | 46 ++++++++++++---- smarttv-client/Javascript/Player.js | 1 + smarttv-client/Javascript/Server.js | 102 ++++++++++++++++++++++++++++++++++- 8 files changed, 289 insertions(+), 53 deletions(-) (limited to 'smarttv-client/Javascript') diff --git a/smarttv-client/Javascript/Buttons.js b/smarttv-client/Javascript/Buttons.js index c069670..b881975 100644 --- a/smarttv-client/Javascript/Buttons.js +++ b/smarttv-client/Javascript/Buttons.js @@ -50,7 +50,16 @@ Buttons.ynEnterCallback = function () { break; case 1: Main.logToServer("ynButtons: Yes "+Player.resumePos); - Server.deleteRecording(Player.guid); + + switch (Main.state) { + case Main.eREC: + Server.deleteRecording(Player.guid); + break; + case Main.eURLS: + Server.deleteUrls(Data.getCurrentItem().childs[Main.selectedVideo].payload.guid); + break; + } + break; } Buttons.ynHide(); diff --git a/smarttv-client/Javascript/Comm.js b/smarttv-client/Javascript/Comm.js index d4cdd18..8c87af6 100644 --- a/smarttv-client/Javascript/Comm.js +++ b/smarttv-client/Javascript/Comm.js @@ -76,26 +76,69 @@ Comm.onMessageReceived = function(message, context) { // context -> message context (headers and etc) Main.logToServer("onMessageReceived:" + message); var msg = eval('(' + message + ')'); - if (msg.type == "YT") { - if (msg.payload.id == "undefined") { - Main.logToServer("ERROR: msg.payload.id is not defined"); - return; - } - Main.logToServer("Found type YT " + msg.payload.id); + switch (msg.type) { + case "YT": + if (msg.payload.id == "undefined") { + Main.logToServer("ERROR: msg.payload.id is not defined"); + return; + } + Main.logToServer("Found type YT " + msg.payload.id); if (Main.state == Main.eURLS) { if (msg.payload.id == "" ) { - Main.logToServer("ERROR: msg.payload.id is empty"); - return; + Main.logToServer("ERROR: msg.payload.id is empty"); + return; } Spinner.show(); UrlsFetcher.autoplay = msg.payload.id; UrlsFetcher.removeWhenStopped = ""; if (msg.payload.store == false) { UrlsFetcher.removeWhenStopped = msg.payload.id; - Main.logToServer("removeWhenStopped= " + msg.payload.id); + Main.logToServer("removeWhenStopped= " + msg.payload.id); } UrlsFetcher.appendGuid(msg.payload.id); } - } + break; + case "CFGADD": + if (msg.payload.serverAddr == "undefined") { + Main.logToServer("ERROR: msg.payload.id is not defined"); + return; + } + Config.updateContext(msg.payload.serverAddr); + if (Config.firstLaunch == true) + Main.state = 1; // ensure, that the cursor is on 1st position + + Main.enableKeys(); + Options.hide(); + Main.changeState(0); + + break; + case "INFO": + Main.logToServer("INFO: type= " + msg.payload.type + " val= " + msg.payload.name); + switch(msg.payload.type) { + case "RECSTART": + Notify.showNotify("Recording started: '" + msg.payload.name +"'", true); + if (Main.state == Main.eREC) { + Server.updateEntry(msg.payload.name); + } + // msg.payload.name is the guid. I should now run a query, then update the database and update the screen (if needed) + + break; + case "RECSTOP": + Notify.showNotify("Recording finished: " + msg.payload.name+"'", true); + break; + case "TCADD": + Notify.showNotify("Timer added: '" + msg.payload.name+"'", true); + break; + case "TCMOD": + Notify.showNotify("Timer modified: '" + msg.payload.name+"'", true); + break; + case "TCDEL": + Notify.showNotify("Timer deleted: '" + msg.payload.name+"'", true); + break; + + } + break; + }; // switch + }; diff --git a/smarttv-client/Javascript/Config.js b/smarttv-client/Javascript/Config.js index 027780a..8f0d898 100755 --- a/smarttv-client/Javascript/Config.js +++ b/smarttv-client/Javascript/Config.js @@ -74,8 +74,8 @@ Config.init = function () { } else { Config.doFirstLaunch(); -// Display.showPopup ("WARNING: Cannot create widget folder. Try Config"); - Display.showPopup (Lang[Lang.sel].configInit); + Display.showPopup ("WARNING: Cannot create widget folder. Try Config"); +// Display.showPopup (Lang[Lang.sel].configInit); // Main.logToServer("ERROR: Cannot create widget folder curWidget.id= " +curWidget.id); } @@ -92,7 +92,7 @@ Config.init = function () { Config.doFirstLaunch = function () { Config.firstLaunch = true; - Main.changeState(4); + Main.changeState(Main.eOPT); }; @@ -160,8 +160,8 @@ Config.fetchConfig = function () { }, error : function (XHR, status, error) { Main.log ("Config Server Error"); -// Display.showPopup("Config Server Error " + XHR.status + " " + status); - Display.showPopup(Lang[Lang.sel].configNoServer + " "+ XHR.status + " " + status); + Display.showPopup("Config Server Error " + XHR.status + " " + status); +// Display.showPopup(Lang[Lang.sel].configNoServer + " "+ XHR.status + " " + status); Main.logToServer("Config Server Error " + XHR.status + " " + status); @@ -208,8 +208,8 @@ Config.readContext = function () { Config.serverUrl = "http://" + Config.serverAddr; } else { -// Display.showPopup ("ERROR: Error in Config File. Try widget re-install."); - Display.showPopup (Lang[Lang.sel].configRead1); + Display.showPopup ("ERROR: Error in Config File. Try widget re-install."); +// Display.showPopup (Lang[Lang.sel].configRead1); // TODO: I should re-write the config file } @@ -227,8 +227,8 @@ Config.readContext = function () { else { Main.log("Config.readContext: Widget Folder creation failed"); -// Display.showPopup ("WARNING: ConfigRead Error and WidgetFolder creation failed.
Launching Config-Menu from here"); - Display.showPopup (Lang[Lang.sel].configRead2); + Display.showPopup ("WARNING: ConfigRead Error and WidgetFolder creation failed.
Launching Config-Menu from here"); +// Display.showPopup (Lang[Lang.sel].configRead2); // Main.log("-------------- Error: res = false ------------------------"); } diff --git a/smarttv-client/Javascript/Data.js b/smarttv-client/Javascript/Data.js index 112785e..5eee3f2 100755 --- a/smarttv-client/Javascript/Data.js +++ b/smarttv-client/Javascript/Data.js @@ -3,7 +3,8 @@ var Data = assets : new Item, folderList : [], createAccessMap : false, - directAccessMap : {} + directAccessMap : {}, + sortType : 0 }; Array.prototype.remove = function(from, to) { @@ -17,14 +18,18 @@ Data.reset = function() { this.assets = new Item; this.folderList = []; this.createAccessMap = false; - + this.sortType = 0; // this.folderList.push({item : this.assets, id: 0}); Main.log("Data.reset: folderList.push. this.folderList.length= " + this.folderList.length); }; Data.completed= function(sort) { - if (sort == true) - this.assets.sortPayload(); + if (sort == true) { + this.assets.sortPayload(Data.sortType); + if (this.createAccessMap == true) { + Main.log("ERROR: access map does not match anymore"); + } + } this.folderList.push({item : this.assets, id: 0}); Main.log("---------- completed ------------"); @@ -32,6 +37,11 @@ Data.completed= function(sort) { Main.log("Data.completed(): createAccessMap= " + ((this.createAccessMap == true) ? "true": "false")); }; +Data.nextSortType = function () { + Data.sortType = (Data.sortType +1) %3; + this.assets.sortPayload(Data.sortType); +}; + Data.selectFolder = function (idx, first_idx) { this.folderList.push({item : this.getCurrentItem().childs[idx], id: idx, first:first_idx}); Main.log("Data.selectFolder: folderList.push. this.folderList.length= " + this.folderList.length); @@ -106,7 +116,7 @@ function Item() { this.title = "root"; this.isFolder = true; this.childs = []; - this.payload = ""; // only set, if (isFolder == false) + this.payload = {}; // only set, if (isFolder == false) } Item.prototype.isFolder = function() { @@ -168,6 +178,7 @@ Item.prototype.addChild = function (key, pyld, level) { Data.directAccessMap[pyld.num].push(this.childs.length); // should start from 1 } folder.title = t; + folder.payload['start'] = 0; folder.addChild(key, pyld, level+1); this.childs.push(folder); } @@ -233,7 +244,7 @@ Item.prototype.print = function(level) { prefix += " "; for (var i = 0; i < this.childs.length; i++) { - Main.log(prefix + this.childs[i].title); + Main.log(prefix + this.childs[i].payload.start + "\t" + this.childs[i].title + " isFolder= " + this.childs[i].isFolder); if (this.childs[i].isFolder == true) { Main.log(prefix+"Childs:"); this.childs[i].print(level +1); @@ -241,6 +252,7 @@ Item.prototype.print = function(level) { } }; +/* Item.prototype.sortPayload = function() { for (var i = 0; i < this.childs.length; i++) { if (this.childs[i].isFolder == true) { @@ -256,4 +268,49 @@ Item.prototype.sortPayload = function() { } }); }; +*/ +Item.prototype.sortPayload = function(sel) { + for (var i = 0; i < this.childs.length; i++) { + if (this.childs[i].isFolder == true) { + this.childs[i].sortPayload(sel); + } + } + switch (sel) { + case 1: + // Dy Date + this.childs.sort(function(a,b) { + if (a.payload.start == b.payload.start) { + return ((a.title < b.title) ? -1 : 1); + } + else { + return (a.payload.start - b.payload.start); + } + }); + break; + case 2: + // Dy Date + this.childs.sort(function(a,b) { + if (a.payload.start == b.payload.start) { + return (a.title >= b.title); + } + else { + return (b.payload.start - a.payload.start); + } + }); + break; + case 0: + default: + this.childs.sort(function(a,b) { + if (a.title == b.title) { + return (a.payload.start - b.payload.start); + } + else { + return ((a.title < b.title) ? -1 : 1); + + } + }); + + break; + } +}; diff --git a/smarttv-client/Javascript/Display.js b/smarttv-client/Javascript/Display.js index 93a38ef..94743bd 100755 --- a/smarttv-client/Javascript/Display.js +++ b/smarttv-client/Javascript/Display.js @@ -324,6 +324,7 @@ Display.setVideoList = function(selected, first) { if ((first_item+i) <0) { // wrap around idx = (first_item+i) + Data.getVideoCount(); + res = Display.getDisplayTitle (Data.getCurrentItem().childs[(first_item+i) + Data.getVideoCount()]); } else if ((first_item+i) >= Data.getVideoCount()) { @@ -589,7 +590,7 @@ Display.getDisplayTitle = function(item) { var min = Display.getNumString (digi.getMinutes(), 2); var d_str = mon + "/" + day + " " + hour + ":" + min; - res.c1 = d_str; + res.c1 = d_str + ((item.payload.isnew == "true") ? " *" : ""); res.c2 = item.title; } break; @@ -923,27 +924,28 @@ Display.handlerHideProgress = function() { Display.handlerShowProgress = function() { $("#overlay").fadeIn(400); - + Main.log("************************ OL width= " + $("#olProgressBarBG").width()); + var bar_width = $("#olProgressBarBG").width(); if (Player.isRecording == true) { - $("#olRecProgressBar").show(); - var now = Display.GetEpochTime(); -//thlo var remaining = Math.round(((Player.startTime + Player.duration) - now) * 100/ Player.duration); - var remaining = Math.round(((Player.startTime + Player.getDuration()) - now) * 100/ Player.getDuration()); - var elm = document.getElementById("olRecProgressBar"); - elm.style.display="block"; - elm.style.width = remaining + "%"; - elm.style.left = (100 - remaining) + "%"; + if ((Player.startTime + Player.getDuration()) > now) { + // not done + $("#olRecProgressBar").show(); + var now = Display.GetEpochTime(); + var remaining_px = ((Player.startTime + Player.getDuration()) - now) * bar_width/ Player.getDuration(); + var elm = document.getElementById("olRecProgressBar"); + elm.style.display="block"; + elm.style.width = remaining_px + "px"; + elm.style.left = (bar_width - remaining_px) + "px"; + } + } else $("#olRecProgressBar").hide(); -//thlo var timePercent = (Player.curPlayTime *100)/ Player.totalTime; - var timePercent = (Player.curPlayTime *100)/ Player.getDuration(); + var time_px = (Player.curPlayTime *bar_width)/ Player.getDuration(); + document.getElementById("olProgressBar").style.width = time_px + "px"; - document.getElementById("olProgressBar").style.width = timePercent + "%"; - -//thlo $("#olTimeInfo").text(Player.curPlayTimeStr + " / " + Player.totalTimeStr); $("#olTimeInfo").text(Player.curPlayTimeStr + " / " + Player.getDurationStr()); var Digital=new Date(); diff --git a/smarttv-client/Javascript/Main.js b/smarttv-client/Javascript/Main.js index 2581074..aa33217 100755 --- a/smarttv-client/Javascript/Main.js +++ b/smarttv-client/Javascript/Main.js @@ -61,11 +61,21 @@ var Main = { menuKeyHndl : null }; +$(document).unload(function(){ + Main.onUnload (); +}); + +Main.onUnload = function() { + Server.notifyServer("stopped"); + Player.deinit(); +}; + $(document).ready(function(){ Main.onLoad (); }); Main.onLoad = function() { + window.onShow = showHandler; window.onshow = showHandler; @@ -166,7 +176,6 @@ Main.init = function () { HeartbeatHandler.start(); Server.updateVdrStatus(); -// Server.notifyServer("started"); DirectAccess.init(); Config.getWidgetVersion(); @@ -187,11 +196,11 @@ Main.init = function () { Main.logToServer (xmlDoc); } -*/ /* - * - Read widget conf. find the file to log +*/ +// Read widget conf. find the file to log +/* xhttp=new XMLHttpRequest(); - xhttp.open("GET","$MANAGER_WIDGET/Common/webapi/1.0/webapis.js",false); + xhttp.open("GET","$MANAGER_WIDGET/Common/webapi/1.0/deviceapis.js",false); xhttp.send(""); xmlDoc=xhttp.responseText; Main.logToServer (xmlDoc); @@ -220,10 +229,6 @@ Main.logToServer = function (msg) { */ }; -Main.onUnload = function() { - Server.notifyServer("stopped"); - Player.deinit(); -}; Main.testUrls = function () { Main.log("################## Main.testUrls"); @@ -318,11 +323,14 @@ Main.liveSelected = function() { }; Main.recordingsSelected = function() { + Server.retries = 0; Player.stopCallback = function() { Display.show(); - Server.saveResume (); Data.getCurrentItem().childs[Main.selectedVideo].payload.isnew = "false"; + var res = Display.getDisplayTitle (Data.getCurrentItem().childs[Main.selectedVideo]); + Display.setVideoItem(Display.videoList[Display.currentWindow +Display.FIRSTIDX], res); + Server.saveResume (); }; Server.errorCallback = Main.serverError; @@ -370,7 +378,7 @@ Main.urlsSelected = function() { Display.showPopup(msg); Main.changeState(0); }; - Server.setSort(true); + Server.setSort(false); Spinner.show(); UrlsFetcher.fetchUrlList(); }; @@ -1061,6 +1069,22 @@ cMenuKeyHndl.prototype.handleKeyDown = function (event) { } break; + + case tvKey.KEY_YELLOW: + if (Main.state == Main.eURLS) { + Buttons.ynShow(); + } + break; + case tvKey.KEY_BLUE: + if (Main.state == Main.eREC) { + //change sorting + Spinner.show(); + Data.nextSortType(); + Main.selectedVideo = 0; + Display.setVideoList(Main.selectedVideo, Main.selectedVideo); + Spinner.hide(); + } + break; case tvKey.KEY_RIGHT: Main.log("Right"); diff --git a/smarttv-client/Javascript/Player.js b/smarttv-client/Javascript/Player.js index 6708558..b6986f5 100755 --- a/smarttv-client/Javascript/Player.js +++ b/smarttv-client/Javascript/Player.js @@ -225,6 +225,7 @@ Player.init = function() { Player.deinit = function() { Main.log("Player deinit !!! " ); + Main.logToServer("Player deinit !!! " ); if (Player.AVPlayerObj != null) { Player.AVPlayerObj.stop(); diff --git a/smarttv-client/Javascript/Server.js b/smarttv-client/Javascript/Server.js index 77b8cff..fae4e83 100755 --- a/smarttv-client/Javascript/Server.js +++ b/smarttv-client/Javascript/Server.js @@ -3,7 +3,7 @@ var Server = { errorCallback : null, doSort : false, retries : 0, - + curGuid : "", XHRObj : null }; @@ -81,6 +81,79 @@ Server.fetchVideoList = function(url) { }); }; +Server.updateEntry = function(guid) { + + Server.curGuid = Data.getCurrentItem().childs[Main.selectedVideo].payload.guid; + + //url is sufficed with ?guid + var url = Config.serverUrl + "/recordings.xml?guid="+guid; + Main.logToServer(" Server.updateEntry: guid= " + guid); + + $.ajax({ + url: url, + type : "GET", + success : function(data, status, XHR ) { + Main.logToServer("Server.updateEntry Success Response - status= " + status + " mime= " + XHR.responseType + " data= "+ data); + + $(data).find("item").each(function () { + var title = $(this).find('title').text(); +// var link = $(this).find('link').text(); + var link = $(this).find('enclosure').attr('url'); + var guid = $(this).find('guid').text(); + var programme = $(this).find('programme').text(); + var description = $(this).find('description').text(); + var startVal = parseInt($(this).find('start').text()); + var durVal = parseInt($(this).find('duration').text()); + var fps = parseFloat($(this).find('fps').text()); + var ispes = $(this).find('ispes').text(); + var isnew = $(this).find('isnew').text(); + var num = parseInt($(this).find('number').text()); + Main.logToServer("Server.updateEntry: title= " + title + " start= " + startVal + " dur= " + durVal + " fps= " + fps); + + var title_list = title.split("~"); + Data.addItem( title_list, {link : link, prog: programme, desc: description, guid : guid, start: startVal, + dur: durVal, ispes : ispes, isnew : isnew, fps : fps, num : num}); + + }); // each + + Data.assets.sortPayload(Data.sortType); + + // check, whether Main.selectedVideo still points to the entry with guid + if (Data.getCurrentItem().childs[Main.selectedVideo].payload.guid != Server.curGuid) { + Main.logToServer("Server.updateEntry: curGuid has changed: curGuid= " + Server.curGuid); + Main.logToServer("Server.updateEntry: selVid= "+ Data.getCurrentItem().childs[Main.selectedVideo].payload.guid); + Main.selectedVideo = Main.selectedVideo+1; + Main.logToServer("Server.updateEntry: curGuid has changed: selVid+1"+ Data.getCurrentItem().childs[Main.selectedVideo].payload.guid); + } + + var first_item = Main.selectedVideo - Display.currentWindow; + if (first_item < 0 ) + first_item = 0; + + Display.setVideoList(Main.selectedVideo, first_item); + // Main.selectedVideo does not fit anymore!!!!! + // should do a general reset (jump to 0), when a new element is added + // should reset to zero + // plus update notif + Main.logToServer(" done"); + + }, + error : function (jqXHR, status, error) { + Main.logToServer("Server.updateEntry Error Response - status= " + status + " error= "+ error); + Display.showPopup("Error with XML File: " + status); + Server.retries ++; + }, + parsererror : function () { + Main.logToServer("Server.updateEntry parserError " ); + Display.showPopup("Error in XML File"); + Server.retries ++; + if (Server.errorCallback != null) { + Server.errorCallback("XmlError"); + } + + } + }); +}; //--------------------------------------------- @@ -181,6 +254,33 @@ Server.deleteRecording = function(guid) { }); }; +Server.deleteUrls = function (guid) { + Main.log("Server.deleteUrls"); + Main.logToServer("Server.deleteUrls guid=" + guid); + Notify.handlerShowNotify("Deleting...", false); + + $.ajax({ + url: Config.serverUrl + "/deleteYtUrl?guid=" +guid, + type : "POST", + success : function(data, status, XHR ) { + Notify.showNotify("Deleted", true); + Data.deleteElm(Main.selectedVideo); + if (Main.selectedVideo >= Data.getVideoCount()) + Main.selectedVideo = Data.getVideoCount() -1; + Server.updateVdrStatus(); + Display.setVideoList(Main.selectedVideo, (Main.selectedVideo - Display.currentWindow)); + Main.logToServer("Server.deleteUrls: Success" ); + }, + error : function (XHR, status, error) { + Main.logToServer("Server.deleteUrls: Error" ); + Notify.showNotify(status, true); + + // show popup +// Notify.showNotify("Error", true); + } + }); + +}; Server.notifyServer = function (state) { Main.log("Server.notifyServer state="+state +"&mac=" + Network.ownMac + "&ip=" + Network.ownIp); -- cgit v1.2.3