maemo-ui/src/mmyth_epg_grid_view.c
author rosfran
Tue Oct 17 01:03:06 2006 +0100 (2006-10-17)
branchtrunk
changeset 31 eb4a812d4073
child 244 c88244670b08
permissions -rw-r--r--
[svn r32] Some adjustments on the performance.
     1 #include <string.h>
     2 #include <stdlib.h>
     3 #include <gtk/gtk.h>
     4 #include <gdk/gdkkeysyms.h>
     5 #include <time.h>
     6 
     7 #include "mmyth_epg_grid_view.h"
     8 #include "mmyth_epg_grid_widget.h"
     9 
    10 /* Service genre */
    11 #define GENRE_MIN               0
    12 #define GENRE_MAX               10
    13 #define GENRE_UNDEFINED         0
    14 #define GENRE_MOVIE             1
    15 #define GENRE_NEWS              2
    16 #define GENRE_SHOW              3
    17 #define GENRE_SPORTS            4
    18 #define GENRE_CHILDREN          5
    19 #define GENRE_MUSIC             6
    20 #define GENRE_CULTURE           7
    21 #define GENRE_SOCIAL            8
    22 #define GENRE_EDUCATION         9
    23 #define GENRE_LEISURE           10
    24 
    25 #define NRO_HOURS 3
    26 
    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, 
    31                                         GdkEventKey * event, 
    32                                         gpointer user_data);
    33 
    34 static GtkWidget *mmyth_epg_grid_widget = NULL;
    35 
    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;
    41 
    42 /* update signal callback from MMythEpgGridWidget */
    43 static void
    44 update_service_details(MMythEpgGridWidget *object, gpointer arg1, gpointer user_data) 
    45 {
    46 	g_return_if_fail(arg1 != NULL);
    47 
    48 	EpgGridItem *epg_grid_item = (EpgGridItem *) arg1;
    49 	
    50 	gchar sel_prog_desc[100] = "<big><b>";
    51 	gchar time_buffer[50];
    52 
    53     /* FIXME: get first content from content_list*/
    54     GMythProgramInfo *proginfo = (GMythProgramInfo *) epg_grid_item->proginfo;
    55 
    56     if(proginfo) {
    57         GString *prog_name = proginfo->title;    
    58         GString *service_name = proginfo->chanid;
    59            
    60     	if(details_vbox != NULL)
    61   	        gtk_container_remove (GTK_CONTAINER (details_main_hbox), details_vbox);	
    62     
    63         /* update service description */
    64         strcat(sel_prog_desc, service_name->str);
    65         strcat(sel_prog_desc, "</b></big>");
    66     
    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);     
    70 
    71         /* freeing char[] */
    72         sel_prog_desc[0] = 0;
    73         strcat(sel_prog_desc, "\t");
    74         strcat(sel_prog_desc, prog_name->str);    
    75             	        		
    76         struct tm loctime_start, loctime_end;
    77     
    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;
    83     
    84         if (localtime_r(&schedule_start_time, &loctime_start) == NULL) {
    85             g_warning ("localtime_r error in mmyth_epg_grid_view!\n");
    86         }
    87     
    88         #if 0 
    89             fprintf (stderr, asctime (loctime_start)); 
    90         #endif
    91     
    92         strftime (time_buffer, 100, "  %H:%M - ", &loctime_start);
    93         strcat(sel_prog_desc, time_buffer );
    94     
    95         if (localtime_r(&schedule_end_time, &loctime_end) == NULL) {
    96             g_warning ("localtime_r error in mmyth_epg_grid_view!\n");
    97         }
    98 
    99         #if 0
   100             fprintf (stderr, asctime (loctime_end));     		    
   101         #endif
   102     
   103         strftime (time_buffer, 100, "%H:%M\n", &loctime_end);
   104         strcat(sel_prog_desc, time_buffer );
   105     
   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);     
   109     
   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);        
   113         
   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);
   122         
   123         gtk_widget_show_all(details_main_hbox);
   124     }        
   125 }
   126 
   127 /* Callback for hardware keys */
   128 static gboolean
   129 key_press_epg_grid_view(GtkWidget * widget, 
   130                         GdkEventKey * event, gpointer user_data)
   131 {
   132     MMythEpgGridWidget *mmyth_epg_grid_widget = (MMythEpgGridWidget *) user_data;
   133 
   134     return mmyth_epg_grid_widget_key_press(mmyth_epg_grid_widget, widget, event); 
   135 }
   136 
   137 GtkWidget *
   138 epg_grid_view_new (MMythUi* mmyth_ui) 
   139 {
   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);                   
   144     
   145     gtk_widget_modify_bg(scrolled_window, GTK_STATE_NORMAL, &main_bg_color);  
   146     
   147     GtkWidget *main_vbox = gtk_vbox_new (FALSE, 0);      
   148     //gtk_container_set_border_width(main_vbox, 4);        
   149     
   150     GtkWidget *details_event_box = gtk_event_box_new();               
   151     gtk_widget_modify_bg(details_event_box, GTK_STATE_NORMAL, &main_bg_color);  
   152     
   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);        
   157 
   158 	details_main_hbox = gtk_hbox_new (FALSE, 10);    
   159 
   160 	gtk_box_pack_start (GTK_BOX (program_details_area),
   161 	                    details_main_hbox, FALSE, FALSE, 0);                    
   162 	                    
   163 	details_logo_vbox = gtk_vbox_new (FALSE, 0);      	 
   164     
   165 	GtkWidget *details_desc_vbox = gtk_vbox_new (FALSE, 0);      
   166 
   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);                    	
   171 	
   172     gtk_widget_set_size_request (program_details_area, -1, 120);          
   173     
   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);    
   177 
   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),
   184                                          fst_service);
   185     }
   186     
   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);                    
   193 
   194     gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window),
   195                                            main_vbox);    
   196     
   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);    
   200 
   201     gtk_widget_show_all (scrolled_window);
   202     
   203     return scrolled_window;
   204 }
   205 
   206 /*
   207 DVBHScheduleEvent * 
   208 mmyth_epg_grid_view_get_selected_schedule()
   209 {
   210     return mmyth_epg_grid_get_selected_schedule
   211             (MMYTH_EPG_GRID_WIDGET(mmyth_epg_grid_widget));
   212 }
   213 */