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