maemo-ui/src/mmyth_uicommon.c
branchtrunk
changeset 78 ac7e49c234d8
child 244 c88244670b08
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/maemo-ui/src/mmyth_uicommon.c	Fri Nov 10 19:35:39 2006 +0000
     1.3 @@ -0,0 +1,134 @@
     1.4 +
     1.5 +#include <gtk/gtk.h>
     1.6 +#include <glib.h>
     1.7 +#include <glib/gprintf.h>
     1.8 +
     1.9 +#include "mmyth_uicommon.h"
    1.10 +#include "mmyth_ui.h"
    1.11 +
    1.12 +static void
    1.13 +refresh_time_on_screen (GtkWidget *label)
    1.14 +{
    1.15 +	time_t real_time;
    1.16 +  	struct tm sched_time;
    1.17 +	GString *time_showed;
    1.18 +
    1.19 +	time_showed = g_string_new("");
    1.20 +	time(&real_time);
    1.21 +
    1.22 +    if (localtime_r((time_t *)&real_time, &sched_time) == NULL) {
    1.23 +        g_error ("localtime_r error in mmyth_epg_grid_view!\n");
    1.24 +        return NULL;
    1.25 +    }
    1.26 +
    1.27 +	g_string_printf(time_showed, "%d:%02d:%02d", 
    1.28 +		sched_time.tm_hour, 
    1.29 +		sched_time.tm_min, 
    1.30 +		sched_time.tm_sec);
    1.31 +
    1.32 +	gtk_label_set_text (GTK_LABEL(label), time_showed->str);
    1.33 +}
    1.34 +
    1.35 +MMythUiCommon *
    1.36 +mmyth_uicommon_new (GtkWidget * main_widget, const gchar * label1,
    1.37 +                    const gchar * label2, const gchar * label3)
    1.38 +{
    1.39 +
    1.40 +    MMythUiCommon *ui_common = g_new0 (MMythUiCommon, 1); 
    1.41 +    
    1.42 +    if (!main_widget) {
    1.43 +    	g_warning ("MMythUICommon created with a NULL main widget\n");
    1.44 +    }
    1.45 +    
    1.46 +    ui_common->main_widget = main_widget;
    1.47 +
    1.48 +    ui_common->event_box = gtk_event_box_new();
    1.49 +    
    1.50 +    /* Vertical box that divides the control area into two (buttons + clock) */
    1.51 +    ui_common->vbox = gtk_vbox_new (FALSE, 0);  /* spacing */
    1.52 +    gtk_container_set_border_width(GTK_CONTAINER (ui_common->vbox), 4);
    1.53 +    
    1.54 +    gtk_container_add (GTK_CONTAINER (ui_common->event_box),
    1.55 +                       ui_common->vbox);
    1.56 +    gtk_widget_modify_bg(ui_common->event_box, GTK_STATE_NORMAL, &main_bg_color);  
    1.57 +    
    1.58 +    /* Vertical box that divides the control area into four */
    1.59 +    ui_common->button_vbox = gtk_vbox_new (TRUE, 0);    /* spacing */
    1.60 +
    1.61 +    gtk_container_set_border_width (GTK_CONTAINER (ui_common->button_vbox), 0);
    1.62 +
    1.63 +    /* The button 1 */
    1.64 +    ui_common->button1 = gtk_button_new_with_label (label1);
    1.65 +    gtk_widget_modify_bg(ui_common->button1, GTK_STATE_NORMAL, &main_bg_color);  
    1.66 +    gtk_widget_set_size_request (ui_common->button1, BUTTON_WIDTH,
    1.67 +                                 BUTTON_HEIGHT);
    1.68 +
    1.69 +    /* The button 2 */
    1.70 +    ui_common->button2 = gtk_button_new_with_label (label2);
    1.71 +    gtk_widget_modify_bg(ui_common->button2, GTK_STATE_NORMAL, &main_bg_color);  
    1.72 +    gtk_widget_set_size_request (ui_common->button2, BUTTON_WIDTH,
    1.73 +                                 BUTTON_HEIGHT);
    1.74 +
    1.75 +    /* The button 3 */
    1.76 +    ui_common->button3 = gtk_button_new_with_label (label3);
    1.77 +    gtk_widget_modify_bg(ui_common->button3, GTK_STATE_NORMAL, &main_bg_color);  
    1.78 +    gtk_widget_set_size_request (ui_common->button3, BUTTON_WIDTH,
    1.79 +                                 BUTTON_HEIGHT);
    1.80 +
    1.81 +    /* The clock label */
    1.82 +    ui_common->label = gtk_label_new ("Starting...");
    1.83 +    gtk_widget_show (ui_common->label);
    1.84 +    ui_common->source_id = g_timeout_add(500, (GSourceFunc) refresh_time_on_screen, ui_common->label);
    1.85 +
    1.86 +    /* Packing components */
    1.87 +    gtk_box_pack_start (GTK_BOX (ui_common->vbox),
    1.88 +                        ui_common->button_vbox, TRUE, TRUE, 0);
    1.89 +
    1.90 +    gtk_box_pack_start (GTK_BOX (ui_common->vbox),
    1.91 +                        ui_common->label, FALSE, FALSE, 0);
    1.92 +
    1.93 +    gtk_box_pack_start (GTK_BOX (ui_common->button_vbox),
    1.94 +                        ui_common->button1, FALSE, FALSE, 0);
    1.95 +
    1.96 +    gtk_box_pack_start (GTK_BOX (ui_common->button_vbox),
    1.97 +                        ui_common->button2, FALSE, FALSE, 0);
    1.98 +
    1.99 +    gtk_box_pack_start (GTK_BOX (ui_common->button_vbox),
   1.100 +                        ui_common->button3, FALSE, FALSE, 0);
   1.101 +
   1.102 +    gtk_widget_show_all (ui_common->event_box);
   1.103 +
   1.104 +    /* FIXME: mmyth_ui->video_alignment == NULL when mmyth_player_init fails */
   1.105 +    if(ui_common->main_widget != NULL)
   1.106 +        g_object_ref (ui_common->main_widget);
   1.107 +        
   1.108 +    g_object_ref (ui_common->vbox);
   1.109 +    g_object_ref (ui_common->button_vbox);
   1.110 +    g_object_ref (ui_common->label);
   1.111 +    g_object_ref (ui_common->button1);
   1.112 +    g_object_ref (ui_common->button2);
   1.113 +    g_object_ref (ui_common->button3);
   1.114 +    g_object_ref (ui_common->event_box);
   1.115 +    return ui_common;
   1.116 +}
   1.117 +
   1.118 +void
   1.119 +mmyth_uicommon_free (MMythUiCommon *ui_common)
   1.120 +{
   1.121 +	g_debug ("[%s] Clean uicommon used memory", __FUNCTION__);
   1.122 +
   1.123 +    g_source_remove (ui_common->source_id);
   1.124 +    	
   1.125 +    g_object_unref (ui_common->main_widget);
   1.126 +    g_object_unref (ui_common->vbox);
   1.127 +    g_object_unref (ui_common->button_vbox);
   1.128 +    g_object_unref (ui_common->label);
   1.129 +    g_object_unref (ui_common->button1);
   1.130 +    g_object_unref (ui_common->button2);
   1.131 +    g_object_unref (ui_common->button3);
   1.132 +    g_object_unref (ui_common->event_box);    
   1.133 +    
   1.134 +    g_free (ui_common);
   1.135 +}
   1.136 +
   1.137 +