From 1b1e09892912bec1d76d91ae4b7de42f28c186fd Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 5 Jan 2010 09:24:36 -0600 Subject: Updating the label with the time --- src/indicator-datetime.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 16a792c..253c86a 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -5,6 +5,7 @@ /* GStuff */ #include #include +#include /* Indicator Stuff */ #include @@ -93,13 +94,42 @@ indicator_datetime_finalize (GObject *object) return; } +static void +update_label (GtkLabel * label) +{ + if (label == NULL) return; + + gchar longstr[128]; + time_t t; + struct tm *ltime; + + t = time(NULL); + ltime = localtime(&t); + if (ltime == NULL) { + g_debug("Error getting local time"); + gtk_label_set_label(label, _("Error getting time")); + return; + } + + strftime(longstr, 128, "%I:%M %p", ltime); + + gchar * utf8 = g_locale_to_utf8(longstr, -1, NULL, NULL, NULL); + gtk_label_set_label(label, utf8); + g_free(utf8); + + return; +} + static GtkLabel * get_label (IndicatorObject * io) { IndicatorDatetime * self = INDICATOR_DATETIME(io); + /* If there's not a label, we'll build ourselves one */ if (self->priv->label == NULL) { self->priv->label = GTK_LABEL(gtk_label_new("Time")); + g_object_ref(G_OBJECT(self->priv->label)); + update_label(self->priv->label); gtk_widget_show(GTK_WIDGET(self->priv->label)); } -- cgit v1.2.3