summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSascha Volkenandt <sascha (at) akv-soft (dot) de>2007-01-12 22:05:30 +0000
committerSascha Volkenandt <sascha (at) akv-soft (dot) de>2007-01-12 22:05:30 +0000
commit2cb8c257e0693fe8c7c7bdfe2b2dbe5c6b156bbe (patch)
treef725782ef5c1a47fbf15d705fade594bc6ef0aa0
parentb405e4e3d31ceda6fa3de366d8c5374a160e1266 (diff)
downloadvdr-plugin-live-2cb8c257e0693fe8c7c7bdfe2b2dbe5c6b156bbe.tar.gz
vdr-plugin-live-2cb8c257e0693fe8c7c7bdfe2b2dbe5c6b156bbe.tar.bz2
- added operators for streaming tChannelID
- passing tChannelID consistently
-rw-r--r--pages/edit_timer.ecpp89
-rw-r--r--pages/schedule.ecpp22
-rw-r--r--pages/whats_on.ecpp28
-rw-r--r--timers.cpp4
-rw-r--r--timers.h3
-rw-r--r--tools.cpp15
-rw-r--r--tools.h11
7 files changed, 108 insertions, 64 deletions
diff --git a/pages/edit_timer.ecpp b/pages/edit_timer.ecpp
index 5772f9f..27b0362 100644
--- a/pages/edit_timer.ecpp
+++ b/pages/edit_timer.ecpp
@@ -1,5 +1,8 @@
<%pre>
+#include <memory>
+#include <vdr/channels.h>
#include <vdr/config.h>
+#include <vdr/epg.h>
#include <vdr/i18n.h>
#include "exception.h"
#include "tools.h"
@@ -10,11 +13,15 @@ using namespace vdrlive;
</%pre>
<%args>
- timerid;
+ // input parameters
+ string timerid;
+ tChannelID channelid;
+ tEventID eventid = 0;
+ // form parameters
+ tChannelID channel;
bool active = true;
- channel = "";
- title = "";
- day = FormatDateTime( "%d", time( 0 ) );
+ string title = "";
+ string day = "";
bool wday_mon = false;
bool wday_tue = false;
bool wday_wed = false;
@@ -22,23 +29,19 @@ using namespace vdrlive;
bool wday_fri = false;
bool wday_sat = false;
bool wday_sun = false;
- int start_h = StringToInt( FormatDateTime( "%H", time( 0 ) ) );
- int start_m = StringToInt( FormatDateTime( "%M", time( 0 ) ) );
- int end_h = StringToInt( FormatDateTime( "%H", time( 0 ) ) );
- int end_m = StringToInt( FormatDateTime( "%M", time( 0 ) ) );
- bool vps = ::Setup.UseVps;
- int priority = ::Setup.DefaultPriority;
- int lifetime = ::Setup.DefaultLifetime;
- aux = "";
+ int start_h = 0;
+ int start_m = 0;
+ int end_h = 0;
+ int end_m = 0;
+ bool vps = 0;
+ int priority = 0;
+ int lifetime = 0;
+ string aux = "";
</%args>
<%include>page_init.eh</%include>
<%cpp>
pageTitle = tr("Edit timer");
- ReadLock channelsLock( Channels );
- if ( !channelsLock )
- throw HtmlError( tr("Couldn't aquire access to channels, please try again later.") );
-
cMutexLock timersLock( &LiveTimerManager() );
SortedTimers& timers = LiveTimerManager().GetTimers();
@@ -46,12 +49,42 @@ using namespace vdrlive;
if ( !timerid.empty() ) {
timer = timers.GetByTimerId( timerid );
if ( timer == 0 )
- throw HtmlError( tr("Couldn't find channel. Maybe you mistyped your request?") );
+ throw HtmlError( tr("Couldn't find timer. Maybe you mistyped your request?") );
}
- if ( request.getMethod() != "POST" && timer != 0 ) {
+ if ( request.getMethod() == "POST" ) {
+ uint flags = ( active ? tfActive : 0 ) | ( vps ? tfVps : 0 );
+ string weekdays = string( wday_mon ? "M" : "-" ) + ( wday_tue ? "T" : "-" ) + ( wday_wed ? "W" : "-" )
+ + ( wday_thu ? "T" : "-" ) + ( wday_fri ? "F" : "-" ) + ( wday_sat ? "S" : "-" )
+ + ( wday_sun ? "S" : "-" );
+ int start = start_h * 100 + start_m;
+ int stop = end_h * 100 + end_m;
+
+ LiveTimerManager().UpdateTimer( timer, flags, channel, weekdays, day, start, stop, priority, lifetime, title, aux );
+
+ return reply.redirect("timers.html");
+ }
+
+ auto_ptr< cTimer > eventTimer;
+ if ( timer == 0 ) {
+ if ( channelid.Valid() && eventid != 0 ) {
+ cerr << "grabbing event" << endl << endl;
+ cSchedulesLock schedLock;
+ cSchedules const* schedules = cSchedules::Schedules( schedLock );
+ cSchedule const* schedule = schedules->GetSchedule( channelid );
+
+ eventTimer.reset( new cTimer( schedule->GetEvent( eventid ) ) );
+ } else {
+ cerr << "grabbing new timer" << endl << endl;
+ eventTimer.reset( new cTimer() );
+ eventTimer->SetFlags( tfActive );
+ }
+ timer = eventTimer.get();
+ }
+
+ if ( timer != 0 ) {
active = timer->Flags() & tfActive;
- channel = *timer->Channel()->GetChannelID().ToString();
+ channel = timer->Channel()->GetChannelID();
title = timer->File() ? timer->File() : "";
day = timer->Day() ? FormatDateTime( "%d", timer->Day() ) : "";
wday_mon = timer->WeekDays() & 0x01;
@@ -70,20 +103,6 @@ using namespace vdrlive;
lifetime = timer->Lifetime();
aux = timer->Aux() ? timer->Aux() : "";
}
-
- string result;
- if ( request.getMethod() == "POST" ) {
- uint flags = ( active ? tfActive : 0 ) | ( vps ? tfVps : 0 );
- string weekdays = string( wday_mon ? "M" : "-" ) + ( wday_tue ? "T" : "-" ) + ( wday_wed ? "W" : "-" )
- + ( wday_thu ? "T" : "-" ) + ( wday_fri ? "F" : "-" ) + ( wday_sat ? "S" : "-" )
- + ( wday_sun ? "S" : "-" );
- int start = start_h * 100 + start_m;
- int stop = end_h * 100 + end_m;
-
- LiveTimerManager().UpdateTimer( timer, flags, channel, weekdays, day, start, stop, priority, lifetime, title, aux );
-
- return reply.redirect("timers.html");
- }
</%cpp>
<& pageelems.doc_type &>
<html>
@@ -99,7 +118,7 @@ using namespace vdrlive;
<div class="right_area">
<div class="inhalt">
<& pageelems.header_box content=(timer ? tr("Edit timer") : tr("New timer")) &>
- <form method="POST" name="edit_timer">
+ <form method="POST" name="edit_timer" action="edit_timer.ecpp">
<input type="hidden" name="timerid" value="<$ timerid $>"/>
<input type="hidden" name="aux" value="<$ aux $>"/>
<table class="edit" cellpadding="0" cellspacing="0">
@@ -113,7 +132,7 @@ using namespace vdrlive;
<tr>
<td class="label"><$ tr("Channel") $>:</td>
<td>
-<& channels_widget name=("channel") channelid=(true) selected=(channel) &>
+<& channels_widget name=("channel") channelid=(true) selected=(*channel.ToString()) &>
</td>
</tr>
diff --git a/pages/schedule.ecpp b/pages/schedule.ecpp
index b8be6ad..4ff06ad 100644
--- a/pages/schedule.ecpp
+++ b/pages/schedule.ecpp
@@ -7,6 +7,7 @@
#include "setup.h"
#include "tools.h"
+using namespace std;
using namespace vdrlive;
</%pre>
@@ -14,7 +15,7 @@ using namespace vdrlive;
int channel = -1;
</%args>
<%request scope="page">
-cChannel* Channel;
+ cChannel* Channel;
</%request>
<%include>page_init.eh</%include>
<%cpp>
@@ -57,29 +58,32 @@ cChannel* Channel;
<table class="schedule" cellspacing="0" callpadding="0">
<{
bool active_line = false;
- std::string current_day = "";
+ string current_day = "";
const cEvent* PresentEvent = Schedule->GetPresentEvent();
time_t now = time(NULL) - ::Setup.EPGLinger * 60;
+ tChannelID channel_id(Channel->GetChannelID());
for (const cEvent *Event = Schedule->Events()->First(); Event; Event = Schedule->Events()->Next(Event)) {
if (Event->EndTime() <= now && Event != PresentEvent)
continue;
active_line = !active_line;
- std::string title(Event->Title() ? Event->Title() : "");
- std::string short_description(Event->ShortText() ? Event->ShortText() : "");
- std::string description(Event->Description() ? Event->Description() : "");
- std::string start(Event->StartTime() ? FormatDateTime(tr("%I:%M %p"), Event->StartTime()) : "");
- std::string end(Event->EndTime() ? FormatDateTime(tr("%I:%M %p"), Event->EndTime()) : "");
- std::string day(Event->StartTime() ? FormatDateTime(tr("%A, %b %d %Y"), Event->StartTime()) : "");
+ string title(Event->Title() ? Event->Title() : "");
+ string short_description(Event->ShortText() ? Event->ShortText() : "");
+ string description(Event->Description() ? Event->Description() : "");
+ string start(Event->StartTime() ? FormatDateTime(tr("%I:%M %p"), Event->StartTime()) : "");
+ string end(Event->EndTime() ? FormatDateTime(tr("%I:%M %p"), Event->EndTime()) : "");
+ string day(Event->StartTime() ? FormatDateTime(tr("%A, %b %d %Y"), Event->StartTime()) : "");
+ tEventID event = Event->EventID();
if (current_day != day) {
current_day = day;
}>
<tr>
- <td class="head" colspan="3"><$ current_day $></td>
+ <td class="head" colspan="4"><$ current_day $></td>
</tr>
% }
<tr class="<? active_line ? "active" ?>">
+ <td><& pageelems.event_timer channelid=(channel_id) eventid=(event) &></td>
<td><$ start $> - <$ end $></td>
<td><strong><$ title $></strong><br /><$ short_description $><br /></td>
<td>&nbsp;</td>
diff --git a/pages/whats_on.ecpp b/pages/whats_on.ecpp
index b4dc791..9bb3171 100644
--- a/pages/whats_on.ecpp
+++ b/pages/whats_on.ecpp
@@ -7,6 +7,7 @@
#include "setup.h"
#include "tools.h"
+using namespace std;
using namespace vdrlive;
</%pre>
@@ -19,9 +20,9 @@ type = "now";
cSchedulesLock schedulesLock;
const cSchedules* Schedules = cSchedules::Schedules(schedulesLock);
-std::string head;
+string head;
if (type == "now") {
- head = tr("What's running at")+std::string(" ")+FormatDateTime(tr("%I:%M %p"), time(0));
+ head = tr("What's running at")+string(" ")+FormatDateTime(tr("%I:%M %p"), time(0));
} else {
head = tr("What's on next?");
}
@@ -55,22 +56,19 @@ if (type == "now") {
if (Schedule) {
const cEvent *Event = (type == "now" ? Schedule->GetPresentEvent() : Schedule->GetFollowingEvent());
if (Event) {
- std::string title(Event->Title() ? Event->Title() : "");
- std::string channel_name(Channel->Name());
- std::string channel_id(*Channel->GetChannelID().ToString());
- std::string short_description(Event->ShortText() ? Event->ShortText() : "");
- std::string description(Event->Description() ? Event->Description() : "");
- std::string start(Event->StartTime() ? FormatDateTime(tr("%I:%M %p"), Event->StartTime()) : "");
- std::string end(Event->EndTime() ? FormatDateTime(tr("%I:%M %p"), Event->EndTime()) : "");
- std::string start_h(FormatDateTime( "%H", Event->StartTime()));
- std::string end_h(FormatDateTime( "%H", Event->EndTime()));
- std::string start_m(FormatDateTime( "%M", Event->StartTime()));
- std::string end_m(FormatDateTime( "%M", Event->EndTime()));
+ string title(Event->Title() ? Event->Title() : "");
+ string channel_name(Channel->Name());
+ string short_description(Event->ShortText() ? Event->ShortText() : "");
+ string description(Event->Description() ? Event->Description() : "");
+ string start(Event->StartTime() ? FormatDateTime(tr("%I:%M %p"), Event->StartTime()) : "");
+ string end(Event->EndTime() ? FormatDateTime(tr("%I:%M %p"), Event->EndTime()) : "");
+ tChannelID channel_id(Channel->GetChannelID());
+ tEventID event = Event->EventID();
bool truncated = false;
description = StringWordTruncate(description, 250, truncated);
if (truncated) {
- description += std::string(" ") + tr("more") + std::string(" ...");
+ description += string(" ") + tr("more") + string(" ...");
}
}>
<div class="event">
@@ -78,7 +76,7 @@ if (type == "now") {
<div><div><div><$ channel_name $></div></div></div>
</div>
<div class="tools">
- <a href="edit_timer.html?channel=<$ channel_id $>&title=<$ title $>&start_h=<$ start_h $>&end_h=<$ end_h $>&start_m=<$ start_m $>&end_m=<$ end_m $>"><img src="/record.png" alt="" <& tooltip_widget tooltip=(tr("Record this")) &> /></a>
+ <& pageelems.event_timer channelid=(channel_id) eventid=(event) &>
</div>
<div class="content">
<div class="info"><$ start $> - <$ end $></div>
diff --git a/timers.cpp b/timers.cpp
index b5ceb52..91e9c67 100644
--- a/timers.cpp
+++ b/timers.cpp
@@ -79,11 +79,11 @@ TimerManager::TimerManager()
{
}
-void TimerManager::UpdateTimer( cTimer* timer, int flags, string const& channel, string const& weekdays, string const& day,
+void TimerManager::UpdateTimer( cTimer* timer, int flags, tChannelID& channel, string const& weekdays, string const& day,
int start, int stop, int priority, int lifetime, string const& title, string const& aux )
{
ostringstream builder;
- builder << flags << ":" << channel << ":" << ( weekdays != "-------" ? weekdays : "" )
+ builder << flags << ":" << *channel.ToString() << ":" << ( weekdays != "-------" ? weekdays : "" )
<< ( weekdays == "-------" || day.empty() ? "" : "@" ) << day << ":" << start << ":" << stop << ":"
<< priority << ":" << lifetime << ":" << title << ":" << aux;
dsyslog("%s", builder.str().c_str());
diff --git a/timers.h b/timers.h
index 861c724..85d6406 100644
--- a/timers.h
+++ b/timers.h
@@ -3,6 +3,7 @@
#include <list>
#include <string>
+#include <vdr/channels.h>
#include <vdr/timers.h>
#include <vdr/thread.h>
#include "live.h"
@@ -33,7 +34,7 @@ class TimerManager: public cMutex
public:
SortedTimers& GetTimers() { return m_timers; }
- void UpdateTimer( cTimer* timer, int flags, std::string const& channel, std::string const& weekdays, std::string const& day,
+ void UpdateTimer( cTimer* timer, int flags, tChannelID& channel, std::string const& weekdays, std::string const& day,
int start, int stop, int priority, int lifetime, std::string const& title, std::string const& aux );
// may only be called from Plugin::MainThreadHook
diff --git a/tools.cpp b/tools.cpp
index da83aff..a6c8973 100644
--- a/tools.cpp
+++ b/tools.cpp
@@ -7,10 +7,21 @@
#include "setup.h"
#include "tools.h"
-namespace vdrlive {
-
using namespace std;
+istream& operator>>( istream& is, tChannelID& ret )
+{
+ if ( is.rdbuf()->in_avail() > 0 ) {
+ string line;
+ if ( !getline( is, line ) || ( !line.empty() && !( ret = tChannelID::FromString( line.c_str() ) ).Valid() ) )
+ is.setstate( ios::badbit );
+ cerr << "channel id " << line << endl << endl;
+ }
+ return is;
+}
+
+namespace vdrlive {
+
string FormatDateTime( char const* format, time_t time )
{
struct tm tm_r;
diff --git a/tools.h b/tools.h
index 36f0c19..a269d22 100644
--- a/tools.h
+++ b/tools.h
@@ -2,12 +2,23 @@
#define VDR_LIVE_TOOLS_H
#include <ctime>
+#include <istream>
+#include <ostream>
#include <sstream>
#include <stdexcept>
#include <string>
#include <vector>
+#include <vdr/channels.h>
#include <vdr/thread.h>
+std::istream& operator>>( std::istream& is, tChannelID& ret );
+
+inline
+std::ostream& operator<<( std::ostream& os, tChannelID const& id )
+{
+ return os << *id.ToString();
+}
+
namespace vdrlive {
std::string FormatDateTime( char const* format, time_t time );