# HG changeset patch # User rosfran # Date 1177020238 -3600 # Node ID 9e589622f097edb385c028094db3172d7b06cf30 # Parent 7dc357cbaa409eb3f6a1be542b2a2a38eb5926dd [svn r583] New functions to get the channel list, fixes on the gmyth/gmyth.h references. diff -r 7dc357cbaa40 -r 9e589622f097 gmyth/src/gmyth.h --- a/gmyth/src/gmyth.h Thu Apr 19 22:38:46 2007 +0100 +++ b/gmyth/src/gmyth.h Thu Apr 19 23:03:58 2007 +0100 @@ -29,29 +29,29 @@ #ifndef _GMYTH_H_ #define _GMYTH_H_ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #endif /* _GMYTH_H_ */ diff -r 7dc357cbaa40 -r 9e589622f097 gmyth/src/gmyth_livetv.c --- a/gmyth/src/gmyth_livetv.c Thu Apr 19 22:38:46 2007 +0100 +++ b/gmyth/src/gmyth_livetv.c Thu Apr 19 23:03:58 2007 +0100 @@ -512,15 +512,19 @@ /* check if the program chain could be obtained from the MythTV protocol message */ if ( prog_info != NULL ) { - /* - GMythProgramInfo *ch_prog = gmyth_util_get_recording_from_channel( livetv->backend_info, channel ); - if ( ch_prog != NULL ) + gmyth_backend_info_set_username( livetv->tvchain->backend_info, "mythtv" ); + gmyth_backend_info_set_password( livetv->tvchain->backend_info, "mythtv" ); + gmyth_backend_info_set_db_name( livetv->tvchain->backend_info, "mythconverg" ); + GList* prog_list = gmyth_tvchain_get_program_info_from_channel( livetv->tvchain, channel ); + GMythProgramInfo *ch_prog = NULL; + if ( prog_list != NULL && g_list_length(prog_list) > 0 ) { - gmyth_debug( "Channel program info!" ); + ch_prog = (GMythProgramInfo*)g_list_nth_data( prog_list, 0 ); + gmyth_debug( "Channel program info (from a list with size = %d)!", g_list_length(prog_list) ); gmyth_program_info_print( ch_prog ); } - */ - gmyth_debug( "Program Info: %s\n", gmyth_program_info_to_string( prog_info ) ); + + gmyth_debug( "Program Info: %s\n", gmyth_program_info_to_string( prog_info ) ); livetv->proginfo = prog_info; /* testing change channel */ //gmyth_recorder_spawntv_no_tvchain( livetv->recorder ); diff -r 7dc357cbaa40 -r 9e589622f097 gmyth/src/gmyth_tvchain.c --- a/gmyth/src/gmyth_tvchain.c Thu Apr 19 22:38:46 2007 +0100 +++ b/gmyth/src/gmyth_tvchain.c Thu Apr 19 23:03:58 2007 +0100 @@ -284,6 +284,134 @@ return ret; } +/** + * Get all the program info entries in the database. + * + * @param tvchain The GMythTVChain instance. + * + * @return A program info listage. + */ +GList * +gmyth_tvchain_get_program_info_list (GMythTVChain *tvchain) +{ + GList *prog_list = NULL; + MYSQL_ROW msql_row; + MYSQL_RES *msql_res = NULL; + GMythQuery *gmyth_query = NULL; + GString *stmt_str = NULL; + + g_mutex_lock( tvchain->mutex ); + + gmyth_query = gmyth_query_new (); + if (!gmyth_query_connect (gmyth_query, tvchain->backend_info)) { + gmyth_debug ("Could not connect to db."); + goto done; + } + + stmt_str = g_string_new (""); + g_string_printf (stmt_str, + "SELECT channum, icon " + "FROM channel " + "ORDER BY channum;"); + + msql_res = gmyth_query_process_statement(gmyth_query, stmt_str->str); + if (msql_res != NULL) { + + while ((msql_row = mysql_fetch_row (msql_res)) != NULL) { + GMythProgramInfo *entry = gmyth_program_info_new(); + entry->channame = g_string_new (msql_row[0]); + entry->chansign = g_string_new (msql_row[1]); + + gmyth_debug( "Reading TV program info entry (channel %s): [%s - {%s, %s}]\n", entry->channame->str, + entry->chansign->str, (gchar*)msql_row[0], (gchar*)msql_row[1] ); + + prog_list = g_list_append (prog_list, entry); + } + } else { + gmyth_debug ("Query error when trying to get the channel list from database!\n"); + goto done; + } + +done: + g_mutex_unlock( tvchain->mutex ); + + if ( stmt_str != NULL ) + g_string_free (stmt_str, TRUE); + + if ( msql_res != NULL ) + mysql_free_result (msql_res); + + if ( gmyth_query != NULL ) + g_object_unref (gmyth_query); + + return prog_list; +} + +/** + * Get all the program info entries in the database, given a channel name. + * + * @param tvchain The GMythTVChain instance. + * @param channel The channel name. + * + * @return A program info listage, based on a given channel name. + */ +GList * +gmyth_tvchain_get_program_info_from_channel (GMythTVChain *tvchain, const gchar* channel) +{ + GList *prog_list = NULL; + MYSQL_ROW msql_row; + MYSQL_RES *msql_res = NULL; + GMythQuery *gmyth_query = NULL; + GString *stmt_str = NULL; + + g_mutex_lock( tvchain->mutex ); + + gmyth_query = gmyth_query_new (); + if (!gmyth_query_connect (gmyth_query, tvchain->backend_info)) { + gmyth_debug ("Could not connect to db."); + goto done; + } + + stmt_str = g_string_new (""); + g_string_printf (stmt_str, + "SELECT channum, icon " + "FROM channel " + "WHERE channum = \"%s\" ORDER BY channum;", + channel); + + msql_res = gmyth_query_process_statement(gmyth_query, stmt_str->str); + if (msql_res != NULL) { + + while ((msql_row = mysql_fetch_row (msql_res)) != NULL) { + GMythProgramInfo *entry = gmyth_program_info_new(); + entry->channame = g_string_new (msql_row[0]); + entry->chansign = g_string_new (msql_row[1]); + + gmyth_debug( "Reading TV program info entry (channel %s): [%s - {%s, %s}]\n", entry->channame->str, + entry->chansign->str, (gchar*)msql_row[0], (gchar*)msql_row[1] ); + + prog_list = g_list_append (prog_list, entry); + } + } else { + gmyth_debug ("Query error when trying to get the channel list from database!\n"); + goto done; + } + +done: + g_mutex_unlock( tvchain->mutex ); + + if ( stmt_str != NULL ) + g_string_free (stmt_str, TRUE); + + if ( msql_res != NULL ) + mysql_free_result (msql_res); + + if ( gmyth_query != NULL ) + g_object_unref (gmyth_query); + + return prog_list; +} + /** Returns the internal index for the TV chain related to the given * channel and start time. * diff -r 7dc357cbaa40 -r 9e589622f097 gmyth/src/gmyth_tvchain.h --- a/gmyth/src/gmyth_tvchain.h Thu Apr 19 22:38:46 2007 +0100 +++ b/gmyth/src/gmyth_tvchain.h Thu Apr 19 23:03:58 2007 +0100 @@ -106,6 +106,11 @@ struct LiveTVChainEntry *entry); GMythProgramInfo* gmyth_tvchain_get_program_at (GMythTVChain *tvchain, gint index); +GList* gmyth_tvchain_get_program_info_from_channel (GMythTVChain *tvchain, + const gchar* channel); + +GList* gmyth_tvchain_get_program_info_list (GMythTVChain *tvchain); + G_END_DECLS #endif /*LIVETVCHAIN_H_*/