maemo-ui/src/mmyth_schedulerui.c
branchtrunk
changeset 441 f310d1d086b5
parent 208 c3c073032757
child 754 cb885ee44618
     1.1 --- a/maemo-ui/src/mmyth_schedulerui.c	Wed Dec 06 20:22:48 2006 +0000
     1.2 +++ b/maemo-ui/src/mmyth_schedulerui.c	Fri Mar 23 14:34:50 2007 +0000
     1.3 @@ -13,9 +13,9 @@
     1.4  #include "mmyth_schedulerui.h"
     1.5  
     1.6  /* GMyth library includes */
     1.7 -#include "gmyth_scheduler.h"
     1.8 -#include "gmyth_common.h"
     1.9 -#include "gmyth_epg.h"
    1.10 +#include <gmyth/gmyth_scheduler.h>
    1.11 +#include <gmyth/gmyth_common.h>
    1.12 +#include <gmyth/gmyth_epg.h>
    1.13  
    1.14  static void run_calendar_dialog (GtkButton *button, gpointer data);
    1.15  
    1.16 @@ -27,7 +27,7 @@
    1.17  static void add_title_field (MMythSchedulerUI *scheduler_ui, GtkWidget *vbox);
    1.18  
    1.19  MMythSchedulerUI*
    1.20 -mmyth_schedulerui_new (void)
    1.21 +mmyth_schedulerui_new ( GMythBackendInfo *backend_info )
    1.22  {
    1.23  	GtkWidget *scrolledwindow;	
    1.24  	GtkWidget *viewport;	
    1.25 @@ -37,6 +37,8 @@
    1.26  	GtkWidget *label;
    1.27  
    1.28  	MMythSchedulerUI *scheduler_ui = g_new0 (MMythSchedulerUI, 1);
    1.29 +
    1.30 +	scheduler_ui->backend_info = backend_info;
    1.31  	
    1.32  	scrolledwindow = gtk_scrolled_window_new (NULL, NULL);
    1.33  	scheduler_ui->main_widget = scrolledwindow;
    1.34 @@ -127,83 +129,85 @@
    1.35  gboolean
    1.36  mmyth_schedulerui_save (MMythSchedulerUI *scheduler_ui)
    1.37  {
    1.38 -    GMythScheduler *scheduler;
    1.39 +	GMythScheduler *scheduler;
    1.40  	ScheduleInfo *schedule_info;
    1.41  	GMythChannelInfo *channel_info;
    1.42  
    1.43  	GList *clist;
    1.44  	gint index, duration;
    1.45 -    gint frequency;
    1.46 -    struct tm start_tm;
    1.47 -	
    1.48 +	gint frequency;
    1.49 +	struct tm start_tm;
    1.50 +
    1.51  	schedule_info = g_new0(ScheduleInfo, 1);
    1.52 -    if(schedule_info == NULL) {
    1.53 -        g_warning ("Error allocating memory");
    1.54 -        return FALSE;
    1.55 -    }
    1.56 -        
    1.57 -    clist = scheduler_ui->channel_list;
    1.58 -      
    1.59 -    index = gtk_combo_box_get_active(GTK_COMBO_BOX(scheduler_ui->channel_combobox));
    1.60 +	if(schedule_info == NULL) {
    1.61 +		g_warning ("Error allocating memory");
    1.62 +		return FALSE;
    1.63 +	}
    1.64  
    1.65 -    if (clist != NULL)
    1.66 +	clist = scheduler_ui->channel_list;
    1.67 +
    1.68 +	index = gtk_combo_box_get_active(GTK_COMBO_BOX(scheduler_ui->channel_combobox));
    1.69 +
    1.70 +	if (clist != NULL)
    1.71  		clist = g_list_nth(clist, index);
    1.72 -    
    1.73 -    if (clist) {
    1.74 -	    g_debug ("[%s] New schedule: %d", __FUNCTION__, index);
    1.75 -    } else {
    1.76 -	    g_warning ("[%s] Error when adding new schedule", __FUNCTION__);
    1.77 -	    return FALSE;
    1.78 -    }
    1.79 -    
    1.80 -    channel_info = clist->data;
    1.81 -    
    1.82 -    /* initialize schedule_info */
    1.83 -    schedule_info->channel_id = channel_info->channel_ID;
    1.84 -    
    1.85 -    start_tm.tm_hour = 
    1.86 -        (int)gtk_spin_button_get_value(GTK_SPIN_BUTTON(scheduler_ui->hour_spinbutton));
    1.87 +
    1.88 +	if (clist) {
    1.89 +		g_debug ("[%s] New schedule: %d", __FUNCTION__, index);
    1.90 +	} else {
    1.91 +		g_warning ("[%s] Error when adding new schedule", __FUNCTION__);
    1.92 +		return FALSE;
    1.93 +	}
    1.94 +
    1.95 +	channel_info = clist->data;
    1.96 +
    1.97 +	/* initialize schedule_info */
    1.98 +	schedule_info->channel_id = channel_info->channel_ID;
    1.99 +
   1.100 +	start_tm.tm_hour = 
   1.101 +		(int)gtk_spin_button_get_value(GTK_SPIN_BUTTON(scheduler_ui->hour_spinbutton));
   1.102  	start_tm.tm_min = 
   1.103 -        (int)gtk_spin_button_get_value(GTK_SPIN_BUTTON(scheduler_ui->min_spinbutton));
   1.104 -    start_tm.tm_sec = 0;
   1.105 +		(int)gtk_spin_button_get_value(GTK_SPIN_BUTTON(scheduler_ui->min_spinbutton));
   1.106 +	start_tm.tm_sec = 0;
   1.107  
   1.108  	start_tm.tm_mday = (gint)scheduler_ui->day_temp;
   1.109  	start_tm.tm_mon =  (gint)scheduler_ui->month_temp;
   1.110  	start_tm.tm_year = (gint)scheduler_ui->year_temp - 1900; //years since 1900
   1.111 +	GTimeVal* time_val_local = g_new0( GTimeVal, 1 );
   1.112 +	time_val_local->tv_sec = timelocal(&start_tm);
   1.113  
   1.114 -    schedule_info->start_time = timelocal(&start_tm);
   1.115 -    if (schedule_info->start_time == (time_t)(-1)) {
   1.116 -        g_warning ("timelocal error!\n");
   1.117 -        return FALSE;
   1.118 -    }
   1.119 +	schedule_info->start_time = time_val_local;
   1.120 +	if ( NULL == schedule_info->start_time ) {
   1.121 +		g_warning ("timelocal error!\n");
   1.122 +		return FALSE;
   1.123 +	}
   1.124  
   1.125  	duration = (gint) gtk_spin_button_get_value(
   1.126 -                        GTK_SPIN_BUTTON(scheduler_ui->duration_spinbutton));
   1.127 -    schedule_info->end_time = schedule_info->start_time + (duration*60);
   1.128 +			GTK_SPIN_BUTTON(scheduler_ui->duration_spinbutton));
   1.129 +	schedule_info->end_time = schedule_info->start_time + (duration*60);
   1.130  
   1.131 -    /* TODO: frequency is not implemented yet */
   1.132 +	/* TODO: frequency is not implemented yet */
   1.133  	frequency = gtk_combo_box_get_active(GTK_COMBO_BOX(scheduler_ui->freq_combobox));
   1.134  
   1.135  	schedule_info->title = g_string_new("");
   1.136  	g_string_printf(schedule_info->title, "%s", 
   1.137 -                    gtk_entry_get_text(GTK_ENTRY(scheduler_ui->title_entry)));
   1.138 -	
   1.139 -    /* FIXME: Architecture change to reuse the scheduler created in the recordui! */
   1.140 -    scheduler = gmyth_scheduler_new ();
   1.141 +			gtk_entry_get_text(GTK_ENTRY(scheduler_ui->title_entry)));
   1.142  
   1.143 -    gmyth_scheduler_connect(scheduler, scheduler->backend_info);
   1.144 +	/* FIXME: Architecture change to reuse the scheduler created in the recordui! */
   1.145 +	scheduler = gmyth_scheduler_new ();
   1.146  
   1.147 -    /* FIXME: set record_id = -1 to add a new schedule */
   1.148 -    schedule_info->record_id = -1;
   1.149 -    gmyth_scheduler_add_schedule (scheduler, schedule_info);
   1.150 +	gmyth_scheduler_connect(scheduler, scheduler->backend_info);
   1.151  
   1.152 -    gmyth_scheduler_disconnect(scheduler);
   1.153 -    
   1.154 -    /* free allocated memory */
   1.155 -    g_object_unref (scheduler);
   1.156 -    g_free (schedule_info);
   1.157 -	
   1.158 -    return TRUE;
   1.159 +	/* FIXME: set record_id = -1 to add a new schedule */
   1.160 +	schedule_info->record_id = -1;
   1.161 +	gmyth_scheduler_add_schedule (scheduler, schedule_info);
   1.162 +
   1.163 +	gmyth_scheduler_disconnect(scheduler);
   1.164 +
   1.165 +	/* free allocated memory */
   1.166 +	g_object_unref (scheduler);
   1.167 +	g_free (schedule_info);
   1.168 +
   1.169 +	return TRUE;
   1.170  } 
   1.171  
   1.172  static GtkWidget*
   1.173 @@ -235,7 +239,7 @@
   1.174  	gtk_box_pack_start (GTK_BOX (hbox), combobox, FALSE, FALSE, 0);
   1.175  			
   1.176  	GMythEPG *mmyth_epg = gmyth_epg_new ();
   1.177 -	if (!gmyth_epg_connect (mmyth_epg, mmyth_epg->sqlquery->backend_info)) {
   1.178 +	if (!gmyth_epg_connect (mmyth_epg, scheduler_ui->backend_info)) {
   1.179  		// FIXME: Without this list the scheduler UI should not be shown!
   1.180  		g_warning ("[%s] Error when getting list of channels", __FUNCTION__);
   1.181  	}
   1.182 @@ -271,7 +275,7 @@
   1.183  
   1.184      if (localtime_r((time_t *)&real_time, &sched_time) == NULL) {
   1.185          g_warning ("localtime_r error in mmyth_epg_grid_view!\n");
   1.186 -        return NULL;
   1.187 +        return;
   1.188      }
   1.189   
   1.190  	if (sched_time.tm_min>30){