aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2010-01-05 09:24:36 -0600
committerTed Gould <ted@gould.cx>2010-01-05 09:24:36 -0600
commit1b1e09892912bec1d76d91ae4b7de42f28c186fd (patch)
tree9df76b446bf9a4fb2a9f89edd365d64477748993 /src
parent81c0869a03e3429685eed1a5598e7d0ea6975bcf (diff)
downloadayatana-indicator-datetime-1b1e09892912bec1d76d91ae4b7de42f28c186fd.tar.gz
ayatana-indicator-datetime-1b1e09892912bec1d76d91ae4b7de42f28c186fd.tar.bz2
ayatana-indicator-datetime-1b1e09892912bec1d76d91ae4b7de42f28c186fd.zip
Updating the label with the time
Diffstat (limited to 'src')
-rw-r--r--src/indicator-datetime.c30
1 files changed, 30 insertions, 0 deletions
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 <glib.h>
#include <glib-object.h>
+#include <glib/gi18n.h>
/* Indicator Stuff */
#include <libindicator/indicator.h>
@@ -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));
}