]> git.0d.be Git - empathy.git/commitdiff
Merge branch 'timestamp-648188'
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Wed, 20 Apr 2011 07:49:52 +0000 (09:49 +0200)
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Wed, 20 Apr 2011 07:49:52 +0000 (09:49 +0200)
20 files changed:
libempathy-gtk/empathy-chat-text-view.c
libempathy-gtk/empathy-chat-text-view.h
libempathy-gtk/empathy-chat.c
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-chatroom-manager.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-chat.c
libempathy/empathy-tp-chat.h
libempathy/empathy-tp-file.c
src/empathy-chat-manager.c
src/empathy-event-manager.c
src/empathy-map-view.c

index b58fbc23934e16365285151db142ddd1b293730b..18d12963e6d636fc9739c8256e1870a640a9b926 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,12 @@ chat_text_view_append_timestamp (EmpathyChatTextView *view,
 
        /* Append date if needed */
        if (show_date) {
-               GDate *date;
-               gchar  buf[256];
-
-               date = g_date_new ();
-               g_date_set_time_t (date, 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 = empathy_time_to_string_utc (timestamp, _("%A %B %d %Y"));
+               g_string_append (str, tmp);
                g_string_append (str, ", ");
-               g_date_free (date);
+               g_free (tmp);
        }
 
        /* Append time */
@@ -444,32 +439,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 +720,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 +1315,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 b7c5192a8bfd14a02ac36ceb2c1aa91297c741ca..53c4677fc6410e74415aca4c633d64d9c7b98b54 100644 (file)
@@ -868,7 +868,7 @@ chat_command_me (EmpathyChat *chat,
                  GStrv        strv)
 {
        EmpathyChatPriv *priv = GET_PRIV (chat);
-       EmpathyMessage *message;
+       TpMessage *message;
        TpChannel *channel;
 
        channel = empathy_tp_chat_get_channel (priv->tp_chat);
@@ -888,12 +888,13 @@ chat_command_me (EmpathyChat *chat,
 
                tmp = g_strdup_printf ("%s %s", empathy_contact_get_alias (self_contact),
                        strv[1]);
-               message = empathy_message_new (tmp);
+               message = tp_client_message_new_text (TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL,
+                       tmp);
                g_free (tmp);
        }
        else {
-               message = empathy_message_new (strv[1]);
-               empathy_message_set_tptype (message, TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION);
+               message = tp_client_message_new_text (TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION,
+                       strv[1]);
        }
 
        empathy_tp_chat_send (priv->tp_chat, message);
@@ -905,9 +906,10 @@ chat_command_say (EmpathyChat *chat,
                  GStrv        strv)
 {
        EmpathyChatPriv *priv = GET_PRIV (chat);
-       EmpathyMessage *message;
+       TpMessage *message;
 
-       message = empathy_message_new (strv[1]);
+       message = tp_client_message_new_text (TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL,
+               strv[1]);
        empathy_tp_chat_send (priv->tp_chat, message);
        g_object_unref (message);
 }
@@ -1074,7 +1076,7 @@ chat_send (EmpathyChat  *chat,
           const gchar *msg)
 {
        EmpathyChatPriv *priv;
-       EmpathyMessage  *message;
+       TpMessage  *message;
        guint            i;
 
        if (EMP_STR_EMPTY (msg)) {
@@ -1144,7 +1146,8 @@ chat_send (EmpathyChat  *chat,
                }
        }
 
-       message = empathy_message_new (msg);
+       message = tp_client_message_new_text (TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL,
+               msg);
        empathy_tp_chat_send (priv->tp_chat, message);
        g_object_unref (message);
 }
@@ -1295,9 +1298,14 @@ chat_send_error_cb (EmpathyTpChat          *tp_chat,
                break;
        }
 
-       str = g_strdup_printf (_("Error sending message '%s': %s"),
-                              message_body,
-                              error);
+       if (message_body != NULL) {
+                       str = g_strdup_printf (_("Error sending message '%s': %s"),
+                               message_body, error);
+       }
+       else {
+                       str = g_strdup_printf (_("Error sending message: %s"), error);
+       }
+
        empathy_chat_view_append_event (chat->view, str);
        g_free (str);
 }
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 dd7ef460e22e1d6ed3b0bd171da4284751709ce3..9ad75ee03269b1e07ca3494f658aad193c8fd92d 100644 (file)
@@ -873,6 +873,9 @@ observe_channels_cb (TpSimpleObserver *observer,
       if (tp_proxy_get_invalidated (channel) != NULL)
         continue;
 
+      if (!TP_IS_TEXT_CHANNEL (channel))
+        continue;
+
       tp_chat = empathy_tp_chat_new (account, channel);
       roomname = empathy_tp_chat_get_id (tp_chat);
       chatroom = empathy_chatroom_manager_find (self, account, roomname);
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 65ea2ae407fd407b0bcf19d02babfbdd966224ef..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;
@@ -93,44 +93,46 @@ empathy_message_class_init (EmpathyMessageClass *class)
                                                            TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL,
                                                            TP_CHANNEL_TEXT_MESSAGE_TYPE_AUTO_REPLY,
                                                            TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL,
-                                                           G_PARAM_READWRITE));
+                                                           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
+                                                           G_PARAM_CONSTRUCT_ONLY));
        g_object_class_install_property (object_class,
                                         PROP_SENDER,
                                         g_param_spec_object ("sender",
                                                              "Message Sender",
                                                              "The sender of the message",
                                                              EMPATHY_TYPE_CONTACT,
-                                                             G_PARAM_READWRITE));
+                                                             G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
        g_object_class_install_property (object_class,
                                         PROP_RECEIVER,
                                         g_param_spec_object ("receiver",
                                                              "Message Receiver",
                                                              "The receiver of the message",
                                                              EMPATHY_TYPE_CONTACT,
-                                                             G_PARAM_READWRITE));
+                                                             G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
        g_object_class_install_property (object_class,
                                         PROP_BODY,
                                         g_param_spec_string ("body",
                                                              "Message Body",
                                                              "The content of the message",
                                                              NULL,
-                                                             G_PARAM_READWRITE));
+                                                             G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
+                                                             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_PARAM_READWRITE));
+                                                           G_MININT64, G_MAXINT64, 0,
+                                                           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
+                                                           G_PARAM_CONSTRUCT_ONLY));
        g_object_class_install_property (object_class,
                                         PROP_IS_BACKLOG,
                                         g_param_spec_boolean ("is-backlog",
                                                               "History message",
                                                               "If the message belongs to history",
                                                               FALSE,
-                                                              G_PARAM_READWRITE));
+                                                              G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
+                                                              G_PARAM_CONSTRUCT_ONLY));
 
 
        g_object_class_install_property (object_class,
@@ -139,7 +141,8 @@ empathy_message_class_init (EmpathyMessageClass *class)
                                                               "Incoming",
                                                               "If this is an incoming (as opposed to sent) message",
                                                               FALSE,
-                                                              G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+                                                              G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
+                                                              G_PARAM_CONSTRUCT_ONLY));
 
        g_object_class_install_property (object_class,
                                         PROP_FLAGS,
@@ -147,7 +150,8 @@ empathy_message_class_init (EmpathyMessageClass *class)
                                                               "Flags",
                                                               "The TpChannelTextMessageFlags of this message",
                                                               0, G_MAXUINT, 0,
-                                                              G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+                                                              G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
+                                                              G_PARAM_CONSTRUCT_ONLY));
 
        g_type_class_add_private (object_class, sizeof (EmpathyMessagePriv));
 
