diff -r c3c073032757 -r 3cf3c6019e3b maemo-ui/src/mmyth_schedulerui.c --- a/maemo-ui/src/mmyth_schedulerui.c Wed Dec 06 20:22:48 2006 +0000 +++ b/maemo-ui/src/mmyth_schedulerui.c Thu Jun 14 18:21:08 2007 +0100 @@ -13,9 +13,9 @@ #include "mmyth_schedulerui.h" /* GMyth library includes */ -#include "gmyth_scheduler.h" -#include "gmyth_common.h" -#include "gmyth_epg.h" +#include +#include +#include static void run_calendar_dialog (GtkButton *button, gpointer data); @@ -27,7 +27,7 @@ static void add_title_field (MMythSchedulerUI *scheduler_ui, GtkWidget *vbox); MMythSchedulerUI* -mmyth_schedulerui_new (void) +mmyth_schedulerui_new ( GMythBackendInfo *backend_info ) { GtkWidget *scrolledwindow; GtkWidget *viewport; @@ -37,6 +37,8 @@ GtkWidget *label; MMythSchedulerUI *scheduler_ui = g_new0 (MMythSchedulerUI, 1); + + scheduler_ui->backend_info = backend_info; scrolledwindow = gtk_scrolled_window_new (NULL, NULL); scheduler_ui->main_widget = scrolledwindow; @@ -127,83 +129,85 @@ gboolean mmyth_schedulerui_save (MMythSchedulerUI *scheduler_ui) { - GMythScheduler *scheduler; + GMythScheduler *scheduler; ScheduleInfo *schedule_info; GMythChannelInfo *channel_info; GList *clist; gint index, duration; - gint frequency; - struct tm start_tm; - + gint frequency; + struct tm start_tm; + schedule_info = g_new0(ScheduleInfo, 1); - if(schedule_info == NULL) { - g_warning ("Error allocating memory"); - return FALSE; - } - - clist = scheduler_ui->channel_list; - - index = gtk_combo_box_get_active(GTK_COMBO_BOX(scheduler_ui->channel_combobox)); + if(schedule_info == NULL) { + g_warning ("Error allocating memory"); + return FALSE; + } - if (clist != NULL) + clist = scheduler_ui->channel_list; + + index = gtk_combo_box_get_active(GTK_COMBO_BOX(scheduler_ui->channel_combobox)); + + if (clist != NULL) clist = g_list_nth(clist, index); - - if (clist) { - g_debug ("[%s] New schedule: %d", __FUNCTION__, index); - } else { - g_warning ("[%s] Error when adding new schedule", __FUNCTION__); - return FALSE; - } - - channel_info = clist->data; - - /* initialize schedule_info */ - schedule_info->channel_id = channel_info->channel_ID; - - start_tm.tm_hour = - (int)gtk_spin_button_get_value(GTK_SPIN_BUTTON(scheduler_ui->hour_spinbutton)); + + if (clist) { + g_debug ("[%s] New schedule: %d", __FUNCTION__, index); + } else { + g_warning ("[%s] Error when adding new schedule", __FUNCTION__); + return FALSE; + } + + channel_info = clist->data; + + /* initialize schedule_info */ + schedule_info->channel_id = channel_info->channel_ID; + + start_tm.tm_hour = + (int)gtk_spin_button_get_value(GTK_SPIN_BUTTON(scheduler_ui->hour_spinbutton)); start_tm.tm_min = - (int)gtk_spin_button_get_value(GTK_SPIN_BUTTON(scheduler_ui->min_spinbutton)); - start_tm.tm_sec = 0; + (int)gtk_spin_button_get_value(GTK_SPIN_BUTTON(scheduler_ui->min_spinbutton)); + start_tm.tm_sec = 0; start_tm.tm_mday = (gint)scheduler_ui->day_temp; start_tm.tm_mon = (gint)scheduler_ui->month_temp; start_tm.tm_year = (gint)scheduler_ui->year_temp - 1900; //years since 1900 + GTimeVal* time_val_local = g_new0( GTimeVal, 1 ); + time_val_local->tv_sec = timelocal(&start_tm); - schedule_info->start_time = timelocal(&start_tm); - if (schedule_info->start_time == (time_t)(-1)) { - g_warning ("timelocal error!\n"); - return FALSE; - } + schedule_info->start_time = time_val_local; + if ( NULL == schedule_info->start_time ) { + g_warning ("timelocal error!\n"); + return FALSE; + } duration = (gint) gtk_spin_button_get_value( - GTK_SPIN_BUTTON(scheduler_ui->duration_spinbutton)); - schedule_info->end_time = schedule_info->start_time + (duration*60); + GTK_SPIN_BUTTON(scheduler_ui->duration_spinbutton)); + schedule_info->end_time = schedule_info->start_time + (duration*60); - /* TODO: frequency is not implemented yet */ + /* TODO: frequency is not implemented yet */ frequency = gtk_combo_box_get_active(GTK_COMBO_BOX(scheduler_ui->freq_combobox)); schedule_info->title = g_string_new(""); g_string_printf(schedule_info->title, "%s", - gtk_entry_get_text(GTK_ENTRY(scheduler_ui->title_entry))); - - /* FIXME: Architecture change to reuse the scheduler created in the recordui! */ - scheduler = gmyth_scheduler_new (); + gtk_entry_get_text(GTK_ENTRY(scheduler_ui->title_entry))); - gmyth_scheduler_connect(scheduler, scheduler->backend_info); + /* FIXME: Architecture change to reuse the scheduler created in the recordui! */ + scheduler = gmyth_scheduler_new (); - /* FIXME: set record_id = -1 to add a new schedule */ - schedule_info->record_id = -1; - gmyth_scheduler_add_schedule (scheduler, schedule_info); + gmyth_scheduler_connect(scheduler, scheduler->backend_info); - gmyth_scheduler_disconnect(scheduler); - - /* free allocated memory */ - g_object_unref (scheduler); - g_free (schedule_info); - - return TRUE; + /* FIXME: set record_id = -1 to add a new schedule */ + schedule_info->record_id = -1; + gmyth_scheduler_add_schedule (scheduler, schedule_info); + + gmyth_scheduler_disconnect(scheduler); + + /* free allocated memory */ + g_object_unref (scheduler); + g_free (schedule_info); + + return TRUE; } static GtkWidget* @@ -235,7 +239,7 @@ gtk_box_pack_start (GTK_BOX (hbox), combobox, FALSE, FALSE, 0); GMythEPG *mmyth_epg = gmyth_epg_new (); - if (!gmyth_epg_connect (mmyth_epg, mmyth_epg->sqlquery->backend_info)) { + if (!gmyth_epg_connect (mmyth_epg, scheduler_ui->backend_info)) { // FIXME: Without this list the scheduler UI should not be shown! g_warning ("[%s] Error when getting list of channels", __FUNCTION__); } @@ -271,7 +275,7 @@ if (localtime_r((time_t *)&real_time, &sched_time) == NULL) { g_warning ("localtime_r error in mmyth_epg_grid_view!\n"); - return NULL; + return; } if (sched_time.tm_min>30){