maemo-ui/src/mmyth_uicommon.c
author rosfran
Wed Feb 07 19:15:48 2007 +0000 (2007-02-07)
branchtrunk
changeset 332 be533d944ceb
parent 20 7174e23f7617
child 754 cb885ee44618
permissions -rw-r--r--
[svn r334] Put all the gmyth recorder and tvchain inseide get_file_info; removed reference to LiveTV.
     1 
     2 #include <gtk/gtk.h>
     3 #include <glib.h>
     4 #include <glib/gprintf.h>
     5 
     6 #include "mmyth_uicommon.h"
     7 #include "mmyth_ui.h"
     8 
     9 static void
    10 refresh_time_on_screen (GtkWidget *label)
    11 {
    12 	time_t real_time;
    13   	struct tm sched_time;
    14 	GString *time_showed;
    15 
    16 	time_showed = g_string_new("");
    17 	time(&real_time);
    18 
    19     if (localtime_r((time_t *)&real_time, &sched_time) == NULL) {
    20         g_error ("localtime_r error in mmyth_epg_grid_view!\n");
    21         return;
    22     }
    23 
    24 	g_string_printf(time_showed, "%d:%02d:%02d", 
    25 		sched_time.tm_hour, 
    26 		sched_time.tm_min, 
    27 		sched_time.tm_sec);
    28 
    29 	gtk_label_set_text (GTK_LABEL(label), time_showed->str);
    30 }
    31 
    32 MMythUiCommon *
    33 mmyth_uicommon_new (GtkWidget * main_widget, const gchar * label1,
    34                     const gchar * label2, const gchar * label3)
    35 {
    36 
    37     MMythUiCommon *ui_common = g_new0 (MMythUiCommon, 1); 
    38     
    39     if (!main_widget) {
    40     	g_warning ("MMythUICommon created with a NULL main widget\n");
    41     }
    42     
    43     ui_common->main_widget = main_widget;
    44 
    45     ui_common->event_box = gtk_event_box_new();
    46     
    47     /* Vertical box that divides the control area into two (buttons + clock) */
    48     ui_common->vbox = gtk_vbox_new (FALSE, 0);  /* spacing */
    49     gtk_container_set_border_width(GTK_CONTAINER (ui_common->vbox), 4);
    50     
    51     gtk_container_add (GTK_CONTAINER (ui_common->event_box),
    52                        ui_common->vbox);
    53     gtk_widget_modify_bg(ui_common->event_box, GTK_STATE_NORMAL, &main_bg_color);  
    54     
    55     /* Vertical box that divides the control area into four */
    56     ui_common->button_vbox = gtk_vbox_new (TRUE, 0);    /* spacing */
    57 
    58     gtk_container_set_border_width (GTK_CONTAINER (ui_common->button_vbox), 0);
    59 
    60     /* The button 1 */
    61     ui_common->button1 = gtk_button_new_with_label (label1);
    62     gtk_widget_modify_bg(ui_common->button1, GTK_STATE_NORMAL, &main_bg_color);  
    63     gtk_widget_set_size_request (ui_common->button1, BUTTON_WIDTH,
    64                                  BUTTON_HEIGHT);
    65 
    66     /* The button 2 */
    67     ui_common->button2 = gtk_button_new_with_label (label2);
    68     gtk_widget_modify_bg(ui_common->button2, GTK_STATE_NORMAL, &main_bg_color);  
    69     gtk_widget_set_size_request (ui_common->button2, BUTTON_WIDTH,
    70                                  BUTTON_HEIGHT);
    71 
    72     /* The button 3 */
    73     ui_common->button3 = gtk_button_new_with_label (label3);
    74     gtk_widget_modify_bg(ui_common->button3, GTK_STATE_NORMAL, &main_bg_color);  
    75     gtk_widget_set_size_request (ui_common->button3, BUTTON_WIDTH,
    76                                  BUTTON_HEIGHT);
    77 
    78     /* The clock label */
    79     ui_common->label = gtk_label_new ("Starting...");
    80     gtk_widget_show (ui_common->label);
    81     ui_common->source_id = g_timeout_add(500, (GSourceFunc) refresh_time_on_screen, ui_common->label);
    82 
    83     /* Packing components */
    84     gtk_box_pack_start (GTK_BOX (ui_common->vbox),
    85                         ui_common->button_vbox, TRUE, TRUE, 0);
    86 
    87     gtk_box_pack_start (GTK_BOX (ui_common->vbox),
    88                         ui_common->label, FALSE, FALSE, 0);
    89 
    90     gtk_box_pack_start (GTK_BOX (ui_common->button_vbox),
    91                         ui_common->button1, FALSE, FALSE, 0);
    92 
    93     gtk_box_pack_start (GTK_BOX (ui_common->button_vbox),
    94                         ui_common->button2, FALSE, FALSE, 0);
    95 
    96     gtk_box_pack_start (GTK_BOX (ui_common->button_vbox),
    97                         ui_common->button3, FALSE, FALSE, 0);
    98 
    99     gtk_widget_show_all (ui_common->event_box);
   100 
   101     /* FIXME: mmyth_ui->video_alignment == NULL when mmyth_player_init fails */
   102     if(ui_common->main_widget != NULL)
   103         g_object_ref (ui_common->main_widget);
   104         
   105     g_object_ref (ui_common->vbox);
   106     g_object_ref (ui_common->button_vbox);
   107     g_object_ref (ui_common->label);
   108     g_object_ref (ui_common->button1);
   109     g_object_ref (ui_common->button2);
   110     g_object_ref (ui_common->button3);
   111     g_object_ref (ui_common->event_box);
   112     return ui_common;
   113 }
   114 
   115 void
   116 mmyth_uicommon_free (MMythUiCommon *ui_common)
   117 {
   118 	g_debug ("[%s] Clean uicommon used memory", __FUNCTION__);
   119 
   120     g_source_remove (ui_common->source_id);
   121     	
   122     g_object_unref (ui_common->main_widget);
   123     g_object_unref (ui_common->vbox);
   124     g_object_unref (ui_common->button_vbox);
   125     g_object_unref (ui_common->label);
   126     g_object_unref (ui_common->button1);
   127     g_object_unref (ui_common->button2);
   128     g_object_unref (ui_common->button3);
   129     g_object_unref (ui_common->event_box);    
   130     
   131     g_free (ui_common);
   132 }
   133 
   134