From 0252d06339a3f834d86aab32845e613314e5e367 Mon Sep 17 00:00:00 2001 From: Sascha Volkenandt Date: Sat, 6 Jan 2007 23:33:34 +0000 Subject: - added simple error handling and regrouped web pages --- pages/channels_widget.ecpp | 27 +++++++------ pages/edit_timer.ecpp | 35 +++++++++++------ pages/schedule.ecpp | 94 ++++++++++++++++++++++++---------------------- pages/timers.ecpp | 9 ++--- 4 files changed, 90 insertions(+), 75 deletions(-) diff --git a/pages/channels_widget.ecpp b/pages/channels_widget.ecpp index 5bd69b2..bdc526c 100644 --- a/pages/channels_widget.ecpp +++ b/pages/channels_widget.ecpp @@ -1,5 +1,6 @@ <%pre> #include +#include "exception.h" #include "setup.h" #include "tools.h" @@ -13,17 +14,19 @@ selected; onchange; bool channelId = false; - +<%cpp> +ReadLock channelsLock( Channels ); +if ( !channelsLock ) + throw HtmlError( tr("Channels"), tr("Couldn't aquire access to channels, please try again later.") ); + diff --git a/pages/edit_timer.ecpp b/pages/edit_timer.ecpp index f093c99..948944d 100644 --- a/pages/edit_timer.ecpp +++ b/pages/edit_timer.ecpp @@ -1,9 +1,9 @@ <%pre> #include -#include #include #include -#include "setup.h" +#include +#include "exception.h" #include "tools.h" #include "timers.h" @@ -13,7 +13,6 @@ using namespace vdrlive; <%args> timerid; -bool submit = false; bool active = true; channel = ""; title = ""; @@ -34,10 +33,14 @@ int priority = ::Setup.DefaultPriority; int lifetime = ::Setup.DefaultLifetime; aux = ""; +<%request scope="global"> +std::string pageTitle( tr("Edit timer") ); + <%cpp> +try { ReadLock channelsLock( Channels ); - if (!channelsLock) - return DECLINED; // XXX error page + if ( !channelsLock ) + throw HtmlError( tr("Channels"), tr("Couldn't aquire access to channels, please try again later.") ); cMutexLock timersLock( &LiveTimerManager() ); SortedTimers& timers = LiveTimerManager().GetTimers(); @@ -46,7 +49,7 @@ aux = ""; if ( !timerid.empty() ) { timer = timers.GetByTimerId( timerid ); if ( timer == 0 ) - return DECLINED; // XXX error page + throw HtmlError( tr("Timers"), tr("Couldn't find channel. Maybe you mistyped your request?") ); } if ( request.getMethod() != "POST" && timer != 0 ) { @@ -72,14 +75,11 @@ aux = ""; } std::string result; - if ( submit ) { + 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" : "-" ); - //( wday_mon ? 0x01 : 0 ) | ( wday_tue ? 0x02 : 0 ) | ( wday_wed ? 0x04 : 0 ) | - //( wday_thu ? 0x08 : 0 ) | ( wday_fri ? 0x10 : 0 ) | ( wday_sat ? 0x20 : 0 ) | - //( wday_sun ? 0x40 : 0 ); ostringstream builder; builder << flags << ":" << channel << ":" << ( weekdays != "-------" ? weekdays : "" ) << ( weekdays == "-------" || day.empty() ? "" : "@" ) << day << ":" << ( start_h * 100 + start_m ) @@ -87,8 +87,10 @@ aux = ""; std::string error = LiveTimerManager().UpdateTimer( timer, builder.str() ); if ( !error.empty() ) - reply.out() << error; + throw HtmlError( tr("Timers"), error ); } + + tnt::Savepoint spoint( reply ); @@ -172,10 +174,19 @@ aux = ""; - + +<%cpp> + spoint.commit(); +} catch ( HtmlError const& ex ) { + cxxtools::QueryParams param = qparam; + param.add( "errorTitle", ex.GetTitle() ); + param.add( "errorMessage", ex.GetMessage() ); + callComp( "error", request, reply, param ); +} + diff --git a/pages/schedule.ecpp b/pages/schedule.ecpp index b22bf2a..20d3911 100644 --- a/pages/schedule.ecpp +++ b/pages/schedule.ecpp @@ -3,6 +3,8 @@ #include #include #include +#include +#include "exception.h" #include "setup.h" #include "tools.h" @@ -12,29 +14,42 @@ using namespace vdrlive; <%args> int channel = -1; -<{ +<%request scope="global"> +std::string pageTitle( tr("Schedule") ); + +<%cpp> +try { cSchedulesLock schedulesLock; - const cSchedules* schedules = cSchedules::Schedules(schedulesLock); - cChannel* Channel; + cSchedules const* schedules = cSchedules::Schedules( schedulesLock ); ReadLock channelsLock( Channels ); - if (channelsLock) { - if (channel > 0) { - Channel = Channels.GetByNumber(channel); - } else { - Channel = Channels.Get(Channels.GetNextNormal(-1)); - } + if ( !channelsLock ) + throw HtmlError( tr("Channels"), tr("Couldn't aquire access to channels, please try again later.") ); -}> + cChannel* Channel; + if ( channel > 0 ) + Channel = Channels.GetByNumber( channel ); + else + Channel = Channels.Get( Channels.GetNextNormal( -1 ) ); + + if ( Channel == 0 ) + throw HtmlError( tr("Channels"), tr("Couldn't find channel or no channels available. Maybe you mistyped your request?") ); + + cSchedule const* Schedule = schedules->GetSchedule( Channel ); + if ( Schedule == 0 ) + throw HtmlError( tr("Schedule"), tr("No schedules available for this channel.") ); + + tnt::Savepoint spoint( reply ); + - VDR Live - <$ tr("Schedule") $> + VDR Live - <$ pageTitle $>
VDR Live! -<& menu > + <& menu >
@@ -43,18 +58,14 @@ int channel = -1; Name() ?>
-<& channels_widget name=("channel") selected=(Channel ? *Channel->GetChannelID().ToString() : "") onchange=("document.forms.channels.submit()") &> + <& channels_widget name=("channel") selected=(Channel ? *Channel->GetChannelID().ToString() : "") + onchange=("document.forms.channels.submit()") &>
-<{ - if (Channel) { - const cSchedule *Schedule = schedules->GetSchedule(Channel); - if (Schedule) { -}> <{ bool active_line = false; @@ -76,33 +87,26 @@ int channel = -1; if (current_day != day) { current_day = day; }> - - - -<{ - } -}> - "> - - - - -<{ - } -}> + + + +% } + "> + + + + +% }
<$ current_day $>
<$ start $> - <$ end $><$ title $>
<$ short_description $>
 
<$ current_day $>
<$ start $> - <$ end $><$ title $>
<$ short_description $>
 
-<{ - } else { -}> - Kein Schedule für Channel <$ Channel->Number() $> -<{ - } - } else { -}> - Kein Channel mit der Nummer <$ channel $> -<{ - } - } -}> +
+<%cpp> + spoint.commit(); +} catch ( HtmlError const& ex ) { + cxxtools::QueryParams param = qparam; + param.add( "errorTitle", ex.GetTitle() ); + param.add( "errorMessage", ex.GetMessage() ); + callComp( "error", request, reply, param ); +} + diff --git a/pages/timers.ecpp b/pages/timers.ecpp index 01d37f3..9c9593c 100644 --- a/pages/timers.ecpp +++ b/pages/timers.ecpp @@ -1,6 +1,4 @@ <%pre> -#include -#include #include #include "timers.h" #include "tools.h" @@ -10,10 +8,9 @@ using namespace vdrlive; <%args> -<{ - - -}> +<%cpp> +//cMutexLock timersLock( &LiveTimerManager() ); + VDR-Live - <$ tr("Timers") $> -- cgit v1.2.3