From 2cb8c257e0693fe8c7c7bdfe2b2dbe5c6b156bbe Mon Sep 17 00:00:00 2001 From: Sascha Volkenandt Date: Fri, 12 Jan 2007 22:05:30 +0000 Subject: - added operators for streaming tChannelID - passing tChannelID consistently --- pages/edit_timer.ecpp | 89 +++++++++++++++++++++++++++++++-------------------- pages/schedule.ecpp | 22 +++++++------ pages/whats_on.ecpp | 28 ++++++++-------- timers.cpp | 4 +-- timers.h | 3 +- tools.cpp | 15 +++++++-- tools.h | 11 +++++++ 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 +#include #include +#include #include #include "exception.h" #include "tools.h" @@ -10,11 +13,15 @@ using namespace vdrlive; <%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 = ""; <%include>page_init.eh <%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"); - } <& pageelems.doc_type &> @@ -99,7 +118,7 @@ using namespace vdrlive;
<& pageelems.header_box content=(timer ? tr("Edit timer") : tr("New timer")) &> -
+ @@ -113,7 +132,7 @@ using namespace vdrlive; 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; @@ -14,7 +15,7 @@ using namespace vdrlive; int channel = -1; <%request scope="page"> -cChannel* Channel; + cChannel* Channel; <%include>page_init.eh <%cpp> @@ -57,29 +58,32 @@ cChannel* Channel;
<$ tr("Channel") $>: -<& channels_widget name=("channel") channelid=(true) selected=(channel) &> +<& channels_widget name=("channel") channelid=(true) selected=(*channel.ToString()) &>
<{ 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; }> - + % } "> + 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; @@ -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(" ..."); } }>
@@ -78,7 +76,7 @@ if (type == "now") {
<$ channel_name $>
- /> + <& pageelems.event_timer channelid=(channel_id) eventid=(event) &>
<$ start $> - <$ end $>
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 #include +#include #include #include #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 +#include +#include #include #include #include #include +#include #include +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 ); -- cgit v1.2.3
<$ current_day $><$ current_day $>
<& pageelems.event_timer channelid=(channel_id) eventid=(event) &> <$ start $> - <$ end $> <$ title $>
<$ short_description $>