[svn r158] Fixes seg fault when getting URI fields.
4 #include <gdk/gdkkeysyms.h>
7 #include "mmyth_epg_grid_view.h"
8 #include "mmyth_epg_grid_widget.h"
13 #define GENRE_UNDEFINED 0
17 #define GENRE_SPORTS 4
18 #define GENRE_CHILDREN 5
20 #define GENRE_CULTURE 7
21 #define GENRE_SOCIAL 8
22 #define GENRE_EDUCATION 9
23 #define GENRE_LEISURE 10
27 /* Function prototypes*/
28 static void update_service_details(MMythEpgGridWidget *object,
29 gpointer arg1, gpointer user_data);
30 static gboolean key_press_epg_grid_view(GtkWidget * widget,
34 static GtkWidget *mmyth_epg_grid_widget = NULL;
36 /* is a GtkEventBox */
37 static GtkWidget *program_details_area = NULL;
38 static GtkWidget *details_main_hbox = NULL;
39 static GtkWidget *details_vbox = NULL;
40 static GtkWidget *details_logo_vbox = NULL;
42 /* update signal callback from MMythEpgGridWidget */
44 update_service_details(MMythEpgGridWidget *object, gpointer arg1, gpointer user_data)
46 g_return_if_fail(arg1 != NULL);
48 EpgGridItem *epg_grid_item = (EpgGridItem *) arg1;
50 gchar sel_prog_desc[100] = "<big><b>";
51 gchar time_buffer[50];
53 /* FIXME: get first content from content_list*/
54 GMythProgramInfo *proginfo = (GMythProgramInfo *) epg_grid_item->proginfo;
57 GString *prog_name = proginfo->title;
58 GString *service_name = proginfo->chanid;
60 if(details_vbox != NULL)
61 gtk_container_remove (GTK_CONTAINER (details_main_hbox), details_vbox);
63 /* update service description */
64 strcat(sel_prog_desc, service_name->str);
65 strcat(sel_prog_desc, "</b></big>");
67 GtkWidget *fst_line_lbl = gtk_label_new(NULL);
68 gtk_misc_set_alignment (GTK_MISC(fst_line_lbl), 0.0, 0.0);
69 gtk_label_set_markup(GTK_LABEL(fst_line_lbl), sel_prog_desc);
73 strcat(sel_prog_desc, "\t");
74 strcat(sel_prog_desc, prog_name->str);
76 struct tm loctime_start, loctime_end;
78 // Convert it to local time representation.
79 /* FIXME: conversion from time to localtime is different
80 in different machines */
81 long int schedule_start_time = proginfo->startts;
82 long int schedule_end_time = proginfo->endts;
84 if (localtime_r(&schedule_start_time, &loctime_start) == NULL) {
85 g_warning ("localtime_r error in mmyth_epg_grid_view!\n");
89 fprintf (stderr, asctime (loctime_start));
92 strftime (time_buffer, 100, " %H:%M - ", &loctime_start);
93 strcat(sel_prog_desc, time_buffer );
95 if (localtime_r(&schedule_end_time, &loctime_end) == NULL) {
96 g_warning ("localtime_r error in mmyth_epg_grid_view!\n");
100 fprintf (stderr, asctime (loctime_end));
103 strftime (time_buffer, 100, "%H:%M\n", &loctime_end);
104 strcat(sel_prog_desc, time_buffer );
106 GtkWidget *snd_line_lbl = gtk_label_new(NULL);
107 gtk_misc_set_alignment (GTK_MISC(snd_line_lbl), 0.0, 0.0);
108 gtk_label_set_markup(GTK_LABEL(snd_line_lbl), sel_prog_desc);
110 // add the current selected program description to the label
111 details_vbox = gtk_vbox_new(FALSE, 0);
112 GtkWidget *fst_line_hbox = gtk_hbox_new(FALSE, 0);
114 gtk_box_pack_start (GTK_BOX (fst_line_hbox),
115 fst_line_lbl, FALSE, FALSE, 6);
116 gtk_box_pack_start (GTK_BOX (details_vbox),
117 fst_line_hbox, FALSE, FALSE, 0);
118 gtk_box_pack_start (GTK_BOX (details_vbox),
119 snd_line_lbl, FALSE, FALSE, 0);
120 gtk_box_pack_start (GTK_BOX (details_main_hbox),
121 details_vbox, FALSE, FALSE, 0);
123 gtk_widget_show_all(details_main_hbox);
127 /* Callback for hardware keys */
129 key_press_epg_grid_view(GtkWidget * widget,
130 GdkEventKey * event, gpointer user_data)
132 MMythEpgGridWidget *mmyth_epg_grid_widget = (MMythEpgGridWidget *) user_data;
134 return mmyth_epg_grid_widget_key_press(mmyth_epg_grid_widget, widget, event);
138 epg_grid_view_new (MMythUi* mmyth_ui)
140 GtkWidget *scrolled_window;
141 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
142 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
143 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
145 gtk_widget_modify_bg(scrolled_window, GTK_STATE_NORMAL, &main_bg_color);
147 GtkWidget *main_vbox = gtk_vbox_new (FALSE, 0);
148 //gtk_container_set_border_width(main_vbox, 4);
150 GtkWidget *details_event_box = gtk_event_box_new();
151 gtk_widget_modify_bg(details_event_box, GTK_STATE_NORMAL, &main_bg_color);
153 program_details_area = gtk_vbox_new (FALSE, 0);
154 gtk_container_add (GTK_CONTAINER (details_event_box),
155 program_details_area);
156 gtk_container_set_border_width(GTK_CONTAINER (program_details_area), 4);
158 details_main_hbox = gtk_hbox_new (FALSE, 10);
160 gtk_box_pack_start (GTK_BOX (program_details_area),
161 details_main_hbox, FALSE, FALSE, 0);
163 details_logo_vbox = gtk_vbox_new (FALSE, 0);
165 GtkWidget *details_desc_vbox = gtk_vbox_new (FALSE, 0);
167 gtk_box_pack_start (GTK_BOX (details_main_hbox),
168 details_desc_vbox, FALSE, FALSE, 0);
169 gtk_box_pack_start (GTK_BOX (details_main_hbox),
170 details_logo_vbox, FALSE, FALSE, 0);
172 gtk_widget_set_size_request (program_details_area, -1, 120);
174 mmyth_epg_grid_widget = mmyth_epg_grid_widget_new();
175 g_signal_connect(mmyth_epg_grid_widget, "selection_updated",
176 G_CALLBACK (update_service_details), NULL);
178 /* select by default the first service */
179 /* depends on mount services */
180 if (MMYTH_EPG_GRID_WIDGET(mmyth_epg_grid_widget)->epg_view_model) {
181 GList *fst_service = (GList *)
182 MMYTH_EPG_GRID_WIDGET(mmyth_epg_grid_widget)->epg_view_model->data;
183 mmyth_epg_grid_widget_update_service(MMYTH_EPG_GRID_WIDGET(mmyth_epg_grid_widget),
187 gtk_box_pack_start (GTK_BOX (main_vbox),
188 details_event_box, FALSE, FALSE, 0);
189 gtk_box_pack_start (GTK_BOX (main_vbox),
190 gtk_hseparator_new(), FALSE, FALSE, 0);
191 gtk_box_pack_start (GTK_BOX (main_vbox),
192 mmyth_epg_grid_widget, FALSE, FALSE, 0);
194 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window),
197 /* Add hardware button listener to application */
198 g_signal_connect(mmyth_ui->main_window, "key_press_event",
199 G_CALLBACK (key_press_epg_grid_view), mmyth_epg_grid_widget);
201 gtk_widget_show_all (scrolled_window);
203 return scrolled_window;
208 mmyth_epg_grid_view_get_selected_schedule()
210 return mmyth_epg_grid_get_selected_schedule
211 (MMYTH_EPG_GRID_WIDGET(mmyth_epg_grid_widget));