3 var loadedChannellist = {};
6 var signalPanelData = {};
8 var mediaPlayerStarted = false;
9 var popUpBlockerHinted = false;
12 var parentControlList = null;
14 var requestcounter = 0;
18 var webRemoteWin = '';
21 var currentBouquet = bouquetsTv;
23 var updateBouquetItemsPoller = '';
24 var updateCurrentPoller = '';
25 var signalPanelUpdatePoller = '';
27 var hideNotifierTimeout = '';
30 isActive.getCurrent = false;
32 var currentLocation = "/hdd/movie";
33 var locationsList = [];
38 function startUpdateCurrentPoller(){
39 clearInterval(updateCurrentPoller);
40 updateCurrentPoller = setInterval(updateItems, userprefs.data.updateCurrentInterval);
43 function stopUpdateCurrentPoller(){
44 clearInterval(updateCurrentPoller);
47 function getXML(request){
50 if(window.ActiveXObject){ // we're on IE
51 xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
53 xmlDoc.loadXML(request.responseText);
54 } else { //we're not on IE
55 if (!window.google || !google.gears){
56 xmlDoc = request.responseXML;
57 } else { //no responseXML on gears
58 xmlDoc = (new DOMParser()).parseFromString(request.responseText, "text/xml");
65 * Set boxtype Variable for being able of determining model specific stuff correctly (like WebRemote)
67 function incomingDeviceInfoBoxtype(request){
68 debug("[incomingAboutBoxtype] returned");
69 boxtype = getXML(request).getElementsByTagName("e2devicename").item(0).firstChild.data;
71 debug("[incomingAboutBoxtype] Boxtype: " + boxtype);
75 function getBoxtype(){
76 doRequest(URL.deviceinfo, incomingDeviceInfoBoxtype, false);
79 function toggleStandby(){
83 function incomingPowerState(request){
84 var standby = getXML(request).getElementsByTagName("e2instandby").item(0).firstChild.data;
86 var signal = $('openSignalPanel');
87 var signalImg = $('openSignalPanelImg');
89 if(standby.strip() == "false"){
90 signal.stopObserving('click', openSignalPanel);
91 signal.observe('click', openSignalPanel);
93 signalImg.src = "/web-data/img/signal.png";
94 signalImg.title = "Show Signal Panel";
97 signal.stopObserving('click', openSignalPanel);
99 signalImg.src = "/web-data/img/signal_off.png";
100 signalImg.title = "Please disable standby first";
104 function getPowerState(){
105 doRequest(URL.powerstate, incomingPowerState);
108 function set(element, value){
109 element = parent.$(element);
111 element.innerHTML = value;
115 function hideNotifier(){
116 $('notification').fade({duration : 0.5 });
119 function notify(text, state){
120 notif = $('notification');
123 //clear possibly existing hideNotifier timeout of a previous notfication
124 clearTimeout(hideNotifierTimeout);
126 notif.style.background = "#C00";
128 notif.style.background = "#85C247";
131 set('notification', "<div>"+text+"</div>");
132 notif.appear({duration : 0.5, to: 0.9 });
133 hideNotifierTimeout = setTimeout(hideNotifier, 10000);
138 function simpleResultHandler(simpleResult){
139 notify(simpleResult.statetext, simpleResult.state);
143 function startUpdateBouquetItemsPoller(){
144 debug("[startUpdateBouquetItemsPoller] called");
145 clearInterval(updateBouquetItemsPoller);
146 updateBouquetItemsPoller = setInterval(updateItemsLazy, userprefs.data.updateBouquetInterval);
150 function stopUpdateBouquetItemsPoller(){
151 debug("[stopUpdateBouquetItemsPoller] called");
152 clearInterval(updateBouquetItemsPoller);
157 function parseNr(num) {
166 function dec2hex(nr, len){
168 var hex = parseInt(nr, 10).toString(16).toUpperCase();
171 while(hex.length < len){
176 //something went wrong, return -1
184 function quotes2html(txt) {
185 if(typeof(txt) != "undefined"){
186 return txt.escapeHTML().replace('\n', '<br>');
192 function addLeadingZero(nr){
199 function dateToString(date){
203 dateString += date.getFullYear();
204 dateString += "-" + addLeadingZero(date.getMonth()+1);
205 dateString += "-" + addLeadingZero(date.getDate());
206 dateString += " " + addLeadingZero(date.getHours());
207 dateString += ":" + addLeadingZero(date.getMinutes());
213 function showhide(id){
215 s.display = (s.display!="none")? "none":"";
221 $(id).style.display = "";
223 debug("[show] Could not show element with id: " + id);
230 $(id).style.display = "none";
232 debug("[hide] Could not hide element with id: " + id);
238 * Sets the Loading Notification to the given HTML Element
239 * @param targetElement - The element the Ajax-Loader should be set in
241 function setAjaxLoad(targetElement){
242 $(targetElement).innerHTML = getAjaxLoad();
246 //Ajax Request Helpers
249 function requestIndicatorUpdate(){
250 /*debug(requestcounter+" open requests");
251 if(requestcounter>=1){
252 $('RequestIndicator').style.display = "inline";
254 $('RequestIndicator').style.display = "none";
258 function requestStarted(){
260 requestIndicatorUpdate();
263 function requestFinished(){
265 requestIndicatorUpdate();
268 //Popup And Messagebox Helpers
269 function messageBox(m){
274 function popUpBlockerHint(){
275 if(!popUpBlockerHinted){
276 popUpBlockerHinted = true;
277 messageBox("Please disable your Popup-Blocker for enigma2 WebControl to work flawlessly!");
282 function setWindowContent(window, html){
283 window.document.write(html);
284 window.document.close();
287 function openPopup(title, html, width, height, x, y){
289 var popup = window.open('about:blank',title,'scrollbars=yes, width='+width+',height='+height);
290 setWindowContent(popup, html);
298 function openPopupPage(title, uri, width, height, x, y){
300 var popup = window.open(uri,title,'scrollbars=yes, width='+width+',height='+height);
308 function debug(text){
309 var DBG = userprefs.data.debug || false;
313 if(!debugWin.closed && debugWin.location){
314 var inner = debugWin.document.getElementById('debugContent').innerHTML;
315 debugWin.document.getElementById('debugContent').innerHTML = new Date().toLocaleString() + ": "+text+"<br>" + inner;
319 setTimeout( function(){
320 var inner = debugWin.document.getElementById('debugContent').innerHTML;
321 debugWin.document.getElementById('debugContent').innerHTML = new Date().toLocaleString() + ": "+text+"<br>" + inner;
326 } catch (Exception) {}
330 function saveSettings(){
333 var debug = $('enableDebug').checked;
335 if(typeof(debug) != "undefined"){
336 if( userprefs.data.debug != debug ){
337 userprefs.data.debug = debug;
346 var updateCurrentInterval = parseNr( $F('updateCurrentInterval') ) * 1000;
347 if( updateCurrentInterval < 10000){
348 updateCurrentInterval = 120000;
351 if( userprefs.data.updateCurrentInterval != updateCurrentInterval){
352 userprefs.data.updateCurrentInterval = updateCurrentInterval;
355 startUpdateCurrentPoller();
358 var updateBouquetInterval = parseNr( $F('updateBouquetInterval') ) * 1000;
359 if( updateBouquetInterval < 60000){
360 updateBouquetInterval = 300000;
363 if( userprefs.data.updateBouquetInterval != updateBouquetInterval){
364 userprefs.data.updateBouquetInterval = updateBouquetInterval;
367 startUpdateBouquetItemsPoller();
376 function saveTpl(request, tplName){
377 debug("[saveTpl] saving template: " + tplName);
378 templates[tplName] = request.responseText;
382 function renderTpl(tpl, data, domElement) {
383 var result = tpl.process(data);
386 $(domElement).innerHTML = result;
388 // debug("[renderTpl] exception: " + ex);
393 function fetchTpl(tplName, callback){
394 if(typeof(templates[tplName]) == "undefined") {
395 var url = URL.tpl+tplName+".htm";
400 saveTpl(transport, tplName);
401 if(typeof(callback) == 'function'){
407 if(typeof(callback) == 'function'){
413 function incomingProcessTpl(request, data, domElement, callback){
414 if(request.readyState == 4){
415 renderTpl(request.responseText, data, domElement);
416 if(typeof(callback) == 'function') {
422 function processTpl(tplName, data, domElement, callback){
423 var url = URL.tpl+tplName+".htm";
427 incomingProcessTpl(transport, data, domElement, callback);
435 function openDebug(){
436 var uri = URL.tpl+'tplDebug.htm';
437 debugWin = openPopupPage("Debug", uri, 500, 300);
440 function requestFailed(transport){
441 var notifText = "Request failed for: " + transport.request.url + "<br>Status: " + transport.status + " " + transport.statusText;
442 notify(notifText, false);
445 function doRequest(url, readyFunction){
448 // gears or not that's the question here
449 if (!window.google || !google.gears){ //no gears, how sad
450 // debug("NO GEARS!!");
452 request = new Ajax.Request(url,
456 requestHeaders: ['Cache-Control', 'no-cache,no-store', 'Expires', '-1'],
457 onException: function(o,e){ throw(e); },
458 onSuccess: function (transport, json) {
459 if(typeof(readyFunction) != "undefined"){
460 readyFunction(transport);
463 onFailure: function(transport){
464 requestFailed(transport);
466 onComplete: requestFinished
469 } else { //we're on gears!
471 request = google.gears.factory.create('beta.httprequest');
472 request.open('GET', url);
475 request.onreadystatechange = function(){
476 if(request.readyState == 4){
477 if(request.status == 200){
478 if( typeof(readyFunction) != "undefined" ){
479 readyFunction(request);
482 requestFailed(transport);
492 function incomingParentControl(request) {
493 if(request.readyState == 4){
494 parentControlList = new ServiceList(getXML(request)).getArray();
495 debug("[incomingParentControl] Got "+parentControlList.length + " services");
499 function getParentControl() {
500 doRequest(URL.parentcontrol, incomingParentControl, false);
504 function getParentControlByRef(txt) {
505 debug("[getParentControlByRef] ("+txt+")");
506 for(var i = 0; i < parentControlList.length; i++) {
507 debug( "[getParentControlByRef] "+parentControlList[i].getClearServiceReference() );
508 if(String(parentControlList[i].getClearServiceReference()) == String(txt)) {
509 return parentControlList[i].getClearServiceReference();
517 function getSettingByName(txt) {
518 debug("[getSettingByName] (" + txt + ")");
519 for(var i = 0; i < settings.length; i++) {
520 debug("("+settings[i].getSettingName()+") (" +settings[i].getSettingValue()+")");
521 if(String(settings[i].getSettingName()) == String(txt)) {
522 return settings[i].getSettingValue().toLowerCase();
528 function parentPin(servicereference) {
529 debug("[parentPin] parentControlList");
530 servicereference = decodeURIComponent(servicereference);
531 if(parentControlList === null || String(getSettingByName("config.ParentalControl.configured")) != "true") {
534 //debug("parentPin " + parentControlList.length);
535 if(getParentControlByRef(servicereference) == servicereference) {
536 if(String(getSettingByName("config.ParentalControl.type.value")) == "whitelist") {
537 debug("[parentPin] Channel in whitelist");
541 debug("[parentPin] sRef differs ");
544 debug("[parentPin] Asking for PIN");
546 var userInput = prompt('Parental Control is enabled!<br> Please enter the Parental Control PIN','PIN');
547 if (userInput !== '' && userInput !== null) {
548 if(String(userInput) == String(getSettingByName("config.ParentalControl.servicepin.0")) ) {
551 return parentPin(servicereference);
559 function incomingGetDreamboxSettings(request){
560 if(request.readyState == 4){
561 settings = new Settings(getXML(request)).getArray();
563 debug("[incomingGetDreamboxSettings] config.ParentalControl.configured="+ getSettingByName("config.ParentalControl.configured"));
565 if(String(getSettingByName("config.ParentalControl.configured")) == "true") {
572 function getDreamboxSettings(){
573 doRequest(URL.settings, incomingGetDreamboxSettings, false);
578 function incomingSubServiceRequest(request){
579 if(request.readyState == 4){
580 var services = new ServiceList(getXML(request)).getArray();
581 debug("[incomingSubServiceRequest] Got " + services.length + " SubServices");
583 if(services.length > 1) {
585 var first = services[0];
587 // we already have the main service in our servicelist so we'll
588 // start with the second element
591 var data = { subservices : services };
594 var id = 'SUB'+first.servicereference;
596 processTpl('tplSubServices', data, id);
602 function getSubServices(bouquet) {
603 doRequest(URL.subservices, incomingSubServiceRequest, false);
607 function delayedGetSubservices(){
608 setTimeout(getSubServices, 5000);
612 function zap(servicereference){
613 doRequest("/web/zap?sRef=" + servicereference);
614 setTimeout(updateItemsLazy, 7000); //reload epg and subservices
615 setTimeout(updateItems, 3000);
620 function updateSignalPanel(){
621 var html = templates.tplSignalPanel.process(signalPanelData);
623 if (!signalWin.closed && signalWin.location) {
624 setWindowContent(signalWin, html);
626 clearInterval(signalPanelUpdatePoller);
627 signalPanelUpdatePoller = '';
631 function incomingSignalPanel(request){
634 if (request.readyState == 4){
635 var xml = getXML(request).getElementsByTagName("e2frontendstatus").item(0);
637 snrdb : xml.getElementsByTagName('e2snrdb').item(0).firstChild.data,
638 snr : xml.getElementsByTagName('e2snr').item(0).firstChild.data,
639 ber : xml.getElementsByTagName('e2ber').item(0).firstChild.data,
640 acg : xml.getElementsByTagName('e2acg').item(0).firstChild.data
644 signalPanelData = { signal : namespace };
645 fetchTpl('tplSignalPanel', updateSignalPanel);
648 function reloadSignalPanel(){
649 doRequest(URL.signal, incomingSignalPanel, false);
652 function openSignalPanel(){
653 if (!(!signalWin.closed && signalWin.location)){
654 signalWin = openPopup('SignalPanel', '', 220, 120);
655 if(signalPanelUpdatePoller === ''){
656 signalPanelUpdatePoller = setInterval(reloadSignalPanel, 5000);
665 function showEpgList(){
666 var html = templates.tplEpgList.process(epgListData);
668 if (!EPGListWin.closed && EPGListWin.location) {
669 setWindowContent(EPGListWin, html);
671 EPGListWin = openPopup("EPG", html, 900, 500);
675 function incomingEPGrequest(request){
676 debug("[incomingEPGrequest] readyState" +request.readyState);
677 if (request.readyState == 4){
678 var EPGItems = new EPGList(getXML(request)).getArray(true);
679 debug("[incomingEPGrequest] got "+EPGItems.length+" e2events");
681 if( EPGItems.length > 0){
682 epgListData = {epg : EPGItems};
683 fetchTpl('tplEpgList', showEpgList);
685 messageBox('No Items found!', 'Sorry but I could not find any EPG Content containing your search value');
690 function loadEPGBySearchString(string){
691 doRequest(URL.epgsearch+escape(string),incomingEPGrequest, false);
694 function loadEPGByServiceReference(servicereference){
695 doRequest(URL.epgservice+servicereference,incomingEPGrequest, false);
698 function buildServiceListEPGItem(epgevent, type){
699 var data = { epg : epgevent,
702 // e.innerHTML = RND(tplServiceListEPGItem, namespace);
704 var id = type + epgevent.servicereference;
708 if(typeof(templates.tplServiceListEPGItem) != "undefined"){
709 renderTpl(templates.tplServiceListEPGItem, data, id, true);
711 debug("[buildServiceListEPGItem] tplServiceListEPGItem N/A");
715 function incomingServiceEPGNowNext(request, type){
716 if(request.readyState == 4){
717 var epgevents = getXML(request).getElementsByTagName("e2eventlist").item(0).getElementsByTagName("e2event");
718 for (var c = 0; c < epgevents.length; c++){
720 var epgEvt = new EPGEvent(epgevents.item(c), c).toJSON();
722 debug("[incomingServiceEPGNowNext]" + e);
725 if (epgEvt.eventid != ''){
726 buildServiceListEPGItem(epgEvt, type);
732 function incomingServiceEPGNow(request){
733 incomingServiceEPGNowNext(request, 'NOW');
736 function incomingServiceEPGNext(request){
737 incomingServiceEPGNowNext(request, 'NEXT');
740 function loadServiceEPGNowNext(servicereference, next){
741 var url = URL.epgnow+servicereference;
743 if(typeof(next) == 'undefined'){
744 doRequest(url, incomingServiceEPGNow, false);
746 url = URL.epgnext+servicereference;
747 doRequest(url, incomingServiceEPGNext, false);
752 function getBouquetEpg(){
753 loadServiceEPGNowNext(currentBouquet);
754 loadServiceEPGNowNext(currentBouquet, true);
758 function recordNowPopup(){
759 var result = confirm(
760 "OK: Record current event\n" +
761 "Cancel: Start infinite recording"
764 if( result === true || result === false){
765 recordNowDecision(result);
770 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
771 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
772 //++++ volume functions ++++
773 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
774 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
775 function handleVolumeRequest(request){
776 if (request.readyState == 4) {
777 var b = getXML(request).getElementsByTagName("e2volume");
778 var newvalue = b.item(0).getElementsByTagName('e2current').item(0).firstChild.data;
779 var mute = b.item(0).getElementsByTagName('e2ismuted').item(0).firstChild.data;
780 debug("[handleVolumeRequest] Volume " + newvalue + " | Mute: " + mute);
782 for (var i = 1; i <= 10; i++) {
783 if ( (newvalue/10)>=i){
784 $("volume"+i).src = "/web-data/img/led_on.png";
786 $("volume"+i).src = "/web-data/img/led_off.png";
789 if (mute == "False"){
790 $("speaker").src = "/web-data/img/speak_on.png";
792 $("speaker").src = "/web-data/img/speak_off.png";
798 function getVolume(){
799 doRequest(URL.getvolume, handleVolumeRequest, false);
802 function volumeSet(val){
803 doRequest(URL.setvolume+val, handleVolumeRequest, false);
807 doRequest(URL.volumeup, handleVolumeRequest, false);
810 function volumeDown(){
811 doRequest(URL.volumedown, handleVolumeRequest, false);
814 function volumeMute(){
815 doRequest(URL.volumemute, handleVolumeRequest, false);
818 function initVolumePanel(){
824 //Channels and Bouquets
826 function incomingChannellist(request){
827 var serviceList = null;
828 if(typeof(loadedChannellist[currentBouquet]) != "undefined"){
829 serviceList = loadedChannellist[currentBouquet];
830 } else if(request.readyState == 4) {
831 serviceList = new ServiceList(getXML(request)).getArray();
832 debug("[incomingChannellist] got "+serviceList.length+" Services");
834 if(serviceList !== null) {
835 var data = { services : serviceList };
837 processTpl('tplServiceList', data, 'contentServices', getBouquetEpg);
838 delayedGetSubservices();
840 debug("[incomingChannellist] services is null");
845 function loadBouquet(servicereference, name){
846 debug("[loadBouquet] called");
848 currentBouquet = servicereference;
851 setAjaxLoad('contentServices');
853 startUpdateBouquetItemsPoller();
854 doRequest(URL.getservices+servicereference, incomingChannellist, true);
859 function incomingBouquetListInitial(request){
860 if (request.readyState == 4) {
861 var bouquetList = new ServiceList(getXML(request)).getArray();
862 debug("[incomingBouquetListInitial] Got " + bouquetList.length + " TV Bouquets!");
864 // loading first entry of TV Favorites as default for ServiceList
868 loadBouquet(bouquetList[0].servicereference, bouquetList[0].servicename);;
875 function incomingBouquetList(request, callback){
876 if (request.readyState == 4) {
877 var bouquetList = new ServiceList(getXML(request)).getArray();
878 debug("[incomingBouquetList] got " + bouquetList.length + " TV Bouquets!");
879 var data = { bouquets : bouquetList };
881 if( $('contentBouquets') != "undefined" && $('contentBouquets') != null ){
882 processTpl('tplBouquetList', data, 'contentBouquets');
883 if(typeof(callback) == 'function')
887 'tplBouquetsAndServices',
891 processTpl('tplBouquetList', data, 'contentBouquets');
892 if(typeof(callback) == 'function')
901 function initChannelList(){
902 var url = URL.getservices+encodeURIComponent(bouquetsTv);
903 currentBouquet = bouquetsTv;
905 doRequest(url, incomingBouquetListInitial, true);
911 function initMovieList(){
912 // get videodirs, last_videodir, and all tags
913 doRequest(URL.getcurrlocation, incomingMovieListCurrentLocation, false);
916 function incomingMovieListCurrentLocation(request){
917 if(request.readyState == 4){
918 result = new SimpleXMLList(getXML(request), "e2location");
919 currentLocation = result.getList()[0];
920 debug("[incomingMovieListCurrentLocation].currentLocation" + currentLocation);
921 doRequest(URL.getlocations, incomingMovieListLocations, false);
925 function incomingMovieListLocations(request){
926 if(request.readyState == 4){
927 result = new SimpleXMLList(getXML(request), "e2location");
928 locationsList = result.getList();
930 if (locationsList.length === 0) {
931 locationsList = ["/hdd/movie"];
933 doRequest(URL.gettags, incomingMovieListTags, false);
937 function incomingMovieListTags(request){
938 if(request.readyState == 4){
939 result = new SimpleXMLList(getXML(request), "e2tag");
940 tagsList = result.getList();
944 function createOptionListSimple(lst, selected) {
945 var namespace = Array();
949 for (i = 0; i < lst.length; i++) {
950 if (lst[i] == selected) {
956 lst = [ selected ].concat(lst);
959 for (i = 0; i < lst.length; i++) {
963 'selected': (lst[i] == selected ? "selected" : " ")};
969 function loadMovieNav(){
972 dirname: createOptionListSimple(locationsList, currentLocation),
973 tags: createOptionListSimple(tagsList, "")
976 processTpl('tplNavMovies', data, 'navContent');
979 function incomingMovieList(request){
980 if(request.readyState == 4){
982 var movieList = new MovieList(getXML(request)).getArray();
983 debug("[incomingMovieList] Got "+movieList.length+" movies");
985 var data = { movies : movieList };
986 processTpl('tplMovieList', data, 'contentMain');
990 function loadMovieList(loc, tag){
991 if(typeof(loc) == 'undefined'){
992 loc = currentLocation;
994 if(typeof(tag) == 'undefined'){
997 debug("[loadMovieList] Loading movies in location '"+loc+"' with tag '"+tag+"'");
998 doRequest(URL.movielist+"?dirname="+loc+"&tag="+tag, incomingMovieList, false);
1002 function incomingDelMovieResult(request) {
1003 debug("[incomingDelMovieResult] called");
1004 if(request.readyState == 4){
1005 var result = new SimpleXMLResult(getXML(request));
1006 if(result.getState()){
1009 simpleResultHandler(result);
1014 function delMovie(sref ,servicename, title, description) {
1015 debug("[delMovie] File(" + unescape(sref) + "), servicename(" + servicename + ")," +
1016 "title(" + unescape(title) + "), description(" + description + ")");
1018 result = confirm( "Are you sure want to delete the Movie?\n" +
1019 "Servicename: " + servicename + "\n" +
1020 "Title: " + unescape(title) + "\n" +
1021 "Description: " + description + "\n");
1024 debug("[delMovie] ok confirm panel");
1025 doRequest(URL.moviedelete+"?sRef="+unescape(sref), incomingDelMovieResult, false);
1029 debug("[delMovie] cancel confirm panel");
1034 //Send Messages and Receive the Answer
1037 function incomingMessageResult(request){
1038 if(request.readyState== 4){
1039 var result = new SimpleXMLResult(getXML(request));
1040 simpleResultHandler(result);
1044 function getMessageAnswer() {
1045 doRequest(URL.messageanswer, incomingMessageResult, false);
1048 function sendMessage(messagetext, messagetype, messagetimeout){
1050 messagetext = $('MessageSendFormText').value;
1052 if(!messagetimeout){
1053 messagetimeout = $('MessageSendFormTimeout').value;
1056 var index = $('MessageSendFormType').selectedIndex;
1057 messagetype = $('MessageSendFormType').options[index].value;
1059 if(parseNr(messagetype) === 0){
1060 doRequest(URL.message+'?text='+messagetext+'&type='+messagetype+'&timeout='+messagetimeout);
1061 setTimeout(getMessageAnswer, parseNr(messagetimeout)*1000);
1063 doRequest(URL.message+'?text='+messagetext+'&type='+messagetype+'&timeout='+messagetimeout, incomingMessageResult, false);
1069 function getScreenShot(what) {
1070 debug("[getScreenShot] called");
1072 var buffer = new Image();
1076 buffer.onload = function () {
1077 debug("[getScreenShot] image assigned");
1079 data = { img : { src : buffer.src } };
1080 processTpl('tplGrab', data, 'contentMain');
1085 buffer.onerror = function (meldung) {
1086 debug("[getScreenShot] Loading image failed");
1102 downloadStart = new Date().getTime();
1103 buffer.src = '/grab?format=jpg&r=720&' + what + '&filename=/tmp/' + downloadStart;
1106 function getVideoShot() {
1110 function getOsdShot(){
1114 //RemoteControl Code
1116 function incomingRemoteControlResult(request){
1117 // if(request.readyState == 4){
1118 // var b = getXML(request).getElementsByTagName("e2remotecontrol");
1119 // var result = b.item(0).getElementsByTagName('e2result').item(0).firstChild.data;
1120 // var resulttext = b.item(0).getElementsByTagName('e2resulttext').item(0).firstChild.data;
1124 function openWebRemote(){
1125 var template = templates.tplWebRemoteOld;
1127 if(boxtype == "dm8000"){
1128 template = templates.tplWebRemote;
1132 if (!webRemoteWin.closed && webRemoteWin.location) {
1133 setWindowContent(webRemoteWin, template);
1135 webRemoteWin = openPopup('WebRemote', template, 250, 600);
1141 function loadAndOpenWebRemote(){
1142 if(boxtype == "dm8000"){
1143 fetchTpl('tplWebRemote', openWebRemote);
1146 fetchTpl('tplWebRemoteOld', openWebRemote);
1151 function sendRemoteControlRequest(command){
1152 doRequest(URL.remotecontrol+'?command='+command, incomingRemoteControlResult, false);
1153 if(webRemoteWin.document.getElementById('getScreen').checked) {
1154 if(webRemoteWin.document.getElementById('getVideo').checked){
1163 // Array.insert( index, value ) - Insert value at index, without overwriting existing keys
1164 Array.prototype.insert = function( j, v ) {
1166 var a = this.slice(), b = a.splice( j );
1168 return a.concat( b );
1172 //Array.splice() - Remove or replace several elements and return any deleted
1174 if( typeof Array.prototype.splice==='undefined' ) {
1175 Array.prototype.splice = function( a, c ) {
1176 var e = arguments, d = this.copy(), f = a, l = this.length;
1182 for( var i = 0; i < e.length - 2; i++ ) {
1183 this[a + i] = e[i + 2];
1187 for( var j = a; j < l - c; j++ ) {
1188 this[j + e.length - 2] = d[j - c];
1190 this.length -= c - e.length + 2;
1192 return d.slice( f, f + c );
1196 function ifChecked(rObj) {
1206 * Handles an incoming request for /web/deviceinfo Parses the Data, and calls
1207 * everything needed to render the Template using the parsed data and set the
1208 * result into contentMain @param request - the XHR
1210 function incomingDeviceInfo(request) {
1211 if(request.readyState == 4){
1212 debug("[incomingDeviceInfo] called");
1213 var deviceInfo = new DeviceInfo(getXML(request));
1215 processTpl('tplDeviceInfo', deviceInfo, 'contentMain');
1221 * Show Device Info Information in contentMain
1223 function showDeviceInfo() {
1224 doRequest(URL.deviceinfo, incomingDeviceInfo, false);
1227 function showGears(){
1228 var enabled = false;
1230 if (window.google && google.gears){
1231 enabled = gearsEnabled();
1234 data = { 'useGears' : enabled };
1235 processTpl('tplGears', data, 'contentMain');
1238 function showSettings(){
1239 var debug = userprefs.data.debug;
1240 var debugChecked = "";
1242 debugChecked = 'checked';
1245 var updateCurrentInterval = userprefs.data.updateCurrentInterval / 1000;
1246 var updateBouquetInterval = userprefs.data.updateBouquetInterval / 1000;
1249 data = {'debug' : debugChecked,
1250 'updateCurrentInterval' : updateCurrentInterval,
1251 'updateBouquetInterval' : updateBouquetInterval
1253 processTpl('tplSettings', data, 'contentMain');
1257 // Spezial functions, mostly for testing purpose
1258 function openHiddenFunctions(){
1259 openPopup("Extra Hidden Functions",tplExtraHiddenFunctions,300,100,920,0);
1263 function startDebugWindow() {
1265 debugWin = openPopup("DEBUG", "", 300, 300,920,140, "debugWindow");
1269 function restartTwisted() {
1270 doRequest( "/web/restarttwisted" );
1275 function sendMediaPlayer(command) {
1276 debug("[sendMediaPlayer] called");
1277 doRequest( URL.mediaplayercmd+command );
1281 function incomingMediaPlayer(request){
1282 if(request.readyState == 4){
1283 var files = new FileList(getXML(request)).getArray();
1285 debug("[loadMediaPlayer] Got "+files.length+" entries in mediaplayer filelist");
1286 // listerHtml = tplMediaPlayerHeader;
1290 var root = files[0].getRoot();
1291 if (root != "playlist") {
1292 namespace = {'root': root};
1294 var re = new RegExp(/(.*)\/(.*)\/$/);
1296 var newroot = RegExp.$1+'/';
1297 if(newroot == '//') {
1302 'servicereference': newroot,
1303 'exec': 'loadMediaPlayer',
1304 'exec_description': 'Change to directory ../',
1312 var itemnamespace = Array();
1313 for ( var i = 0; i <files.length; i++){
1314 var file = files[i];
1315 if(file.getNameOnly() == '') {
1318 var exec = 'loadMediaPlayer';
1319 var exec_description = 'Change to directory' + file.getServiceReference();
1320 var color = '000000';
1323 if (file.getIsDirectory() == "False") {
1325 exec_description = 'play file';
1330 itemnamespace[i] = {
1332 'servicereference': file.getServiceReference(),
1334 'exec_description': exec_description,
1336 'root': file.getRoot(),
1337 'name': file.getNameOnly()
1342 if (root == "playlist") {
1343 listerHtml += tplMediaPlayerFooterPlaylist;
1347 var data = { mp : namespace,
1348 items: itemnamespace
1351 processTpl('tplMediaPlayer', data, 'contentMain');
1352 var sendMediaPlayerTMP = sendMediaPlayer;
1353 sendMediaPlayer = false;
1354 // setBodyMainContent('BodyContent');
1355 sendMediaPlayer = sendMediaPlayerTMP;
1360 function loadMediaPlayer(directory){
1361 debug("[loadMediaPlayer] called");
1362 if(typeof(directory) == 'undefined') directory = 'Filesystems';
1363 doRequest(URL.mediaplayerlist+directory, incomingMediaPlayer, false);
1367 function playFile(file,root) {
1368 debug("[playFile] called");
1369 mediaPlayerStarted = true;
1370 doRequest( URL.mediaplayerplay+file+"&root="+root );
1374 function deleteFile(sref) {
1375 debug("[deleteFile] called");
1376 mediaPlayerStarted = true;
1377 doRequest( URL.mediaplayerremove+sref );
1381 function openMediaPlayerPlaylist() {
1382 debug("[openMediaPlayerPlaylist] called");
1383 doRequest(URL.mediaplayerlist+"playlist", incomingMediaPlayer, false);
1387 function writePlaylist() {
1388 debug("[writePlaylist] called");
1390 filename = prompt("Please enter a name for the playlist", "");
1392 if(filename !== "") {
1393 doRequest( URL.mediaplayerwrite+filename );
1399 * Sets the Powerstate @param newState - the new Powerstate Possible Values
1400 * (also see WebComponents/Sources/PowerState.py) #-1: get current state # 0:
1401 * toggle standby # 1: poweroff/deepstandby # 2: rebootdreambox # 3:
1404 function sendPowerState(newState){
1405 doRequest( URL.powerstate+'?newstate='+newState, incomingPowerState);
1409 //Currently Running Service
1410 function incomingCurrent(request){
1411 // debug("[incomingCurrent called]");
1412 if(request.readyState == 4){
1414 var epg = new EPGList(getXML(request)).getArray();
1417 var data = { current : epg };
1419 if(typeof(templates.tplCurrent) != "undefined"){
1420 var display = 'none';
1422 var display = $('trExtCurrent').style.display;
1425 renderTpl(templates.tplCurrent, data, "currentContent");
1426 $('trExtCurrent').style.display = display;
1428 debug("[incomingCurrent] tplCurrent N/A");
1433 isActive.getCurrent = false;
1438 function getCurrent(){
1439 if(!isActive.getCurrent){
1440 isActive.getCurrent = true;
1441 doRequest(URL.getcurrent, incomingCurrent, false);
1446 //Navigation and Content Helper Functions
1449 * Loads all Bouquets for the given enigma2 servicereference and sets the
1450 * according contentHeader @param sRef - the Servicereference for the bouquet to
1453 function getBouquets(sRef){
1454 var url = URL.getservices+encodeURIComponent(sRef);
1456 doRequest(url, incomingBouquetList, true);
1460 * Loads another navigation template and sets the navigation header
1461 * @param template - The name of the template
1462 * @param title - The title to set for the navigation
1464 function reloadNav(template, title){
1465 setAjaxLoad('navContent');
1466 processTpl(template, null, 'navContent');
1470 function reloadNavDynamic(fnc, title){
1471 setAjaxLoad('navContent');
1476 function getBouquetsTv(){
1477 getBouquets(bouquetsTv);
1480 function getProviderTv(){
1481 getBouquets(providerTv);
1484 function getSatellitesTv(){
1485 getBouquets(satellitesTv);
1488 function getAllTv(){
1489 loadBouquet(allTv, "All (TV)");
1493 function getBouquetsRadio(){
1494 getBouquets(bouquetsRadio);
1497 function getProviderRadio(){
1498 getBouquets(providerRadio);
1501 function getSatellitesRadio(){
1502 getBouquets(satellitesRadio);
1505 function getAllRadio(){
1506 loadBouquet(allRadio, "All (Radio)");
1510 * Loads dynamic content to $(contentMain) by calling a execution function
1511 * @param fnc - The function used to load the content
1512 * @param title - The Title to set on the contentpanel
1514 function loadContentDynamic(fnc, title, domid){
1515 if(typeof(domid) != "undefined" && $(domid) != null){
1518 setAjaxLoad('contentMain');
1520 setContentHd(title);
1521 stopUpdateBouquetItemsPoller();
1527 * like loadContentDynamic but without the AjaxLoaderAnimation being shown
1529 function reloadContentDynamic(fnc, title){
1530 setContentHd(title);
1535 * Loads a static template to $(contentMain)
1536 * @param template - Name of the Template
1537 * @param title - The Title to set on the Content-Panel
1539 function loadContentStatic(template, title){
1540 setAjaxLoad('contentMain');
1541 setContentHd(title);
1542 stopUpdateBouquetItemsPoller();
1543 processTpl(template, null, 'contentMain');
1548 * Opens the given Control
1549 * @param control - Control Page as String
1550 * Possible Values: power, extras, message, screenshot, videoshot, osdshot
1552 function loadControl(control){
1555 loadContentStatic('tplPower', 'PowerControl');
1559 loadContentStatic('tplSendMessage', 'Send a Message');
1563 loadAndOpenWebRemote();
1567 loadContentDynamic(getScreenShot, 'Screenshot');
1571 loadContentDynamic(getVideoShot, 'Videoshot');
1575 loadContentDynamic(getOsdShot, 'OSDshot');
1584 function loadDeviceInfo(){
1585 loadContentDynamic(showDeviceInfo, 'Device Information');
1588 function loadAbout(){
1589 loadContentStatic('tplAbout', 'About');
1592 function loadSettings(){
1593 loadContentDynamic(showSettings, 'Settings');
1596 function loadGearsInfo(){
1597 loadContentDynamic(showGears, 'Google Gears');
1600 function reloadGearsInfo(){
1601 loadContentDynamic(showGears, 'Google Gears');
1606 * Switches Navigation Modes
1607 * @param mode - The Navigation Mode you want to switch to
1608 * Possible Values: TV, Radio, Movies, Timer, Extras
1610 function switchMode(mode){
1613 reloadNav('tplNavTv', 'TeleVision');
1617 reloadNav('tplNavRadio', 'Radio');
1622 reloadNavDynamic(loadMovieNav, 'Movies');
1625 loadContentDynamic(loadMovieList, 'Movies');
1630 reloadNav('tplNavTimer', 'Timer');
1633 loadContentDynamic(loadTimerList, 'Timer');
1637 loadContentDynamic(loadMediaPlayer, 'MediaPlayer');
1641 reloadNav('tplNavBoxControl', 'BoxControl');
1645 reloadNav('tplNavExtras', 'Extras');
1653 function openWebTV(){
1654 window.open('/web-data/streaminterface.html', 'WebTV', 'scrollbars=no, width=800, height=730');
1659 function updateItems(){
1664 function updateItemsLazy(bouquet){
1670 * Does the everything required on initial pageload
1674 var DBG = userprefs.data.debug || false;
1680 if( parseNr(userprefs.data.updateCurrentInterval) < 10000){
1681 userprefs.data.updateCurrentInterval = 120000;
1685 if( parseNr(userprefs.data.updateBouquetInterval) < 60000 ){
1686 userprefs.data.updateBouquetInterval = 300000;
1690 if (typeof document.body.style.maxHeight == "undefined") {
1691 alert("Due to the tremendous amount of work needed to get everthing to " +
1692 "work properly, there is (for now) no support for Internet Explorer Versions below 7");
1697 setAjaxLoad('navContent');
1698 setAjaxLoad('contentMain');
1700 fetchTpl('tplServiceListEPGItem');
1701 fetchTpl('tplBouquetsAndServices');
1702 fetchTpl('tplCurrent');
1703 reloadNav('tplNavTv', 'TeleVision');
1710 startUpdateCurrentPoller();