maemo-ui/src/mmyth_epg_grid_view.c
branchtrunk
changeset 31 eb4a812d4073
child 244 c88244670b08
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/maemo-ui/src/mmyth_epg_grid_view.c	Tue Oct 17 01:03:06 2006 +0100
     1.3 @@ -0,0 +1,213 @@
     1.4 +#include <string.h>
     1.5 +#include <stdlib.h>
     1.6 +#include <gtk/gtk.h>
     1.7 +#include <gdk/gdkkeysyms.h>
     1.8 +#include <time.h>
     1.9 +
    1.10 +#include "mmyth_epg_grid_view.h"
    1.11 +#include "mmyth_epg_grid_widget.h"
    1.12 +
    1.13 +/* Service genre */
    1.14 +#define GENRE_MIN               0
    1.15 +#define GENRE_MAX               10
    1.16 +#define GENRE_UNDEFINED         0
    1.17 +#define GENRE_MOVIE             1
    1.18 +#define GENRE_NEWS              2
    1.19 +#define GENRE_SHOW              3
    1.20 +#define GENRE_SPORTS            4
    1.21 +#define GENRE_CHILDREN          5
    1.22 +#define GENRE_MUSIC             6
    1.23 +#define GENRE_CULTURE           7
    1.24 +#define GENRE_SOCIAL            8
    1.25 +#define GENRE_EDUCATION         9
    1.26 +#define GENRE_LEISURE           10
    1.27 +
    1.28 +#define NRO_HOURS 3
    1.29 +
    1.30 +/* Function prototypes*/
    1.31 +static void update_service_details(MMythEpgGridWidget *object, 
    1.32 +                                   gpointer arg1, gpointer user_data);
    1.33 +static gboolean key_press_epg_grid_view(GtkWidget * widget, 
    1.34 +                                        GdkEventKey * event, 
    1.35 +                                        gpointer user_data);
    1.36 +
    1.37 +static GtkWidget *mmyth_epg_grid_widget = NULL;
    1.38 +
    1.39 +/* is a GtkEventBox */
    1.40 +static GtkWidget *program_details_area = NULL;
    1.41 +static GtkWidget *details_main_hbox = NULL;
    1.42 +static GtkWidget *details_vbox = NULL;
    1.43 +static GtkWidget *details_logo_vbox = NULL;
    1.44 +
    1.45 +/* update signal callback from MMythEpgGridWidget */
    1.46 +static void
    1.47 +update_service_details(MMythEpgGridWidget *object, gpointer arg1, gpointer user_data) 
    1.48 +{
    1.49 +	g_return_if_fail(arg1 != NULL);
    1.50 +
    1.51 +	EpgGridItem *epg_grid_item = (EpgGridItem *) arg1;
    1.52 +	
    1.53 +	gchar sel_prog_desc[100] = "<big><b>";
    1.54 +	gchar time_buffer[50];
    1.55 +
    1.56 +    /* FIXME: get first content from content_list*/
    1.57 +    GMythProgramInfo *proginfo = (GMythProgramInfo *) epg_grid_item->proginfo;
    1.58 +
    1.59 +    if(proginfo) {
    1.60 +        GString *prog_name = proginfo->title;    
    1.61 +        GString *service_name = proginfo->chanid;
    1.62 +           
    1.63 +    	if(details_vbox != NULL)
    1.64 +  	        gtk_container_remove (GTK_CONTAINER (details_main_hbox), details_vbox);	
    1.65 +    
    1.66 +        /* update service description */
    1.67 +        strcat(sel_prog_desc, service_name->str);
    1.68 +        strcat(sel_prog_desc, "</b></big>");
    1.69 +    
    1.70 +        GtkWidget *fst_line_lbl = gtk_label_new(NULL);
    1.71 +        gtk_misc_set_alignment (GTK_MISC(fst_line_lbl), 0.0, 0.0); 
    1.72 +        gtk_label_set_markup(GTK_LABEL(fst_line_lbl), sel_prog_desc);     
    1.73 +
    1.74 +        /* freeing char[] */
    1.75 +        sel_prog_desc[0] = 0;
    1.76 +        strcat(sel_prog_desc, "\t");
    1.77 +        strcat(sel_prog_desc, prog_name->str);    
    1.78 +            	        		
    1.79 +        struct tm loctime_start, loctime_end;
    1.80 +    
    1.81 +        // Convert it to local time representation. 
    1.82 +        /* FIXME: conversion from time to localtime is different
    1.83 +        in different machines */
    1.84 +        long int schedule_start_time = proginfo->startts;
    1.85 +        long int schedule_end_time   = proginfo->endts;
    1.86 +    
    1.87 +        if (localtime_r(&schedule_start_time, &loctime_start) == NULL) {
    1.88 +            g_warning ("localtime_r error in mmyth_epg_grid_view!\n");
    1.89 +        }
    1.90 +    
    1.91 +        #if 0 
    1.92 +            fprintf (stderr, asctime (loctime_start)); 
    1.93 +        #endif
    1.94 +    
    1.95 +        strftime (time_buffer, 100, "  %H:%M - ", &loctime_start);
    1.96 +        strcat(sel_prog_desc, time_buffer );
    1.97 +    
    1.98 +        if (localtime_r(&schedule_end_time, &loctime_end) == NULL) {
    1.99 +            g_warning ("localtime_r error in mmyth_epg_grid_view!\n");
   1.100 +        }
   1.101 +
   1.102 +        #if 0
   1.103 +            fprintf (stderr, asctime (loctime_end));     		    
   1.104 +        #endif
   1.105 +    
   1.106 +        strftime (time_buffer, 100, "%H:%M\n", &loctime_end);
   1.107 +        strcat(sel_prog_desc, time_buffer );
   1.108 +    
   1.109 +        GtkWidget *snd_line_lbl = gtk_label_new(NULL);
   1.110 +        gtk_misc_set_alignment (GTK_MISC(snd_line_lbl), 0.0, 0.0); 
   1.111 +        gtk_label_set_markup(GTK_LABEL(snd_line_lbl), sel_prog_desc);     
   1.112 +    
   1.113 +        // add the current selected program description to the label
   1.114 +        details_vbox = gtk_vbox_new(FALSE, 0);
   1.115 +        GtkWidget *fst_line_hbox = gtk_hbox_new(FALSE, 0);        
   1.116 +        
   1.117 +        gtk_box_pack_start (GTK_BOX (fst_line_hbox),
   1.118 +                            fst_line_lbl, FALSE, FALSE, 6);
   1.119 +        gtk_box_pack_start (GTK_BOX (details_vbox),
   1.120 +                            fst_line_hbox, FALSE, FALSE, 0);
   1.121 +        gtk_box_pack_start (GTK_BOX (details_vbox),
   1.122 +                            snd_line_lbl, FALSE, FALSE, 0);
   1.123 +        gtk_box_pack_start (GTK_BOX (details_main_hbox),
   1.124 +                            details_vbox, FALSE, FALSE, 0);
   1.125 +        
   1.126 +        gtk_widget_show_all(details_main_hbox);
   1.127 +    }        
   1.128 +}
   1.129 +
   1.130 +/* Callback for hardware keys */
   1.131 +static gboolean
   1.132 +key_press_epg_grid_view(GtkWidget * widget, 
   1.133 +                        GdkEventKey * event, gpointer user_data)
   1.134 +{
   1.135 +    MMythEpgGridWidget *mmyth_epg_grid_widget = (MMythEpgGridWidget *) user_data;
   1.136 +
   1.137 +    return mmyth_epg_grid_widget_key_press(mmyth_epg_grid_widget, widget, event); 
   1.138 +}
   1.139 +
   1.140 +GtkWidget *
   1.141 +epg_grid_view_new (MMythUi* mmyth_ui) 
   1.142 +{
   1.143 +    GtkWidget *scrolled_window;
   1.144 +    scrolled_window = gtk_scrolled_window_new (NULL, NULL);
   1.145 +    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
   1.146 +                                    GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);                   
   1.147 +    
   1.148 +    gtk_widget_modify_bg(scrolled_window, GTK_STATE_NORMAL, &main_bg_color);  
   1.149 +    
   1.150 +    GtkWidget *main_vbox = gtk_vbox_new (FALSE, 0);      
   1.151 +    //gtk_container_set_border_width(main_vbox, 4);        
   1.152 +    
   1.153 +    GtkWidget *details_event_box = gtk_event_box_new();               
   1.154 +    gtk_widget_modify_bg(details_event_box, GTK_STATE_NORMAL, &main_bg_color);  
   1.155 +    
   1.156 +    program_details_area = gtk_vbox_new (FALSE, 0);
   1.157 +    gtk_container_add (GTK_CONTAINER (details_event_box),
   1.158 +                       program_details_area);   
   1.159 +    gtk_container_set_border_width(GTK_CONTAINER (program_details_area), 4);        
   1.160 +
   1.161 +	details_main_hbox = gtk_hbox_new (FALSE, 10);    
   1.162 +
   1.163 +	gtk_box_pack_start (GTK_BOX (program_details_area),
   1.164 +	                    details_main_hbox, FALSE, FALSE, 0);                    
   1.165 +	                    
   1.166 +	details_logo_vbox = gtk_vbox_new (FALSE, 0);      	 
   1.167 +    
   1.168 +	GtkWidget *details_desc_vbox = gtk_vbox_new (FALSE, 0);      
   1.169 +
   1.170 +    gtk_box_pack_start (GTK_BOX (details_main_hbox),
   1.171 +	                    details_desc_vbox, FALSE, FALSE, 0);                    
   1.172 +    gtk_box_pack_start (GTK_BOX (details_main_hbox),
   1.173 +	                    details_logo_vbox, FALSE, FALSE, 0);                    	
   1.174 +	
   1.175 +    gtk_widget_set_size_request (program_details_area, -1, 120);          
   1.176 +    
   1.177 +    mmyth_epg_grid_widget = mmyth_epg_grid_widget_new();
   1.178 +    g_signal_connect(mmyth_epg_grid_widget, "selection_updated", 
   1.179 +                     G_CALLBACK (update_service_details), NULL);    
   1.180 +
   1.181 +    /* select by default the first service */
   1.182 +    /* depends on mount services */
   1.183 +    if (MMYTH_EPG_GRID_WIDGET(mmyth_epg_grid_widget)->epg_view_model) {
   1.184 +	    GList *fst_service = (GList *) 
   1.185 +	    	MMYTH_EPG_GRID_WIDGET(mmyth_epg_grid_widget)->epg_view_model->data;
   1.186 +    	mmyth_epg_grid_widget_update_service(MMYTH_EPG_GRID_WIDGET(mmyth_epg_grid_widget),
   1.187 +                                         fst_service);
   1.188 +    }
   1.189 +    
   1.190 +    gtk_box_pack_start (GTK_BOX (main_vbox),
   1.191 +                        details_event_box, FALSE, FALSE, 0); 
   1.192 +    gtk_box_pack_start (GTK_BOX (main_vbox),
   1.193 +                        gtk_hseparator_new(), FALSE, FALSE, 0);         
   1.194 +    gtk_box_pack_start (GTK_BOX (main_vbox),
   1.195 +                        mmyth_epg_grid_widget, FALSE, FALSE, 0);                    
   1.196 +
   1.197 +    gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window),
   1.198 +                                           main_vbox);    
   1.199 +    
   1.200 +    /* Add hardware button listener to application */
   1.201 +    g_signal_connect(mmyth_ui->main_window, "key_press_event", 
   1.202 +                     G_CALLBACK (key_press_epg_grid_view), mmyth_epg_grid_widget);    
   1.203 +
   1.204 +    gtk_widget_show_all (scrolled_window);
   1.205 +    
   1.206 +    return scrolled_window;
   1.207 +}
   1.208 +
   1.209 +/*
   1.210 +DVBHScheduleEvent * 
   1.211 +mmyth_epg_grid_view_get_selected_schedule()
   1.212 +{
   1.213 +    return mmyth_epg_grid_get_selected_schedule
   1.214 +            (MMYTH_EPG_GRID_WIDGET(mmyth_epg_grid_widget));
   1.215 +}
   1.216 +*/