[svn r771] * Mencoder doesnt work well with "Transfer-Encoding: chunked".
* Put this method just for gmencoder
3 #include <glib/gprintf.h>
11 #include "mmyth_uicommon.h"
12 #include "mmyth_recordui.h"
13 #include "mmyth_schedulerui.h"
16 * GMyth library includes
18 #include <gmyth/gmyth_scheduler.h>
19 #include <gmyth/gmyth_common.h>
20 #include <gmyth/gmyth_epg.h>
22 static void run_calendar_dialog(GtkButton * button, gpointer data);
24 static void add_channel_field(MMythSchedulerUI * scheduler_ui,
26 static void add_time_field(MMythSchedulerUI * scheduler_ui,
28 static void add_date_field(MMythSchedulerUI * scheduler_ui,
30 static void add_duration_field(MMythSchedulerUI * scheduler_ui,
32 static void add_frequency_field(MMythSchedulerUI * scheduler_ui,
34 static void add_title_field(MMythSchedulerUI * scheduler_ui,
38 mmyth_schedulerui_new(GMythBackendInfo * backend_info)
40 GtkWidget *scrolledwindow;
43 GtkWidget *fields_vbox;
44 GtkWidget *hseparator;
47 MMythSchedulerUI *scheduler_ui = g_new0(MMythSchedulerUI, 1);
49 scheduler_ui->backend_info = backend_info;
51 scrolledwindow = gtk_scrolled_window_new(NULL, NULL);
52 scheduler_ui->main_widget = scrolledwindow;
53 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwindow),
55 GTK_POLICY_AUTOMATIC);
58 viewport = gtk_viewport_new(NULL, NULL);
59 gtk_container_add(GTK_CONTAINER(scrolledwindow), viewport);
62 head_hbox = gtk_hbox_new(FALSE, 0);
63 gtk_container_add(GTK_CONTAINER(viewport), head_hbox);
65 fields_vbox = gtk_vbox_new(FALSE, 0);
66 gtk_box_pack_start(GTK_BOX(head_hbox), fields_vbox, TRUE, TRUE, 0);
67 gtk_container_set_border_width(GTK_CONTAINER(fields_vbox), 10);
69 label = gtk_label_new_with_mnemonic(("Manual Schedule Recording"));
70 gtk_box_pack_start(GTK_BOX(fields_vbox), label, FALSE, FALSE, 0);
71 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
73 hseparator = gtk_hseparator_new();
74 gtk_box_pack_start(GTK_BOX(fields_vbox), hseparator, FALSE, TRUE, 0);
76 add_channel_field(scheduler_ui, fields_vbox);
77 add_time_field(scheduler_ui, fields_vbox);
78 add_date_field(scheduler_ui, fields_vbox);
79 add_duration_field(scheduler_ui, fields_vbox);
80 add_frequency_field(scheduler_ui, fields_vbox);
81 add_title_field(scheduler_ui, fields_vbox);
87 set_date_from_calendar(GtkCalendar * calendar, gpointer data)
91 MMythSchedulerUI *scheduler_ui = (MMythSchedulerUI *) data;
93 // FIXME: Change this, save another value instead of month_temp,
95 gtk_calendar_get_date(GTK_CALENDAR(calendar),
96 &(scheduler_ui->year_temp),
97 &(scheduler_ui->month_temp),
98 &(scheduler_ui->day_temp));
100 sched_date[23] = '\0';
101 g_sprintf(sched_date, "%04d %02d %02d (yyyy mm dd)",
102 scheduler_ui->year_temp, scheduler_ui->month_temp + 1,
103 scheduler_ui->day_temp);
105 gtk_button_set_label(GTK_BUTTON(scheduler_ui->date_button),
108 gtk_widget_destroy(scheduler_ui->calendar_dialog);
109 scheduler_ui->calendar_dialog = NULL;
110 scheduler_ui->calendar = NULL;
115 run_calendar_dialog(GtkButton * button, gpointer data)
118 GtkWidget *dialog_vbox;
119 MMythSchedulerUI *scheduler_ui = (MMythSchedulerUI *) data;
121 // calendar_dialog and calendar are been released at
122 // set_date_from_calendar ()
123 scheduler_ui->calendar_dialog = gtk_dialog_new();
124 gtk_container_set_border_width(GTK_CONTAINER
125 (scheduler_ui->calendar_dialog), 1);
126 gtk_window_set_title(GTK_WINDOW(scheduler_ui->calendar_dialog),
127 "Select starting date");
128 gtk_window_set_position(GTK_WINDOW(scheduler_ui->calendar_dialog),
130 gtk_window_set_decorated(GTK_WINDOW(scheduler_ui->calendar_dialog),
133 dialog_vbox = GTK_DIALOG(scheduler_ui->calendar_dialog)->vbox;
135 scheduler_ui->calendar = gtk_calendar_new();
137 gtk_box_pack_start(GTK_BOX(dialog_vbox), scheduler_ui->calendar, TRUE,
139 gtk_calendar_display_options(GTK_CALENDAR(scheduler_ui->calendar),
140 GTK_CALENDAR_SHOW_HEADING |
141 GTK_CALENDAR_SHOW_DAY_NAMES);
143 gtk_widget_show_all(scheduler_ui->calendar_dialog);
145 g_signal_connect(G_OBJECT(scheduler_ui->calendar),
146 "day-selected-double-click",
147 G_CALLBACK(set_date_from_calendar), data);
152 mmyth_schedulerui_save(MMythSchedulerUI * scheduler_ui)
154 GMythScheduler *scheduler;
155 ScheduleInfo *schedule_info;
156 GMythChannelInfo *channel_info;
164 schedule_info = g_new0(ScheduleInfo, 1);
165 if (schedule_info == NULL) {
166 g_warning("Error allocating memory");
170 clist = scheduler_ui->channel_list;
173 gtk_combo_box_get_active(GTK_COMBO_BOX
174 (scheduler_ui->channel_combobox));
177 clist = g_list_nth(clist, index);
180 g_debug("[%s] New schedule: %d", __FUNCTION__, index);
182 g_warning("[%s] Error when adding new schedule", __FUNCTION__);
186 channel_info = clist->data;
189 * initialize schedule_info
191 schedule_info->channel_id = channel_info->channel_ID;
195 gtk_spin_button_get_value(GTK_SPIN_BUTTON
196 (scheduler_ui->hour_spinbutton));
199 gtk_spin_button_get_value(GTK_SPIN_BUTTON
200 (scheduler_ui->min_spinbutton));
203 start_tm.tm_mday = (gint) scheduler_ui->day_temp;
204 start_tm.tm_mon = (gint) scheduler_ui->month_temp;
205 start_tm.tm_year = (gint) scheduler_ui->year_temp - 1900; // years
208 GTimeVal *time_val_local = g_new0(GTimeVal, 1);
209 time_val_local->tv_sec = timelocal(&start_tm);
211 schedule_info->start_time = time_val_local;
212 if (NULL == schedule_info->start_time) {
213 g_warning("timelocal error!\n");
219 gtk_spin_button_get_value(GTK_SPIN_BUTTON
220 (scheduler_ui->duration_spinbutton));
221 schedule_info->end_time = schedule_info->start_time + (duration * 60);
224 * TODO: frequency is not implemented yet
227 gtk_combo_box_get_active(GTK_COMBO_BOX
228 (scheduler_ui->freq_combobox));
230 schedule_info->title = g_string_new("");
231 g_string_printf(schedule_info->title, "%s",
232 gtk_entry_get_text(GTK_ENTRY
233 (scheduler_ui->title_entry)));
236 * FIXME: Architecture change to reuse the scheduler created in the
239 scheduler = gmyth_scheduler_new();
241 gmyth_scheduler_connect(scheduler, scheduler->backend_info);
244 * FIXME: set record_id = -1 to add a new schedule
246 schedule_info->record_id = -1;
247 gmyth_scheduler_add_schedule(scheduler, schedule_info);
249 gmyth_scheduler_disconnect(scheduler);
252 * free allocated memory
254 g_object_unref(scheduler);
255 g_free(schedule_info);
261 add_line(GtkWidget * vbox, const gchar * str)
264 GtkWidget *hbox = gtk_hbox_new(FALSE, 0);
266 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
267 gtk_container_set_border_width(GTK_CONTAINER(hbox), 3);
269 label = gtk_label_new(str);
270 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
271 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
277 add_channel_field(MMythSchedulerUI * scheduler_ui, GtkWidget * vbox)
281 GtkWidget *hbox = add_line(vbox, "Channel: ");
283 combobox = gtk_combo_box_new_text();
285 scheduler_ui->channel_combobox = combobox;
286 gtk_box_pack_start(GTK_BOX(hbox), combobox, FALSE, FALSE, 0);
288 GMythEPG *mmyth_epg = gmyth_epg_new();
289 if (!gmyth_epg_connect(mmyth_epg, scheduler_ui->backend_info)) {
290 // FIXME: Without this list the scheduler UI should not be shown!
291 g_warning("[%s] Error when getting list of channels",
295 if (gmyth_epg_get_channel_list
296 (mmyth_epg, &(scheduler_ui->channel_list)) < 0) {
297 g_debug("[%s] Error while trying to retrieve channel list",
300 GList *clist = scheduler_ui->channel_list;
301 GMythChannelInfo *channel_info;
303 while (clist != NULL) {
304 channel_info = clist->data;
306 gtk_combo_box_append_text(GTK_COMBO_BOX
307 (scheduler_ui->channel_combobox),
308 (channel_info->channel_name->str));
311 gtk_combo_box_set_active(GTK_COMBO_BOX
312 (scheduler_ui->channel_combobox), 0);
317 add_time_field(MMythSchedulerUI * scheduler_ui, GtkWidget * vbox)
320 GtkObject *spinbutton_adj;
321 GtkWidget *hbox = add_line(vbox, "Time: ");
324 struct tm sched_time;
328 if (localtime_r((time_t *) & real_time, &sched_time) == NULL) {
329 g_warning("localtime_r error in mmyth_epg_grid_view!\n");
333 if (sched_time.tm_min > 30) {
334 sched_time.tm_hour = sched_time.tm_hour + 1;
335 sched_time.tm_min = 0;
336 } else if (sched_time.tm_min > 0) {
337 sched_time.tm_min = 30;
340 scheduler_ui->year_temp = (guint) sched_time.tm_year + 1900;
341 scheduler_ui->month_temp = (guint) sched_time.tm_mon;
342 scheduler_ui->day_temp = (guint) sched_time.tm_mday;
346 gtk_adjustment_new(sched_time.tm_hour, 00, 23, 1, 10, 10);
347 scheduler_ui->hour_spinbutton =
348 gtk_spin_button_new(GTK_ADJUSTMENT(spinbutton_adj), 1, 0);
349 gtk_box_pack_start(GTK_BOX(hbox), scheduler_ui->hour_spinbutton, FALSE,
352 label = gtk_label_new((" : "));
353 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
354 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_RIGHT);
355 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
359 gtk_adjustment_new(sched_time.tm_min, 0, 59, 1, 10, 10);
360 scheduler_ui->min_spinbutton =
361 gtk_spin_button_new(GTK_ADJUSTMENT(spinbutton_adj), 1, 0);
362 gtk_box_pack_start(GTK_BOX(hbox), scheduler_ui->min_spinbutton, FALSE,
365 label = gtk_label_new((" (hh:mm)"));
367 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
372 add_date_field(MMythSchedulerUI * scheduler_ui, GtkWidget * vbox)
375 GtkWidget *hbox = add_line(vbox, "Date: ");
377 // sched_date = ctime(&real_time);
378 g_sprintf(sched_date, "%04d %02d %02d (yyyy mm dd)",
379 scheduler_ui->year_temp, scheduler_ui->month_temp + 1,
380 scheduler_ui->day_temp);
381 sched_date[23] = '\0';
383 scheduler_ui->date_button = gtk_button_new_with_label(sched_date);
384 gtk_box_pack_start(GTK_BOX(hbox), scheduler_ui->date_button, FALSE,
386 gtk_button_set_relief(GTK_BUTTON(scheduler_ui->date_button),
389 g_signal_connect(G_OBJECT(scheduler_ui->date_button), "clicked",
390 G_CALLBACK(run_calendar_dialog), scheduler_ui);
395 add_duration_field(MMythSchedulerUI * scheduler_ui, GtkWidget * vbox)
397 GtkWidget *hbox = add_line(vbox, "Duration: ");
399 GtkObject *spinbutton_adj;
401 spinbutton_adj = gtk_adjustment_new(60, 5, 360, 5, 60, 60);
402 scheduler_ui->duration_spinbutton =
403 gtk_spin_button_new(GTK_ADJUSTMENT(spinbutton_adj), 1, 0);
404 gtk_box_pack_start(GTK_BOX(hbox), scheduler_ui->duration_spinbutton,
406 gtk_spin_button_set_numeric(GTK_SPIN_BUTTON
407 (scheduler_ui->duration_spinbutton), TRUE);
409 label = gtk_label_new((" (minutes) "));
410 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
414 add_frequency_field(MMythSchedulerUI * scheduler_ui, GtkWidget * vbox)
417 GtkWidget *hbox = add_line(vbox, "Frequency: ");
419 scheduler_ui->freq_combobox = gtk_combo_box_new_text();
420 gtk_box_pack_start(GTK_BOX(hbox), scheduler_ui->freq_combobox, FALSE,
422 gtk_combo_box_append_text(GTK_COMBO_BOX(scheduler_ui->freq_combobox),
424 gtk_combo_box_append_text(GTK_COMBO_BOX(scheduler_ui->freq_combobox),
426 gtk_combo_box_append_text(GTK_COMBO_BOX(scheduler_ui->freq_combobox),
428 gtk_combo_box_set_active(GTK_COMBO_BOX(scheduler_ui->freq_combobox),
434 add_title_field(MMythSchedulerUI * scheduler_ui, GtkWidget * vbox)
436 GtkWidget *hbox = add_line(vbox, "Title: ");
438 scheduler_ui->title_entry = gtk_entry_new();
439 gtk_box_pack_start(GTK_BOX(hbox), scheduler_ui->title_entry, FALSE,
441 gtk_entry_set_text(GTK_ENTRY(scheduler_ui->title_entry), "(Optional)");