1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/maemo-ui-old/src/mmyth_uicommon.c Wed Aug 01 14:50:29 2007 +0100
1.3 @@ -0,0 +1,156 @@
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;
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, sched_time.tm_sec);
1.30 +
1.31 + gtk_label_set_text(GTK_LABEL(label), time_showed->str);
1.32 +}
1.33 +
1.34 +MMythUiCommon *
1.35 +mmyth_uicommon_new(GtkWidget * main_widget, const gchar * label1,
1.36 + const gchar * label2, const gchar * label3)
1.37 +{
1.38 +
1.39 + MMythUiCommon *ui_common = g_new0(MMythUiCommon, 1);
1.40 +
1.41 + if (!main_widget) {
1.42 + g_warning("MMythUICommon created with a NULL main widget\n");
1.43 + }
1.44 +
1.45 + ui_common->main_widget = main_widget;
1.46 +
1.47 + ui_common->event_box = gtk_event_box_new();
1.48 +
1.49 + /*
1.50 + * Vertical box that divides the control area into two (buttons +
1.51 + * clock)
1.52 + */
1.53 + ui_common->vbox = gtk_vbox_new(FALSE, 0); /* spacing */
1.54 + gtk_container_set_border_width(GTK_CONTAINER(ui_common->vbox), 4);
1.55 +
1.56 + gtk_container_add(GTK_CONTAINER(ui_common->event_box),
1.57 + ui_common->vbox);
1.58 + gtk_widget_modify_bg(ui_common->event_box, GTK_STATE_NORMAL,
1.59 + &main_bg_color);
1.60 +
1.61 + /*
1.62 + * Vertical box that divides the control area into four
1.63 + */
1.64 + ui_common->button_vbox = gtk_vbox_new(TRUE, 0); /* spacing */
1.65 +
1.66 + gtk_container_set_border_width(GTK_CONTAINER(ui_common->button_vbox),
1.67 + 0);
1.68 +
1.69 + /*
1.70 + * The button 1
1.71 + */
1.72 + ui_common->button1 = gtk_button_new_with_label(label1);
1.73 + gtk_widget_modify_bg(ui_common->button1, GTK_STATE_NORMAL,
1.74 + &main_bg_color);
1.75 + gtk_widget_set_size_request(ui_common->button1, BUTTON_WIDTH,
1.76 + BUTTON_HEIGHT);
1.77 +
1.78 + /*
1.79 + * The button 2
1.80 + */
1.81 + ui_common->button2 = gtk_button_new_with_label(label2);
1.82 + gtk_widget_modify_bg(ui_common->button2, GTK_STATE_NORMAL,
1.83 + &main_bg_color);
1.84 + gtk_widget_set_size_request(ui_common->button2, BUTTON_WIDTH,
1.85 + BUTTON_HEIGHT);
1.86 +
1.87 + /*
1.88 + * The button 3
1.89 + */
1.90 + ui_common->button3 = gtk_button_new_with_label(label3);
1.91 + gtk_widget_modify_bg(ui_common->button3, GTK_STATE_NORMAL,
1.92 + &main_bg_color);
1.93 + gtk_widget_set_size_request(ui_common->button3, BUTTON_WIDTH,
1.94 + BUTTON_HEIGHT);
1.95 +
1.96 + /*
1.97 + * The clock label
1.98 + */
1.99 + ui_common->label = gtk_label_new("Starting...");
1.100 + gtk_widget_show(ui_common->label);
1.101 + ui_common->source_id =
1.102 + g_timeout_add(500, (GSourceFunc) refresh_time_on_screen,
1.103 + ui_common->label);
1.104 +
1.105 + /*
1.106 + * Packing components
1.107 + */
1.108 + gtk_box_pack_start(GTK_BOX(ui_common->vbox),
1.109 + ui_common->button_vbox, TRUE, TRUE, 0);
1.110 +
1.111 + gtk_box_pack_start(GTK_BOX(ui_common->vbox),
1.112 + ui_common->label, FALSE, FALSE, 0);
1.113 +
1.114 + gtk_box_pack_start(GTK_BOX(ui_common->button_vbox),
1.115 + ui_common->button1, FALSE, FALSE, 0);
1.116 +
1.117 + gtk_box_pack_start(GTK_BOX(ui_common->button_vbox),
1.118 + ui_common->button2, FALSE, FALSE, 0);
1.119 +
1.120 + gtk_box_pack_start(GTK_BOX(ui_common->button_vbox),
1.121 + ui_common->button3, FALSE, FALSE, 0);
1.122 +
1.123 + gtk_widget_show_all(ui_common->event_box);
1.124 +
1.125 + /*
1.126 + * FIXME: mmyth_ui->video_alignment == NULL when mmyth_player_init
1.127 + * fails
1.128 + */
1.129 + if (ui_common->main_widget != NULL)
1.130 + g_object_ref(ui_common->main_widget);
1.131 +
1.132 + g_object_ref(ui_common->vbox);
1.133 + g_object_ref(ui_common->button_vbox);
1.134 + g_object_ref(ui_common->label);
1.135 + g_object_ref(ui_common->button1);
1.136 + g_object_ref(ui_common->button2);
1.137 + g_object_ref(ui_common->button3);
1.138 + g_object_ref(ui_common->event_box);
1.139 + return ui_common;
1.140 +}
1.141 +
1.142 +void
1.143 +mmyth_uicommon_free(MMythUiCommon * ui_common)
1.144 +{
1.145 + g_debug("[%s] Clean uicommon used memory", __FUNCTION__);
1.146 +
1.147 + g_source_remove(ui_common->source_id);
1.148 +
1.149 + g_object_unref(ui_common->main_widget);
1.150 + g_object_unref(ui_common->vbox);
1.151 + g_object_unref(ui_common->button_vbox);
1.152 + g_object_unref(ui_common->label);
1.153 + g_object_unref(ui_common->button1);
1.154 + g_object_unref(ui_common->button2);
1.155 + g_object_unref(ui_common->button3);
1.156 + g_object_unref(ui_common->event_box);
1.157 +
1.158 + g_free(ui_common);
1.159 +}