maemo-ui-old/src/mmyth_epg_grid_view.c
author melunko
Mon Oct 08 19:35:09 2007 +0100 (2007-10-08)
branchtrunk
changeset 860 bb5592a9ac48
parent 754 cb885ee44618
permissions -rw-r--r--
[svn r866] Fixed gst-gmyth Makefile to get source from gstreamer cvs
     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 /*
    11  * Service genre 
    12  */
    13 #define GENRE_MIN               0
    14 #define GENRE_MAX               10
    15 #define GENRE_UNDEFINED         0
    16 #define GENRE_MOVIE             1
    17 #define GENRE_NEWS              2
    18 #define GENRE_SHOW              3
    19 #define GENRE_SPORTS            4
    20 #define GENRE_CHILDREN          5
    21 #define GENRE_MUSIC             6
    22 #define GENRE_CULTURE           7
    23 #define GENRE_SOCIAL            8
    24 #define GENRE_EDUCATION         9
    25 #define GENRE_LEISURE           10
    26 
    27 #define NRO_HOURS 3
    28 
    29 /*
    30  * Function prototypes
    31  */
    32 static void     update_service_details(MMythEpgGridWidget * object,
    33                                        gpointer arg1, gpointer user_data);
    34 static gboolean key_press_epg_grid_view(GtkWidget * widget,
    35                                         GdkEventKey * event,
    36                                         gpointer user_data);
    37 
    38 static GtkWidget *mmyth_epg_grid_widget = NULL;
    39 
    40 /*
    41  * is a GtkEventBox 
    42  */
    43 static GtkWidget *program_details_area = NULL;
    44 static GtkWidget *details_main_hbox = NULL;
    45 static GtkWidget *details_vbox = NULL;
    46 static GtkWidget *details_logo_vbox = NULL;
    47 
    48 /*
    49  * update signal callback from MMythEpgGridWidget 
    50  */
    51 static void
    52 update_service_details(MMythEpgGridWidget * object, gpointer arg1,
    53                        gpointer user_data)
    54 {
    55     g_return_if_fail(arg1 != NULL);
    56 
    57     EpgGridItem    *epg_grid_item = (EpgGridItem *) arg1;
    58 
    59     gchar           sel_prog_desc[100] = "<big><b>";
    60     gchar           time_buffer[50];
    61 
    62     /*
    63      * FIXME: get first content from content_list
    64      */
    65     GMythProgramInfo *proginfo =
    66         (GMythProgramInfo *) epg_grid_item->proginfo;
    67 
    68     if (proginfo) {
    69         GString        *prog_name = proginfo->title;
    70         GString        *service_name = proginfo->chanid;
    71 
    72         if (details_vbox != NULL)
    73             gtk_container_remove(GTK_CONTAINER(details_main_hbox),
    74                                  details_vbox);
    75 
    76         /*
    77          * update service description 
    78          */
    79         strcat(sel_prog_desc, service_name->str);
    80         strcat(sel_prog_desc, "</b></big>");
    81 
    82         GtkWidget      *fst_line_lbl = gtk_label_new(NULL);
    83         gtk_misc_set_alignment(GTK_MISC(fst_line_lbl), 0.0, 0.0);
    84         gtk_label_set_markup(GTK_LABEL(fst_line_lbl), sel_prog_desc);
    85 
    86         /*
    87          * freeing char[] 
    88          */
    89         sel_prog_desc[0] = 0;
    90         strcat(sel_prog_desc, "\t");
    91         strcat(sel_prog_desc, prog_name->str);
    92 
    93         struct tm       loctime_start,
    94                         loctime_end;
    95 
    96         // Convert it to local time representation. 
    97         /*
    98          * FIXME: conversion from time to localtime is different in
    99          * different machines 
   100          */
   101         long int        schedule_start_time = proginfo->startts->tv_sec;
   102         long int        schedule_end_time = proginfo->endts->tv_sec;
   103 
   104         if (localtime_r(&schedule_start_time, &loctime_start) == NULL) {
   105             g_warning("localtime_r error in mmyth_epg_grid_view!\n");
   106         }
   107 #if 0
   108         fprintf(stderr, asctime(loctime_start));
   109 #endif
   110 
   111         strftime(time_buffer, 100, "  %H:%M - ", &loctime_start);
   112         strcat(sel_prog_desc, time_buffer);
   113 
   114         if (localtime_r(&schedule_end_time, &loctime_end) == NULL) {
   115             g_warning("localtime_r error in mmyth_epg_grid_view!\n");
   116         }
   117 #if 0
   118         fprintf(stderr, asctime(loctime_end));
   119 #endif
   120 
   121         strftime(time_buffer, 100, "%H:%M\n", &loctime_end);
   122         strcat(sel_prog_desc, time_buffer);
   123 
   124         GtkWidget      *snd_line_lbl = gtk_label_new(NULL);
   125         gtk_misc_set_alignment(GTK_MISC(snd_line_lbl), 0.0, 0.0);
   126         gtk_label_set_markup(GTK_LABEL(snd_line_lbl), sel_prog_desc);
   127 
   128         // add the current selected program description to the label
   129         details_vbox = gtk_vbox_new(FALSE, 0);
   130         GtkWidget      *fst_line_hbox = gtk_hbox_new(FALSE, 0);
   131 
   132         gtk_box_pack_start(GTK_BOX(fst_line_hbox),
   133                            fst_line_lbl, FALSE, FALSE, 6);
   134         gtk_box_pack_start(GTK_BOX(details_vbox),
   135                            fst_line_hbox, FALSE, FALSE, 0);
   136         gtk_box_pack_start(GTK_BOX(details_vbox),
   137                            snd_line_lbl, FALSE, FALSE, 0);
   138         gtk_box_pack_start(GTK_BOX(details_main_hbox),
   139                            details_vbox, FALSE, FALSE, 0);
   140 
   141         gtk_widget_show_all(details_main_hbox);
   142     }
   143 }
   144 
   145 /*
   146  * Callback for hardware keys 
   147  */
   148 static          gboolean
   149 key_press_epg_grid_view(GtkWidget * widget,
   150                         GdkEventKey * event, gpointer user_data)
   151 {
   152     MMythEpgGridWidget *mmyth_epg_grid_widget =
   153         (MMythEpgGridWidget *) user_data;
   154 
   155     return mmyth_epg_grid_widget_key_press(mmyth_epg_grid_widget, widget,
   156                                            event);
   157 }
   158 
   159 GtkWidget      *
   160 epg_grid_view_new(MMythUi * mmyth_ui)
   161 {
   162     GtkWidget      *scrolled_window;
   163     scrolled_window = gtk_scrolled_window_new(NULL, NULL);
   164     gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
   165                                    GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
   166 
   167     gtk_widget_modify_bg(scrolled_window, GTK_STATE_NORMAL,
   168                          &main_bg_color);
   169 
   170     GtkWidget      *main_vbox = gtk_vbox_new(FALSE, 0);
   171     // gtk_container_set_border_width(main_vbox, 4); 
   172 
   173     GtkWidget      *details_event_box = gtk_event_box_new();
   174     gtk_widget_modify_bg(details_event_box, GTK_STATE_NORMAL,
   175                          &main_bg_color);
   176 
   177     program_details_area = gtk_vbox_new(FALSE, 0);
   178     gtk_container_add(GTK_CONTAINER(details_event_box),
   179                       program_details_area);
   180     gtk_container_set_border_width(GTK_CONTAINER(program_details_area), 4);
   181 
   182     details_main_hbox = gtk_hbox_new(FALSE, 10);
   183 
   184     gtk_box_pack_start(GTK_BOX(program_details_area),
   185                        details_main_hbox, FALSE, FALSE, 0);
   186 
   187     details_logo_vbox = gtk_vbox_new(FALSE, 0);
   188 
   189     GtkWidget      *details_desc_vbox = gtk_vbox_new(FALSE, 0);
   190 
   191     gtk_box_pack_start(GTK_BOX(details_main_hbox),
   192                        details_desc_vbox, FALSE, FALSE, 0);
   193     gtk_box_pack_start(GTK_BOX(details_main_hbox),
   194                        details_logo_vbox, FALSE, FALSE, 0);
   195 
   196     gtk_widget_set_size_request(program_details_area, -1, 120);
   197 
   198     mmyth_epg_grid_widget = mmyth_epg_grid_widget_new();
   199     g_signal_connect(mmyth_epg_grid_widget, "selection_updated",
   200                      G_CALLBACK(update_service_details), NULL);
   201 
   202     /*
   203      * select by default the first service 
   204      */
   205     /*
   206      * depends on mount services 
   207      */
   208     if (MMYTH_EPG_GRID_WIDGET(mmyth_epg_grid_widget)->epg_view_model) {
   209         GList          *fst_service = (GList *)
   210             MMYTH_EPG_GRID_WIDGET(mmyth_epg_grid_widget)->epg_view_model->
   211             data;
   212         mmyth_epg_grid_widget_update_service(MMYTH_EPG_GRID_WIDGET
   213                                              (mmyth_epg_grid_widget),
   214                                              fst_service);
   215     }
   216 
   217     gtk_box_pack_start(GTK_BOX(main_vbox),
   218                        details_event_box, FALSE, FALSE, 0);
   219     gtk_box_pack_start(GTK_BOX(main_vbox),
   220                        gtk_hseparator_new(), FALSE, FALSE, 0);
   221     gtk_box_pack_start(GTK_BOX(main_vbox),
   222                        mmyth_epg_grid_widget, FALSE, FALSE, 0);
   223 
   224     gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW
   225                                           (scrolled_window), main_vbox);
   226 
   227     /*
   228      * Add hardware button listener to application 
   229      */
   230     g_signal_connect(mmyth_ui->main_window, "key_press_event",
   231                      G_CALLBACK(key_press_epg_grid_view),
   232                      mmyth_epg_grid_widget);
   233 
   234     gtk_widget_show_all(scrolled_window);
   235 
   236     return scrolled_window;
   237 }
   238 
   239 /*
   240  * DVBHScheduleEvent * mmyth_epg_grid_view_get_selected_schedule() {
   241  * return mmyth_epg_grid_get_selected_schedule
   242  * (MMYTH_EPG_GRID_WIDGET(mmyth_epg_grid_widget)); } 
   243  */