[svn r820] Added gmyth_scheduler_add_exception() function to remove only one schedule when all occurrences options has been used. trunk
authormelunko
Tue Aug 21 16:02:24 2007 +0100 (2007-08-21)
branchtrunk
changeset 8148a6b143057d7
parent 813 e3911c7373f7
child 815 7f290a3a34b1
[svn r820] Added gmyth_scheduler_add_exception() function to remove only one schedule when all occurrences options has been used.
gmyth/src/gmyth_scheduler.c
gmyth/src/gmyth_scheduler.h
     1.1 --- a/gmyth/src/gmyth_scheduler.c	Mon Aug 20 21:26:20 2007 +0100
     1.2 +++ b/gmyth/src/gmyth_scheduler.c	Tue Aug 21 16:02:24 2007 +0100
     1.3 @@ -418,7 +418,7 @@
     1.4  _set_int_value(GMythQuery * myth_query, char *field, gint value,
     1.5                 gint rec_id)
     1.6  {
     1.7 -    gchar          *str_value = g_strdup_printf("%d", value);
     1.8 +    gchar *str_value = g_strdup_printf("%d", value);
     1.9  
    1.10      _set_value(myth_query, field, str_value, rec_id);
    1.11      g_free(str_value);
    1.12 @@ -500,9 +500,13 @@
    1.13      _set_value(scheduler->msqlquery, "search", "0", rec_id);
    1.14  
    1.15      if (type == GMYTH_SCHEDULE_ALL_OCCURRENCES) {
    1.16 -        _set_value(scheduler->msqlquery, "type", "4", rec_id);
    1.17 -    } else {
    1.18 -        _set_value(scheduler->msqlquery, "type", "1", rec_id);
    1.19 +        _set_int_value(scheduler->msqlquery, "type", 4, rec_id);
    1.20 +    } else if (type == GMYTH_SCHEDULE_ONE_OCCURRENCE) {
    1.21 +        _set_int_value(scheduler->msqlquery, "type", 1, rec_id);
    1.22 +    } else if (type == GMYTH_SCHEDULE_EXCEPTION) {
    1.23 +        _set_int_value(scheduler->msqlquery, "type", 8, rec_id);
    1.24 +	_set_int_value(scheduler->msqlquery, "parentid", schedule_info->parentid,
    1.25 +		       rec_id);
    1.26      }
    1.27  
    1.28      _set_value(scheduler->msqlquery, "recpriority", "0", rec_id);
    1.29 @@ -556,26 +560,28 @@
    1.30  /** Requests the Mysql database in the backend to remove an existing schedule.
    1.31   * 
    1.32   * @param scheduler the GMythScheduler instance.
    1.33 - * @param record_id The schedule's record id to be removed
    1.34 + * @param schedule_id The schedule's record id to be removed
    1.35   * @return gboolean TRUE if success, FALSE if error
    1.36   */
    1.37  gboolean
    1.38 -gmyth_scheduler_delete_schedule(GMythScheduler * scheduler, gint record_id)
    1.39 +gmyth_scheduler_delete_schedule(GMythScheduler * scheduler, gint schedule_id)
    1.40  {
    1.41  
    1.42      MYSQL_RES      *msql_res;
    1.43 -    GString        *query_str = g_string_new("");
    1.44 +    GString        *query_str = NULL;
    1.45  
    1.46 -    assert(scheduler);
    1.47 +    g_return_val_if_fail (scheduler != NULL, FALSE);
    1.48 +
    1.49  
    1.50      if (scheduler->msqlquery == NULL) {
    1.51          g_warning("[%s] Scheduler db connection not initialized",
    1.52                    __FUNCTION__);
    1.53          return FALSE;
    1.54      }
    1.55 -    // ========================================
    1.56 +
    1.57 +    query_str = g_string_new("");
    1.58      g_string_printf(query_str,
    1.59 -                    "DELETE FROM record WHERE recordid=%d", record_id);
    1.60 +                    "DELETE FROM record WHERE recordid=%d", schedule_id);
    1.61  
    1.62      msql_res =
    1.63          gmyth_query_process_statement(scheduler->msqlquery,
    1.64 @@ -586,7 +592,31 @@
    1.65      g_string_free(query_str, TRUE);
    1.66  
    1.67      // Notify the backend of the changes
    1.68 -    return update_backend(scheduler, record_id);
    1.69 +    return update_backend(scheduler, schedule_id);
    1.70 +}
    1.71 +
    1.72 +/*
    1.73 + * Add an exception program to be removed from the schedule list, when programs
    1.74 + * where scheduled with the GMYTH_SCHEDULE_ALL_OCCURRENCES option.
    1.75 + * @param scheduler the GMythScheduler instance.
    1.76 + * @param schedule_id the schedule id of the all occurrence schedule to be changed
    1.77 + * @param exception_info the ScheduleInfo to be removed from all schedule occurrences
    1.78 + * @return TRUE if success, FALSE if any error happens
    1.79 + */
    1.80 +gboolean
    1.81 +gmyth_scheduler_add_exception (GMythScheduler *scheduler, gint schedule_id,
    1.82 +			       ScheduleInfo *exception_info)
    1.83 +{
    1.84 +    GString *query_str;
    1.85 +    gboolean res;
    1.86 +
    1.87 +    g_return_val_if_fail (scheduler != NULL, FALSE);
    1.88 +    g_return_val_if_fail (exception_info != NULL, FALSE);
    1.89 +
    1.90 +    exception_info->parentid = schedule_id;
    1.91 +    res = gmyth_scheduler_add_schedule_full (scheduler, exception_info, GMYTH_SCHEDULE_EXCEPTION);
    1.92 +
    1.93 +    return res;
    1.94  }
    1.95  
    1.96  /** Requests the Mysql database in the backend to remove an existing recorded item.
     2.1 --- a/gmyth/src/gmyth_scheduler.h	Mon Aug 20 21:26:20 2007 +0100
     2.2 +++ b/gmyth/src/gmyth_scheduler.h	Tue Aug 21 16:02:24 2007 +0100
     2.3 @@ -39,7 +39,8 @@
     2.4  
     2.5  typedef enum {
     2.6      GMYTH_SCHEDULE_ONE_OCCURRENCE,
     2.7 -    GMYTH_SCHEDULE_ALL_OCCURRENCES
     2.8 +    GMYTH_SCHEDULE_ALL_OCCURRENCES,
     2.9 +    GMYTH_SCHEDULE_EXCEPTION
    2.10  } GMythScheduleType;
    2.11  
    2.12  
    2.13 @@ -109,6 +110,8 @@
    2.14      GString        *description;
    2.15      GString        *category;
    2.16  
    2.17 +    gint parentid;
    2.18 +
    2.19  } ScheduleInfo;
    2.20  
    2.21  typedef struct {
    2.22 @@ -153,6 +156,9 @@
    2.23                                                       ScheduleInfo * schedule_info);
    2.24  gboolean        gmyth_scheduler_add_schedule_full (GMythScheduler * scheduler,
    2.25                               ScheduleInfo * schedule_info, GMythScheduleType type);
    2.26 +gboolean        gmyth_scheduler_add_exception (GMythScheduler *scheduler, gint schedule_id,
    2.27 +                             ScheduleInfo *exception_info);
    2.28 +
    2.29  
    2.30  gint            gmyth_scheduler_delete_schedule     (GMythScheduler * scheduler,
    2.31                                                       gint record_id);