]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-theme-boxes.c
local-xmpp-assistant-widget: increase row-spacing
[empathy.git] / libempathy-gtk / empathy-theme-boxes.c
index f5224278caace526613ea0891e515e5fa2b0ac06..cf0c652686893ed224c8d53cddd198ecbaf9b461 100644 (file)
@@ -33,7 +33,6 @@
 #include <libempathy/empathy-utils.h>
 #include "empathy-theme-boxes.h"
 #include "empathy-ui-utils.h"
-#include "empathy-conf.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
 #include <libempathy/empathy-debug.h>
 #define MARGIN 4
 #define HEADER_PADDING 2
 
+/* "Join" consecutive messages with timestamps within five minutes */
+#define MESSAGE_JOIN_PERIOD 5*60
+
 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyThemeBoxes)
 typedef struct {
        gboolean show_avatars;
-       guint    notify_show_avatars_id;
 } EmpathyThemeBoxesPriv;
 
 G_DEFINE_TYPE (EmpathyThemeBoxes, empathy_theme_boxes, EMPATHY_TYPE_CHAT_TEXT_VIEW);
@@ -105,7 +106,7 @@ theme_boxes_pad_to_size (GdkPixbuf *pixbuf,
 
 typedef struct {
        GdkPixbuf *pixbuf;
-       gchar     *token;
+       gchar     *filename;
 } AvatarData;
 
 static void
@@ -114,7 +115,7 @@ theme_boxes_avatar_cache_data_free (gpointer ptr)
        AvatarData *data = ptr;
 
        g_object_unref (data->pixbuf);
-       g_free (data->token);
+       g_free (data->filename);
        g_slice_free (AvatarData, data);
 }
 
