# HG changeset patch # User melunko # Date 1187708544 -3600 # Node ID 8a6b143057d7f6216795c5bb24e93fcc2d04a4f2 # Parent e3911c7373f751f398dfa6c71590e9d73e98e99a [svn r820] Added gmyth_scheduler_add_exception() function to remove only one schedule when all occurrences options has been used. diff -r e3911c7373f7 -r 8a6b143057d7 gmyth/src/gmyth_scheduler.c --- a/gmyth/src/gmyth_scheduler.c Mon Aug 20 21:26:20 2007 +0100 +++ b/gmyth/src/gmyth_scheduler.c Tue Aug 21 16:02:24 2007 +0100 @@ -418,7 +418,7 @@ _set_int_value(GMythQuery * myth_query, char *field, gint value, gint rec_id) { - gchar *str_value = g_strdup_printf("%d", value); + gchar *str_value = g_strdup_printf("%d", value); _set_value(myth_query, field, str_value, rec_id); g_free(str_value); @@ -500,9 +500,13 @@ _set_value(scheduler->msqlquery, "search", "0", rec_id); if (type == GMYTH_SCHEDULE_ALL_OCCURRENCES) { - _set_value(scheduler->msqlquery, "type", "4", rec_id); - } else { - _set_value(scheduler->msqlquery, "type", "1", rec_id); + _set_int_value(scheduler->msqlquery, "type", 4, rec_id); + } else if (type == GMYTH_SCHEDULE_ONE_OCCURRENCE) { + _set_int_value(scheduler->msqlquery, "type", 1, rec_id); + } else if (type == GMYTH_SCHEDULE_EXCEPTION) { + _set_int_value(scheduler->msqlquery, "type", 8, rec_id); + _set_int_value(scheduler->msqlquery, "parentid", schedule_info->parentid, + rec_id); } _set_value(scheduler->msqlquery, "recpriority", "0", rec_id); @@ -556,26 +560,28 @@ /** Requests the Mysql database in the backend to remove an existing schedule. * * @param scheduler the GMythScheduler instance. - * @param record_id The schedule's record id to be removed + * @param schedule_id The schedule's record id to be removed * @return gboolean TRUE if success, FALSE if error */ gboolean -gmyth_scheduler_delete_schedule(GMythScheduler * scheduler, gint record_id) +gmyth_scheduler_delete_schedule(GMythScheduler * scheduler, gint schedule_id) { MYSQL_RES *msql_res; - GString *query_str = g_string_new(""); + GString *query_str = NULL; - assert(scheduler); + g_return_val_if_fail (scheduler != NULL, FALSE); + if (scheduler->msqlquery == NULL) { g_warning("[%s] Scheduler db connection not initialized", __FUNCTION__); return FALSE; } - // ======================================== + + query_str = g_string_new(""); g_string_printf(query_str, - "DELETE FROM record WHERE recordid=%d", record_id); + "DELETE FROM record WHERE recordid=%d", schedule_id); msql_res = gmyth_query_process_statement(scheduler->msqlquery, @@ -586,7 +592,31 @@ g_string_free(query_str, TRUE); // Notify the backend of the changes - return update_backend(scheduler, record_id); + return update_backend(scheduler, schedule_id); +} + +/* + * Add an exception program to be removed from the schedule list, when programs + * where scheduled with the GMYTH_SCHEDULE_ALL_OCCURRENCES option. + * @param scheduler the GMythScheduler instance. + * @param schedule_id the schedule id of the all occurrence schedule to be changed + * @param exception_info the ScheduleInfo to be removed from all schedule occurrences + * @return TRUE if success, FALSE if any error happens + */ +gboolean +gmyth_scheduler_add_exception (GMythScheduler *scheduler, gint schedule_id, + ScheduleInfo *exception_info) +{ + GString *query_str; + gboolean res; + + g_return_val_if_fail (scheduler != NULL, FALSE); + g_return_val_if_fail (exception_info != NULL, FALSE); + + exception_info->parentid = schedule_id; + res = gmyth_scheduler_add_schedule_full (scheduler, exception_info, GMYTH_SCHEDULE_EXCEPTION); + + return res; } /** Requests the Mysql database in the backend to remove an existing recorded item. diff -r e3911c7373f7 -r 8a6b143057d7 gmyth/src/gmyth_scheduler.h --- a/gmyth/src/gmyth_scheduler.h Mon Aug 20 21:26:20 2007 +0100 +++ b/gmyth/src/gmyth_scheduler.h Tue Aug 21 16:02:24 2007 +0100 @@ -39,7 +39,8 @@ typedef enum { GMYTH_SCHEDULE_ONE_OCCURRENCE, - GMYTH_SCHEDULE_ALL_OCCURRENCES + GMYTH_SCHEDULE_ALL_OCCURRENCES, + GMYTH_SCHEDULE_EXCEPTION } GMythScheduleType; @@ -109,6 +110,8 @@ GString *description; GString *category; + gint parentid; + } ScheduleInfo; typedef struct { @@ -153,6 +156,9 @@ ScheduleInfo * schedule_info); gboolean gmyth_scheduler_add_schedule_full (GMythScheduler * scheduler, ScheduleInfo * schedule_info, GMythScheduleType type); +gboolean gmyth_scheduler_add_exception (GMythScheduler *scheduler, gint schedule_id, + ScheduleInfo *exception_info); + gint gmyth_scheduler_delete_schedule (GMythScheduler * scheduler, gint record_id);