maemo-ui/src/mmyth_uicommon.c
author renatofilho
Thu Jun 14 20:40:47 2007 +0100 (2007-06-14)
branchtrunk
changeset 754 cb885ee44618
parent 244 c88244670b08
permissions -rw-r--r--
[svn r760] changed code style to Kernel Normal Form style with tabsize=4
     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, sched_time.tm_sec);
    27 
    28     gtk_label_set_text(GTK_LABEL(label), time_showed->str);
    29 }
    30 
    31 MMythUiCommon  *
    32 mmyth_uicommon_new(GtkWidget * main_widget, const gchar * label1,
    33                    const gchar * label2, const gchar * label3)
    34 {
    35 
    36     MMythUiCommon  *ui_common = g_new0(MMythUiCommon, 1);
    37 
    38     if (!main_widget) {
    39         g_warning("MMythUICommon created with a NULL main widget\n");
    40     }
    41 
    42     ui_common->main_widget = main_widget;
    43 
    44     ui_common->event_box = gtk_event_box_new();
    45 
    46     /*
    47      * Vertical box that divides the control area into two (buttons +
    48      * clock) 
    49      */
    50     ui_common->vbox = gtk_vbox_new(FALSE, 0);   /* spacing */
    51     gtk_container_set_border_width(GTK_CONTAINER(ui_common->vbox), 4);
    52 
    53     gtk_container_add(GTK_CONTAINER(ui_common->event_box),
    54                       ui_common->vbox);
    55     gtk_widget_modify_bg(ui_common->event_box, GTK_STATE_NORMAL,
    56                          &main_bg_color);
    57 
    58     /*
    59      * Vertical box that divides the control area into four 
    60      */
    61     ui_common->button_vbox = gtk_vbox_new(TRUE, 0); /* spacing */
    62 
    63     gtk_container_set_border_width(GTK_CONTAINER(ui_common->button_vbox),
    64                                    0);
    65 
    66     /*
    67      * The button 1 
    68      */
    69     ui_common->button1 = gtk_button_new_with_label(label1);
    70     gtk_widget_modify_bg(ui_common->button1, GTK_STATE_NORMAL,
    71                          &main_bg_color);
    72     gtk_widget_set_size_request(ui_common->button1, BUTTON_WIDTH,
    73                                 BUTTON_HEIGHT);
    74 
    75     /*
    76      * The button 2 
    77      */
    78     ui_common->button2 = gtk_button_new_with_label(label2);
    79     gtk_widget_modify_bg(ui_common->button2, GTK_STATE_NORMAL,
    80                          &main_bg_color);
    81     gtk_widget_set_size_request(ui_common->button2, BUTTON_WIDTH,
    82                                 BUTTON_HEIGHT);
    83 
    84     /*
    85      * The button 3 
    86      */
    87     ui_common->button3 = gtk_button_new_with_label(label3);
    88     gtk_widget_modify_bg(ui_common->button3, GTK_STATE_NORMAL,
    89                          &main_bg_color);
    90     gtk_widget_set_size_request(ui_common->button3, BUTTON_WIDTH,
    91                                 BUTTON_HEIGHT);
    92 
    93     /*
    94      * The clock label 
    95      */
    96     ui_common->label = gtk_label_new("Starting...");
    97     gtk_widget_show(ui_common->label);
    98     ui_common->source_id =
    99         g_timeout_add(500, (GSourceFunc) refresh_time_on_screen,
   100                       ui_common->label);
   101 
   102     /*
   103      * Packing components 
   104      */
   105     gtk_box_pack_start(GTK_BOX(ui_common->vbox),
   106                        ui_common->button_vbox, TRUE, TRUE, 0);
   107 
   108     gtk_box_pack_start(GTK_BOX(ui_common->vbox),
   109                        ui_common->label, FALSE, FALSE, 0);
   110 
   111     gtk_box_pack_start(GTK_BOX(ui_common->button_vbox),
   112                        ui_common->button1, FALSE, FALSE, 0);
   113 
   114     gtk_box_pack_start(GTK_BOX(ui_common->button_vbox),
   115                        ui_common->button2, FALSE, FALSE, 0);
   116 
   117     gtk_box_pack_start(GTK_BOX(ui_common->button_vbox),
   118                        ui_common->button3, FALSE, FALSE, 0);
   119 
   120     gtk_widget_show_all(ui_common->event_box);
   121 
   122     /*
   123      * FIXME: mmyth_ui->video_alignment == NULL when mmyth_player_init
   124      * fails 
   125      */
   126     if (ui_common->main_widget != NULL)
   127         g_object_ref(ui_common->main_widget);
   128 
   129     g_object_ref(ui_common->vbox);
   130     g_object_ref(ui_common->button_vbox);
   131     g_object_ref(ui_common->label);
   132     g_object_ref(ui_common->button1);
   133     g_object_ref(ui_common->button2);
   134     g_object_ref(ui_common->button3);
   135     g_object_ref(ui_common->event_box);
   136     return ui_common;
   137 }
   138 
   139 void
   140 mmyth_uicommon_free(MMythUiCommon * ui_common)
   141 {
   142     g_debug("[%s] Clean uicommon used memory", __FUNCTION__);
   143 
   144     g_source_remove(ui_common->source_id);
   145 
   146     g_object_unref(ui_common->main_widget);
   147     g_object_unref(ui_common->vbox);
   148     g_object_unref(ui_common->button_vbox);
   149     g_object_unref(ui_common->label);
   150     g_object_unref(ui_common->button1);
   151     g_object_unref(ui_common->button2);
   152     g_object_unref(ui_common->button3);
   153     g_object_unref(ui_common->event_box);
   154 
   155     g_free(ui_common);
   156 }