@@ -205,9 +209,18 @@ message_get_property (GObject    *object,
        case PROP_BODY:
                g_value_set_string (value, priv->body);
                break;
+       case PROP_TIMESTAMP:
+               g_value_set_int64 (value, priv->timestamp);
+               break;
+       case PROP_IS_BACKLOG:
+               g_value_set_boolean (value, priv->is_backlog);
+               break;
        case PROP_INCOMING:
                g_value_set_boolean (value, priv->incoming);
                break;
+       case PROP_FLAGS:
+               g_value_set_uint (value, priv->flags);
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
                break;
@@ -226,8 +239,7 @@ message_set_property (GObject      *object,
 
        switch (param_id) {
        case PROP_TYPE:
-               empathy_message_set_tptype (EMPATHY_MESSAGE (object),
-                                           g_value_get_uint (value));
+               priv->type = g_value_get_uint (value);
                break;
        case PROP_SENDER:
                empathy_message_set_sender (EMPATHY_MESSAGE (object),
@@ -238,26 +250,29 @@ message_set_property (GObject      *object,
                                             EMPATHY_CONTACT (g_value_get_object (value)));
                break;
        case PROP_BODY:
-               empathy_message_set_body (EMPATHY_MESSAGE (object),
-                                        g_value_get_string (value));
+               g_assert (priv->body == NULL); /* construct only */
+               priv->body = g_value_dup_string (value);
+               break;
+       case PROP_TIMESTAMP:
+               priv->timestamp = g_value_get_int64 (value);
+               if (priv->timestamp <= 0)
+                       priv->timestamp = empathy_time_get_current ();
+               break;
+       case PROP_IS_BACKLOG:
+               priv->is_backlog = g_value_get_boolean (value);
                break;
        case PROP_INCOMING:
                priv->incoming = g_value_get_boolean (value);
                break;
+       case PROP_FLAGS:
+               priv->flags = g_value_get_uint (value);
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
                break;
        };
 }
 
-EmpathyMessage *
-empathy_message_new (const gchar *body)
-{
-       return g_object_new (EMPATHY_TYPE_MESSAGE,
-                            "body", body,
-                            NULL);
-}
-
 EmpathyMessage *
 empathy_message_from_tpl_log_event (TplEvent *logevent)
 {
@@ -303,7 +318,13 @@ empathy_message_from_tpl_log_event (TplEvent *logevent)
        receiver = tpl_event_get_receiver (logevent);
        sender = tpl_event_get_sender (logevent);
 
-       retval = empathy_message_new (body);
+       retval = g_object_new (EMPATHY_TYPE_MESSAGE,
+               "type", tpl_text_event_get_message_type (TPL_TEXT_EVENT (logevent)),
+               "body", body,
+               "is-backlog", TRUE,
+               "timestamp", tpl_event_get_timestamp (logevent),
+               NULL);
+
        if (receiver != NULL) {
                contact = empathy_contact_from_tpl_contact (account, receiver);
                empathy_message_set_receiver (retval, contact);
@@ -316,12 +337,6 @@ empathy_message_from_tpl_log_event (TplEvent *logevent)
                g_object_unref (contact);
        }
 
-       empathy_message_set_timestamp (retval,
-                       tpl_event_get_timestamp (logevent));
-        empathy_message_set_tptype (retval,
-            tpl_text_event_get_message_type (TPL_TEXT_EVENT (logevent)));
-       empathy_message_set_is_backlog (retval, TRUE);
-
        g_free (body);
 
        return retval;
@@ -340,21 +355,6 @@ empathy_message_get_tptype (EmpathyMessage *message)
        return priv->type;
 }
 
-void
-empathy_message_set_tptype (EmpathyMessage           *message,
-                           TpChannelTextMessageType  type)
-{
-       EmpathyMessagePriv *priv;
-
-       g_return_if_fail (EMPATHY_IS_MESSAGE (message));
-
-       priv = GET_PRIV (message);
-
-       priv->type = type;
-
-       g_object_notify (G_OBJECT (message), "type");
-}
-
 EmpathyContact *
 empathy_message_get_sender (EmpathyMessage *message)
 {
@@ -433,26 +433,7 @@ empathy_message_get_body (EmpathyMessage *message)
        return priv->body;
 }
 
-void
-empathy_message_set_body (EmpathyMessage *message,
-                         const gchar    *body)
-{
-       EmpathyMessagePriv       *priv = GET_PRIV (message);
-
-       g_return_if_fail (EMPATHY_IS_MESSAGE (message));
-
-       g_free (priv->body);
-
-       if (body) {
-               priv->body = g_strdup (body);
-       } else {
-               priv->body = NULL;
-       }
-
-       g_object_notify (G_OBJECT (message), "body");
-}
-
-time_t
+gint64
 empathy_message_get_timestamp (EmpathyMessage *message)
 {
        EmpathyMessagePriv *priv;
@@ -464,26 +445,6 @@ empathy_message_get_timestamp (EmpathyMessage *message)
        return priv->timestamp;
 }
 
-void
-empathy_message_set_timestamp (EmpathyMessage *message,
-                              time_t          timestamp)
-{
-       EmpathyMessagePriv *priv;
-
-       g_return_if_fail (EMPATHY_IS_MESSAGE (message));
-       g_return_if_fail (timestamp >= -1);
-
-       priv = GET_PRIV (message);
-
-       if (timestamp <= 0) {
-               priv->timestamp = empathy_time_get_current ();
-       } else {
-               priv->timestamp = timestamp;
-       }
-
-       g_object_notify (G_OBJECT (message), "timestamp");
-}
-
 gboolean
 empathy_message_is_backlog (EmpathyMessage *message)
 {
@@ -496,21 +457,6 @@ empathy_message_is_backlog (EmpathyMessage *message)
        return priv->is_backlog;
 }
 
-void
-empathy_message_set_is_backlog (EmpathyMessage *message,
-                               gboolean is_backlog)
-{
-       EmpathyMessagePriv *priv;
-
-       g_return_if_fail (EMPATHY_IS_MESSAGE (message));
-
-       priv = GET_PRIV (message);
-
-       priv->is_backlog = is_backlog;
-
-       g_object_notify (G_OBJECT (message), "is-backlog");
-}
-
 #define IS_SEPARATOR(ch) (ch == ' ' || ch == ',' || ch == '.' || ch == ':')
 gboolean
 empathy_message_should_highlight (EmpathyMessage *message)
@@ -627,28 +573,6 @@ empathy_message_get_id (EmpathyMessage *message)
        return priv->id;
 }
 
-void
-empathy_message_set_id (EmpathyMessage *message, guint id)
-{
-       EmpathyMessagePriv *priv = GET_PRIV (message);
-
-       priv->id = id;
-}
-
-void
-empathy_message_set_incoming (EmpathyMessage *message, gboolean incoming)
-{
-       EmpathyMessagePriv *priv;
-
-       g_return_if_fail (EMPATHY_IS_MESSAGE (message));
-
-       priv = GET_PRIV (message);
-
-       priv->incoming = incoming;
-
-       g_object_notify (G_OBJECT (message), "incoming");
-}
-
 gboolean
 empathy_message_is_incoming (EmpathyMessage *message)
 {
@@ -689,17 +613,38 @@ empathy_message_get_flags (EmpathyMessage *self)
        return priv->flags;
 }
 
-void
-empathy_message_set_flags        (EmpathyMessage           *self,
-                               TpChannelTextMessageFlags flags)
+EmpathyMessage *
+empathy_message_new_from_tp_message (TpMessage *tp_msg,
+                                    gboolean incoming)
 {
+       EmpathyMessage *message;
        EmpathyMessagePriv *priv;
+       gchar *body;
+       TpChannelTextMessageFlags flags;
+       guint id;
+
+       g_return_val_if_fail (TP_IS_MESSAGE (tp_msg), NULL);
 
-       g_return_if_fail (EMPATHY_IS_MESSAGE (self));
+       body = tp_message_to_text (tp_msg, &flags);
 
-       priv = GET_PRIV (self);
+       message = g_object_new (EMPATHY_TYPE_MESSAGE,
+               "body", body,
+               "type", tp_message_get_message_type (tp_msg),
+               "timestamp", tp_message_get_received_timestamp (tp_msg),
+               "flags", flags,
+               "is-backlog", flags & TP_CHANNEL_TEXT_MESSAGE_FLAG_SCROLLBACK,
+               "incoming", incoming,
+               NULL);
 
-       priv->flags = flags;
+       priv = GET_PRIV (message);
+
+       /* FIXME: this is pretty low level, ideally we shouldn't have to use the
+        * ID directly but we don't use TpTextChannel's ack API everywhere yet. */
+       id = tp_asv_get_uint32 (tp_message_peek (tp_msg, 0),
+               "pending-message-id", NULL);
 
-       g_object_notify (G_OBJECT (self), "flags");
+       priv->id = id;
+
+       g_free (body);
+       return message;
 }
index 1db0eff600bb0e612de3673b09b5f76f9131df74..7508cb08e615f06f9c13e80c8c0c81996f948e5a 100644 (file)
@@ -26,6 +26,7 @@
 #define __EMPATHY_MESSAGE_H__
 
 #include <glib-object.h>
+#include <telepathy-glib/message.h>
 #include <telepathy-logger/event.h>
 
 #include "empathy-contact.h"
@@ -53,11 +54,12 @@ struct _EmpathyMessageClass {
 };
 
 GType                    empathy_message_get_type          (void) G_GNUC_CONST;
-EmpathyMessage *         empathy_message_new               (const gchar              *body);
+
 EmpathyMessage *         empathy_message_from_tpl_log_event (TplEvent                *logevent);
+EmpathyMessage *         empathy_message_new_from_tp_message (TpMessage *tp_msg,
+                                                             gboolean incoming);
+
 TpChannelTextMessageType empathy_message_get_tptype        (EmpathyMessage           *message);
-void                     empathy_message_set_tptype        (EmpathyMessage           *message,
-                                                           TpChannelTextMessageType  type);
 EmpathyContact *         empathy_message_get_sender        (EmpathyMessage           *message);
 void                     empathy_message_set_sender        (EmpathyMessage           *message,
                                                            EmpathyContact           *contact);
@@ -65,30 +67,19 @@ EmpathyContact *         empathy_message_get_receiver      (EmpathyMessage
 void                     empathy_message_set_receiver      (EmpathyMessage           *message,
                                                            EmpathyContact           *contact);
 const gchar *            empathy_message_get_body          (EmpathyMessage           *message);
-void                     empathy_message_set_body          (EmpathyMessage           *message,
-                                                           const gchar              *body);
-time_t                   empathy_message_get_timestamp     (EmpathyMessage           *message);
-void                     empathy_message_set_timestamp     (EmpathyMessage           *message,
-                                                           time_t                    timestamp);
+gint64                   empathy_message_get_timestamp     (EmpathyMessage           *message);
 gboolean                 empathy_message_is_backlog        (EmpathyMessage           *message);
-void                     empathy_message_set_is_backlog    (EmpathyMessage           *message,
-                                                           gboolean                 is_backlog);
 gboolean                 empathy_message_is_incoming       (EmpathyMessage           *message);
-void                     empathy_message_set_incoming      (EmpathyMessage           *message,
-                                                           gboolean                 incoming);
 
 gboolean                 empathy_message_should_highlight  (EmpathyMessage           *message);
 TpChannelTextMessageType empathy_message_type_from_str     (const gchar              *type_str);
 const gchar *            empathy_message_type_to_str       (TpChannelTextMessageType  type);
 
 guint                    empathy_message_get_id (EmpathyMessage *message);
-void                     empathy_message_set_id (EmpathyMessage *message, guint id);
 
 gboolean                 empathy_message_equal (EmpathyMessage *message1, EmpathyMessage *message2);
 
 TpChannelTextMessageFlags empathy_message_get_flags        (EmpathyMessage           *message);
-void                      empathy_message_set_flags        (EmpathyMessage           *message,
-                                                           TpChannelTextMessageFlags flags);
 
 G_END_DECLS
 
index 13e17d152730e9a23f49c903a08e6a7f868b80a3..f33152d972cfae4c7daf5ab39b8b34bd981bc306 100644 (file)
 
 /* Note: EmpathyTime is always in UTC. */
 
-time_t
+gint64
 empathy_time_get_current (void)
 {
-       return time (NULL);
-}
-
-time_t
-empathy_time_get_local_time (struct tm *tm)
-{
-       const gchar *tz;
-       time_t       t;
-
-       tz = g_getenv ("TZ");
-       g_setenv ("TZ", "", TRUE);
-
-       tzset ();
-
-       t = mktime (tm);
+       GDateTime *now;
+       gint64 result;
 
-       if (tz) {
-               g_setenv ("TZ", tz, TRUE);
-       } else {
-               g_unsetenv ("TZ");
-       }
-
-       tzset ();
+       now = g_date_time_new_now_utc ();
+       result = g_date_time_to_unix (now);
+       g_date_time_unref (now);
 
-       return t;
-}
-
-/* The format is: "20021209T23:51:30" and is in UTC. 0 is returned on
- * failure. The alternative format "20021209" is also accepted.
- */
-time_t
-empathy_time_parse (const gchar *str)
-{
-       struct tm tm;
-       gint      year, month;
-       gint      n_parsed;
-
-       memset (&tm, 0, sizeof (struct tm));
-
-       n_parsed = sscanf (str, "%4d%2d%2dT%2d:%2d:%2d",
-                   &year, &month, &tm.tm_mday, &tm.tm_hour,
-                          &tm.tm_min, &tm.tm_sec);
-       if (n_parsed != 3 && n_parsed != 6) {
-               return 0;
-       }
-
-       tm.tm_year = year - 1900;
-       tm.tm_mon = month - 1;
-       tm.tm_isdst = -1;
-
-       return empathy_time_get_local_time (&tm);
+       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);
+
+       result = g_date_time_format (local, format);
+       g_date_time_unref (local);
 
-       return g_strdup (stamp);
+       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 65e0127c7cabd59048ea4f9118ae091cfa18be44..7fac48221ae91ecbfcaf4e961c64349e92fcb56a 100644 (file)
@@ -39,14 +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);
-time_t  empathy_time_get_local_time  (struct tm   *tm);
-time_t  empathy_time_parse           (const gchar *str);
-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 1b2fe46b742765afd79f077cc665fccb02f05601..a56c08a3286dd4426d1fea176eb8c444c4645fb2 100644 (file)
@@ -47,7 +47,6 @@ typedef struct {
        EmpathyContact        *remote_contact;
        GList                 *members;
        TpChannel             *channel;
-       gboolean               listing_pending_messages;
        /* Queue of messages not signalled yet */
        GQueue                *messages_queue;
        /* Queue of messages signalled but not acked yet */
@@ -280,149 +279,176 @@ tp_chat_got_sender_cb (TpConnection            *connection,
 
 static void
 tp_chat_build_message (EmpathyTpChat *chat,
-                      gboolean       incoming,
-                      guint          id,
-                      guint          type,
-                      guint          timestamp,
-                      guint          from_handle,
-                      const gchar   *message_body,
-                      TpChannelTextMessageFlags flags)
+                      TpMessage     *msg,
+                      gboolean       incoming)
 {
        EmpathyTpChatPriv *priv;
        EmpathyMessage    *message;
+       TpContact *sender;
 
        priv = GET_PRIV (chat);
 
-       message = empathy_message_new (message_body);
-       empathy_message_set_tptype (message, type);
+       message = empathy_message_new_from_tp_message (msg, incoming);
+       /* FIXME: this is actually a lie for incoming messages. */
        empathy_message_set_receiver (message, priv->user);
-       empathy_message_set_timestamp (message, timestamp);
-       empathy_message_set_id (message, id);
-       empathy_message_set_incoming (message, incoming);
-       empathy_message_set_flags (message, flags);
-
-       if (flags & TP_CHANNEL_TEXT_MESSAGE_FLAG_SCROLLBACK)
-               empathy_message_set_is_backlog (message, TRUE);
 
        g_queue_push_tail (priv->messages_queue, message);
 
-       if (from_handle == 0) {
+       sender = tp_signalled_message_get_sender (msg);
+       g_assert (sender != NULL);
+
+       if (tp_contact_get_handle (sender) == 0) {
                empathy_message_set_sender (message, priv->user);
                tp_chat_emit_queued_messages (chat);
        } else {
                empathy_tp_contact_factory_get_from_handle (priv->connection,
-                       from_handle,
+                       tp_contact_get_handle (sender),
                        tp_chat_got_sender_cb,
                        message, NULL, G_OBJECT (chat));
        }
 }
 
 static void
-tp_chat_received_cb (TpChannel   *channel,
-                    guint        message_id,
-                    guint        timestamp,
-                    guint        from_handle,
-                    guint        message_type,
-                    guint        message_flags,
-                    const gchar *message_body,
-                    gpointer     user_data,
-                    GObject     *chat_)
-{
-       EmpathyTpChat *chat = EMPATHY_TP_CHAT (chat_);
-       EmpathyTpChatPriv *priv = GET_PRIV (chat);
+handle_delivery_report (EmpathyTpChat *self,
+               TpMessage *message)
+{
+       EmpathyTpChatPriv *priv = GET_PRIV (self);
+       TpDeliveryStatus delivery_status;
+       const GHashTable *header;
+       TpChannelTextSendError delivery_error;
+       gboolean valid;
+       GPtrArray *echo;
+       const gchar *message_body = NULL;
+
+       header = tp_message_peek (message, 0);
+       if (header == NULL)
+               goto out;
 
-       if (priv->channel == NULL)
-               return;
+       delivery_status = tp_asv_get_uint32 (header, "delivery-status", &valid);
+       if (!valid || delivery_status != TP_DELIVERY_STATUS_PERMANENTLY_FAILED)
+               goto out;
+
+       delivery_error = tp_asv_get_uint32 (header, "delivery-error", &valid);
+       if (!valid)
+               delivery_error = TP_CHANNEL_TEXT_SEND_ERROR_UNKNOWN;
 
-       if (priv->listing_pending_messages) {
+       /* TODO: ideally we should use tp-glib API giving us the echoed message as a
+        * TpMessage. (fdo #35884) */
+       echo = tp_asv_get_boxed (header, "delivery-echo",
+               TP_ARRAY_TYPE_MESSAGE_PART_LIST);
+       if (echo != NULL && echo->len >= 1) {
+               const GHashTable *echo_body;
+
+               echo_body = g_ptr_array_index (echo, 1);
+               if (echo_body != NULL)
+                       message_body = tp_asv_get_string (echo_body, "content");
+       }
+
+       g_signal_emit (self, signals[SEND_ERROR], 0, message_body, delivery_error);
+
+out:
+       tp_text_channel_ack_message_async (TP_TEXT_CHANNEL (priv->channel),
+               message, NULL, NULL);
+}
+
+static void
+handle_incoming_message (EmpathyTpChat *self,
+                        TpMessage *message,
+                        gboolean pending)
+{
+       EmpathyTpChatPriv *priv = GET_PRIV (self);
+       gchar *message_body;
+
+       if (tp_message_is_delivery_report (message)) {
+               handle_delivery_report (self, message);
                return;
        }
 
-       DEBUG ("Message received from channel %s: %s",
-               tp_proxy_get_object_path (channel), message_body);
+       message_body = tp_message_to_text (message, NULL);
 
-       if (message_flags & TP_CHANNEL_TEXT_MESSAGE_FLAG_NON_TEXT_CONTENT &&
-           !tp_strdiff (message_body, "")) {
-               GArray *ids;
+       DEBUG ("Message %s (channel %s): %s",
+               pending ? "pending" : "received",
+               tp_proxy_get_object_path (priv->channel), message_body);
 
+       if (message_body == NULL) {
                DEBUG ("Empty message with NonTextContent, ignoring and acking.");
 
-               ids = g_array_sized_new (FALSE, FALSE, sizeof (guint), 1);
-               g_array_append_val (ids, message_id);
-               acknowledge_messages (chat, ids);
-               g_array_free (ids, TRUE);
-
+               tp_text_channel_ack_message_async (TP_TEXT_CHANNEL (priv->channel),
+                       message, NULL, NULL);
                return;
        }
 
-       tp_chat_build_message (chat,
-                              TRUE,
-                              message_id,
-                              message_type,
-                              timestamp,
-                              from_handle,
-                              message_body,
-                              message_flags);
+       tp_chat_build_message (self, message, TRUE);
+
+       g_free (message_body);
 }
 
 static void
-tp_chat_sent_cb (TpChannel   *channel,
-                guint        timestamp,
-                guint        message_type,
-                const gchar *message_body,
-                gpointer     user_data,
-                GObject     *chat_)
-{
-       EmpathyTpChat *chat = EMPATHY_TP_CHAT (chat_);
-       EmpathyTpChatPriv *priv = GET_PRIV (chat);
+message_received_cb (TpTextChannel   *channel,
+                    TpMessage *message,
+                    EmpathyTpChat *chat)
+{
+       handle_incoming_message (chat, message, FALSE);
+}
 
-       if (priv->channel == NULL)
-               return;
+static void
+message_sent_cb (TpTextChannel   *channel,
+                TpMessage *message,
+                TpMessageSendingFlags flags,
+                gchar              *token,
+                EmpathyTpChat      *chat)
+{
+       gchar *message_body;
+
+       message_body = tp_message_to_text (message, NULL);
 
        DEBUG ("Message sent: %s", message_body);
 
-       tp_chat_build_message (chat,
-                              FALSE,
-                              0,
-                              message_type,
-                              timestamp,
-                              0,
-                              message_body,
-                              0);
+       tp_chat_build_message (chat, message, FALSE);
+
+       g_free (message_body);
 }
 
-static void
-tp_chat_send_error_cb (TpChannel   *channel,
-                      guint        error_code,
-                      guint        timestamp,
-                      guint        message_type,
-                      const gchar *message_body,
-                      gpointer     user_data,
-                      GObject     *chat)
+static TpChannelTextSendError
+error_to_text_send_error (GError *error)
 {
-       EmpathyTpChatPriv *priv = GET_PRIV (chat);
-
-       if (priv->channel == NULL)
-               return;
+       if (error->domain != TP_ERRORS)
+               return TP_CHANNEL_TEXT_SEND_ERROR_UNKNOWN;
 
-       DEBUG ("Error sending '%s' (%d)", message_body, error_code);
+       switch (error->code) {
+               case TP_ERROR_OFFLINE:
+                       return TP_CHANNEL_TEXT_SEND_ERROR_OFFLINE;
+               case TP_ERROR_INVALID_HANDLE:
+                       return TP_CHANNEL_TEXT_SEND_ERROR_INVALID_CONTACT;
+               case TP_ERROR_PERMISSION_DENIED:
+                       return TP_CHANNEL_TEXT_SEND_ERROR_PERMISSION_DENIED;
+               case TP_ERROR_NOT_IMPLEMENTED:
+                       return TP_CHANNEL_TEXT_SEND_ERROR_NOT_IMPLEMENTED;
+       }
 
-       g_signal_emit (chat, signals[SEND_ERROR], 0, message_body, error_code);
+       return TP_CHANNEL_TEXT_SEND_ERROR_UNKNOWN;
 }
 
 static void
-tp_chat_send_cb (TpChannel    *proxy,
-                const GError *error,
-                gpointer      user_data,
-                GObject      *chat)
+message_send_cb (GObject *source,
+                GAsyncResult *result,
+                gpointer      user_data)
 {
-       EmpathyMessage *message = EMPATHY_MESSAGE (user_data);
+       EmpathyTpChat *chat = user_data;
+       TpTextChannel *channel = (TpTextChannel *) source;
+       GError *error = NULL;
 
-       if (error) {
+       if (!tp_text_channel_send_message_finish (channel, result, NULL, &error)) {
                DEBUG ("Error: %s", error->message);
+
+               /* FIXME: we should use the body of the message as first argument of the
+                * signal but can't easily get it as we just get a user_data pointer. Once
+                * we'll have rebased EmpathyTpChat on top of TpTextChannel we'll be able
+                * to use the user_data pointer to pass the message and fix this. */
                g_signal_emit (chat, signals[SEND_ERROR], 0,
-                              empathy_message_get_body (message),
-                              TP_CHANNEL_TEXT_SEND_ERROR_UNKNOWN);
+                              NULL, error_to_text_send_error (error));
+
+               g_error_free (error);
        }
 }
 
@@ -457,86 +483,33 @@ static void
 tp_chat_state_changed_cb (TpChannel *channel,
                          TpHandle   handle,
                          TpChannelChatState state,
-                         gpointer   user_data,
-                         GObject   *chat)
+                         EmpathyTpChat *chat)
 {
        EmpathyTpChatPriv *priv = GET_PRIV (chat);
 
        empathy_tp_contact_factory_get_from_handle (priv->connection, handle,
                tp_chat_state_changed_got_contact_cb, GUINT_TO_POINTER (state),
-               NULL, chat);
+               NULL, G_OBJECT (chat));
 }
 
 static void
-tp_chat_list_pending_messages_cb (TpChannel       *channel,
-                                 const GPtrArray *messages_list,
-                                 const GError    *error,
-                                 gpointer         user_data,
-                                 GObject         *chat_)
+list_pending_messages (EmpathyTpChat *self)
 {
-       EmpathyTpChat     *chat = EMPATHY_TP_CHAT (chat_);
-       EmpathyTpChatPriv *priv = GET_PRIV (chat);
-       guint              i;
-       GArray            *empty_non_text_content_ids = NULL;
-
-       priv->listing_pending_messages = FALSE;
-
-       if (priv->channel == NULL)
-               return;
-
-       if (error) {
-               DEBUG ("Error listing pending messages: %s", error->message);
-               return;
-       }
-
-       for (i = 0; i < messages_list->len; i++) {
-               GValueArray    *message_struct;
-               const gchar    *message_body;
-               guint           message_id;
-               guint           timestamp;
-               guint           from_handle;
-               guint           message_type;
-               guint           message_flags;
-
-               message_struct = g_ptr_array_index (messages_list, i);
-
-               message_id = g_value_get_uint (g_value_array_get_nth (message_struct, 0));
-               timestamp = g_value_get_uint (g_value_array_get_nth (message_struct, 1));
-               from_handle = g_value_get_uint (g_value_array_get_nth (message_struct, 2));
-               message_type = g_value_get_uint (g_value_array_get_nth (message_struct, 3));
-               message_flags = g_value_get_uint (g_value_array_get_nth (message_struct, 4));
-               message_body = g_value_get_string (g_value_array_get_nth (message_struct, 5));
-
-               DEBUG ("Message pending: %s", message_body);
+       EmpathyTpChatPriv *priv = GET_PRIV (self);
+       GList *messages, *l;
 
-               if (message_flags & TP_CHANNEL_TEXT_MESSAGE_FLAG_NON_TEXT_CONTENT &&
-                   !tp_strdiff (message_body, "")) {
-                       DEBUG ("Empty message with NonTextContent, ignoring and acking.");
+       g_assert (priv->channel != NULL);
 
-                       if (empty_non_text_content_ids == NULL) {
-                               empty_non_text_content_ids = g_array_new (FALSE, FALSE, sizeof (guint));
-                       }
+       messages = tp_text_channel_get_pending_messages (
+               TP_TEXT_CHANNEL (priv->channel));
 
-                       g_array_append_val (empty_non_text_content_ids, message_id);
-                       continue;
-               }
+       for (l = messages; l != NULL; l = g_list_next (l)) {
+               TpMessage *message = l->data;
 
-               tp_chat_build_message (chat,
-                                      TRUE,
-                                      message_id,
-                                      message_type,
-                                      timestamp,
-                                      from_handle,
-                                      message_body,
-                                      message_flags);
+               handle_incoming_message (self, message, FALSE);
        }
 
-       if (empty_non_text_content_ids != NULL) {
-               acknowledge_messages (chat, empty_non_text_content_ids);
-               g_array_free (empty_non_text_content_ids, TRUE);
-       }
-
-       check_ready (chat);
+       g_list_free (messages);
 }
 
 static void
@@ -861,32 +834,22 @@ check_almost_ready (EmpathyTpChat *chat)
            priv->remote_contact == NULL)
                return;
 
-       tp_cli_channel_type_text_connect_to_received (priv->channel,
-                                                     tp_chat_received_cb,
-                                                     NULL, NULL,
-                                                     G_OBJECT (chat), NULL);
-       priv->listing_pending_messages = TRUE;
-
-       /* TpChat will be ready once ListPendingMessages returned and all the messages
-        * have been added to the pending messages queue. */
-       tp_cli_channel_type_text_call_list_pending_messages (priv->channel, -1,
-                                                            FALSE,
-                                                            tp_chat_list_pending_messages_cb,
-                                                            NULL, NULL,
-                                                            G_OBJECT (chat));
-
-       tp_cli_channel_type_text_connect_to_sent (priv->channel,
-                                                 tp_chat_sent_cb,
-                                                 NULL, NULL,
-                                                 G_OBJECT (chat), NULL);
-       tp_cli_channel_type_text_connect_to_send_error (priv->channel,
-                                                       tp_chat_send_error_cb,
-                                                       NULL, NULL,
-                                                       G_OBJECT (chat), NULL);
-       tp_cli_channel_interface_chat_state_connect_to_chat_state_changed (priv->channel,
-                                                                          tp_chat_state_changed_cb,
-                                                                          NULL, NULL,
-                                                                          G_OBJECT (chat), NULL);
+       /* We use the default factory so this feature should have been prepared */
+       g_assert (tp_proxy_is_prepared (priv->channel,
+               TP_TEXT_CHANNEL_FEATURE_INCOMING_MESSAGES));
+
+       tp_g_signal_connect_object (priv->channel, "message-received",
+               G_CALLBACK (message_received_cb), chat, 0);
+
+       list_pending_messages (chat);
+
+       tp_g_signal_connect_object (priv->channel, "message-sent",
+               G_CALLBACK (message_sent_cb), chat, 0);
+
+       tp_g_signal_connect_object (priv->channel, "chat-state-changed",
+               G_CALLBACK (tp_chat_state_changed_cb), chat, 0);
+
+       check_ready (chat);
 }
 
 static void
@@ -1551,7 +1514,7 @@ empathy_tp_chat_new (TpAccount *account,
                     TpChannel *channel)
 {
        g_return_val_if_fail (TP_IS_ACCOUNT (account), NULL);
-       g_return_val_if_fail (TP_IS_CHANNEL (channel), NULL);
+       g_return_val_if_fail (TP_IS_TEXT_CHANNEL (channel), NULL);
 
        return g_object_new (EMPATHY_TYPE_TP_CHAT,
                             "account", account,
@@ -1630,27 +1593,23 @@ empathy_tp_chat_is_ready (EmpathyTpChat *chat)
 
 void
 empathy_tp_chat_send (EmpathyTpChat *chat,
-                     EmpathyMessage *message)
+                     TpMessage *message)
 {
        EmpathyTpChatPriv        *priv = GET_PRIV (chat);
-       const gchar              *message_body;
-       TpChannelTextMessageType  message_type;
+       gchar *message_body;
 
        g_return_if_fail (EMPATHY_IS_TP_CHAT (chat));
-       g_return_if_fail (EMPATHY_IS_MESSAGE (message));
+       g_return_if_fail (TP_IS_CLIENT_MESSAGE (message));
        g_return_if_fail (priv->ready);
 
-       message_body = empathy_message_get_body (message);
-       message_type = empathy_message_get_tptype (message);
+       message_body = tp_message_to_text (message, NULL);
 
        DEBUG ("Sending message: %s", message_body);
-       tp_cli_channel_type_text_call_send (priv->channel, -1,
-                                           message_type,
-                                           message_body,
-                                           tp_chat_send_cb,
-                                           g_object_ref (message),
-                                           (GDestroyNotify) g_object_unref,
-                                           G_OBJECT (chat));
+
+       tp_text_channel_send_message_async (TP_TEXT_CHANNEL (priv->channel),
+               message, 0, message_send_cb, chat);
+
+       g_free (message_body);
 }
 
 void
index f7998e06f1dc6258eda99451ab18f3f2127d1d23..7c998a3fad82e2dd2fc85925ab3f17e151d8f318 100644 (file)
@@ -69,7 +69,7 @@ TpAccount    * empathy_tp_chat_get_account          (EmpathyTpChat      *chat);
 TpConnection * empathy_tp_chat_get_connection       (EmpathyTpChat      *chat);
 gboolean       empathy_tp_chat_is_ready             (EmpathyTpChat      *chat);
 void           empathy_tp_chat_send                 (EmpathyTpChat      *chat,
-                                                    EmpathyMessage     *message);
+                                                    TpMessage     *message);
 void           empathy_tp_chat_set_state            (EmpathyTpChat      *chat,
                                                     TpChannelChatState  state);
 void           empathy_tp_chat_set_property         (EmpathyTpChat      *chat,
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 ff715fe375acab2604cd76be1efcb342befb024e..6c92c25cb4df8ab4b8b6e0d6dad17fa31828b758 100644 (file)
@@ -231,6 +231,13 @@ handle_channels (TpSimpleHandler *handler,
       if (tp_proxy_get_invalidated (channel) != NULL)
         continue;
 
+      if (!TP_IS_TEXT_CHANNEL (channel))
+        {
+          DEBUG ("Channel %s doesn't implement Messages; can't handle it",
+              tp_proxy_get_object_path (channel));
+          continue;
+        }
+
       handling = TRUE;
 
       tp_chat = empathy_tp_chat_new (account, channel);
index 342d3e11e3821c701b2935898f3fc37a342beb76..6125ec89597e57d9befb89e350566b9f1683e10e 100644 (file)
@@ -934,7 +934,7 @@ approve_channels (TpSimpleApprover *approver,
 
   channel_type = tp_channel_get_channel_type_id (channel);
 
-  if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_TEXT)
+  if (TP_IS_TEXT_CHANNEL (channel))
     {
       EmpathyTpChat *tp_chat;
 
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
     {