]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-theme-boxes.c
use gtk_box_new() instead of gtk_[h,v]box_new()
[empathy.git] / libempathy-gtk / empathy-theme-boxes.c
index 458543fa405de3182fdcaa3f23eca1fd3c0b9f46..b9fd08d84b27e5738fcb05d753a283d980e0473c 100644 (file)
@@ -15,8 +15,8 @@
  *
  * You should have received a copy of the GNU General Public
  * License along with this program; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA  02110-1301  USA
  *
  * Authors: Xavier Claessens <xclaesse@gmail.com>
  */
@@ -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",
@@ -167,7 +170,7 @@ table_size_allocate_cb (GtkWidget     *view,
         gtk_widget_get_size_request (box, NULL, &height);
 
        width = allocation->width;
-       
+
        width -= \
                gtk_text_view_get_right_margin (GTK_TEXT_VIEW (view)) - \
                gtk_text_view_get_left_margin (GTK_TEXT_VIEW (view));
@@ -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. This catches all the different cases:
+       /* 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 (last_contact && 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,18 +275,26 @@ 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);
-       
+
        /* Set foreground color of labels to the same color than the header tag. */
        table = gtk_text_buffer_get_tag_table (buffer);
        tag = gtk_text_tag_table_lookup (table, EMPATHY_THEME_BOXES_TAG_HEADER);
        g_object_get (tag, "foreground-set", &color_set, NULL);
        if (color_set) {
-               GdkColor color;
+               GdkColor *color;
+
                g_object_get (tag, "foreground-gdk", &color, NULL);
-               gtk_widget_modify_fg (label1, GTK_STATE_NORMAL, &color);
-               gtk_widget_modify_fg (label2, GTK_STATE_NORMAL, &color);
+               gtk_widget_modify_fg (label1, GTK_STATE_NORMAL, color);
+               gtk_widget_modify_fg (label2, GTK_STATE_NORMAL, color);
+               gdk_color_free (color);
        }
 
        /* Pack labels into the box */
@@ -288,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);
@@ -328,8 +348,8 @@ theme_boxes_append_message (EmpathyChatTextView *view,
            TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION) {
                gchar *body;
 
-               body = g_strdup_printf (" * %s %s", 
-                                       empathy_contact_get_name (sender),
+               body = g_strdup_printf (" * %s %s",
+                                       empathy_contact_get_logged_alias (sender),
                                        empathy_message_get_body (message));
                empathy_chat_text_view_append_body (EMPATHY_CHAT_TEXT_VIEW (view),
                                                    body,
@@ -341,27 +361,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)
 {
@@ -371,7 +370,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));
@@ -385,17 +383,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,