@@ -130,7 +131,7 @@ theme_boxes_get_avatar_pixbuf_with_cache (EmpathyContact *contact)
        avatar = empathy_contact_get_avatar (contact);
        data = g_object_get_data (G_OBJECT (contact), "chat-view-avatar-cache");
        if (data) {
-               if (avatar && !tp_strdiff (avatar->token, data->token)) {
+               if (avatar && !tp_strdiff (avatar->filename, data->filename)) {
                        /* We have the avatar in cache */
                        return data->pixbuf;
                }
@@ -146,9 +147,11 @@ theme_boxes_get_avatar_pixbuf_with_cache (EmpathyContact *contact)
                return NULL;
        }
 
-       /* Insert new pixbuf in cache */
+       /* Insert new pixbuf in cache. We store the filename as it's unique
+        * for each version of an avatar, so we can use it to perform change
+        * detection (as above). */
        data = g_slice_new0 (AvatarData);
-       data->token = g_strdup (avatar->token);
+       data->filename = g_strdup (avatar->filename);
        data->pixbuf = pixbuf;
 
        g_object_set_data_full (G_OBJECT (contact), "chat-view-avatar-cache",
@@ -193,24 +196,30 @@ 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;
        GtkTextTagTable      *table;
        GtkTextTag           *tag;
+       GString              *str_obj;
+       gboolean              consecutive;
 
        contact = empathy_message_get_sender (msg);
-       name = empathy_contact_get_name (contact);
+       name = empathy_contact_get_logged_alias (contact);
        last_contact = empathy_chat_text_view_get_last_contact (view);
        buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (theme));
+       time_ = empathy_message_get_timestamp (msg);
+       consecutive = (time_ - empathy_chat_text_view_get_last_timestamp (view)
+               < MESSAGE_JOIN_PERIOD);
 
        DEBUG ("Maybe add fancy header");
 
-       /* Only insert a header if the previously inserted block is not the same
-        * as this one.
+       /* Only insert a header if
+        *   - the previously inserted block is not the same as this one.
+        *   - the delay between two messages is lower then MESSAGE_JOIN_PERIOD
         */
-       if (empathy_contact_equal (last_contact, contact)) {
+       if (empathy_contact_equal (last_contact, contact) && consecutive) {
                return;
        }
 
@@ -230,7 +239,7 @@ theme_boxes_maybe_append_header (EmpathyThemeBoxes *theme,
 
        /* Create a hbox for the header and resize it when the view allocation
         * changes */
-       box = gtk_hbox_new (FALSE, 0);
+       box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
        g_signal_connect_object (view, "size-allocate",
                                 G_CALLBACK (table_size_allocate_cb),
                                 box, 0);
@@ -258,8 +267,7 @@ theme_boxes_maybe_append_header (EmpathyThemeBoxes *theme,
        g_free (str);
 
        /* Add the message receive time */
-       time = empathy_message_get_timestamp (msg);
-       tmp = empathy_time_to_string_local (time,
+       tmp = empathy_time_to_string_local (time_,
                                           EMPATHY_TIME_FORMAT_DISPLAY_SHORT);
        str = g_strdup_printf ("<i>%s</i>", tmp);
        label2 = g_object_new (GTK_TYPE_LABEL,
@@ -267,6 +275,12 @@ theme_boxes_maybe_append_header (EmpathyThemeBoxes *theme,
                               "use-markup", TRUE,
                               "xalign", 1.0,
                               NULL);
+
+       str_obj = g_string_new ("\n- ");
+       g_string_append (str_obj, name);
+       g_string_append (str_obj, ", ");
+       g_string_append (str_obj, tmp);
+       g_string_append (str_obj, " -");
        g_free (tmp);
        g_free (str);
 
@@ -290,6 +304,10 @@ theme_boxes_maybe_append_header (EmpathyThemeBoxes *theme,
        gtk_box_pack_start (GTK_BOX (box), label2, TRUE, TRUE, 0);
 
        /* Add the header box to the text view */
+       g_object_set_data_full (G_OBJECT (box),
+                               "str_obj",
+                               g_string_free (str_obj, FALSE),
+                               g_free);
        gtk_text_view_add_child_at_anchor (GTK_TEXT_VIEW (view),
                                           box,
                                           anchor);
@@ -319,7 +337,8 @@ theme_boxes_maybe_append_header (EmpathyThemeBoxes *theme,
 
 static void
 theme_boxes_append_message (EmpathyChatTextView *view,
-                           EmpathyMessage      *message)
+                           EmpathyMessage      *message,
+                           gboolean             should_highlight)
 {
        EmpathyContact *sender;
 
@@ -331,7 +350,7 @@ theme_boxes_append_message (EmpathyChatTextView *view,
                gchar *body;
 
                body = g_strdup_printf (" * %s %s",
-                                       empathy_contact_get_name (sender),
+                                       empathy_contact_get_logged_alias (sender),
                                        empathy_message_get_body (message));
                empathy_chat_text_view_append_body (EMPATHY_CHAT_TEXT_VIEW (view),
                                                    body,
@@ -343,27 +362,6 @@ theme_boxes_append_message (EmpathyChatTextView *view,
        }
 }
 
-static void
-theme_boxes_notify_show_avatars_cb (EmpathyConf *conf,
-                                   const gchar *key,
-                                   gpointer     user_data)
-{
-       EmpathyThemeBoxesPriv *priv = GET_PRIV (user_data);
-
-       empathy_conf_get_bool (conf, key, &priv->show_avatars);
-}
-
-static void
-theme_boxes_finalize (GObject *object)
-{
-       EmpathyThemeBoxesPriv *priv = GET_PRIV (object);
-
-       empathy_conf_notify_remove (empathy_conf_get (),
-                                   priv->notify_show_avatars_id);
-
-       G_OBJECT_CLASS (empathy_theme_boxes_parent_class)->finalize (object);
-}
-
 static void
 empathy_theme_boxes_class_init (EmpathyThemeBoxesClass *class)
 {
@@ -373,7 +371,6 @@ empathy_theme_boxes_class_init (EmpathyThemeBoxesClass *class)
        object_class = G_OBJECT_CLASS (class);
        chat_text_view_class  = EMPATHY_CHAT_TEXT_VIEW_CLASS (class);
 
-       object_class->finalize = theme_boxes_finalize;
        chat_text_view_class->append_message = theme_boxes_append_message;
 
        g_type_class_add_private (object_class, sizeof (EmpathyThemeBoxesPriv));
@@ -387,17 +384,11 @@ empathy_theme_boxes_init (EmpathyThemeBoxes *theme)
 
        theme->priv = priv;
 
-       theme_boxes_create_tags (theme);
-
-       priv->notify_show_avatars_id =
-               empathy_conf_notify_add (empathy_conf_get (),
-                                        EMPATHY_PREFS_UI_SHOW_AVATARS,
-                                        theme_boxes_notify_show_avatars_cb,
-                                        theme);
+       /* This is just hard-coded to TRUE until someone adds a tickybox in the
+        * Theme tab for it. */
+       priv->show_avatars = TRUE;
 
-       empathy_conf_get_bool (empathy_conf_get (),
-                              EMPATHY_PREFS_UI_SHOW_AVATARS,
-                              &priv->show_avatars);
+       theme_boxes_create_tags (theme);
 
        /* Define margin */
        g_object_set (theme,