diff options
author | Lars Uebernickel <lars.uebernickel@canonical.com> | 2012-08-24 19:11:33 +0200 |
---|---|---|
committer | Lars Uebernickel <lars.uebernickel@canonical.com> | 2012-08-24 19:11:33 +0200 |
commit | 4376e3e3650b18b421b53f2d441f7e74cabb70f1 (patch) | |
tree | 5c129a15b7409f1df1f4573514cc051e833a01e3 | |
parent | 8c307acb3c043645580c7a613c85fd0a5f019d49 (diff) | |
download | ayatana-indicator-messages-4376e3e3650b18b421b53f2d441f7e74cabb70f1.tar.gz ayatana-indicator-messages-4376e3e3650b18b421b53f2d441f7e74cabb70f1.tar.bz2 ayatana-indicator-messages-4376e3e3650b18b421b53f2d441f7e74cabb70f1.zip |
Make sure the time shown in the menu is always current
-rw-r--r-- | src/im-source-menu-item.c | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/src/im-source-menu-item.c b/src/im-source-menu-item.c index 269c75d..43c0afb 100644 --- a/src/im-source-menu-item.c +++ b/src/im-source-menu-item.c @@ -29,6 +29,9 @@ struct _ImSourceMenuItemPrivate GtkWidget *icon; GtkWidget *label; GtkWidget *detail; + + gint64 time; + guint timer_id; }; enum @@ -144,6 +147,19 @@ im_source_menu_item_time_span_string (gint64 timestamp) } static gboolean +im_source_menu_item_update_time (gpointer data) +{ + ImSourceMenuItem *self = data; + gchar *str; + + str = im_source_menu_item_time_span_string (self->priv->time); + gtk_label_set_text (GTK_LABEL (self->priv->detail), str); + + g_free (str); + return TRUE; +} + +static gboolean im_source_menu_item_set_state (ImSourceMenuItem *self, GVariant *state) { @@ -153,6 +169,12 @@ im_source_menu_item_set_state (ImSourceMenuItem *self, const gchar *str; gchar *detail; + if (priv->timer_id != 0) + { + g_source_remove (priv->timer_id); + priv->timer_id = 0; + } + g_return_val_if_fail (g_variant_is_of_type (state, G_VARIANT_TYPE ("(uxsb)")), FALSE); g_variant_get (state, "(ux&sb)", &count, &time, &str, NULL); @@ -160,7 +182,11 @@ im_source_menu_item_set_state (ImSourceMenuItem *self, if (count != 0) detail = g_strdup_printf ("%d", count); else if (time != 0) - detail = im_source_menu_item_time_span_string (time); + { + priv->time = time; + detail = im_source_menu_item_time_span_string (time); + priv->timer_id = g_timeout_add_seconds (59, im_source_menu_item_update_time, self); + } else if (str != NULL && *str) detail = collapse_whitespace (str); else @@ -275,6 +301,12 @@ im_source_menu_item_dispose (GObject *object) { ImSourceMenuItem *self = IM_SOURCE_MENU_ITEM (object); + if (self->priv->timer_id != 0) + { + g_source_remove (self->priv->timer_id); + self->priv->timer_id = 0; + } + if (self->priv->action_group) im_source_menu_item_set_action_group (self, NULL); |