]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-theme-boxes.c
Merge branch 'irc-dialog-579800'
[empathy.git] / libempathy-gtk / empathy-theme-boxes.c
index 2905f2bece4338635dc811188d56155800028bcb..5b435f1d5d9cd9aff3ee05b80ebec9f0c2ad1f07 100644 (file)
@@ -1,6 +1,7 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
 /*
  * Copyright (C) 2007 Imendio AB
+ * Copyright (C) 2008 Collabora Ltd.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
  * License along with this program; if not, write to the
  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  * Boston, MA 02111-1307, USA.
+ *
+ * Authors: Xavier Claessens <xclaesse@gmail.com>
  */
 
 #include <config.h>
 
 #include <string.h>
 
-#include <glib/gi18n.h>
+#include <glib/gi18n-lib.h>
 #include <gtk/gtk.h>
 
-#include <libempathy/empathy-debug.h>
+#include <telepathy-glib/util.h>
 
-#include "empathy-ui-utils.h"
-#include "empathy-main-window.h"
-#include "empathy-theme-utils.h"
+#include <libempathy/empathy-utils.h>
 #include "empathy-theme-boxes.h"
+#include "empathy-ui-utils.h"
+#include "empathy-conf.h"
 
-#define DEBUG_DOMAIN "FancyTheme"
+#define DEBUG_FLAG EMPATHY_DEBUG_OTHER
+#include <libempathy/empathy-debug.h>
 
 #define MARGIN 4
 #define HEADER_PADDING 2
 
-#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EMPATHY_TYPE_THEME_BOXES, EmpathyThemeBoxesPriv))
-
-typedef struct _EmpathyThemeBoxesPriv EmpathyThemeBoxesPriv;
-
-struct _EmpathyThemeBoxesPriv {
-       gchar *header_foreground;
-       gchar *header_background;
-       gchar *header_line_background;
-       gchar *text_foreground;
-       gchar *text_background;
-       gchar *action_foreground;
-       gchar *highlight_foreground;
-       gchar *time_foreground;
-       gchar *event_foreground;
-       gchar *invite_foreground;
-       gchar *link_foreground;
-};
-
-static void     theme_boxes_finalize          (GObject            *object);
-static void     theme_boxes_get_property      (GObject            *object,
-                                              guint               param_id,
-                                              GValue             *value,
-                                              GParamSpec         *pspec);
-static void     theme_boxes_set_property      (GObject            *object,
-                                              guint               param_id,
-                                              const GValue       *value,
-                                              GParamSpec         *pspec);
-static void     theme_boxes_define_theme_tags (EmpathyTheme        *theme,
-                                              EmpathyChatView     *view);
-static EmpathyThemeContext *
-theme_boxes_setup_with_view                   (EmpathyTheme        *theme,
-                                              EmpathyChatView     *view);
-static void     theme_boxes_detach_from_view  (EmpathyTheme        *theme,
-                                              EmpathyThemeContext *context,
-                                              EmpathyChatView     *view);
-static void     theme_boxes_view_cleared      (EmpathyTheme        *theme,
-                                              EmpathyThemeContext *context,
-                                              EmpathyChatView     *view);
-
-static void     theme_boxes_append_message    (EmpathyTheme        *theme,
-                                              EmpathyThemeContext *context,
-                                              EmpathyChatView     *view,
-                                              EmpathyMessage      *message);
-static void     theme_boxes_append_event      (EmpathyTheme        *theme,
-                                              EmpathyThemeContext *context,
-                                              EmpathyChatView     *view,
-                                              const gchar        *str);
-static void     theme_boxes_append_timestamp  (EmpathyTheme        *theme,
-                                              EmpathyThemeContext *context,
-                                              EmpathyChatView     *view,
-                                              EmpathyMessage      *message,
-                                              gboolean            show_date,
-                                              gboolean            show_time);
-static void     theme_boxes_append_spacing    (EmpathyTheme        *theme,
-                                              EmpathyThemeContext *context,
-                                              EmpathyChatView     *view);
-
-enum {
-       PROP_0,
-       PROP_HEADER_FOREGROUND,
-       PROP_HEADER_BACKGROUND,
-       PROP_HEADER_LINE_BACKGROUND,
-       PROP_TEXT_FOREGROUND,
-       PROP_TEXT_BACKGROUND,
-       PROP_ACTION_FOREGROUND,
-       PROP_HIGHLIGHT_FOREGROUND,
-       PROP_TIME_FOREGROUND,
-       PROP_EVENT_FOREGROUND,
-       PROP_INVITE_FOREGROUND,
-       PROP_LINK_FOREGROUND
-};
-
-enum {
-       PROP_FLOP,
-       PROP_MY_PROP
-};
-
-G_DEFINE_TYPE (EmpathyThemeBoxes, empathy_theme_boxes, EMPATHY_TYPE_THEME);
+#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);
 
 static void
-empathy_theme_boxes_class_init (EmpathyThemeBoxesClass *class)
+theme_boxes_create_tags (EmpathyThemeBoxes *theme)
 {
-       GObjectClass     *object_class;
-       EmpathyThemeClass *theme_class;
-
-       object_class = G_OBJECT_CLASS (class);
-       theme_class  = EMPATHY_THEME_CLASS (class);
-
-       object_class->finalize       = theme_boxes_finalize;
-       object_class->get_property   = theme_boxes_get_property;
-       object_class->set_property   = theme_boxes_set_property;
-
-       theme_class->setup_with_view  = theme_boxes_setup_with_view;
-       theme_class->detach_from_view = theme_boxes_detach_from_view;
-       theme_class->view_cleared     = theme_boxes_view_cleared;
-       theme_class->append_message   = theme_boxes_append_message;
-       theme_class->append_event     = theme_boxes_append_event;
-       theme_class->append_timestamp = theme_boxes_append_timestamp;
-       theme_class->append_spacing   = theme_boxes_append_spacing;
-
-       g_object_class_install_property (object_class,
-                                        PROP_HEADER_FOREGROUND,
-                                        g_param_spec_string ("header-foreground",
-                                                             "",
-                                                             "",
-                                                             NULL,
-                                                             G_PARAM_READWRITE));
-
-       g_object_class_install_property (object_class,
-                                        PROP_HEADER_BACKGROUND,
-                                        g_param_spec_string ("header-background",
-                                                             "",
-                                                             "",
-                                                             NULL,
-                                                             G_PARAM_READWRITE));
-
-       g_object_class_install_property (object_class,
-                                        PROP_HEADER_LINE_BACKGROUND,
-                                        g_param_spec_string ("header-line-background",
-                                                             "",
-                                                             "",
-                                                             NULL,
-                                                             G_PARAM_READWRITE));
-
-
-       g_object_class_install_property (object_class,
-                                        PROP_TEXT_FOREGROUND,
-                                        g_param_spec_string ("text-foreground",
-                                                             "",
-                                                             "",
-                                                             NULL,
-                                                             G_PARAM_READWRITE));
-
-       g_object_class_install_property (object_class,
-                                        PROP_TEXT_BACKGROUND,
-                                        g_param_spec_string ("text-background",
-                                                             "",
-                                                             "",
-                                                             NULL,
-                                                             G_PARAM_READWRITE));
-
-       g_object_class_install_property (object_class,
-                                        PROP_ACTION_FOREGROUND,
-                                        g_param_spec_string ("action-foreground",
-                                                             "",
-                                                             "",
-                                                             NULL,
-                                                             G_PARAM_READWRITE));
-
-       g_object_class_install_property (object_class,
-                                        PROP_HIGHLIGHT_FOREGROUND,
-                                        g_param_spec_string ("highlight-foreground",
-                                                             "",
-                                                             "",
-                                                             NULL,
-                                                             G_PARAM_READWRITE));
-
-       g_object_class_install_property (object_class,
-                                        PROP_TIME_FOREGROUND,
-                                        g_param_spec_string ("time-foreground",
-                                                             "",
-                                                             "",
-                                                             NULL,
-                                                             G_PARAM_READWRITE));
-
-       g_object_class_install_property (object_class,
-                                        PROP_EVENT_FOREGROUND,
-                                        g_param_spec_string ("event-foreground",
-                                                             "",
-                                                             "",
-                                                             NULL,
-                                                             G_PARAM_READWRITE));
-
-       g_object_class_install_property (object_class,
-                                        PROP_INVITE_FOREGROUND,
-                                        g_param_spec_string ("invite-foreground",
-                                                             "",
-                                                             "",
-                                                             NULL,
-                                                             G_PARAM_READWRITE));
-
-       g_object_class_install_property (object_class,
-                                        PROP_LINK_FOREGROUND,
-                                        g_param_spec_string ("link-foreground",
-                                                             "",
-                                                             "",
-                                                             NULL,
-                                                             G_PARAM_READWRITE));
+       GtkTextBuffer *buffer;
 
-       g_type_class_add_private (object_class, sizeof (EmpathyThemeBoxesPriv));
-}
+       buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (theme));
 
-static void
-empathy_theme_boxes_init (EmpathyThemeBoxes *theme)
-{
-       EmpathyThemeBoxesPriv *priv;
+       gtk_text_buffer_create_tag (buffer, EMPATHY_THEME_BOXES_TAG_HEADER,
+                                   "pixels-above-lines", HEADER_PADDING,
+                                   "pixels-below-lines", HEADER_PADDING,
+                                   NULL);
 
-       priv = GET_PRIV (theme);
+       gtk_text_buffer_create_tag (buffer, EMPATHY_THEME_BOXES_TAG_HEADER_LINE, NULL);
 }
 
-static void
-theme_boxes_finalize (GObject *object)
+/* Pads a pixbuf to the specified size, by centering it in a larger transparent
+ * pixbuf. Returns a new ref.
+ */
+static GdkPixbuf *
+theme_boxes_pad_to_size (GdkPixbuf *pixbuf,
+                        gint       width,
+                        gint       height,
+                        gint       extra_padding_right)
 {
-       EmpathyThemeBoxesPriv *priv;
-
-       priv = GET_PRIV (object);
-
-       g_free (priv->header_foreground);
-       g_free (priv->header_background);
-       g_free (priv->header_line_background);
-       g_free (priv->text_foreground);
-       g_free (priv->text_background);
-       g_free (priv->action_foreground);
-       g_free (priv->highlight_foreground);
-       g_free (priv->time_foreground);
-       g_free (priv->event_foreground);
-       g_free (priv->invite_foreground);
-       g_free (priv->link_foreground);
-       
-       (G_OBJECT_CLASS (empathy_theme_boxes_parent_class)->finalize) (object);
+       gint       src_width, src_height;
+       GdkPixbuf *padded;
+       gint       x_offset, y_offset;
+
+       src_width = gdk_pixbuf_get_width (pixbuf);
+       src_height = gdk_pixbuf_get_height (pixbuf);
+
+       x_offset = (width - src_width) / 2;
+       y_offset = (height - src_height) / 2;
+
+       padded = gdk_pixbuf_new (gdk_pixbuf_get_colorspace (pixbuf),
+                                TRUE, /* alpha */
+                                gdk_pixbuf_get_bits_per_sample (pixbuf),
+                                width + extra_padding_right,
+                                height);
+
+       gdk_pixbuf_fill (padded, 0);
+
+       gdk_pixbuf_copy_area (pixbuf,
+                             0, /* source coords */
+                             0,
+                             src_width,
+                             src_height,
+                             padded,
+                             x_offset, /* dest coords */
+                             y_offset);
+
+       return padded;
 }
 
-static void
-theme_boxes_get_property (GObject    *object,
-                         guint       param_id,
-                         GValue     *value,
-                         GParamSpec *pspec)
-{
-       EmpathyThemeBoxesPriv *priv;
-
-       priv = GET_PRIV (object);
-
-       switch (param_id) {
-       case PROP_HEADER_FOREGROUND:
-               g_value_set_string (value, priv->header_foreground);
-               break;
-       case PROP_HEADER_BACKGROUND:
-               g_value_set_string (value, priv->header_background);
-               break;
-       case PROP_HEADER_LINE_BACKGROUND:
-               g_value_set_string (value, priv->header_line_background);
-               break;
-       case PROP_TEXT_FOREGROUND:
-               g_value_set_string (value, priv->text_foreground);
-               break;
-       case PROP_TEXT_BACKGROUND:
-               g_value_set_string (value, priv->text_background);
-               break;
-       case PROP_ACTION_FOREGROUND:
-               g_value_set_string (value, priv->action_foreground);
-               break;
-       case PROP_HIGHLIGHT_FOREGROUND:
-               g_value_set_string (value, priv->highlight_foreground);
-               break;
-       case PROP_TIME_FOREGROUND:
-               g_value_set_string (value, priv->time_foreground);
-               break;
-       case PROP_EVENT_FOREGROUND:
-               g_value_set_string (value, priv->event_foreground);
-               break;
-       case PROP_INVITE_FOREGROUND:
-               g_value_set_string (value, priv->invite_foreground);
-               break;
-       case PROP_LINK_FOREGROUND:
-               g_value_set_string (value, priv->link_foreground);
-               break;
-       default:
-               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
-               break;
-       }
-}
-static void
-theme_boxes_set_property (GObject      *object,
-                   guint         param_id,
-                   const GValue *value,
-                   GParamSpec   *pspec)
-{
-       EmpathyThemeBoxesPriv *priv;
-
-       priv = GET_PRIV (object);
-
-       switch (param_id) {
-       case PROP_HEADER_FOREGROUND:
-               g_free (priv->header_foreground);
-               priv->header_foreground = g_value_dup_string (value);
-               break;
-       case PROP_HEADER_BACKGROUND:
-               g_free (priv->header_background);
-               priv->header_background = g_value_dup_string (value);
-               break;
-       case PROP_HEADER_LINE_BACKGROUND:
-               g_free (priv->header_line_background);
-               priv->header_line_background = g_value_dup_string (value);
-               break;
-       case PROP_TEXT_FOREGROUND:
-               g_free (priv->text_foreground);
-               priv->text_foreground = g_value_dup_string (value);
-               break;
-       case PROP_TEXT_BACKGROUND:
-               g_free (priv->text_background);
-               priv->text_background = g_value_dup_string (value);
-               break;
-       case PROP_ACTION_FOREGROUND:
-               g_free (priv->action_foreground);
-               priv->action_foreground = g_value_dup_string (value);
-               break;
-       case PROP_HIGHLIGHT_FOREGROUND:
-               g_free (priv->highlight_foreground);
-               priv->highlight_foreground = g_value_dup_string (value);
-               break;
-       case PROP_TIME_FOREGROUND:
-               g_free (priv->time_foreground);
-               priv->time_foreground = g_value_dup_string (value);
-               break;
-       case PROP_EVENT_FOREGROUND:
-               g_free (priv->event_foreground);
-               priv->event_foreground = g_value_dup_string (value);
-               break;
-       case PROP_INVITE_FOREGROUND:
-               g_free (priv->invite_foreground);
-               priv->invite_foreground = g_value_dup_string (value);
-               break;
-       case PROP_LINK_FOREGROUND:
-               g_free (priv->link_foreground);
-               priv->link_foreground = g_value_dup_string (value);
-               break;
-       default:
-               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
-               break;
-       }
-}
+typedef struct {
+       GdkPixbuf *pixbuf;
+       gchar     *token;
+} AvatarData;
 
 static void
-theme_boxes_define_theme_tags (EmpathyTheme *theme, EmpathyChatView *view)
+theme_boxes_avatar_cache_data_free (gpointer ptr)
 {
-       EmpathyThemeBoxesPriv *priv;
-       GtkTextBuffer   *buffer;
-       GtkTextTagTable *table;
-       GtkTextTag      *tag;
-
-       priv = GET_PRIV (theme);
-
-       buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
-       table = gtk_text_buffer_get_tag_table (buffer);
-
-       tag = empathy_theme_utils_init_tag_by_name (table, "fancy-spacing");
-       g_object_set (tag,
-                     "size", 3000,
-                     "pixels-above-lines", 8,
-                     NULL);
-       empathy_theme_utils_add_tag (table, tag);
-
-       tag = empathy_theme_utils_init_tag_by_name (table, 
-                                                  "fancy-header");
-       g_object_set (tag,
-                     "weight", PANGO_WEIGHT_BOLD,
-                     "pixels-above-lines", HEADER_PADDING,
-                     "pixels-below-lines", HEADER_PADDING,
-                     NULL);
-       if (priv->header_foreground) {
-               g_object_set (tag,
-                             "foreground", priv->header_foreground,
-                             "paragraph-background", priv->header_background,
-                             NULL);
-       }
-       empathy_theme_utils_add_tag (table, tag);
-
-       tag = empathy_theme_utils_init_tag_by_name (table, "fancy-header-line");
-       g_object_set (tag,
-                     "size", 1,
-                     NULL);
-       if (priv->header_line_background) {
-               g_object_set (tag,
-                             "paragraph-background", priv->header_line_background,
-                             NULL);
-       }
-
-       empathy_theme_utils_add_tag (table, tag);
-
-       tag = empathy_theme_utils_init_tag_by_name (table, "fancy-body");
-       g_object_set (tag,
-                     "pixels-above-lines", 4,
-                     NULL);
-       if (priv->text_background) {
-               g_object_set (tag,
-                             "paragraph-background", priv->text_background,
-                             NULL);
-       }
-
-       if (priv->text_foreground) {
-               g_object_set (tag,
-                             "foreground", priv->text_foreground,
-                             NULL);
-       }
-       empathy_theme_utils_add_tag (table, tag);
-
-       tag = empathy_theme_utils_init_tag_by_name (table, "fancy-action");
-       g_object_set (tag,
-                     "style", PANGO_STYLE_ITALIC,
-                     "pixels-above-lines", 4,
-                     NULL);
-
-       if (priv->text_background) {
-               g_object_set (tag,
-                             "paragraph-background", priv->text_background,
-                             NULL);
-       }
-
-       if (priv->action_foreground) {
-               g_object_set (tag,
-                             "foreground", priv->action_foreground,
-                             NULL);
-       } 
-
-       empathy_theme_utils_add_tag (table, tag);
-
-       tag = empathy_theme_utils_init_tag_by_name (table,
-                                                  "fancy-highlight");
-       g_object_set (tag,
-                     "weight", PANGO_WEIGHT_BOLD,
-                     "pixels-above-lines", 4,
-                     NULL);
-       if (priv->text_background) {
-               g_object_set (tag,
-                             "paragraph-background", priv->text_background,
-                             NULL);
-       }
+       AvatarData *data = ptr;
 
+       g_object_unref (data->pixbuf);
+       g_free (data->token);
+       g_slice_free (AvatarData, data);
+}
 
-       if (priv->highlight_foreground) {
-               g_object_set (tag,
-                             "foreground", priv->highlight_foreground,
-                             NULL);
-       }
-       empathy_theme_utils_add_tag (table, tag);
-
-       tag = empathy_theme_utils_init_tag_by_name (table, "fancy-time");
-       g_object_set (tag,
-                     "justification", GTK_JUSTIFY_CENTER,
-                     NULL);
-       if (priv->time_foreground) {
-               g_object_set (tag,
-                             "foreground", priv->time_foreground,
-                             NULL);
+static GdkPixbuf *
+theme_boxes_get_avatar_pixbuf_with_cache (EmpathyContact *contact)
+{
+       AvatarData        *data;
+       EmpathyAvatar     *avatar;
+       GdkPixbuf         *tmp_pixbuf;
+       GdkPixbuf         *pixbuf = NULL;
+
+       /* Check if avatar is in cache and if it's up to date */
+       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)) {
+                       /* We have the avatar in cache */
+                       return data->pixbuf;
+               }
        }
-       empathy_theme_utils_add_tag (table, tag);
 
-       tag = empathy_theme_utils_init_tag_by_name (table, "fancy-event");
-       g_object_set (tag,
-                     "justification", GTK_JUSTIFY_LEFT,
-                     NULL);
-       if (priv->event_foreground) {
-               g_object_set (tag,
-                             "foreground", priv->event_foreground,
-                             NULL);
+       /* Avatar not in cache, create pixbuf */
+       tmp_pixbuf = empathy_pixbuf_avatar_from_contact_scaled (contact, 32, 32);
+       if (tmp_pixbuf) {
+               pixbuf = theme_boxes_pad_to_size (tmp_pixbuf, 32, 32, 6);
+               g_object_unref (tmp_pixbuf);
        }
-       empathy_theme_utils_add_tag (table, tag);
-
-       tag = empathy_theme_utils_init_tag_by_name (table, "invite");
-       if (priv->invite_foreground) {
-               g_object_set (tag,
-                             "foreground", priv->invite_foreground,
-                             NULL);
+       if (!pixbuf) {
+               return NULL;
        }
-       empathy_theme_utils_add_tag (table, tag);
-
-       tag = empathy_theme_utils_init_tag_by_name (table, "fancy-link");
-       g_object_set (tag,
-                     "underline", PANGO_UNDERLINE_SINGLE,
-                     NULL);
-       if (priv->link_foreground) {
-               g_object_set (tag,
-                             "foreground", priv->link_foreground,
-                             NULL);
-       } 
-       empathy_theme_utils_add_tag (table, tag);
-}
-
-static void
-theme_boxes_fixup_tag_table (EmpathyTheme *theme, EmpathyChatView *view)
-{
-       GtkTextBuffer *buffer;
-
-       buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
-
-       /* "Fancy" style tags. */
-       empathy_theme_utils_ensure_tag_by_name (buffer, "fancy-header");
-       empathy_theme_utils_ensure_tag_by_name (buffer, "fancy-header-line");
-       empathy_theme_utils_ensure_tag_by_name (buffer, "fancy-body");
-       empathy_theme_utils_ensure_tag_by_name (buffer, "fancy-action");
-       empathy_theme_utils_ensure_tag_by_name (buffer, "fancy-highlight");
-       empathy_theme_utils_ensure_tag_by_name (buffer, "fancy-spacing");
-       empathy_theme_utils_ensure_tag_by_name (buffer, "fancy-time");
-       empathy_theme_utils_ensure_tag_by_name (buffer, "fancy-event");
-       empathy_theme_utils_ensure_tag_by_name (buffer, "fancy-link");
-}
-
-typedef struct {
-       BlockType last_block_type;
-       time_t    last_timestamp;
-} FancyContext;
-
-static EmpathyThemeContext *
-theme_boxes_setup_with_view (EmpathyTheme *theme, EmpathyChatView *view)
-{
-       EmpathyThemeBoxesPriv *priv;
-
-       g_return_val_if_fail (EMPATHY_IS_THEME_BOXES (theme), NULL);
-
-       priv = GET_PRIV (theme);
-
-       theme_boxes_fixup_tag_table (theme, view);
 
-       theme_boxes_define_theme_tags (theme, view);
-       
-       empathy_chat_view_set_margin (view, MARGIN);
+       /* Insert new pixbuf in cache */
+       data = g_slice_new0 (AvatarData);
+       data->token = g_strdup (avatar->token);
+       data->pixbuf = pixbuf;
 
-       return NULL;
-}
+       g_object_set_data_full (G_OBJECT (contact), "chat-view-avatar-cache",
+                               data, theme_boxes_avatar_cache_data_free);
 
-static void
-theme_boxes_detach_from_view (EmpathyTheme        *theme,
-                             EmpathyThemeContext *context,
-                             EmpathyChatView     *view)
-{
-       /* FIXME: Free the context */
-}
-
-static void 
-theme_boxes_view_cleared (EmpathyTheme        *theme,
-                         EmpathyThemeContext *context,
-                         EmpathyChatView     *view)
-{
-       /* FIXME: clear the context data */
+       return data->pixbuf;
 }
 
 static void
@@ -594,17 +178,16 @@ table_size_allocate_cb (GtkWidget     *view,
 }
 
 static void
-theme_boxes_maybe_append_header (EmpathyTheme        *theme,
-                                EmpathyThemeContext *context,
-                                EmpathyChatView     *view,
-                                EmpathyMessage      *msg)
+theme_boxes_maybe_append_header (EmpathyThemeBoxes *theme,
+                                EmpathyMessage    *msg)
 {
-       EmpathyThemeBoxesPriv *priv;
-       EmpathyContact        *contact;
+       EmpathyChatTextView  *view = EMPATHY_CHAT_TEXT_VIEW (theme);
+       EmpathyThemeBoxesPriv*priv = GET_PRIV (theme);
+       EmpathyContact       *contact;
+       EmpathyContact       *last_contact;
        GdkPixbuf            *avatar = NULL;
        GtkTextBuffer        *buffer;
        const gchar          *name;
-       gboolean              header;
        GtkTextIter           iter;
        GtkWidget            *label1, *label2;
        GtkTextChildAnchor   *anchor;
@@ -613,424 +196,221 @@ theme_boxes_maybe_append_header (EmpathyTheme        *theme,
        time_t                time;
        gchar                *tmp;
        GtkTextIter           start;
-       GdkColor              color;
-       gboolean              parse_success;
-       gboolean              from_self;
-
-       priv = GET_PRIV (theme);
+       gboolean              color_set;
+       GtkTextTagTable      *table;
+       GtkTextTag           *tag;
 
        contact = empathy_message_get_sender (msg);
-       from_self = empathy_contact_is_user (contact);
-       buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
-
-       empathy_debug (DEBUG_DOMAIN, "Maybe add fancy header");
-
        name = empathy_contact_get_name (contact);
+       last_contact = empathy_chat_text_view_get_last_contact (view);
+       buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (theme));
 
-       header = FALSE;
+       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:
+        * as this one.
         */
-       if (empathy_chat_view_get_last_block_type (view) != BLOCK_TYPE_SELF &&
-           empathy_chat_view_get_last_block_type (view) != BLOCK_TYPE_OTHER) {
-               header = TRUE;
-       }
-       else if (from_self &&
-                empathy_chat_view_get_last_block_type (view) == BLOCK_TYPE_OTHER) {
-               header = TRUE;
-       }
-       else if (!from_self && 
-                empathy_chat_view_get_last_block_type (view) == BLOCK_TYPE_SELF) {
-               header = TRUE;
-       }
-       else if (!from_self &&
-                (!empathy_chat_view_get_last_contact (view) ||
-                 !empathy_contact_equal (contact, empathy_chat_view_get_last_contact (view)))) {
-               header = TRUE;
-       }
-
-       if (!header) {
+       if (last_contact == contact) {
                return;
        }
 
-       empathy_theme_append_spacing (theme, context, view);
+       empathy_chat_text_view_append_spacing (view);
 
+       /* Insert header line */
        gtk_text_buffer_get_end_iter (buffer, &iter);
        gtk_text_buffer_insert_with_tags_by_name (buffer,
                                                  &iter,
                                                  "\n",
                                                  -1,
-                                                 "fancy-header-line",
+                                                 EMPATHY_THEME_BOXES_TAG_HEADER_LINE,
                                                  NULL);
 
        gtk_text_buffer_get_end_iter (buffer, &iter);
        anchor = gtk_text_buffer_create_child_anchor (buffer, &iter);
 
+       /* Create a hbox for the header and resize it when the view allocation
+        * changes */
        box = gtk_hbox_new (FALSE, 0);
-
-
-       avatar = empathy_chat_view_get_avatar_pixbuf_with_cache (contact);
-       if (avatar && empathy_theme_get_show_avatars (theme)) {
-               GtkWidget *image;
-
-               image = gtk_image_new_from_pixbuf (avatar);
-
-               gtk_box_pack_start (GTK_BOX (box), image,
-                                   FALSE, TRUE, 2);
-
-       }
-
        g_signal_connect_object (view, "size-allocate",
                                 G_CALLBACK (table_size_allocate_cb),
                                 box, 0);
 
-       str = g_strdup_printf ("<b>%s</b>", name);
+       /* Add avatar to the box if needed */
+       if (priv->show_avatars) {
+               avatar = theme_boxes_get_avatar_pixbuf_with_cache (contact);
+               if (avatar) {
+                       GtkWidget *image;
+
+                       image = gtk_image_new_from_pixbuf (avatar);
+
+                       gtk_box_pack_start (GTK_BOX (box), image,
+                                           FALSE, TRUE, 2);
+               }
+       }
 
+       /* Add contact alias */
+       str = g_markup_printf_escaped ("<b>%s</b>", name);
        label1 = g_object_new (GTK_TYPE_LABEL,
                               "label", str,
                               "use-markup", TRUE,
                               "xalign", 0.0,
                               NULL);
-
-       parse_success = gdk_color_parse (priv->header_foreground, &color);
-
-       if (parse_success) {
-               gtk_widget_modify_fg (label1, GTK_STATE_NORMAL, &color);
-       }
-
        g_free (str);
 
+       /* Add the message receive time */
        time = empathy_message_get_timestamp (msg);
-
        tmp = empathy_time_to_string_local (time, 
                                           EMPATHY_TIME_FORMAT_DISPLAY_SHORT);
        str = g_strdup_printf ("<i>%s</i>", tmp);
-       g_free (tmp);
-
        label2 = g_object_new (GTK_TYPE_LABEL,
                               "label", str,
                               "use-markup", TRUE,
                               "xalign", 1.0,
                               NULL);
+       g_free (tmp);
+       g_free (str);
        
-       if (parse_success) {
-               gtk_widget_modify_fg (label2, GTK_STATE_NORMAL, &color);
+       /* 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;
+
+               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);
+               gdk_color_free (color);
        }
 
-       g_free (str);
-
+       /* Pack labels into the box */
        gtk_misc_set_alignment (GTK_MISC (label1), 0.0, 0.5);
        gtk_misc_set_alignment (GTK_MISC (label2), 1.0, 0.5);
-
        gtk_box_pack_start (GTK_BOX (box), label1, TRUE, TRUE, 0);
        gtk_box_pack_start (GTK_BOX (box), label2, TRUE, TRUE, 0);
 
+       /* Add the header box to the text view */
        gtk_text_view_add_child_at_anchor (GTK_TEXT_VIEW (view),
                                           box,
                                           anchor);
-
        gtk_widget_show_all (box);
 
+       /* Insert a header line */
        gtk_text_buffer_get_end_iter (buffer, &iter);
        start = iter;
        gtk_text_iter_backward_char (&start);
        gtk_text_buffer_apply_tag_by_name (buffer,
-                                          "fancy-header",
+                                          EMPATHY_THEME_BOXES_TAG_HEADER,
                                           &start, &iter);
-
        gtk_text_buffer_insert_with_tags_by_name (buffer,
                                                  &iter,
                                                  "\n",
                                                  -1,
-                                                 "fancy-header",
+                                                 EMPATHY_THEME_BOXES_TAG_HEADER,
                                                  NULL);
-
        gtk_text_buffer_get_end_iter (buffer, &iter);
        gtk_text_buffer_insert_with_tags_by_name (buffer,
                                                  &iter,
                                                  "\n",
                                                  -1,
-                                                 "fancy-header-line",
+                                                 EMPATHY_THEME_BOXES_TAG_HEADER_LINE,
                                                  NULL);
 }
 
 static void
-theme_boxes_append_message (EmpathyTheme        *theme,
-                           EmpathyThemeContext *context,
-                           EmpathyChatView     *view,
+theme_boxes_append_message (EmpathyChatTextView *view,
                            EmpathyMessage      *message)
 {
        EmpathyContact *sender;
 
-       empathy_theme_maybe_append_date_and_time (theme, context, view, message);
-       theme_boxes_maybe_append_header (theme, context, view, message);
+       theme_boxes_maybe_append_header (EMPATHY_THEME_BOXES (view), message);
 
        sender = empathy_message_get_sender (message);
-
-       if (empathy_message_get_type (message) == EMPATHY_MESSAGE_TYPE_ACTION) {
+       if (empathy_message_get_tptype (message) ==
+           TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION) {
                gchar *body;
 
                body = g_strdup_printf (" * %s %s", 
                                        empathy_contact_get_name (sender),
                                        empathy_message_get_body (message));
-               empathy_theme_append_text (theme, context, view, body,
-                                          "fancy-action", "fancy-link");
-       } else {
-               empathy_theme_append_text (theme, context, view,
-                                          empathy_message_get_body (message),
-                                          "fancy-body", "fancy-link");
-       }
-       
-       if (empathy_contact_is_user (sender)) {
-               empathy_chat_view_set_last_block_type (view, BLOCK_TYPE_SELF);
-               empathy_chat_view_set_last_contact (view, NULL);
+               empathy_chat_text_view_append_body (EMPATHY_CHAT_TEXT_VIEW (view),
+                                                   body,
+                                                   EMPATHY_CHAT_TEXT_VIEW_TAG_ACTION);
        } else {
-               empathy_chat_view_set_last_block_type (view, BLOCK_TYPE_OTHER);
-               empathy_chat_view_set_last_contact (view, sender);
+               empathy_chat_text_view_append_body (EMPATHY_CHAT_TEXT_VIEW (view),
+                                                   empathy_message_get_body (message),
+                                                   EMPATHY_CHAT_TEXT_VIEW_TAG_BODY);
        }
 }
 
 static void
-theme_boxes_append_event (EmpathyTheme        *theme,
-                         EmpathyThemeContext *context,
-                         EmpathyChatView     *view,
-                         const gchar        *str)
+theme_boxes_notify_show_avatars_cb (EmpathyConf *conf,
+                                   const gchar *key,
+                                   gpointer     user_data)
 {
-       GtkTextBuffer *buffer;
-       GtkTextIter    iter;
-       gchar         *msg;
-
-       buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
-
-       empathy_theme_maybe_append_date_and_time (theme, context, view, NULL);
-
-       gtk_text_buffer_get_end_iter (buffer, &iter);
-
-       msg = g_strdup_printf (" - %s\n", str);
-
-       gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
-                                                 msg, -1,
-                                                 "fancy-event",
-                                                 NULL);
-       g_free (msg);
-
-       empathy_chat_view_set_last_block_type (view, BLOCK_TYPE_EVENT);
+       EmpathyThemeBoxesPriv *priv = GET_PRIV (user_data);
+       
+       empathy_conf_get_bool (conf, key, &priv->show_avatars);
 }
 
 static void
-theme_boxes_append_timestamp (EmpathyTheme        *theme,
-                             EmpathyThemeContext *context,
-                             EmpathyChatView     *view,
-                             EmpathyMessage      *message,
-                             gboolean            show_date,
-                             gboolean            show_time)
+theme_boxes_finalize (GObject *object)
 {
-       GtkTextBuffer *buffer;
-       time_t         timestamp;
-       GDate         *date;
-       GtkTextIter    iter;
-       GString       *str;
-       
-       if (!show_date) {
-               return;
-       }
-
-       buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
-
-       date = empathy_message_get_date_and_time (message, &timestamp);
-
-       str = g_string_new (NULL);
-
-       if (show_time || show_date) {
-               empathy_theme_append_spacing (theme, 
-                                            context,
-                                            view);
-
-               g_string_append (str, "- ");
-       }
-
-       if (show_date) {
-               gchar buf[256];
-
-               g_date_strftime (buf, 256, _("%A %d %B %Y"), date);
-               g_string_append (str, buf);
-
-               if (show_time) {
-                       g_string_append (str, ", ");
-               }
-       }
-
-       g_date_free (date);
-
-       if (show_time) {
-               gchar *tmp;
-
-               tmp = empathy_time_to_string_local (timestamp, EMPATHY_TIME_FORMAT_DISPLAY_SHORT);
-               g_string_append (str, tmp);
-               g_free (tmp);
-       }
-
-       if (show_time || show_date) {
-               g_string_append (str, " -\n");
-
-               gtk_text_buffer_get_end_iter (buffer, &iter);
-               gtk_text_buffer_insert_with_tags_by_name (buffer,
-                                                         &iter,
-                                                         str->str, -1,
-                                                         "fancy-time",
-                                                         NULL);
+       EmpathyThemeBoxesPriv *priv = GET_PRIV (object);
 
-               empathy_chat_view_set_last_block_type (view, BLOCK_TYPE_TIME);
-               empathy_chat_view_set_last_timestamp (view, timestamp);
-       }
+       empathy_conf_notify_remove (empathy_conf_get (),
+                                   priv->notify_show_avatars_id);
 
-       g_string_free (str, TRUE);
-       
+       G_OBJECT_CLASS (empathy_theme_boxes_parent_class)->finalize (object);
 }
 
 static void
-theme_boxes_append_spacing (EmpathyTheme        *theme,
-                           EmpathyThemeContext *context,
-                           EmpathyChatView     *view)
+empathy_theme_boxes_class_init (EmpathyThemeBoxesClass *class)
 {
-       GtkTextBuffer *buffer;
-       GtkTextIter    iter;
+       GObjectClass             *object_class;
+       EmpathyChatTextViewClass *chat_text_view_class;
 
-       g_return_if_fail (EMPATHY_IS_THEME (theme));
-       g_return_if_fail (EMPATHY_IS_CHAT_VIEW (view));
-
-       buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
-
-       gtk_text_buffer_get_end_iter (buffer, &iter);
-       gtk_text_buffer_insert_with_tags_by_name (buffer,
-                                                 &iter,
-                                                 "\n",
-                                                 -1,
-                                                 "cut",
-                                                 "fancy-spacing",
-                                                 NULL);
-}
+       object_class = G_OBJECT_CLASS (class);
+       chat_text_view_class  = EMPATHY_CHAT_TEXT_VIEW_CLASS (class);
 
-static void
-theme_boxes_setup_clean (EmpathyTheme *theme)
-{
-       g_object_set (theme,
-                     "header-foreground", "black",
-                     "header-background", "#efefdf",
-                     "header_line_background", "#e3e3d3",
-                     "action_foreground", "brown4",
-                     "time_foreground", "darkgrey",
-                     "event_foreground", "darkgrey",
-                     "invite_foreground", "sienna",
-                     "link_foreground","#49789e",
-                     NULL);
-}
+       object_class->finalize = theme_boxes_finalize;
+       chat_text_view_class->append_message = theme_boxes_append_message;
 
-static void
-theme_boxes_gdk_color_to_hex (GdkColor *gdk_color, gchar *str_color)
-{
-       g_snprintf (str_color, 10, 
-                   "#%02x%02x%02x", 
-                   gdk_color->red >> 8, 
-                   gdk_color->green >> 8, 
-                   gdk_color->blue >> 8);
+       g_type_class_add_private (object_class, sizeof (EmpathyThemeBoxesPriv));
 }
 
 static void
-theme_boxes_setup_themed (EmpathyTheme *theme)
+empathy_theme_boxes_init (EmpathyThemeBoxes *theme)
 {
-       EmpathyThemeBoxesPriv *priv;
-       GtkWidget            *widget;
-       GtkStyle             *style;
-       gchar                 color[10];
-
-       priv = GET_PRIV (theme);
-
-       widget = gtk_entry_new ();
-       style = gtk_widget_get_style (widget);
-       gtk_widget_destroy (widget);
-
-       theme_boxes_gdk_color_to_hex (&style->base[GTK_STATE_SELECTED], color);
+       EmpathyThemeBoxesPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (theme,
+               EMPATHY_TYPE_THEME_BOXES, EmpathyThemeBoxesPriv);
 
-       g_object_set (theme,
-                     "action-foreground", color,
-                     "link-foreground", color,
-                     NULL);
-
-       theme_boxes_gdk_color_to_hex (&style->bg[GTK_STATE_SELECTED], color);
-
-       g_object_set (theme,
-                     "header-background", color,
-                     NULL);
-
-       theme_boxes_gdk_color_to_hex (&style->dark[GTK_STATE_SELECTED], color);
+       theme->priv = priv;
 
-       g_object_set (theme,
-                     "header_line-background", color,
-                     NULL);
-
-       theme_boxes_gdk_color_to_hex (&style->fg[GTK_STATE_SELECTED], color);
-
-       g_object_set (theme,
-                     "header-foreground", color,
-                     NULL);
-}
+       theme_boxes_create_tags (theme);
 
-static void
-theme_boxes_theme_changed_cb (GtkWidget *widget,
-                             GtkStyle  *previous_style,
-                             gpointer   user_data)
-{
-       theme_boxes_setup_themed (EMPATHY_THEME (user_data));
+       priv->notify_show_avatars_id =
+               empathy_conf_notify_add (empathy_conf_get (),
+                                        EMPATHY_PREFS_UI_SHOW_AVATARS,
+                                        theme_boxes_notify_show_avatars_cb,
+                                        theme);
 
-       g_signal_emit_by_name (G_OBJECT (user_data), "updated");
-}
+       empathy_conf_get_bool (empathy_conf_get (),
+                              EMPATHY_PREFS_UI_SHOW_AVATARS,
+                              &priv->show_avatars);
 
-static void
-theme_boxes_setup_blue (EmpathyTheme *theme)
-{
+       /* Define margin */
        g_object_set (theme,
-                     "header_foreground", "black",
-                     "header_background", "#88a2b4",
-                     "header_line_background", "#7f96a4",
-                     "text_foreground", "black",
-                     "text_background", "#adbdc8",
-                     "highlight_foreground", "black",
-                     "action_foreground", "brown4",
-                     "time_foreground", "darkgrey",
-                     "event_foreground", "#7f96a4",
-                     "invite_foreground", "sienna",
-                     "link_foreground", "#49789e",
+                     "left-margin", MARGIN,
+                     "right-margin", MARGIN,
                      NULL);
 }
 
-EmpathyTheme *
-empathy_theme_boxes_new (const gchar *name)
+EmpathyThemeBoxes *
+empathy_theme_boxes_new (void)
 {
-       EmpathyTheme          *theme;
-       EmpathyThemeBoxesPriv *priv;
-
-       theme = g_object_new (EMPATHY_TYPE_THEME_BOXES, NULL);
-       priv  = GET_PRIV (theme);
-
-       if (strcmp (name, "clean") == 0) {
-               theme_boxes_setup_clean (theme);
-       }
-       else if (strcmp (name, "simple") == 0) {
-               /* FIXME: Make an actual accessor function */
-               g_signal_connect (empathy_main_window_show (),
-                                 "style-set",
-                                 G_CALLBACK (theme_boxes_theme_changed_cb),
-                                 theme);
-
-               theme_boxes_setup_themed (theme);
-       }
-       else if (strcmp (name, "blue") == 0) {
-               theme_boxes_setup_blue (theme);
-       }
-
-       return theme;
+       return g_object_new (EMPATHY_TYPE_THEME_BOXES,
+                            "only-if-date", TRUE,
+                            NULL);
 }
 
-