# HG changeset patch # User melunko # Date 1204565912 0 # Node ID 1418e08cee7a10cdf5460f6c3bcd929840827be6 # Parent d2bfa2e06cfa58445e868c0f4c479f0d283a1228 [svn r948] Added new function to retrieve old schedules in order to reactivate them diff -r d2bfa2e06cfa -r 1418e08cee7a gmyth/gmyth/gmyth_recorder.c --- a/gmyth/gmyth/gmyth_recorder.c Mon Mar 03 13:50:41 2008 +0000 +++ b/gmyth/gmyth/gmyth_recorder.c Mon Mar 03 17:38:32 2008 +0000 @@ -707,14 +707,14 @@ return ret; } -static gboolean +static gboolean gmyth_recorder_find_if_program_exists(GMythRecorder * recorder, GMythProgramInfo * prog) { - GList *lst = NULL; + GList *lst = NULL; - g_return_val_if_fail(recorder != NULL - && recorder->progs_info_list != NULL, FALSE); + g_return_val_if_fail (recorder != NULL, FALSE); + g_return_val_if_fail (recorder->progs_info_list != NULL, FALSE); for (lst = recorder->progs_info_list; lst != NULL; lst = g_list_next(lst)) { @@ -736,7 +736,7 @@ * @return The actual program info. */ GMythProgramInfo * -gmyth_recorder_get_current_program_info(GMythRecorder *recorder) +gmyth_recorder_get_current_program_info (GMythRecorder *recorder) { GMythStringList *str_list = NULL; GMythProgramInfo *program_info = NULL; diff -r d2bfa2e06cfa -r 1418e08cee7a gmyth/gmyth/gmyth_scheduler.c --- a/gmyth/gmyth/gmyth_scheduler.c Mon Mar 03 13:50:41 2008 +0000 +++ b/gmyth/gmyth/gmyth_scheduler.c Mon Mar 03 17:38:32 2008 +0000 @@ -65,7 +65,12 @@ gmyth_scheduler_query_schedule_list (GMythScheduler * scheduler, GList ** schedule_list, gchar *filter); - +static gint +gmyth_scheduler_query_schedule_id (GMythScheduler *scheduler, + GMythProgramInfo *prog_info); +static gint gmyth_scheduler_query_old_schedule (GMythScheduler *scheduler, + gint channel_id, GTimeVal *startts, + gboolean reactivate); static gboolean update_backend(GMythScheduler * scheduler, gint record_id); @@ -534,7 +539,7 @@ gboolean gmyth_scheduler_add_schedule_full (GMythScheduler * scheduler, - ScheduleInfo * schedule_info, GMythScheduleType type) + ScheduleInfo *schedule_info, GMythScheduleType type) { MYSQL_RES *msql_res; gchar *query_str = NULL; @@ -563,11 +568,29 @@ gmyth_scheduler_is_program_live_recorded (scheduler, schedule_info, &prog_info); if ((recorder_num > 0) && (prog_info != NULL)) { + gboolean res; gmyth_scheduler_change_record_group (scheduler, prog_info, "Default"); - schedule_info->schedule_id = prog_info->recordid; - return gmyth_scheduler_set_live_record (scheduler, schedule_info, + res = gmyth_scheduler_set_live_record (scheduler, schedule_info, recorder_num, TRUE); + schedule_info->schedule_id = gmyth_scheduler_query_schedule_id (scheduler, prog_info); + return res; + } + } + + /* Now, verifies if there is an old schedule for this program */ + /* If threre is one, we reactivate it */ + { + gint sched_id; + time_t now = time (NULL); + + if (schedule_info->start_time->tv_sec < now) { + sched_id = gmyth_scheduler_query_old_schedule (scheduler, schedule_info->channel_id, + schedule_info->start_time, TRUE); + if (sched_id > 0) { + schedule_info->schedule_id = sched_id; + return TRUE; + } } } @@ -690,6 +713,68 @@ GMYTH_SCHEDULE_ONE_OCCURRENCE); } +static gint +gmyth_scheduler_query_schedule_id (GMythScheduler *scheduler, + GMythProgramInfo *prog_info) +{ + MYSQL_RES *mysql_res; + gint sched_id = -1; + gchar *query_str, *startts; + + startts = gmyth_util_time_to_string_from_time_val (prog_info->recstartts); + query_str = g_strdup_printf ("SELECT recordid from recorded " + "WHERE chanid= \"%d\" AND starttime = \"%s\";", + prog_info->channel_id, startts); + + mysql_res = gmyth_query_process_statement(scheduler->msqlquery, query_str); + + if (mysql_res) { + MYSQL_ROW msql_row = mysql_fetch_row(mysql_res); + if (msql_row) { + sched_id = g_ascii_strtoull (msql_row[0], NULL, 10); + } + } + + return sched_id; +} + +/* Queries if there is an old schedule previously set to this program. + * If reactivate flag is set, the recording will be reactivated. + * @returns the schedule id. + */ +static int +gmyth_scheduler_query_old_schedule (GMythScheduler *scheduler, + gint channel_id, GTimeVal *startts, + gboolean reactivate) +{ + MYSQL_RES *mysql_res; + gint sched_id = -1; + gchar *query_str, *startts_str; + + startts_str = gmyth_util_time_to_string_from_time_val (startts); + query_str = g_strdup_printf ("SELECT recordid from oldrecorded " + "WHERE chanid= \"%d\" AND starttime=\"%s\";", + channel_id, startts_str); + + mysql_res = gmyth_query_process_statement(scheduler->msqlquery, query_str); + g_free (query_str); + + if (mysql_res) { + MYSQL_ROW msql_row = mysql_fetch_row(mysql_res); + if (msql_row) { + sched_id = g_ascii_strtoull (msql_row[0], NULL, 10); + if ((sched_id > 0) && (reactivate)) { + query_str = g_strdup_printf ("UPDATE oldrecorded SET reactivate = 1 " + "WHERE chanid= \"%d\" AND starttime=\"%s\";", + channel_id, startts_str); + update_backend (scheduler, 0); + } + } + } + + return sched_id; +} + /** Queries if the given schedule info is currently been recorded by any * backend recorder. * @return The recorder num currently recording the scheduled item, or -1 @@ -777,7 +862,7 @@ startts = gmyth_util_time_to_string_from_time_val (prog_info->recstartts); query_str = g_strdup_printf("UPDATE recorded SET recgroup = \"%s\" " - "WHERE chanid = \"%d\" AND starttime = \"%s\"", + "WHERE chanid = \"%d\" AND starttime = \"%s\";", new_group, prog_info->channel_id, startts); gmyth_query_process_statement(scheduler->msqlquery, query_str); @@ -804,7 +889,6 @@ g_return_val_if_fail (scheduler != NULL, FALSE); - if (scheduler->msqlquery == NULL) { g_warning("[%s] Scheduler db connection not initialized", __FUNCTION__); @@ -831,6 +915,7 @@ return ret; } } + } query_str = g_string_new(""); @@ -911,37 +996,6 @@ return update_backend(scheduler, record_id); } - -gboolean gmyth_scheduler_was_recorded_before(GMythScheduler* scheduler, gint channel_id, - time_t start_time) -{ - MYSQL_RES *msql_res; - GString *query_str = g_string_new(""); - - assert(scheduler); - g_string_printf(query_str, "SELECT callsign FROM channel " - "WHERE chanid = \"%d\"", channel_id); - - msql_res = gmyth_query_process_statement(scheduler->msqlquery, query_str->str); - - if (msql_res) { - MYSQL_ROW msql_row = mysql_fetch_row(msql_res); - if (msql_row) { - GString* callsign = g_string_new(msql_row[0]); - GString* startts = gmyth_util_time_to_string(start_time); - g_string_printf(query_str, "SELECT * FROM oldrecorded " - "WHERE station = \"%s\" AND starttime = \"%s\"", - callsign->str, startts->str); - msql_res = gmyth_query_process_statement(scheduler->msqlquery, query_str->str); - g_string_free(callsign, TRUE); - g_string_free(startts, TRUE); - g_string_free(query_str, TRUE); - if (mysql_fetch_row(msql_res)) return TRUE; - } - } - return FALSE; -} - /** Retrieves an existing recorded item information from database. The information * is used to fill the returned GMythProgramInfo. *