diff options
author | Sascha Volkenandt <sascha (at) akv-soft (dot) de> | 2007-01-15 19:35:06 +0000 |
---|---|---|
committer | Sascha Volkenandt <sascha (at) akv-soft (dot) de> | 2007-01-15 19:35:06 +0000 |
commit | 6fd53f0b97b06f8bb718bef6da0d90df95f64e03 (patch) | |
tree | 5a5aa5d9a1b46741b8f2237cfaff8977aaa49ed6 | |
parent | e6818d2fe11ac37dde92cb53cfb6c9f9ef283dab (diff) | |
download | vdr-plugin-live-6fd53f0b97b06f8bb718bef6da0d90df95f64e03.tar.gz vdr-plugin-live-6fd53f0b97b06f8bb718bef6da0d90df95f64e03.tar.bz2 |
- moved ajax script to separate file
- moved call of ajax object to page element
- introduced page element for replaying recordings
- introduced task for replaying recordings
- added replay button to recordings page
-rw-r--r-- | javascript/Makefile | 2 | ||||
-rw-r--r-- | javascript/ajax.js | 57 | ||||
-rw-r--r-- | pages/Makefile | 2 | ||||
-rw-r--r-- | pages/pageelems.ecpp | 13 | ||||
-rw-r--r-- | pages/play_recording.ecpp | 26 | ||||
-rw-r--r-- | pages/recordings.ecpp | 5 | ||||
-rw-r--r-- | pages/remote.ecpp | 44 | ||||
-rw-r--r-- | recordings.h | 8 | ||||
-rw-r--r-- | tasks.cpp | 57 | ||||
-rw-r--r-- | tasks.h | 28 |
10 files changed, 180 insertions, 62 deletions
diff --git a/javascript/Makefile b/javascript/Makefile index 1e228f1..5419c64 100644 --- a/javascript/Makefile +++ b/javascript/Makefile @@ -16,7 +16,7 @@ VDRDIR ?= ../../../.. ### The object files (add further files here): OBJS = alphaAPI.o domLib.o domTT_drag.o domTT.o fadomatic.o \ - treeview.o + treeview.o ajax.o ### Default rules: diff --git a/javascript/ajax.js b/javascript/ajax.js new file mode 100644 index 0000000..042ebc9 --- /dev/null +++ b/javascript/ajax.js @@ -0,0 +1,57 @@ +function LiveAjaxCall(url) +{ + var xml = null; + if (window.XMLHttpRequest) { + xml = new XMLHttpRequest(); + if (xml.overrideMimeType) + xml.overrideMimeType('text/xml'); + } else if (window.ActiveXObject) { + try { + xml = new ActiveXObject("Msxml2.XMLHTTP"); + } catch (e) { + try { + xml = new ActiveXObject("Microsoft.XMLHTTP"); + } catch (e) {} + } + } + + this.url = url; + this.xml = xml; + + this.onerror = function(message) {}; + this.oncomplete = function(result) {}; + + this.request = function(param, value) + { + var url = this.url+'?'+name+"="+value; + this.xml.onreadystatechange = function() { this.readystatechanged(); } + this.xml.open('GET', url, true); + this.xml.send(null); + }; + + this.readystatechanged = function() + { + try { + if (this.xml.readyState == 4) { + if (this.xml.status == 200) { + var xmldoc = xml.responseXML; + var result = xmldoc.getElementsByTagName('response').item(0).firstChild.data; + this.oncomplete(result); + } else { + this.onerror('Invocation of webservice "'+this.url+'" failed with http status code '+this.xml.status); + } + } + } catch (e) { + this.onerror('Invocation of webservice "'+this.url+'" failed with exception: '+e.description); + } + }; +} + +function LiveSimpleAjaxRequest(url, param, value) +{ + var xml = new LiveAjaxCall(url); + xml.onerror = function(message) { alert(message); } + xml.oncomplete = function(response) { } + xml.request(param, value); +}; + diff --git a/pages/Makefile b/pages/Makefile index 38828ff..3e913a8 100644 --- a/pages/Makefile +++ b/pages/Makefile @@ -18,7 +18,7 @@ VDRDIR ?= ../../../.. OBJS = menu.o channels.o recordings.o schedule.o \ screenshot.o timers.o whats_on.o switch_channel.o \ keypress.o remote.o channels_widget.o edit_timer.o \ - error.o pageelems.o tooltip.o + error.o pageelems.o tooltip.o play_recording.o ### Default rules: diff --git a/pages/pageelems.ecpp b/pages/pageelems.ecpp index 9c170a6..326a8b8 100644 --- a/pages/pageelems.ecpp +++ b/pages/pageelems.ecpp @@ -46,3 +46,16 @@ component; </%args> <a href="edit_timer.html?channelid=<$ *channelid.ToString() $>&eventid=<$ eventid $>"><img src="record.png" alt="" <& tooltip.hint text=(tr("Record this")) &> border="0"/></a> </%def> + +<%def ajax_js> + <script type="text/javascript" language="javascript" src="ajax.js"></script> +</%def> + +<%def play_recording> +<%args> + string recordingid; + string image; + string alt = ""; +</%args> + <a href="javascript:LiveSimpleAjaxRequest('play_recording.xml', 'recording', '<$ recordingid $>');"><img src="<$ image $>" alt="<$ alt $>" border="0"/></a> +</%def> diff --git a/pages/play_recording.ecpp b/pages/play_recording.ecpp new file mode 100644 index 0000000..8356697 --- /dev/null +++ b/pages/play_recording.ecpp @@ -0,0 +1,26 @@ +<%pre> +#include <string> +#include <vdr/recording.h> +#include "exception.h" +#include "tasks.h" +#include "tools.h" + +using namespace std; +using namespace vdrlive; + +</%pre> +<%args> + string recordingid; +</%args> +<%cpp> + reply.setContentType( "application/xml" ); + + bool result = LiveTaskManager().ReplayRecording( recordingid ); +</%cpp> +<?xml version="1.0"?> +<service> +<request name="switch_channel"> +<param name="recording"><$ recordingid $></param> +</request> +<response><$ result ? "1" : "0" $></response> +</service> diff --git a/pages/recordings.ecpp b/pages/recordings.ecpp index e07784a..2defee4 100644 --- a/pages/recordings.ecpp +++ b/pages/recordings.ecpp @@ -25,7 +25,8 @@ const std::string sPref("short_"); <title>VDR-Live - <$ pageTitle $></title> <link rel="stylesheet" type="text/css" href="styles.css" /> <script type="text/javascript" language="javascript" src="treeview.js"></script> -<& tooltip.javascript var=("domTT_oneOnly") value=("true") var=("domTT_styleClass") value=("domTTrecordings") &> + <& tooltip.javascript var=("domTT_oneOnly") value=("true") var=("domTT_styleClass") value=("domTTrecordings") &> + <& pageelems.ajax_js &> </head> <body> <& pageelems.logo &> @@ -116,7 +117,7 @@ for (iter = recordingsTree.begin(path); iter != end; ++iter) { <div class="recording_time"><$ FormatDateTime(tr("%I:%M %p"), recItem->StartTime()) $></div> <div class="recording_name" <& tooltip.hint text=(shortDescr) &><& tooltip.display domId=(lPref + recItem->Id()) &>><$ recItem->Name() $></div> <div class="recording_actions"> - <img src="play.png" alt="" /> + <& pageelems.play_recording recordingid=(recItem->Recording()->FileName()) image="play.png" alt="" &> <img src="edit.png" alt="" /> <img src="del.png" alt="" /> </div> diff --git a/pages/remote.ecpp b/pages/remote.ecpp index 798a759..6f23d9a 100644 --- a/pages/remote.ecpp +++ b/pages/remote.ecpp @@ -12,6 +12,7 @@ using namespace vdrlive; <& pageelems.doc_type &> <html> <head> + <& pageelems.ajax_js &> <script type="text/javascript"><!-- var newImg = new Image(); var imgsrc = ""; @@ -42,50 +43,9 @@ using namespace vdrlive; interval = window.setInterval("StreamLoad()", timeout); } - function NewXMLHttpRequest() - { - var xml = null; - if (window.XMLHttpRequest) { - xml = new XMLHttpRequest(); - if (xml.overrideMimeType) - xml.overrideMimeType('text/xml'); - } else if (window.ActiveXObject) { - try { - xml = new ActiveXObject("Msxml2.XMLHTTP"); - } catch (e) { - try { - xml = new ActiveXObject("Microsoft.XMLHTTP"); - } catch (e) {} - } - } - return xml; - } - function KeyPress(keycode) { - var xml = NewXMLHttpRequest(); - xml.onreadystatechange = function() { KeyPressResponse(xml); } - xml.open('GET', 'keypress.xml?keycode='+keycode, true); - xml.send(null); - } - - function KeyPressResponse(xml) - { - try { - if (xml.readyState == 4) { - if (xml.status == 200) { - var xmldoc = xml.responseXML; - var result = xmldoc.getElementsByTagName('response').item(0).firstChild.data; - if (result != 1) { - alert("Unable to queue keypress"); - } - } else { - alert("Invokation of webservice 'keypress' failed with http status code "+xml.status); - } - } - } catch (e) { - alert("Invokation of webservice 'keypress' failed with description: "+e.description); - } + LiveSimpleAjaxRequest('keypress.xml', 'keycode', keycode); } function FillIntervals() diff --git a/recordings.h b/recordings.h index d070271..a8ea907 100644 --- a/recordings.h +++ b/recordings.h @@ -31,8 +31,9 @@ namespace vdrlive { virtual time_t StartTime() const = 0; virtual bool IsDir() const = 0; virtual const string& Name() const { return m_name; } - virtual const string& Id() const = 0; + virtual const string Id() const = 0; + virtual const cRecording* Recording() const { return 0; } virtual const cRecordingInfo* RecInfo() const { return 0; } protected: @@ -53,7 +54,7 @@ namespace vdrlive { virtual time_t StartTime() const { return 0; } virtual bool IsDir() const { return true; } - virtual const string& Id() const { return ""; } + virtual const string Id() const { return ""; } private: int m_level; @@ -68,8 +69,9 @@ namespace vdrlive { virtual time_t StartTime() const; virtual bool IsDir() const { return false; } - virtual const string& Id() const { return m_id; } + virtual const string Id() const { return m_id; } + virtual const cRecording* Recording() const { return m_recording; } virtual const cRecordingInfo* RecInfo() const { return m_recording->Info(); } private: @@ -1,33 +1,68 @@ #include <vdr/channels.h> +#include <vdr/menu.h> +#include <vdr/recording.h> #include "tasks.h" namespace vdrlive { TaskManager::TaskManager(): - m_switchChannel( 0 ), - m_switchResult( false ) + m_switchChannel( 0, false ), + m_replayRecording( "", false ) { } bool TaskManager::SwitchChannel( int number ) { - cMutexLock lock( this ); - m_switchChannel = number; - m_scheduleWait.Wait( *this ); - return m_switchResult; + return ScheduleCommand( m_switchChannel, number ); + //cMutexLock lock( this ); + //m_switchChannel.first = number; + //m_scheduleWait.Wait( *this ); + //return m_switchChannel.second; +} + +bool TaskManager::ReplayRecording( std::string const& fileName ) +{ + return ScheduleCommand( m_replayRecording, fileName ); + //cMutexLock lock( this ); + //m_replayFileName = fileName; + //m_scheduleWait.Wait( *this ); + //return m_replayResult; } void TaskManager::DoScheduledWork() { - if ( m_switchChannel == 0 ) + if ( m_switchChannel.first == 0 && m_replayRecording.first.empty() ) return; cMutexLock lock( this ); - if ( m_switchChannel != 0 ) { - m_switchResult = Channels.SwitchTo( m_switchChannel ); - m_switchChannel = 0; - m_scheduleWait.Broadcast(); + if ( m_switchChannel.first != 0 ) + DoSwitchChannel(); + if ( !m_replayRecording.first.empty() ) + DoReplayRecording(); + m_scheduleWait.Broadcast(); +} + +void TaskManager::DoSwitchChannel() +{ + m_switchChannel.second = Channels.SwitchTo( m_switchChannel.first ); + m_switchChannel.first = 0; +} + +void TaskManager::DoReplayRecording() +{ + bool result = false; + cThreadLock lock( &Recordings ); + + cRecording* recording = Recordings.GetByName( m_replayRecording.first.c_str() ); + if ( recording ) { + cReplayControl::SetRecording( 0, 0 ); + cControl::Shutdown(); + cReplayControl::SetRecording( recording->FileName(), recording->Title() ); + cControl::Launch( new cReplayControl ); + cControl::Attach(); + result = true; } + m_replayRecording.first.clear(); } TaskManager& LiveTaskManager() @@ -1,6 +1,8 @@ #ifndef VDR_LIVE_TASKS_H #define VDR_LIVE_TASKS_H +#include <string> +#include <utility> #include <vdr/thread.h> namespace vdrlive { @@ -11,18 +13,40 @@ class TaskManager: public cMutex public: bool SwitchChannel( int number ); + bool ReplayRecording( std::string const& fileName ); // may only be called from Plugin::MainThreadHook void DoScheduledWork(); private: + template< typename Type > + struct Task: std::pair< Type, bool > + { + Task( Type const& first, bool second ): std::pair< Type, bool >( first, second ) {} + }; + TaskManager(); TaskManager( TaskManager const& ); - int m_switchChannel; - bool m_switchResult; + Task< int > m_switchChannel; + Task< std::string > m_replayRecording; cCondVar m_scheduleWait; + + template< typename Type > + bool ScheduleCommand( Task< Type >& member, Type const& param ); + + void DoSwitchChannel(); + void DoReplayRecording(); }; + +template< typename Type > +inline bool TaskManager::ScheduleCommand( Task< Type >& member, Type const& param ) +{ + cMutexLock lock( this ); + member.first = param; + m_scheduleWait.Wait( *this ); + return member.second; +} TaskManager& LiveTaskManager(); |