[svn r948] Added new function to retrieve old schedules in order to reactivate them trunk
authormelunko
Mon Mar 03 17:38:32 2008 +0000 (2008-03-03)
branchtrunk
changeset 9391418e08cee7a
parent 938 d2bfa2e06cfa
child 940 1ac1550f69b6
[svn r948] Added new function to retrieve old schedules in order to reactivate them
gmyth/gmyth/gmyth_recorder.c
gmyth/gmyth/gmyth_scheduler.c
     1.1 --- a/gmyth/gmyth/gmyth_recorder.c	Mon Mar 03 13:50:41 2008 +0000
     1.2 +++ b/gmyth/gmyth/gmyth_recorder.c	Mon Mar 03 17:38:32 2008 +0000
     1.3 @@ -707,14 +707,14 @@
     1.4      return ret;
     1.5  }
     1.6  
     1.7 -static          gboolean
     1.8 +static gboolean
     1.9  gmyth_recorder_find_if_program_exists(GMythRecorder * recorder,
    1.10                                        GMythProgramInfo * prog)
    1.11  {
    1.12 -    GList          *lst = NULL;
    1.13 +    GList *lst = NULL;
    1.14  
    1.15 -    g_return_val_if_fail(recorder != NULL
    1.16 -                         && recorder->progs_info_list != NULL, FALSE);
    1.17 +    g_return_val_if_fail (recorder != NULL, FALSE);
    1.18 +    g_return_val_if_fail (recorder->progs_info_list != NULL, FALSE);
    1.19  
    1.20      for (lst = recorder->progs_info_list; lst != NULL;
    1.21           lst = g_list_next(lst)) {
    1.22 @@ -736,7 +736,7 @@
    1.23   * @return The actual program info.
    1.24   */
    1.25  GMythProgramInfo *
    1.26 -gmyth_recorder_get_current_program_info(GMythRecorder *recorder)
    1.27 +gmyth_recorder_get_current_program_info (GMythRecorder *recorder)
    1.28  {
    1.29      GMythStringList *str_list = NULL;
    1.30      GMythProgramInfo *program_info = NULL;
     2.1 --- a/gmyth/gmyth/gmyth_scheduler.c	Mon Mar 03 13:50:41 2008 +0000
     2.2 +++ b/gmyth/gmyth/gmyth_scheduler.c	Mon Mar 03 17:38:32 2008 +0000
     2.3 @@ -65,7 +65,12 @@
     2.4  gmyth_scheduler_query_schedule_list (GMythScheduler * scheduler,
     2.5                                       GList ** schedule_list,
     2.6                                       gchar *filter);
     2.7 -
     2.8 +static gint 
     2.9 +gmyth_scheduler_query_schedule_id (GMythScheduler *scheduler,
    2.10 +                                   GMythProgramInfo *prog_info);
    2.11 +static gint gmyth_scheduler_query_old_schedule (GMythScheduler *scheduler,
    2.12 +                                    gint channel_id, GTimeVal *startts,
    2.13 +                                    gboolean reactivate);
    2.14  
    2.15  static gboolean update_backend(GMythScheduler * scheduler, gint record_id);
    2.16  
    2.17 @@ -534,7 +539,7 @@
    2.18  
    2.19  gboolean
    2.20  gmyth_scheduler_add_schedule_full (GMythScheduler * scheduler,
    2.21 -                             ScheduleInfo * schedule_info, GMythScheduleType type)
    2.22 +                             ScheduleInfo *schedule_info, GMythScheduleType type)
    2.23  {
    2.24      MYSQL_RES      *msql_res;
    2.25      gchar          *query_str = NULL;
    2.26 @@ -563,11 +568,29 @@
    2.27                  gmyth_scheduler_is_program_live_recorded (scheduler, schedule_info,
    2.28                                                            &prog_info);
    2.29  	if ((recorder_num > 0) && (prog_info != NULL)) {
    2.30 +	    gboolean res;
    2.31              gmyth_scheduler_change_record_group (scheduler, prog_info, "Default");
    2.32 -	    schedule_info->schedule_id = prog_info->recordid;
    2.33  
    2.34 -            return gmyth_scheduler_set_live_record (scheduler, schedule_info,
    2.35 +            res = gmyth_scheduler_set_live_record (scheduler, schedule_info,
    2.36  			recorder_num, TRUE);
    2.37 +	    schedule_info->schedule_id = gmyth_scheduler_query_schedule_id (scheduler, prog_info);
    2.38 +            return res;
    2.39 +	} 
    2.40 +    }
    2.41 +
    2.42 +    /* Now, verifies if there is an old schedule for this program */
    2.43 +    /* If threre is one, we reactivate it */
    2.44 +    {
    2.45 +        gint sched_id;
    2.46 +	time_t now = time (NULL);
    2.47 +
    2.48 +	if (schedule_info->start_time->tv_sec < now) {
    2.49 +	    sched_id = gmyth_scheduler_query_old_schedule (scheduler, schedule_info->channel_id,
    2.50 +			                               schedule_info->start_time, TRUE);
    2.51 +	    if (sched_id > 0) {
    2.52 +                schedule_info->schedule_id = sched_id;
    2.53 +	        return TRUE;
    2.54 +            } 
    2.55  	}
    2.56      }
    2.57  
    2.58 @@ -690,6 +713,68 @@
    2.59                                                GMYTH_SCHEDULE_ONE_OCCURRENCE);
    2.60  }
    2.61  
    2.62 +static gint
    2.63 +gmyth_scheduler_query_schedule_id (GMythScheduler *scheduler,
    2.64 +		                   GMythProgramInfo *prog_info)
    2.65 +{
    2.66 +    MYSQL_RES *mysql_res;
    2.67 +    gint sched_id = -1;
    2.68 +    gchar *query_str, *startts;
    2.69 +
    2.70 +    startts = gmyth_util_time_to_string_from_time_val (prog_info->recstartts);
    2.71 +    query_str = g_strdup_printf ("SELECT recordid from recorded "
    2.72 +		    "WHERE chanid= \"%d\" AND starttime = \"%s\";",
    2.73 +                    prog_info->channel_id, startts);
    2.74 +
    2.75 +    mysql_res = gmyth_query_process_statement(scheduler->msqlquery, query_str);
    2.76 +
    2.77 +    if (mysql_res) {
    2.78 +        MYSQL_ROW msql_row = mysql_fetch_row(mysql_res);
    2.79 +        if (msql_row) {
    2.80 +            sched_id = g_ascii_strtoull (msql_row[0], NULL, 10);
    2.81 +        } 
    2.82 +    }
    2.83 +
    2.84 +    return sched_id;
    2.85 +}
    2.86 +
    2.87 +/* Queries if there is an old schedule previously set to this program.
    2.88 + * If reactivate flag is set, the recording will be reactivated.
    2.89 + * @returns the schedule id.
    2.90 + */
    2.91 +static int
    2.92 +gmyth_scheduler_query_old_schedule (GMythScheduler *scheduler,
    2.93 +		                    gint channel_id, GTimeVal *startts,
    2.94 +                                    gboolean reactivate)
    2.95 +{
    2.96 +    MYSQL_RES *mysql_res;
    2.97 +    gint sched_id = -1;
    2.98 +    gchar *query_str, *startts_str;
    2.99 +
   2.100 +    startts_str = gmyth_util_time_to_string_from_time_val (startts);
   2.101 +    query_str = g_strdup_printf ("SELECT recordid from oldrecorded "
   2.102 +                    "WHERE chanid= \"%d\" AND starttime=\"%s\";",
   2.103 +                    channel_id, startts_str);
   2.104 +
   2.105 +    mysql_res = gmyth_query_process_statement(scheduler->msqlquery, query_str);
   2.106 +    g_free (query_str);
   2.107 +
   2.108 +    if (mysql_res) {
   2.109 +        MYSQL_ROW msql_row = mysql_fetch_row(mysql_res);
   2.110 +        if (msql_row) {
   2.111 +            sched_id = g_ascii_strtoull (msql_row[0], NULL, 10);
   2.112 +            if ((sched_id > 0) && (reactivate)) {
   2.113 +                query_str = g_strdup_printf ("UPDATE oldrecorded SET reactivate = 1 "
   2.114 +                    "WHERE chanid= \"%d\" AND starttime=\"%s\";",
   2.115 +                    channel_id, startts_str);
   2.116 +                update_backend (scheduler, 0);
   2.117 +            }
   2.118 +        }
   2.119 +    }
   2.120 +
   2.121 +    return sched_id;
   2.122 +}
   2.123 +
   2.124  /** Queries if the given schedule info is currently been recorded by any 
   2.125   * backend recorder.
   2.126   * @return The recorder num currently recording the scheduled item, or -1
   2.127 @@ -777,7 +862,7 @@
   2.128      startts = gmyth_util_time_to_string_from_time_val (prog_info->recstartts);
   2.129  
   2.130      query_str = g_strdup_printf("UPDATE recorded SET recgroup = \"%s\" "
   2.131 -                    "WHERE chanid = \"%d\" AND starttime = \"%s\"",
   2.132 +                    "WHERE chanid = \"%d\" AND starttime = \"%s\";",
   2.133                       new_group, prog_info->channel_id, startts);
   2.134  
   2.135      gmyth_query_process_statement(scheduler->msqlquery, query_str);
   2.136 @@ -804,7 +889,6 @@
   2.137  
   2.138      g_return_val_if_fail (scheduler != NULL, FALSE);
   2.139  
   2.140 -
   2.141      if (scheduler->msqlquery == NULL) {
   2.142          g_warning("[%s] Scheduler db connection not initialized",
   2.143                    __FUNCTION__);
   2.144 @@ -831,6 +915,7 @@
   2.145  		return ret;		
   2.146              } 
   2.147  	}
   2.148 +			    
   2.149      }
   2.150  
   2.151      query_str = g_string_new("");
   2.152 @@ -911,37 +996,6 @@
   2.153      return update_backend(scheduler, record_id);
   2.154  }
   2.155  
   2.156 -
   2.157 -gboolean gmyth_scheduler_was_recorded_before(GMythScheduler* scheduler, gint channel_id,
   2.158 -                                             time_t start_time)
   2.159 -{
   2.160 -    MYSQL_RES      *msql_res;
   2.161 -    GString        *query_str = g_string_new("");
   2.162 -
   2.163 -    assert(scheduler);
   2.164 -    g_string_printf(query_str, "SELECT callsign FROM channel "
   2.165 -                    "WHERE chanid = \"%d\"", channel_id);
   2.166 -
   2.167 -    msql_res = gmyth_query_process_statement(scheduler->msqlquery, query_str->str);
   2.168 -
   2.169 -    if (msql_res) {
   2.170 -        MYSQL_ROW msql_row = mysql_fetch_row(msql_res);
   2.171 -        if (msql_row) {
   2.172 -            GString* callsign = g_string_new(msql_row[0]);
   2.173 -            GString* startts = gmyth_util_time_to_string(start_time);
   2.174 -            g_string_printf(query_str, "SELECT * FROM oldrecorded "
   2.175 -                            "WHERE station = \"%s\" AND starttime = \"%s\"",
   2.176 -                            callsign->str, startts->str);
   2.177 -            msql_res = gmyth_query_process_statement(scheduler->msqlquery, query_str->str);
   2.178 -            g_string_free(callsign, TRUE);
   2.179 -            g_string_free(startts, TRUE);
   2.180 -            g_string_free(query_str, TRUE);
   2.181 -            if (mysql_fetch_row(msql_res)) return TRUE;
   2.182 -        }
   2.183 -    }
   2.184 -    return FALSE;
   2.185 -}
   2.186 -
   2.187  /** Retrieves an existing recorded item information from database. The information
   2.188   * is used to fill the returned GMythProgramInfo.
   2.189   *