diff options
author | Pierre-Luc Beaudoin <pierre-luc@pierlux.com> | 2009-05-27 03:38:32 +0800 |
---|---|---|
committer | Pierre-Luc Beaudoin <pierre-luc@pierlux.com> | 2009-05-28 00:52:09 +0800 |
commit | c40737394bff5c27daea7e4ee08f240224475904 (patch) | |
tree | 23b00052be64cd0601148b67c41a59e96e44648b | |
parent | c734c5e2451582a52596e44f96e617ee346b6598 (diff) | |
download | gsoc2013-empathy-c40737394bff5c27daea7e4ee08f240224475904.tar gsoc2013-empathy-c40737394bff5c27daea7e4ee08f240224475904.tar.gz gsoc2013-empathy-c40737394bff5c27daea7e4ee08f240224475904.tar.bz2 gsoc2013-empathy-c40737394bff5c27daea7e4ee08f240224475904.tar.lz gsoc2013-empathy-c40737394bff5c27daea7e4ee08f240224475904.tar.xz gsoc2013-empathy-c40737394bff5c27daea7e4ee08f240224475904.tar.zst gsoc2013-empathy-c40737394bff5c27daea7e4ee08f240224475904.zip |
Display relative time to user
The time of the geolocation update is displayed relatively to
current time (1 min ago, 3 hours ago).
The function just prints ("in the future") for debugging purpuses
for time in the future.
-rw-r--r-- | libempathy-gtk/empathy-contact-widget.c | 13 | ||||
-rw-r--r-- | libempathy/empathy-time.c | 41 | ||||
-rw-r--r-- | libempathy/empathy-time.h | 1 | ||||
-rw-r--r-- | src/empathy-map-view.c | 19 |
4 files changed, 69 insertions, 5 deletions
diff --git a/libempathy-gtk/empathy-contact-widget.c b/libempathy-gtk/empathy-contact-widget.c index 22f274640..226c5cb90 100644 --- a/libempathy-gtk/empathy-contact-widget.c +++ b/libempathy-gtk/empathy-contact-widget.c @@ -1340,9 +1340,9 @@ contact_widget_location_update (EmpathyContactWidget *information) stamp = g_value_get_int64 (value); time = stamp; - user_date = empathy_time_to_string_local (time, _("%B %e, %Y at %R")); + user_date = empathy_time_to_string_relative (time); - text = g_strconcat ( _("<b>Location</b> on "), user_date, NULL); + text = g_strconcat ( _("<b>Location</b>, "), user_date, NULL); gtk_label_set_markup (GTK_LABEL (information->label_location), text); g_free (text); } @@ -1367,8 +1367,6 @@ contact_widget_location_update (EmpathyContactWidget *information) char *svalue = NULL; skey = (const gchar *) key; - if (tp_strdiff (skey, EMPATHY_LOCATION_TIMESTAMP) == FALSE) - continue; user_label = location_key_to_label (skey); gvalue = (GValue *) pvalue; @@ -1389,6 +1387,13 @@ contact_widget_location_update (EmpathyContactWidget *information) { svalue = g_value_dup_string (gvalue); } + else if (G_VALUE_TYPE (gvalue) == G_TYPE_INT64) + { + time_t time; + + time = g_value_get_int64 (value); + svalue = empathy_time_to_string_utc (time, _("%B %e, %Y at %R UTC")); + } if (svalue != NULL) { diff --git a/libempathy/empathy-time.c b/libempathy/empathy-time.c index 15b5c30a4..a482f4dc3 100644 --- a/libempathy/empathy-time.c +++ b/libempathy/empathy-time.c @@ -25,6 +25,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <glib/gi18n.h> #include "empathy-time.h" @@ -122,3 +123,43 @@ empathy_time_to_string_local (time_t t, return g_strdup (stamp); } +gchar * +empathy_time_to_string_relative (time_t then) +{ + time_t now; + gint seconds; + + now = time (NULL); + seconds = now - then; + + if (seconds > 0) { + if (seconds < 60) { + seconds /= 60; + return g_strdup_printf (ngettext ("%d second ago", + "%d seconds ago", seconds), seconds); + } + else if (seconds < (60 * 60)) { + seconds /= 60; + return g_strdup_printf (ngettext ("%d minute ago", + "%d minutes ago", seconds), seconds); + } + else if (seconds < (60 * 60 * 24)) { + seconds /= 60 * 60; + return g_strdup_printf (ngettext ("%d hour ago", + "%d hours ago", seconds), seconds); + } + else if (seconds < (60 * 60 * 24 * 7)) { + seconds /= 60 * 60 * 24; + return g_strdup_printf (ngettext ("%d day ago", + "%d days ago", seconds), seconds); + } + else { + seconds /= 60 * 60 * 24 * 30; + return g_strdup_printf (ngettext ("%d month ago", + "%d months ago", seconds), seconds); + } + } + else { + return g_strdup ("in the future"); + } +} diff --git a/libempathy/empathy-time.h b/libempathy/empathy-time.h index a6737386c..2875d2f9f 100644 --- a/libempathy/empathy-time.h +++ b/libempathy/empathy-time.h @@ -40,6 +40,7 @@ gchar *empathy_time_to_string_utc (time_t t, const gchar *format); gchar *empathy_time_to_string_local (time_t t, const gchar *format); +gchar *empathy_time_to_string_relative (time_t t); G_END_DECLS diff --git a/src/empathy-map-view.c b/src/empathy-map-view.c index 688195443..8c6dc54e6 100644 --- a/src/empathy-map-view.c +++ b/src/empathy-map-view.c @@ -296,6 +296,10 @@ map_view_contacts_foreach (GtkTreeModel *model, GHashTable *location; GdkPixbuf *avatar; const gchar *name; + gchar *date; + gchar *label; + GValue *gtime; + time_t time; gtk_tree_model_get (model, iter, EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact, -1); @@ -321,7 +325,20 @@ map_view_contacts_foreach (GtkTreeModel *model, champlain_marker_set_image (CHAMPLAIN_MARKER (marker), NULL); name = empathy_contact_get_name (contact); - champlain_marker_set_text (CHAMPLAIN_MARKER (marker), name); + gtime = g_hash_table_lookup (location, EMPATHY_LOCATION_TIMESTAMP); + if (gtime != NULL) + { + time = g_value_get_int64 (gtime); + date = empathy_time_to_string_relative (time); + label = g_strconcat ("<b>", name, "</b>\n<small>", date, "</small>", NULL); + } + else + { + label = g_strconcat ("<b>", name, "</b>\n", NULL); + } + champlain_marker_set_use_markup (CHAMPLAIN_MARKER (marker), TRUE); + champlain_marker_set_text (CHAMPLAIN_MARKER (marker), label); + g_free (label); clutter_container_add (CLUTTER_CONTAINER (window->layer), marker, NULL); |