]> git.0d.be Git - empathy.git/commitdiff
Port all timestamps from time_t to gint64 (#648188)
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Tue, 19 Apr 2011 09:06:52 +0000 (11:06 +0200)
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Tue, 19 Apr 2011 10:16:11 +0000 (12:16 +0200)
14 files changed:
libempathy-gtk/empathy-chat-text-view.c
libempathy-gtk/empathy-chat-text-view.h
libempathy-gtk/empathy-contact-widget.c
libempathy-gtk/empathy-individual-widget.c
libempathy-gtk/empathy-location-manager.c
libempathy-gtk/empathy-theme-adium.c
libempathy-gtk/empathy-theme-boxes.c
libempathy/empathy-ft-handler.c
libempathy/empathy-message.c
libempathy/empathy-message.h
libempathy/empathy-time.c
libempathy/empathy-time.h
libempathy/empathy-tp-file.c
src/empathy-map-view.c

index b58fbc23934e16365285151db142ddd1b293730b..b04d3e9d2879bc2b43618caa76849801d46a373d 100644 (file)
@@ -48,7 +48,7 @@
 #include <libempathy/empathy-debug.h>
 
 /* Number of seconds between timestamps when using normal mode, 5 minutes. */
-#define TIMESTAMP_INTERVAL 300
+#define TIMESTAMP_INTERVAL (5 * G_TIME_SPAN_MINUTE)
 
 #define MAX_LINES 800
 #define MAX_SCROLL_TIME 0.4 /* seconds */
@@ -65,7 +65,7 @@ typedef struct {
        gboolean              find_wrapped;
        gboolean              find_last_direction;
        EmpathyContact       *last_contact;
-       time_t                last_timestamp;
+       gint64                last_timestamp;
        gboolean              allow_scrolling;
        guint                 notify_system_fonts_id;
        GSettings            *gsettings_desktop;
@@ -398,7 +398,7 @@ chat_text_view_maybe_trim_buffer (EmpathyChatTextView *view)
 
 static void
 chat_text_view_append_timestamp (EmpathyChatTextView *view,
-                                time_t               timestamp,
+                                gint64               timestamp,
                                 gboolean             show_date)
 {
        EmpathyChatTextViewPriv *priv = GET_PRIV (view);
@@ -410,17 +410,16 @@ chat_text_view_append_timestamp (EmpathyChatTextView *view,
 
        /* Append date if needed */
        if (show_date) {
-               GDate *date;
-               gchar  buf[256];
+               GDateTime *date;
 
-               date = g_date_new ();
-               g_date_set_time_t (date, timestamp);
+               date = g_date_time_new_from_unix_utc (timestamp);
                /* Translators: timestamp displayed between conversations in
                 * chat windows (strftime format string) */
-               g_date_strftime (buf, 256, _("%A %B %d %Y"), date);
-               g_string_append (str, buf);
+               tmp = g_date_time_format (date, _("%A %B %d %Y"));
+               g_string_append (str, tmp);
                g_string_append (str, ", ");
-               g_date_free (date);
+               g_date_time_unref (date);
+               g_free (tmp);
        }
 
        /* Append time */
@@ -444,32 +443,32 @@ chat_text_view_append_timestamp (EmpathyChatTextView *view,
 
 static void
 chat_text_maybe_append_date_and_time (EmpathyChatTextView *view,
-                                     time_t               timestamp)
+                                     gint64               timestamp)
 {
        EmpathyChatTextViewPriv *priv = GET_PRIV (view);
-       GDate                   *date, *last_date;
+       GDateTime               *date, *last_date;
        gboolean                 append_date = FALSE;
        gboolean                 append_time = FALSE;
+       GTimeSpan                delta;
 
        /* Get the date from last message */
-       last_date = g_date_new ();
-       g_date_set_time_t (last_date, priv->last_timestamp);
+       last_date = g_date_time_new_from_unix_utc (priv->last_timestamp);
 
        /* Get the date of the message we are appending */
-       date = g_date_new ();
-       g_date_set_time_t (date, timestamp);
+       date = g_date_time_new_from_unix_utc (timestamp);
 
+       delta = g_date_time_difference (last_date, date);
        /* If last message was from another day we append date and time */
-       if (g_date_compare (date, last_date) > 0) {
+       if (delta >= G_TIME_SPAN_DAY) {
                append_date = TRUE;
                append_time = TRUE;
        }
 
-       g_date_free (last_date);
-       g_date_free (date);
+       g_date_time_unref (last_date);
+       g_date_time_unref (date);
 
        /* If last message is 'old' append the time */
-       if (timestamp - priv->last_timestamp >= TIMESTAMP_INTERVAL) {
+       if (delta >= TIMESTAMP_INTERVAL) {
                append_time = TRUE;
        }
 
@@ -725,7 +724,7 @@ chat_text_view_append_message (EmpathyChatView *view,
        EmpathyChatTextView     *text_view = EMPATHY_CHAT_TEXT_VIEW (view);
        EmpathyChatTextViewPriv *priv = GET_PRIV (text_view);
        gboolean                 bottom;
-       time_t                   timestamp;
+       gint64                   timestamp;
 
        g_return_if_fail (EMPATHY_IS_CHAT_TEXT_VIEW (view));
        g_return_if_fail (EMPATHY_IS_MESSAGE (msg));
@@ -1320,7 +1319,7 @@ empathy_chat_text_view_get_last_contact (EmpathyChatTextView *view)
        return priv->last_contact;
 }
 
-time_t
+gint64
 empathy_chat_text_view_get_last_timestamp (EmpathyChatTextView *view)
 {
        EmpathyChatTextViewPriv *priv = GET_PRIV (view);
index 7ee7ba8a2bb911c90c840d98e84ba24e623ff39d..12edbcc64ba46e36c84ac5ad260081f38bd6c69f 100644 (file)
@@ -70,7 +70,7 @@ struct _EmpathyChatTextViewClass {
 
 GType                empathy_chat_text_view_get_type           (void) G_GNUC_CONST;
 EmpathyContact *     empathy_chat_text_view_get_last_contact   (EmpathyChatTextView *view);
-time_t               empathy_chat_text_view_get_last_timestamp (EmpathyChatTextView *view);
+gint64               empathy_chat_text_view_get_last_timestamp (EmpathyChatTextView *view);
 void                 empathy_chat_text_view_set_only_if_date   (EmpathyChatTextView *view,
                                                                gboolean             only_if_date);
 void                 empathy_chat_text_view_append_body        (EmpathyChatTextView *view,
index 15b8ed39b7cb9e6858e4d1fd517e1bd61bcddb5a..acf206ad38252427f86eed2a6c45f72be31c4ef8 100644 (file)
@@ -877,13 +877,11 @@ contact_widget_location_update (EmpathyContactWidget *information)
       gchar *user_date;
       gchar *text;
       gint64 stamp;
-      time_t time_;
       gchar *tmp;
 
       stamp = g_value_get_int64 (value);
-      time_ = stamp;
 
-      user_date = empathy_time_to_string_relative (time_);
+      user_date = empathy_time_to_string_relative (stamp);
 
       tmp = g_strdup_printf ("<b>%s</b>", _("Location"));
       /* translators: format is "Location, $date" */
@@ -936,7 +934,7 @@ contact_widget_location_update (EmpathyContactWidget *information)
         }
       else if (G_VALUE_TYPE (gvalue) == G_TYPE_INT64)
         {
-          time_t time_;
+          gint64 time_;
 
           time_ = g_value_get_int64 (value);
           svalue = empathy_time_to_string_utc (time_, _("%B %e, %Y at %R UTC"));
index ebad685be9ddffb987d9617452cc2ac04a7b79ff..dc45191a6303cfc0a904fc0a9a5d5fc519c5529a 100644 (file)
@@ -622,13 +622,11 @@ location_update (EmpathyIndividualWidget *self)
       gchar *user_date;
       gchar *text;
       gint64 stamp;
-      time_t time_;
       gchar *tmp;
 
       stamp = g_value_get_int64 (value);
-      time_ = stamp;
 
-      user_date = empathy_time_to_string_relative (time_);
+      user_date = empathy_time_to_string_relative (stamp);
 
       tmp = g_strdup_printf ("<b>%s</b>", _("Location"));
       /* translators: format is "Location, $date" */
@@ -678,7 +676,7 @@ location_update (EmpathyIndividualWidget *self)
         }
       else if (G_VALUE_TYPE (gvalue) == G_TYPE_INT64)
         {
-          time_t time_;
+          gint64 time_;
 
           time_ = g_value_get_int64 (value);
           svalue = empathy_time_to_string_utc (time_, _("%B %e, %Y at %R UTC"));
index 1c09c358c0cec9602464353b865a10f48174fcf1..1925d4371e9f74cb032fa6282cb7ca8952229dfb 100644 (file)
@@ -39,6 +39,7 @@
 #include "libempathy/empathy-gsettings.h"
 #include "libempathy/empathy-location.h"
 #include "libempathy/empathy-utils.h"
+#include "libempathy/empathy-time.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_LOCATION
 #include "libempathy/empathy-debug.h"
@@ -322,16 +323,12 @@ static void
 update_timestamp (EmpathyLocationManager *self)
 {
   EmpathyLocationManagerPriv *priv= GET_PRIV (self);
-  GValue *new_value;
-  gint64 stamp64;
-  time_t timestamp;
-
-  timestamp = time (NULL);
-  stamp64 = (gint64) timestamp;
-  new_value = tp_g_value_slice_new_int64 (stamp64);
-  g_hash_table_insert (priv->location, g_strdup (EMPATHY_LOCATION_TIMESTAMP),
-      new_value);
-  DEBUG ("\t - Timestamp: %" G_GINT64_FORMAT, stamp64);
+  gint64 timestamp;
+
+  timestamp = empathy_time_get_current ();
+  tp_asv_set_int64 (priv->location, EMPATHY_LOCATION_TIMESTAMP, timestamp);
+
+  DEBUG ("\t - Timestamp: %" G_GINT64_FORMAT, timestamp);
 }
 
 static void
index e7e4cbd375c58bd30be34a313909ad20f4e24744..659bbac876f1bca6a27642a392cc6b1495f88439 100644 (file)
@@ -56,7 +56,7 @@ typedef struct {
        EmpathyAdiumData     *data;
        EmpathySmileyManager *smiley_manager;
        EmpathyContact       *last_contact;
-       time_t                last_timestamp;
+       gint64                last_timestamp;
        gboolean              last_is_backlog;
        guint                 pages_loading;
        GList                *message_queue;
@@ -327,7 +327,7 @@ theme_adium_append_html (EmpathyThemeAdium *theme,
                         const gchar       *contact_id,
                         const gchar       *service_name,
                         const gchar       *message_classes,
-                        time_t             timestamp,
+                        gint64             timestamp,
                         gboolean           is_backlog)
 {
        GString     *string;
@@ -445,7 +445,7 @@ theme_adium_append_message (EmpathyChatView *view,
        const gchar           *contact_id;
        EmpathyAvatar         *avatar;
        const gchar           *avatar_filename = NULL;
-       time_t                 timestamp;
+       gint64                 timestamp;
        gchar                 *html = NULL;
        gsize                  len = 0;
        const gchar           *func;
index bf97f3f97dcdebf5fcc6b2f74fd4d7b7e9254ec2..c0377b6ae6adb24ba0b7f19b550bc95ecffdf65a 100644 (file)
@@ -196,7 +196,7 @@ theme_boxes_maybe_append_header (EmpathyThemeBoxes *theme,
        GtkTextChildAnchor   *anchor;
        GtkWidget            *box;
        gchar                *str;
-       time_t                time_;
+       gint64                time_;
        gchar                *tmp;
        GtkTextIter           start;
        gboolean              color_set;
index 1c3f4209eb9b9cf4c7b88b30dded8d31c66f3c92..a1ca07d8b0582e9dd02701c82f4d024eb654755b 100644 (file)
@@ -141,7 +141,7 @@ typedef struct {
   /* time and speed */
   gdouble speed;
   guint remaining_time;
-  time_t last_update_time;
+  gint64 last_update_time;
 
   gboolean is_completed;
 } EmpathyFTHandlerPriv;
@@ -652,7 +652,7 @@ update_remaining_time_and_speed (EmpathyFTHandler *handler,
     guint64 transferred_bytes)
 {
   EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
-  time_t elapsed_time, current_time;
+  gint64 elapsed_time, current_time;
   guint64 transferred, last_transferred_bytes;
   gdouble speed;
   gint remaining_time;
index 883c5e7bbd0845ca73fad3cd119e60ebf88d282b..076a10053a0cfb0e1398a980a5cf0c1811fa9a4c 100644 (file)
@@ -44,7 +44,7 @@ typedef struct {
        EmpathyContact           *sender;
        EmpathyContact           *receiver;
        gchar                    *body;
-       time_t                    timestamp;
+       gint64                    timestamp;
        gboolean                  is_backlog;
        guint                     id;
        gboolean                  incoming;
@@ -119,12 +119,10 @@ empathy_message_class_init (EmpathyMessageClass *class)
                                                              G_PARAM_CONSTRUCT_ONLY));
        g_object_class_install_property (object_class,
                                         PROP_TIMESTAMP,
-                                        g_param_spec_long ("timestamp",
+                                        g_param_spec_int64 ("timestamp",
                                                            "timestamp",
                                                            "timestamp",
-                                                           -1,
-                                                           G_MAXLONG,
-                                                           -1,
+                                                           G_MININT64, G_MAXINT64, 0,
                                                            G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
                                                            G_PARAM_CONSTRUCT_ONLY));
        g_object_class_install_property (object_class,
@@ -212,7 +210,7 @@ message_get_property (GObject    *object,
                g_value_set_string (value, priv->body);
                break;
        case PROP_TIMESTAMP:
-               g_value_set_long (value, priv->timestamp);
+               g_value_set_int64 (value, priv->timestamp);
                break;
        case PROP_IS_BACKLOG:
                g_value_set_boolean (value, priv->is_backlog);
@@ -256,7 +254,7 @@ message_set_property (GObject      *object,
                priv->body = g_value_dup_string (value);
                break;
        case PROP_TIMESTAMP:
-               priv->timestamp = g_value_get_long (value);
+               priv->timestamp = g_value_get_int64 (value);
                if (priv->timestamp <= 0)
                        priv->timestamp = empathy_time_get_current ();
                break;
@@ -324,7 +322,7 @@ empathy_message_from_tpl_log_event (TplEvent *logevent)
                "type", tpl_text_event_get_message_type (TPL_TEXT_EVENT (logevent)),
                "body", body,
                "is-backlog", TRUE,
-               "timestamp", (glong) tpl_event_get_timestamp (logevent),
+               "timestamp", tpl_event_get_timestamp (logevent),
                NULL);
 
        if (receiver != NULL) {
@@ -435,7 +433,7 @@ empathy_message_get_body (EmpathyMessage *message)
        return priv->body;
 }
 
-time_t
+gint64
 empathy_message_get_timestamp (EmpathyMessage *message)
 {
        EmpathyMessagePriv *priv;
@@ -632,7 +630,7 @@ empathy_message_new_from_tp_message (TpMessage *tp_msg,
        message = g_object_new (EMPATHY_TYPE_MESSAGE,
                "body", body,
                "type", tp_message_get_message_type (tp_msg),
-               "timestamp", (glong) tp_message_get_received_timestamp (tp_msg),
+               "timestamp", tp_message_get_received_timestamp (tp_msg),
                "flags", flags,
                "is-backlog", flags & TP_CHANNEL_TEXT_MESSAGE_FLAG_SCROLLBACK,
                "incoming", incoming,
index bba65aeb2a6b7f4ad9ac4420ab967d6fd91c4713..7508cb08e615f06f9c13e80c8c0c81996f948e5a 100644 (file)
@@ -67,7 +67,7 @@ EmpathyContact *         empathy_message_get_receiver      (EmpathyMessage
 void                     empathy_message_set_receiver      (EmpathyMessage           *message,
                                                            EmpathyContact           *contact);
 const gchar *            empathy_message_get_body          (EmpathyMessage           *message);
-time_t                   empathy_message_get_timestamp     (EmpathyMessage           *message);
+gint64                   empathy_message_get_timestamp     (EmpathyMessage           *message);
 gboolean                 empathy_message_is_backlog        (EmpathyMessage           *message);
 gboolean                 empathy_message_is_incoming       (EmpathyMessage           *message);
 
index b0ad0188883439cc4f92f0e90e9679a8d17ff7b4..f33152d972cfae4c7daf5ab39b8b34bd981bc306 100644 (file)
 
 /* Note: EmpathyTime is always in UTC. */
 
-time_t
+gint64
 empathy_time_get_current (void)
 {
-       return time (NULL);
+       GDateTime *now;
+       gint64 result;
+
+       now = g_date_time_new_now_utc ();
+       result = g_date_time_to_unix (now);
+       g_date_time_unref (now);
+
+       return result;
 }
 
 /* Converts the UTC timestamp to a string, also in UTC. Returns NULL on failure. */
 gchar *
-empathy_time_to_string_utc (time_t       t,
+empathy_time_to_string_utc (gint64       t,
                            const gchar *format)
 {
-       gchar      stamp[128];
-       struct tm *tm;
+       GDateTime *d;
+       char *result;
 
        g_return_val_if_fail (format != NULL, NULL);
 
-       tm = gmtime (&t);
-       if (strftime (stamp, sizeof (stamp), format, tm) == 0) {
-               return NULL;
-       }
+       d = g_date_time_new_from_unix_utc (t);
+       result = g_date_time_format (d, format);
+       g_date_time_unref (d);
 
-       return g_strdup (stamp);
+       return result;
 }
 
 /* Converts the UTC timestamp to a string, in local time. Returns NULL on failure. */
 gchar *
-empathy_time_to_string_local (time_t       t,
+empathy_time_to_string_local (gint64 t,
                              const gchar *format)
 {
-       gchar      stamp[128];
-       struct tm *tm;
+       GDateTime *d, *local;
+       gchar *result;
 
        g_return_val_if_fail (format != NULL, NULL);
 
-       tm = localtime (&t);
-       if (strftime (stamp, sizeof (stamp), format, tm) == 0) {
-               return NULL;
-       }
+       d = g_date_time_new_from_unix_utc (t);
+       local = g_date_time_to_local (d);
+       g_date_time_unref (d);
 
-       return g_strdup (stamp);
+       result = g_date_time_format (local, format);
+       g_date_time_unref (local);
+
+       return result;
 }
 
 gchar  *
-empathy_time_to_string_relative (time_t then)
+empathy_time_to_string_relative (gint64 t)
 {
-       time_t now;
+       GDateTime *now, *then;
        gint   seconds;
+       GTimeSpan delta;
+       gchar *result;
+
+       now = g_date_time_new_now_utc ();
+       then = g_date_time_new_from_unix_utc (t);
 
-       now = time (NULL);
-       seconds = now - then;
+       delta = g_date_time_difference (now, then);
+       seconds = delta / G_TIME_SPAN_SECOND;
 
        if (seconds > 0) {
                if (seconds < 60) {
-                       return g_strdup_printf (ngettext ("%d second ago",
+                       result = 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",
+                       result = 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",
+                       result = 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",
+                       result = g_strdup_printf (ngettext ("%d day ago",
                                "%d days ago", seconds), seconds);
                }
                else if (seconds < (60 * 60 * 24 * 30)) {
                        seconds /= 60 * 60 * 24 * 7;
-                       return g_strdup_printf (ngettext ("%d week ago",
+                       result = g_strdup_printf (ngettext ("%d week ago",
                                "%d weeks ago", seconds), seconds);
                }
                else {
                        seconds /= 60 * 60 * 24 * 30;
-                       return g_strdup_printf (ngettext ("%d month ago",
+                       result = g_strdup_printf (ngettext ("%d month ago",
                                "%d months ago", seconds), seconds);
                }
        }
        else {
-               return g_strdup (_("in the future"));
+               result = g_strdup (_("in the future"));
        }
+
+       g_date_time_unref (now);
+       g_date_time_unref (then);
+
+       return result;
 }
index 5c20a6a5a80517c36ad977e287f7589e81d71994..7fac48221ae91ecbfcaf4e961c64349e92fcb56a 100644 (file)
@@ -39,12 +39,12 @@ G_BEGIN_DECLS
 #define EMPATHY_DATE_FORMAT_DISPLAY_SHORT  _("%a %d %b %Y")
 #define EMPATHY_TIME_DATE_FORMAT_DISPLAY_SHORT _("%a %d %b %Y, %H:%M")
 
-time_t  empathy_time_get_current     (void);
-gchar  *empathy_time_to_string_utc   (time_t       t,
+gint64  empathy_time_get_current     (void);
+gchar  *empathy_time_to_string_utc   (gint64       t,
                                      const gchar *format);
-gchar  *empathy_time_to_string_local (time_t       t,
+gchar  *empathy_time_to_string_local (gint64       t,
                                      const gchar *format);
-gchar  *empathy_time_to_string_relative (time_t t);
+gchar  *empathy_time_to_string_relative (gint64 t);
 
 G_END_DECLS
 
index d69b2153a038f0181ab93cdfc38f92e4af1beae3..3bb2dd49c43eaa8383e8ce7f3e352b10cc55bec3 100644 (file)
@@ -79,7 +79,7 @@ struct _EmpathyTpFilePrivate {
 
   /* transfer properties */
   gboolean incoming;
-  time_t start_time;
+  gint64 start_time;
   GArray *socket_address;
   guint port;
   guint64 offset;
index b7a2e1975cc091d6c39e65d4adfa9854728d7c61..9e6cc6dee0e7be7e0c2e4f286dd8e6771379f844 100644 (file)
@@ -221,7 +221,7 @@ map_view_contacts_update_label (ClutterActor *marker)
   gchar *date;
   gchar *label;
   GValue *gtime;
-  time_t loctime;
+  gint64 loctime;
   GHashTable *location;
   EmpathyContact *contact;
 
@@ -232,18 +232,24 @@ map_view_contacts_update_label (ClutterActor *marker)
 
   if (gtime != NULL)
     {
-      time_t now;
+      GDateTime *now, *d;
+      GTimeSpan delta;
 
       loctime = g_value_get_int64 (gtime);
       date = empathy_time_to_string_relative (loctime);
       label = g_strconcat ("<b>", name, "</b>\n<small>", date, "</small>", NULL);
       g_free (date);
 
-      now = time (NULL);
+      now = g_date_time_new_now_utc ();
+      d = g_date_time_new_from_unix_utc (loctime);
+      delta = g_date_time_difference (now, d);
 
       /* if location is older than a week */
-      if (now - loctime > (60 * 60 * 24 * 7))
+      if (delta > G_TIME_SPAN_DAY * 7)
         clutter_actor_set_opacity (marker, 0.75 * 255);
+
+      g_date_time_unref (now);
+      g_date_time_unref (d);
     }
   else
     {