This is an automatic generated email to let you know that the following patch were queued at the http://git.linuxtv.org/tvtime.git tree:
Subject: program guide from #1097855, needs some fixes Author: Mikael Magnusson <mika...@gmail.com> Date: Mon Sep 19 15:51:12 2011 -0300 Signed-off-by: Mauro Carvalho Chehab <mche...@redhat.com> src/Makefile.am | 2 +- src/commands.c | 96 ++++++++++++++++++++++--- src/epg.c | 212 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/epg.h | 18 +++++ src/station.c | 42 +++++++++++ src/station.h | 16 ++++ src/tvtime.c | 2 +- src/tvtimeconf.c | 2 +- src/tvtimeosd.c | 1 - src/utils.c | 8 ++- src/utils.h | 4 + src/xmltv.c | 154 +++++++++++++++++++++++++++++++++------ src/xmltv.h | 7 ++- 13 files changed, 524 insertions(+), 40 deletions(-) --- http://git.linuxtv.org/tvtime.git?a=commitdiff;h=109d2f6202f77a6754acb367cb6128e1361b02d0 diff --git a/src/Makefile.am b/src/Makefile.am index e48ef4c..9781ccf 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -46,7 +46,7 @@ COMMON_SRCS = mixer.c videoinput.c rtctimer.c leetft.c osdtools.c tvtimeconf.c \ cpuinfo.h cpuinfo.c menu.c menu.h \ outputfilter.h outputfilter.c xmltv.h xmltv.c gettext.h tvtimeglyphs.h \ copyfunctions.h copyfunctions.c alsa_stream.c alsa_stream.h \ - mixer-oss.c $(ALSA_SRCS) + epg.h epg.c mixer-oss.c $(ALSA_SRCS) if ARCH_X86 DSCALER_SRCS = $(top_srcdir)/plugins/dscalerapi.h \ diff --git a/src/commands.c b/src/commands.c index 83de966..d459de3 100644 --- a/src/commands.c +++ b/src/commands.c @@ -23,6 +23,7 @@ #include <unistd.h> #include <ctype.h> #include <time.h> +#include <sys/time.h> #ifdef HAVE_CONFIG_H # include "config.h" #endif @@ -32,13 +33,13 @@ #else # define _(string) (string) #endif -#include "station.h" #include "mixer.h" #include "input.h" #include "commands.h" #include "utils.h" #include "xmltv.h" #include "tvtimeglyphs.h" +#include "epg.h" #define NUM_FAVORITES 9 #define MAX_USER_MENUS 64 @@ -167,6 +168,10 @@ struct commands_s { int numfavorites; int favorites[ NUM_FAVORITES ]; + int epg; + int epg_nowandnext; // We are showing page [epg_nowandnext] of the epg + int epg_channel; + int menuactive; int curmenu; int curmenupos; @@ -216,7 +221,7 @@ static void display_xmltv_description( commands_t *cmd, const char *title, if( subtitle && *subtitle ) { cur = tvtime_osd_list_set_multitext( cmd->osd, cur, subtitle, 1 ); - } else { + } else if( title ) { tvtime_osd_list_set_text( cmd->osd, cur++, _("No program information available") ); } @@ -1133,6 +1138,10 @@ commands_t *commands_new( config_t *cfg, videoinput_t *vidin, cmd->numfavorites = 0; memset( cmd->favorites, 0, sizeof( cmd->favorites ) ); + cmd->epg = 0; + cmd->epg_nowandnext = 0; + cmd->epg_channel = 0; + cmd->menuactive = 0; cmd->curmenu = MENU_FAVORITES; cmd->curmenupos = 0; @@ -2124,6 +2133,61 @@ void commands_handle( commands_t *cmd, int tvtime_cmd, const char *arg ) return; } + if( (cmd->epg) && (tvtime_is_epg_command( tvtime_cmd )) ){ + if (cmd->epg_nowandnext) { + switch( tvtime_cmd ) { + case TVTIME_MENU_UP: + cmd->epg_nowandnext = epg_show_nowandnext( cmd->osd, cmd->epg_nowandnext-1, cmd->stationmgr, cmd->xmltv ); + break; + case TVTIME_MENU_DOWN: + cmd->epg_nowandnext = epg_show_nowandnext( cmd->osd, cmd->epg_nowandnext+1, cmd->stationmgr, cmd->xmltv ); + break; + case TVTIME_SHOW_MENU: + cmd->epg = 0; + cmd->epg_nowandnext = 0; + commands_handle( cmd, TVTIME_SHOW_MENU, "" ); + return; + break; + case TVTIME_MENU_BACK: + cmd->epg_nowandnext = 0; + cmd->epg = 0; + break; + case TVTIME_SHOW_EPG: + cmd->epg_nowandnext = 0; + cmd->epg_channel = epg_show_perchannel( cmd->osd, 1, cmd->stationmgr, cmd->xmltv , station_get_current_pos(cmd->stationmgr)+1); + break; + } + } else if (cmd->epg_channel) { + switch( tvtime_cmd ) { + case TVTIME_MENU_UP: + cmd->epg_channel = epg_show_perchannel( cmd->osd, 1, cmd->stationmgr, cmd->xmltv , cmd->epg_channel-1); + break; + case TVTIME_MENU_DOWN: + cmd->epg_channel = epg_show_perchannel( cmd->osd, 1, cmd->stationmgr, cmd->xmltv , cmd->epg_channel+1); + break; + case TVTIME_SHOW_MENU: + cmd->epg = 0; + cmd->epg_channel = 0; + commands_handle( cmd, TVTIME_SHOW_MENU, "" ); + return; + break; + case TVTIME_MENU_BACK: + case TVTIME_SHOW_EPG: + cmd->epg_channel = 0; + cmd->epg = 0; + break; + } + + } + if (!cmd->epg_nowandnext && !cmd->epg_channel) { + // No data to show, so clear the osd screen + cmd->epg = 0; + tvtime_osd_hold( cmd->osd, 0 ); + tvtime_osd_clear( cmd->osd ); + } + return; + } + switch( tvtime_cmd ) { case TVTIME_NOOP: break; @@ -2141,6 +2205,16 @@ void commands_handle( commands_t *cmd, int tvtime_cmd, const char *arg ) } break; + case TVTIME_SHOW_EPG: + if( cmd->osd ) { + if(( cmd->epg_nowandnext = epg_show_nowandnext( cmd->osd, 1, cmd->stationmgr, cmd->xmltv ))) { + cmd->epg = 1; + tvtime_osd_hold( cmd->osd, 1 ); + tvtime_osd_show_info( cmd->osd ); + } + } + break; + case TVTIME_KEY_EVENT: key = input_string_to_special_key( arg ); if( !key ) key = arg[ 0 ]; @@ -2151,28 +2225,28 @@ void commands_handle( commands_t *cmd, int tvtime_cmd, const char *arg ) break; case TVTIME_UP: - if( cmd->menuactive ) { + if( cmd->menuactive || cmd->epg ) { commands_handle( cmd, TVTIME_MENU_UP, "" ); } else { commands_handle( cmd, TVTIME_CHANNEL_INC, "" ); } break; case TVTIME_DOWN: - if( cmd->menuactive ) { + if( cmd->menuactive || cmd->epg ) { commands_handle( cmd, TVTIME_MENU_DOWN, "" ); } else { commands_handle( cmd, TVTIME_CHANNEL_DEC, "" ); } break; case TVTIME_LEFT: - if( cmd->menuactive ) { + if( cmd->menuactive || cmd->epg ) { commands_handle( cmd, TVTIME_MENU_BACK, "" ); } else { commands_handle( cmd, TVTIME_MIXER_DOWN, "" ); } break; case TVTIME_RIGHT: - if( cmd->menuactive ) { + if( cmd->menuactive || cmd->epg ) { commands_handle( cmd, TVTIME_MENU_ENTER, "" ); } else { commands_handle( cmd, TVTIME_MIXER_UP, "" ); @@ -2674,11 +2748,12 @@ void commands_handle( commands_t *cmd, int tvtime_cmd, const char *arg ) case TVTIME_DISPLAY_INFO: cmd->displayinfo = !cmd->displayinfo; if( cmd->osd ) { - if( cmd->xmltv && cmd->vidin && - videoinput_has_tuner( cmd->vidin ) ) { - update_xmltv_display( cmd ); - } if( cmd->displayinfo ) { + cmd->epg = 0; + if( cmd->xmltv && cmd->vidin && + videoinput_has_tuner( cmd->vidin ) ) { + update_xmltv_display( cmd ); + } tvtime_osd_hold( cmd->osd, 1 ); tvtime_osd_show_info( cmd->osd ); } else { @@ -3729,4 +3804,3 @@ void commands_get_menu_bounding_box( commands_t *cmd, int *x, int *y, *x = *y = *width = *height = 0; } } - diff --git a/src/epg.c b/src/epg.c new file mode 100644 index 0000000..4e04156 --- /dev/null +++ b/src/epg.c @@ -0,0 +1,212 @@ +/** + * Copyright (c) 2005 Marijn van Galen <m.p.vanga...@ewi.tudelft.nl> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <ctype.h> +#include <time.h> +#include <sys/time.h> +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif +#ifdef ENABLE_NLS +# define _(string) gettext (string) +# include "gettext.h" +#else +# define _(string) (string) +#endif + +#include "commands.h" +#include "utils.h" +#include "xmltv.h" +#include "station.h" + +/** + * Draws electronic programguide based on XMLTV data + * + * PRE: osd : initialized tvtime osd + * page : number of the page we want to show, starting with 1 + * stationmgr : actual stationmanager + * xmltv : initialized xmltv object + * + * RETURNS: pagenumber of the page showing if there is one, 0 otherwise + * + */ + +int epg_show_nowandnext( tvtime_osd_t* osd, int page, station_mgr_t *stationmgr, xmltv_t *xmltv ) +{ + if (!page) + return 0; + if ( xmltv ){ + const int buf_length = 255; + const int max_num_lines = 15; + const int num_station_per_page = max_num_lines / 3; + const int num_stations = station_get_num_stations(stationmgr); + char *old_channel = strdup(xmltv_get_channel(xmltv)); + char buf[buf_length+1]; + int i, count, cur = 0; + + + /* List Header */ + snprintf(buf, buf_length, "Now showing and next on (%d/%d):", page, num_stations/num_station_per_page); + tvtime_osd_list_set_text( osd, cur++, buf); + tvtime_osd_list_set_hilight(osd, -1); + + for (i = (page-1) * num_station_per_page, count = 0; (i < num_stations) && (count < num_station_per_page ); i++, count++) { + const char *xmltv_id = 0; + if (!(xmltv_id = station_get_xmltv_id( stationmgr, i))) + xmltv_id = xmltv_lookup_channel(xmltv, station_get_name( stationmgr, i)); + xmltv_set_channel( xmltv, xmltv_id); + xmltv_refresh( xmltv ); + /* Channel number + name */ + snprintf(buf, buf_length, "[%s] %s:", station_get_channel(stationmgr,i), station_get_name( stationmgr, i)); + tvtime_osd_list_set_multitext( osd, cur++, buf, 1); + + if (xmltv_get_title( xmltv )) { + char start_time[50]; + char end_time[50]; + time_t start_timestamp = xmltv_get_start_time( xmltv ); + time_t end_timestamp = xmltv_get_end_time( xmltv ); + strftime( start_time, 50, "%H:%M", localtime( &start_timestamp ) ); + strftime( end_time, 50, "%H:%M", localtime( &end_timestamp ) ); + + + /* Highlight if current channel */ + if (station_get_current_id(stationmgr) == i+1) + tvtime_osd_list_set_hilight(osd, cur-1); + + /* starttime of current program + Now showing program */ + snprintf(buf, buf_length, "* %s %s", start_time, xmltv_get_title( xmltv )); + if (xmltv_get_sub_title( xmltv )){ + strncat(buf," (",buf_length-strlen(buf)); + strncat(buf,xmltv_get_sub_title( xmltv ),buf_length-strlen(buf)); + strncat(buf,")",buf_length-strlen(buf)); + } + tvtime_osd_list_set_multitext( osd, cur++, buf, 1); + + /* endtime of current programme + Next program */ + snprintf(buf, buf_length, "* %s %s", end_time, xmltv_get_next_title( xmltv ) ? xmltv_get_next_title( xmltv ) : ""); + tvtime_osd_list_set_multitext( osd, cur++, buf, 1); + + } else { + /* No XMLTV information for this channel */ + tvtime_osd_list_set_text( osd, cur++, ""); + tvtime_osd_list_set_text( osd, cur++, ""); + } + + } + tvtime_osd_list_set_lines( osd, cur ); + tvtime_osd_show_list( osd, 1, 1 ); + + xmltv_set_channel(xmltv, old_channel); + free(old_channel); + xmltv_refresh( xmltv ); + + if (cur > 1){ + return page; + } else { + return 0; + } + } else { + tvtime_osd_list_set_text( osd, 0, "No XMLTV Program Guide information available" ); + tvtime_osd_list_set_lines( osd, 1 ); + tvtime_osd_show_list( osd, 1, 1 ); + return !page; + } +} + + +int epg_show_perchannel( tvtime_osd_t* osd, int page, station_mgr_t *stationmgr, xmltv_t *xmltv, int channel ) +{ + if (!page) + return 0; + if ( xmltv ){ + const int buf_length = 255; + const int max_num_lines = 15; +// const int num_station_per_page = max_num_lines / 3; + const int num_stations = station_get_num_stations( stationmgr ); + char *old_channel = strdup( xmltv_get_channel( xmltv ) ); + char buf[buf_length+1]; + int cur = 0; + time_t curtime = time( 0 ); + const char *xmltv_id = 0; + + if (channel > num_stations) + channel = 1; + else if (channel < 1 ) + channel = num_stations; + + if (!(xmltv_id = station_get_xmltv_id( stationmgr, channel-1 ))) + xmltv_id = xmltv_lookup_channel( xmltv, station_get_name( stationmgr, channel-1 )); + xmltv_set_channel( xmltv, xmltv_id); + xmltv_refresh_withtime( xmltv, curtime ); + + /* List header with Channel number + name */ + snprintf(buf, buf_length, "%d Next on [%s] %s:", channel, station_get_channel(stationmgr,channel-1), station_get_name( stationmgr, channel-1)); + tvtime_osd_list_set_text( osd, cur++, buf ); + tvtime_osd_list_set_hilight(osd, -1); + + while (cur < max_num_lines) { + xmltv_refresh_withtime( xmltv, curtime ); + + if (xmltv_get_title( xmltv )) { + char start_time[50]; + time_t start_timestamp = xmltv_get_start_time( xmltv ); + time_t end_timestamp = xmltv_get_end_time( xmltv ); + strftime( start_time, 50, "%H:%M", localtime( &start_timestamp ) ); + + /* starttime of current program + Now showing program */ + snprintf(buf, buf_length, "%s %s", start_time, xmltv_get_title( xmltv )); + if (xmltv_get_sub_title( xmltv )){ + strncat(buf," (",buf_length-strlen(buf)); + strncat(buf,xmltv_get_sub_title( xmltv ),buf_length-strlen(buf)); + strncat(buf,")",buf_length-strlen(buf)); + } + tvtime_osd_list_set_multitext( osd, cur++, buf, 1); + + if (!xmltv_get_next_title( xmltv )) { + char end_time[50]; + /* no next program, print endtime of current programme */ + strftime( end_time, 50, "%H:%M", localtime( &end_timestamp ) ); + snprintf(buf, buf_length, "%s %s", end_time, ""); + tvtime_osd_list_set_multitext( osd, cur++, buf, 1); + } + curtime = end_timestamp; + + } else { + /* No XMLTV information for this channel */ + tvtime_osd_list_set_text( osd, cur++, ""); + } + + } + tvtime_osd_list_set_lines( osd, cur ); + tvtime_osd_show_list( osd, 1, 1 ); + + xmltv_set_channel(xmltv, old_channel); + free(old_channel); + xmltv_refresh( xmltv ); + + } else { + tvtime_osd_list_set_text( osd, 0, "No XMLTV Program Guide information available" ); + tvtime_osd_list_set_lines( osd, 1 ); + tvtime_osd_show_list( osd, 1, 1 ); + } + return channel; +} diff --git a/src/epg.h b/src/epg.h new file mode 100644 index 0000000..3b4fc9c --- /dev/null +++ b/src/epg.h @@ -0,0 +1,18 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +int epg_show_nowandnext( tvtime_osd_t* osd, int page, station_mgr_t *stationmgr, xmltv_t *xmltv ); +int epg_show_perchannel( tvtime_osd_t* osd, int page, station_mgr_t *stationmgr, xmltv_t *xmltv, int channel ); diff --git a/src/station.c b/src/station.c index 3083bb8..c08b4ea 100644 --- a/src/station.c +++ b/src/station.c @@ -754,6 +754,48 @@ const char *station_get_current_xmltv_id( station_mgr_t *mgr ) } } +const station_info_t *station_get_station( station_mgr_t *mgr, int pos) +{ + const station_info_t *tmp = mgr->first; + int i; + for (i = 0; tmp && i < pos; i++) + tmp = tmp->next; + return tmp; +} + +const char *station_get_xmltv_id( station_mgr_t *mgr, int pos ) +{ + const station_info_t *station = station_get_station(mgr, pos); + if( (station) && (*station->xmltvid) ) { + return station->xmltvid; + } else { + return 0; + } +} + +const char *station_get_channel( station_mgr_t *mgr, int pos ) +{ + const station_info_t *station = station_get_station(mgr, pos); + if( (station) && (station->network_name) ) { + static char buf[10]; + snprintf(buf, 10 ,"%d", station->pos); + return buf; + } else { + return 0; + } +} + +const char *station_get_name( station_mgr_t *mgr, int pos ) +{ + const station_info_t *station = station_get_station(mgr, pos); + if( (station) && (*station->name) ) { + return station->name; + } else { + return 0; + } +} + + void station_set_current_xmltv_id( station_mgr_t *mgr, const char *xmltvid ) { if( mgr->current ) { diff --git a/src/station.h b/src/station.h index edef3a3..feb24c4 100644 --- a/src/station.h +++ b/src/station.h @@ -160,6 +160,22 @@ const char *station_get_current_network_call_letters( station_mgr_t *mgr ); const char *station_get_current_xmltv_id( station_mgr_t *mgr ); /** + * Returns the XMLTV identifier for the channel in pos. + */ +const char *station_get_xmltv_id( station_mgr_t *mgr, int pos ); + +/** + * Returns the name of the channel in pos. + */ +const char *station_get_name( station_mgr_t *mgr, int pos ); + +/** + * Returns the channel nr of the channel in pos. + */ +const char *station_get_channel( station_mgr_t *mgr, int pos ); + + +/** * Returns the norm set for this channel. */ const char *station_get_current_norm( station_mgr_t *mgr ); diff --git a/src/tvtime.c b/src/tvtime.c index 3d42d53..5e47002 100644 --- a/src/tvtime.c +++ b/src/tvtime.c @@ -2200,6 +2200,7 @@ int tvtime_main( rtctimer_t *rtctimer, int read_stdin, int realtime, } } } + if( config_get_debug( ct ) && commands_check_freq_present( commands ) ) { if( curmethod ) { @@ -2730,4 +2731,3 @@ int main( int argc, char **argv ) return result; } - diff --git a/src/tvtimeconf.c b/src/tvtimeconf.c index 74d8bb9..4d9e25b 100644 --- a/src/tvtimeconf.c +++ b/src/tvtimeconf.c @@ -841,6 +841,7 @@ config_t *config_new( void ) ct->keymap[ I_F6 ] = TVTIME_PICTURE_DOWN; ct->keymap[ I_F7 ] = TVTIME_PICTURE_UP; ct->keymap[ 'd' ] = TVTIME_SHOW_STATS; + ct->keymap[ 'g' ] = TVTIME_SHOW_EPG; ct->keymap[ 'a' ] = TVTIME_TOGGLE_ASPECT; ct->keymap[ 'f' ] = TVTIME_TOGGLE_FULLSCREEN; ct->keymap[ 'i' ] = TVTIME_TOGGLE_INPUT; @@ -1744,7 +1745,6 @@ int config_get_square_pixels( config_t *ct ) { return ct->squarepixels; } - const char *config_get_alsa_inputdev( config_t *ct ) { return ct->alsa_inputdev; diff --git a/src/tvtimeosd.c b/src/tvtimeosd.c index 4aa72dc..48232bf 100644 --- a/src/tvtimeosd.c +++ b/src/tvtimeosd.c @@ -1076,4 +1076,3 @@ int tvtime_osd_list_set_multitext( tvtime_osd_t *osd, int cur, { return osd_list_set_multitext( osd->list, cur, text, numlines, 65 ); } - diff --git a/src/utils.c b/src/utils.c index 1816ac1..7662dcf 100644 --- a/src/utils.c +++ b/src/utils.c @@ -523,6 +523,7 @@ static command_names_t command_table[] = { { "SHOW_DEINTERLACER_INFO", TVTIME_SHOW_DEINTERLACER_INFO }, { "SHOW_MENU", TVTIME_SHOW_MENU }, { "SHOW_STATS", TVTIME_SHOW_STATS }, + { "SHOW_EPG", TVTIME_SHOW_EPG }, { "SLEEP", TVTIME_SLEEP }, @@ -605,6 +606,12 @@ int tvtime_is_menu_command( int command ) return (command >= TVTIME_MENU_UP); } +int tvtime_is_epg_command( int command ) +{ + return (command >= TVTIME_SHOW_EPG); +} + + int tvtime_command_takes_arguments( int command ) { return (command == TVTIME_DISPLAY_MESSAGE || command == TVTIME_SCREENSHOT || @@ -797,4 +804,3 @@ int lfprintf( FILE *stream, const char *format, ... ) va_end( ap ); return ret; } - diff --git a/src/utils.h b/src/utils.h index 413de26..9471687 100644 --- a/src/utils.h +++ b/src/utils.h @@ -222,6 +222,9 @@ enum tvtime_commands TVTIME_LEFT, TVTIME_RIGHT, + /* Everything below here is a epg-mode command. */ + TVTIME_SHOW_EPG, + /* Everything below here is a menu-mode command. */ TVTIME_MENU_UP, TVTIME_MENU_DOWN, @@ -248,6 +251,7 @@ int tvtime_num_commands( void ); const char *tvtime_get_command( int pos ); int tvtime_get_command_id( int pos ); int tvtime_is_menu_command( int command ); +int tvtime_is_epg_command( int command ); int tvtime_command_takes_arguments( int command ); diff --git a/src/xmltv.c b/src/xmltv.c index e944f59..f5bf16e 100644 --- a/src/xmltv.c +++ b/src/xmltv.c @@ -201,6 +201,9 @@ static time_t parse_xmltv_timezone( const char *tzstr ) return 0; } +/** + * Parse xmltv date string according to timezone + */ static time_t parse_xmltv_date( const char *date ) { char syear[ 6 ]; @@ -281,6 +284,11 @@ static time_t parse_xmltv_date( const char *date ) return mktime( &tm_obj ); } +/** + * Reinit a program object using data from [cur] xmlNode and applying [locale] + * When [cur]==0 the object is cleared, memory freed and the object is put to its + * initial empty state + */ static void reinit_program( program_t *pro, xmlNodePtr cur, xmlChar *locale ) { if( cur ) { @@ -350,6 +358,9 @@ static void reinit_program( program_t *pro, xmlNodePtr cur, xmlChar *locale ) } } +/** + * Creates a new empty program object + */ static program_t *program_new( void ) { program_t *pro = malloc( sizeof( program_t ) ); @@ -357,6 +368,10 @@ static program_t *program_new( void ) return pro; } +/** + * Returns xmlNodePtr pointing to the program starting on or before [time] on + * [channelid] which has not finished at [time] + */ static xmlNodePtr get_program( xmlNodePtr root, const char *channelid, time_t time ) { @@ -396,6 +411,9 @@ static xmlNodePtr get_program( xmlNodePtr root, const char *channelid, return 0; } +/** + * IS THIS CORRECT: XMLTV was file created by tv_grab_na? + */ static int xmltv_is_tv_grab_na( xmltv_t *xmltv ) { xmlNodePtr cur = xmltv->root->xmlChildrenNode; @@ -417,6 +435,9 @@ static int xmltv_is_tv_grab_na( xmltv_t *xmltv ) return 0; } +/** + * Adds language to list of language objects + */ static language_t *xmltv_add_language( xmltv_t *xmltv, const xmlChar *lang ) { language_t *last = 0; @@ -462,6 +483,9 @@ static language_t *xmltv_add_language( xmltv_t *xmltv, const xmlChar *lang ) return l; } +/** + * Exctracts al languages from XMLTV tree + */ static int xmltv_find_languages( xmlNodePtr node, xmltv_t *xmltv ) { xmlNodePtr cur = node->xmlChildrenNode; @@ -474,6 +498,35 @@ static int xmltv_find_languages( xmlNodePtr node, xmltv_t *xmltv ) return 0; } +/** + * Cleans up, deletes end frees an XMLTV program obejct + */ +static void program_delete( program_t *pro ) +{ + if( pro->title ) xmlFree( pro->title ); + if( pro->subtitle ) xmlFree( pro->subtitle ); + if( pro->description ) xmlFree( pro->description ); + reinit_program( pro, 0, 0 ); + free( pro ); +} + +/** + * Deletes and frees a language from the list of languages + */ +static void languages_delete( language_t *languages ) +{ + language_t *cur, *next; + cur = languages; + while( cur ) { + next = cur->next; + free( cur ); + cur = next; + } +} + +/** + * Creates a new XMLTV parser object. + */ xmltv_t *xmltv_new( const char *filename, const char *locale ) { xmltv_t *xmltv = malloc( sizeof( xmltv_t ) ); @@ -527,26 +580,9 @@ xmltv_t *xmltv_new( const char *filename, const char *locale ) return xmltv; } -static void program_delete( program_t *pro ) -{ - if( pro->title ) xmlFree( pro->title ); - if( pro->subtitle ) xmlFree( pro->subtitle ); - if( pro->description ) xmlFree( pro->description ); - reinit_program( pro, 0, 0 ); - free( pro ); -} - -static void languages_delete( language_t *languages ) -{ - language_t *cur, *next; - cur = languages; - while( cur ) { - next = cur->next; - free( cur ); - cur = next; - } -} - +/** + * Cleans up and deletes an XMLTV parser object. + */ void xmltv_delete( xmltv_t *xmltv ) { program_delete( xmltv->pro ); @@ -558,6 +594,9 @@ void xmltv_delete( xmltv_t *xmltv ) free( xmltv ); } +/** + * Sets the current channel to use for xmltv. + */ void xmltv_set_channel( xmltv_t *xmltv, const char *channel ) { if( channel ) { @@ -569,9 +608,11 @@ void xmltv_set_channel( xmltv_t *xmltv, const char *channel ) xmltv->refresh = 1; } -void xmltv_refresh( xmltv_t *xmltv ) +/** + * + */ +void xmltv_refresh_withtime ( xmltv_t *xmltv, time_t curtime ) { - time_t curtime = time( 0 ); if( xmltv->pro->title ) xmlFree( xmltv->pro->title ); if( xmltv->pro->subtitle ) xmlFree( xmltv->pro->subtitle ); @@ -601,6 +642,19 @@ void xmltv_refresh( xmltv_t *xmltv ) xmltv->refresh = 0; } + +/** + * Refreshes the information given a new time or when the channel has changed. + */ +void xmltv_refresh( xmltv_t *xmltv ) +{ + time_t curtime = time( 0 ); + xmltv_refresh_withtime(xmltv, curtime); +} + +/** + * Returns the current show title if one is set, 0 otherwise. + */ const char *xmltv_get_title( xmltv_t *xmltv ) { if ( xmltv->pro->title_local ) { @@ -609,6 +663,9 @@ const char *xmltv_get_title( xmltv_t *xmltv ) return (char *) xmltv->pro->title; } +/** + * Returns the current show sub-title if one is set, 0 otherwise. + */ const char *xmltv_get_sub_title( xmltv_t *xmltv ) { if ( xmltv->pro->subtitle_local ) { @@ -617,6 +674,9 @@ const char *xmltv_get_sub_title( xmltv_t *xmltv ) return (char *) xmltv->pro->subtitle; } +/** + * Returns the current show description if one is set, 0 otherwise. + */ const char *xmltv_get_description( xmltv_t *xmltv ) { if ( xmltv->pro->description_local ) { @@ -625,16 +685,25 @@ const char *xmltv_get_description( xmltv_t *xmltv ) return (char *) xmltv->pro->description; } +/** + * Returns the current show's start time if one is set, 0 otherwise. + */ time_t xmltv_get_start_time( xmltv_t *xmltv ) { return xmltv->pro->start_time; } +/** + * Returns the current show's end time if one is set, 0 otherwise. + */ time_t xmltv_get_end_time( xmltv_t *xmltv ) { return xmltv->pro->end_time; } +/** + * Returns the title of the next show (preview) + */ const char *xmltv_get_next_title( xmltv_t *xmltv ) { if ( xmltv->next_pro->title_local ) { @@ -643,11 +712,18 @@ const char *xmltv_get_next_title( xmltv_t *xmltv ) return (char *) xmltv->next_pro->title; } +/** + * Returns the xmltvid of the current channel. +*/ const char *xmltv_get_channel( xmltv_t *xmltv ) { return (char *) xmltv->curchannel; } +/** + * Returns true if the show information must be updated (the current + * program has ended. + */ int xmltv_needs_refresh( xmltv_t *xmltv ) { time_t curtime = time( 0 ); @@ -655,6 +731,9 @@ int xmltv_needs_refresh( xmltv_t *xmltv ) return xmltv->refresh || (curtime >= xmltv->pro->end_time); } +/** + * Looks up the xmltv id of a channel given a corresponding xmltv display name. + */ const char *xmltv_lookup_channel( xmltv_t *xmltv, const char *name ) { xmlNodePtr cur = xmltv->root->xmlChildrenNode; @@ -686,6 +765,9 @@ const char *xmltv_lookup_channel( xmltv_t *xmltv, const char *name ) return 0; } +/** + * + */ static const char *tv_grab_na_skip( const char *name ) { const char *ret = name; @@ -700,6 +782,9 @@ static const char *tv_grab_na_skip( const char *name ) return ret; } +/** + * Looks up the xmltv user display name of a channel given its xmltv id. +*/ const char *xmltv_lookup_channel_name( xmltv_t *xmltv, const char *id ) { xmlNodePtr cur = xmltv->root->xmlChildrenNode; @@ -735,6 +820,10 @@ const char *xmltv_lookup_channel_name( xmltv_t *xmltv, const char *id ) return 0; } +/** + * Sets the preferred language for xmltv data, add it to + * language list if not yet known. + */ void xmltv_set_language( xmltv_t *xmltv, const char *locale ) { language_t *l; @@ -747,17 +836,28 @@ void xmltv_set_language( xmltv_t *xmltv, const char *locale ) if( l ) xmltv->locale = l; } +/** + * Get the currently selected language code. + */ const char *xmltv_get_language( xmltv_t *xmltv ) { if( xmltv->locale ) return (char *) xmltv->locale->code; return 0; } +/** + * Number of known languages. + */ int xmltv_get_num_languages( xmltv_t *xmltv ) { return xmltv->num_languages; } +/** + * Select one of the known languages. + * n = 0..xmltv_get_num_languages() + * 0: default language + */ void xmltv_select_language( xmltv_t *xmltv, int n ) { int i; @@ -771,6 +871,9 @@ void xmltv_select_language( xmltv_t *xmltv, int n ) for( i=1; i<n; i++ ) xmltv->locale = xmltv->locale->next; } +/** + * Get the current language number. + */ int xmltv_get_langnum( xmltv_t *xmltv ) { language_t *l = xmltv->languages; @@ -784,6 +887,9 @@ int xmltv_get_langnum( xmltv_t *xmltv ) return 0; /* should never happen */ } +/** + * Get the code for language n. + */ const char *xmltv_get_language_code( xmltv_t *xmltv, int n ) { language_t *l = xmltv->languages; @@ -793,6 +899,9 @@ const char *xmltv_get_language_code( xmltv_t *xmltv, int n ) return (char *) l->code; } +/** + * Get the name of language n. + */ const char *xmltv_get_language_name( xmltv_t *xmltv, int n ) { language_t *l = xmltv->languages; @@ -801,4 +910,3 @@ const char *xmltv_get_language_name( xmltv_t *xmltv, int n ) for( i=1; i<n; i++ ) l = l->next; return (char *) l->name; } - diff --git a/src/xmltv.h b/src/xmltv.h index d34bd46..3eee04d 100644 --- a/src/xmltv.h +++ b/src/xmltv.h @@ -43,7 +43,12 @@ void xmltv_delete( xmltv_t *xmltv ); void xmltv_set_channel( xmltv_t *xmltv, const char *channel ); /** - * Refreshes the information given a new time. + * Refreshes the information given a new time or when the channel has changed. + */ +void xmltv_refresh_withtime( xmltv_t *xmltv, time_t curtime ); + +/** + * Refreshes the information given a new time or when the channel has changed. */ void xmltv_refresh( xmltv_t *xmltv ); _______________________________________________ linuxtv-commits mailing list linuxtv-commits@linuxtv.org http://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits