]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-theme-manager.c
de.po: Updated German translation
[empathy.git] / libempathy-gtk / empathy-theme-manager.c
index 48e2963d3876985a958c373ec9e63219ac78f2b4..a67536fb423773037fc40c76070b42f38d69c01d 100644 (file)
@@ -28,6 +28,7 @@
 #include <glib/gi18n-lib.h>
 #include <gtk/gtk.h>
 
+#include <telepathy-glib/util.h>
 #include <libempathy/empathy-utils.h>
 
 #include "empathy-theme-manager.h"
@@ -45,6 +46,7 @@ typedef struct {
        gchar       *name;
        guint        name_notify_id;
        GtkSettings *settings;
+       GList       *boxes_views;
 } EmpathyThemeManagerPriv;
 
 enum {
@@ -74,180 +76,16 @@ theme_manager_gdk_color_to_hex (GdkColor *gdk_color, gchar *str_color)
                    gdk_color->blue >> 8);
 }
 
-static void
-theme_manager_color_hash_notify_cb (EmpathyThemeManager *manager)
-{
-#if 0
-
-FIXME: Make that work, it should update color when theme changes but it
-       doesnt seems to work with all themes.
-
-  
---------
-
-       g_object_get (priv->settings,
-                     "color-hash", &color_hash,
-                     NULL);
-
-       /*
-        * base_color: #ffffffffffff
-        * fg_color: #000000000000
-        * bg_color: #e6e6e7e7e8e8
-        * text_color: #000000000000
-        * selected_bg_color: #58589a9adbdb
-        * selected_fg_color: #ffffffffffff
-        */
-
-       color = g_hash_table_lookup (color_hash, "base_color");
-       if (color) {
-               theme_manager_gdk_color_to_hex (color, color_str);
-               g_object_set (priv->simple_theme,
-                             "action-foreground", color_str,
-                             "link-foreground", color_str,
-                             NULL);
-       }
-
-       color = g_hash_table_lookup (color_hash, "selected_bg_color");
-       if (color) {
-               theme_manager_gdk_color_to_hex (color, color_str);
-               g_object_set (priv->simple_theme,
-                             "header-background", color_str,
-                             NULL);
-       }
-
-       color = g_hash_table_lookup (color_hash, "bg_color");
-       if (color) {
-               GdkColor tmp;
-
-               tmp = *color;
-               tmp.red /= 2;
-               tmp.green /= 2;
-               tmp.blue /= 2;
-               theme_manager_gdk_color_to_hex (&tmp, color_str);
-               g_object_set (priv->simple_theme,
-                             "header-line-background", color_str,
-                             NULL);
-       }
-
-       color = g_hash_table_lookup (color_hash, "selected_fg_color");
-       if (color) {
-               theme_manager_gdk_color_to_hex (color, color_str);
-               g_object_set (priv->simple_theme,
-                             "header-foreground", color_str,
-                             NULL);
-       }
-
-       g_hash_table_unref (color_hash);
-
-#endif
-}
-
-static gboolean
-theme_manager_ensure_theme_exists (const gchar *name)
-{
-       gint i;
-
-       if (G_STR_EMPTY (name)) {
-               return FALSE;
-       }
-
-       for (i = 0; themes[i]; i += 2) {
-               if (strcmp (themes[i], name) == 0) {
-                       return TRUE;
-               }
-       }
-
-       return FALSE;
-}
-
-static void
-theme_manager_notify_name_cb (EmpathyConf *conf,
-                             const gchar *key,
-                             gpointer     user_data)
-{
-       EmpathyThemeManager     *manager = EMPATHY_THEME_MANAGER (user_data);
-       EmpathyThemeManagerPriv *priv = GET_PRIV (manager);
-       gchar                   *name;
-
-       g_free (priv->name);
-
-       name = NULL;
-       if (!empathy_conf_get_string (conf, key, &name) ||
-           !theme_manager_ensure_theme_exists (name)) {
-               priv->name = g_strdup ("classic");
-               g_free (name);
-       } else {
-               priv->name = name;
-       }
-
-       g_signal_emit (manager, signals[THEME_CHANGED], 0, NULL);
-}
-
-static void
-theme_manager_finalize (GObject *object)
-{
-       EmpathyThemeManagerPriv *priv = GET_PRIV (object);
-
-       empathy_conf_notify_remove (empathy_conf_get (), priv->name_notify_id);
-       g_free (priv->name);
-
-       G_OBJECT_CLASS (empathy_theme_manager_parent_class)->finalize (object);
-}
-
-static void
-empathy_theme_manager_class_init (EmpathyThemeManagerClass *klass)
-{
-       GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
-       signals[THEME_CHANGED] =
-               g_signal_new ("theme-changed",
-                             G_OBJECT_CLASS_TYPE (object_class),
-                             G_SIGNAL_RUN_LAST,
-                             0,
-                             NULL, NULL,
-                             g_cclosure_marshal_VOID__VOID,
-                             G_TYPE_NONE,
-                             0);
-
-       g_type_class_add_private (object_class, sizeof (EmpathyThemeManagerPriv));
-
-       object_class->finalize = theme_manager_finalize;
-}
-
-static void
-empathy_theme_manager_init (EmpathyThemeManager *manager)
-{
-       EmpathyThemeManagerPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (manager,
-               EMPATHY_TYPE_THEME_MANAGER, EmpathyThemeManagerPriv);
-
-       manager->priv = priv;
-
-       /* Take the theme name and track changes */
-       priv->name_notify_id =
-               empathy_conf_notify_add (empathy_conf_get (),
-                                        EMPATHY_PREFS_CHAT_THEME,
-                                        theme_manager_notify_name_cb,
-                                        manager);
-       theme_manager_notify_name_cb (empathy_conf_get (),
-                                     EMPATHY_PREFS_CHAT_THEME,
-                                     manager);
-
-       /* Track GTK color changes */
-       priv->settings = gtk_settings_get_default ();
-       g_signal_connect_swapped (priv->settings, "notify::color-hash",
-                                 G_CALLBACK (theme_manager_color_hash_notify_cb),
-                                 manager);
-}
-
-static EmpathyChatView *
+static EmpathyThemeIrc *
 theme_manager_create_irc_view (EmpathyThemeManager *manager)
 {
        EmpathyChatTextView *view;
+       EmpathyThemeIrc     *theme;
 
-       view = EMPATHY_CHAT_TEXT_VIEW (empathy_theme_irc_new ());
+       theme = empathy_theme_irc_new ();
+       view = EMPATHY_CHAT_TEXT_VIEW (theme);
 
        /* Define base tags */
-       /* FIXME: Missing define for highlight */
        empathy_chat_text_view_tag_set (view, EMPATHY_CHAT_TEXT_VIEW_TAG_SPACING,
                                        "size", 2000,
                                        NULL);
@@ -283,31 +121,75 @@ theme_manager_create_irc_view (EmpathyThemeManager *manager)
                                        "weight", PANGO_WEIGHT_BOLD,
                                        NULL);
 
-       return EMPATHY_CHAT_VIEW (view);
+       return theme;
 }
 
-static EmpathyChatView *
-theme_manager_create_boxes_view (EmpathyThemeManager *manager,
-                                const gchar         *header_foreground,
-                                const gchar         *header_background,
-                                const gchar         *header_line_background,
-                                const gchar         *action_foreground,
-                                const gchar         *time_foreground,
-                                const gchar         *event_foreground,
-                                const gchar         *link_foreground,
-                                const gchar         *text_foreground,
-                                const gchar         *text_background,
-                                const gchar         *highlight_foreground)
+static void
+theme_manager_boxes_weak_notify_cb (gpointer data,
+                                   GObject *where_the_object_was)
+{
+       EmpathyThemeManagerPriv *priv = GET_PRIV (data);
+
+       priv->boxes_views = g_list_remove (priv->boxes_views, where_the_object_was);
+}
 
+static EmpathyThemeBoxes *
+theme_manager_create_boxes_view (EmpathyThemeManager *manager)
 {
-       EmpathyChatTextView *view;
-       GtkTextTag          *tag;
+       EmpathyThemeManagerPriv *priv = GET_PRIV (manager);
+       EmpathyThemeBoxes       *theme;
 
-       view = EMPATHY_CHAT_TEXT_VIEW (empathy_theme_boxes_new ());
+       theme = empathy_theme_boxes_new ();
+       priv->boxes_views = g_list_prepend (priv->boxes_views, theme);
+       g_object_weak_ref (G_OBJECT (theme),
+                          theme_manager_boxes_weak_notify_cb,
+                          manager);
 
-       #define TAG_SET(prop, value) \
+       return theme;
+}
+
+static void
+theme_manager_update_boxes_tags (EmpathyThemeBoxes *theme,
+                                const gchar       *header_foreground,
+                                const gchar       *header_background,
+                                const gchar       *header_line_background,
+                                const gchar       *action_foreground,
+                                const gchar       *time_foreground,
+                                const gchar       *event_foreground,
+                                const gchar       *link_foreground,
+                                const gchar       *text_foreground,
+                                const gchar       *text_background,
+                                const gchar       *highlight_foreground)
+
+{
+       EmpathyChatTextView *view = EMPATHY_CHAT_TEXT_VIEW (theme);
+       GtkTextTag          *tag;
+
+       DEBUG ("Update view with new colors:\n"
+               "header_foreground = %s\n"
+               "header_background = %s\n"
+               "header_line_background = %s\n"
+               "action_foreground = %s\n"
+               "time_foreground = %s\n"
+               "event_foreground = %s\n"
+               "link_foreground = %s\n"
+               "text_foreground = %s\n"
+               "text_background = %s\n"
+               "highlight_foreground = %s\n",
+               header_foreground, header_background, header_line_background,
+               action_foreground, time_foreground, event_foreground,
+               link_foreground, text_foreground, text_background,
+               highlight_foreground);
+
+
+       /* FIXME: GtkTextTag don't support to set color properties to NULL.
+        * See bug #542523 */
+       
+       #define TAG_SET(prop, prop_set, value) \
                if (value != NULL) { \
                        g_object_set (tag, prop, value, NULL); \
+               } else { \
+                       g_object_set (tag, prop_set, FALSE, NULL); \
                }
 
        /* Define base tags */
@@ -315,8 +197,8 @@ theme_manager_create_boxes_view (EmpathyThemeManager *manager,
                                              "weight", PANGO_WEIGHT_BOLD,
                                              "pixels-above-lines", 4,
                                              NULL);
-       TAG_SET ("paragraph-background", text_background);
-       TAG_SET ("foreground", highlight_foreground);
+       TAG_SET ("paragraph-background", "paragraph-background-set", text_background);
+       TAG_SET ("foreground", "foreground-set",highlight_foreground);
 
        empathy_chat_text_view_tag_set (view, EMPATHY_CHAT_TEXT_VIEW_TAG_SPACING,
                                        "size", 3000,
@@ -325,26 +207,26 @@ theme_manager_create_boxes_view (EmpathyThemeManager *manager,
        tag = empathy_chat_text_view_tag_set (view, EMPATHY_CHAT_TEXT_VIEW_TAG_TIME,
                                              "justification", GTK_JUSTIFY_CENTER,
                                              NULL);
-       TAG_SET ("foreground", time_foreground);
+       TAG_SET ("foreground", "foreground-set", time_foreground);
        tag = empathy_chat_text_view_tag_set (view, EMPATHY_CHAT_TEXT_VIEW_TAG_ACTION,
                                              "style", PANGO_STYLE_ITALIC,
                                              "pixels-above-lines", 4,
                                              NULL);
-       TAG_SET ("paragraph-background", text_background);
-       TAG_SET ("foreground", action_foreground);
+       TAG_SET ("paragraph-background", "paragraph-background-set", text_background);
+       TAG_SET ("foreground", "foreground-set", action_foreground);
        tag = empathy_chat_text_view_tag_set (view, EMPATHY_CHAT_TEXT_VIEW_TAG_BODY,
                                              "pixels-above-lines", 4,
                                              NULL);
-       TAG_SET ("paragraph-background", text_background);
-       TAG_SET ("foreground", text_foreground);
+       TAG_SET ("paragraph-background", "paragraph-background-set", text_background);
+       TAG_SET ("foreground", "foreground-set", text_foreground);
        tag = empathy_chat_text_view_tag_set (view, EMPATHY_CHAT_TEXT_VIEW_TAG_EVENT,
                                              "justification", GTK_JUSTIFY_LEFT,
                                              NULL);
-       TAG_SET ("foreground", event_foreground);
+       TAG_SET ("foreground", "foreground-set", event_foreground);
        tag = empathy_chat_text_view_tag_set (view, EMPATHY_CHAT_TEXT_VIEW_TAG_LINK,
                                              "underline", PANGO_UNDERLINE_SINGLE,
                                              NULL);
-       TAG_SET ("foreground", link_foreground);
+       TAG_SET ("foreground", "foreground-set", link_foreground);
 
        /* Define BOXES tags */
        tag = empathy_chat_text_view_tag_set (view, EMPATHY_THEME_BOXES_TAG_HEADER,
@@ -352,21 +234,19 @@ theme_manager_create_boxes_view (EmpathyThemeManager *manager,
                                              "foreground", header_foreground,
                                              "paragraph-background", header_background,
                                              NULL);
-       TAG_SET ("foreground", header_foreground);
-       TAG_SET ("paragraph-background", header_background);
+       TAG_SET ("foreground", "foreground-set", header_foreground);
+       TAG_SET ("paragraph-background", "paragraph-background-set", header_background);
        tag = empathy_chat_text_view_tag_set (view, EMPATHY_THEME_BOXES_TAG_HEADER_LINE,
                                              "size", 1,
                                              "paragraph-background", header_line_background,
                                              NULL);
-       TAG_SET ("paragraph-background", header_line_background);
+       TAG_SET ("paragraph-background", "paragraph-background-set", header_line_background);
 
        #undef TAG_SET
-
-       return EMPATHY_CHAT_VIEW (view);
 }
 
-static EmpathyChatView *
-theme_manager_create_simple_view (EmpathyThemeManager *manager)
+static void
+theme_manager_update_simple_tags (EmpathyThemeBoxes *theme)
 {
        GtkStyle *style;
        gchar     color1[10];
@@ -376,202 +256,235 @@ theme_manager_create_simple_view (EmpathyThemeManager *manager)
 
        style = gtk_widget_get_default_style ();
 
-       theme_manager_gdk_color_to_hex (&style->base[GTK_STATE_SELECTED], color1); 
+       theme_manager_gdk_color_to_hex (&style->base[GTK_STATE_SELECTED], color1);
        theme_manager_gdk_color_to_hex (&style->bg[GTK_STATE_SELECTED], color2);
        theme_manager_gdk_color_to_hex (&style->dark[GTK_STATE_SELECTED], color3);
        theme_manager_gdk_color_to_hex (&style->fg[GTK_STATE_SELECTED], color4);
 
-       return theme_manager_create_boxes_view (manager,
-                                               color4,     /* header_foreground */
-                                               color2,     /* header_background */
-                                               color3,     /* header_line_background */
-                                               color1,     /* action_foreground */
-                                               "darkgrey", /* time_foreground */
-                                               "darkgrey", /* event_foreground */
-                                               color1,     /* link_foreground */
-                                               NULL,       /* text_foreground */
-                                               NULL,       /* text_background */
-                                               NULL);      /* highlight_foreground */
+       theme_manager_update_boxes_tags (theme,
+                                        color4,     /* header_foreground */
+                                        color2,     /* header_background */
+                                        color3,     /* header_line_background */
+                                        color1,     /* action_foreground */
+                                        "darkgrey", /* time_foreground */
+                                        "darkgrey", /* event_foreground */
+                                        color1,     /* link_foreground */
+                                        NULL,       /* text_foreground */
+                                        NULL,       /* text_background */
+                                        NULL);      /* highlight_foreground */
+}
+
+static void
+theme_manager_update_boxes_theme (EmpathyThemeManager *manager,
+                                 EmpathyThemeBoxes   *theme)
+{
+       EmpathyThemeManagerPriv *priv = GET_PRIV (manager);
+
+       if (strcmp (priv->name, "simple") == 0) {
+               theme_manager_update_simple_tags (theme);
+       }
+       else if (strcmp (priv->name, "clean") == 0) {
+               theme_manager_update_boxes_tags (theme,
+                                                "black",    /* header_foreground */
+                                                "#efefdf",  /* header_background */
+                                                "#e3e3d3",  /* header_line_background */
+                                                "brown4",   /* action_foreground */
+                                                "darkgrey", /* time_foreground */
+                                                "darkgrey", /* event_foreground */
+                                                "#49789e",  /* link_foreground */
+                                                NULL,       /* text_foreground */
+                                                NULL,       /* text_background */
+                                                NULL);      /* highlight_foreground */
+       }
+       else if (strcmp (priv->name, "blue") == 0) {
+               theme_manager_update_boxes_tags (theme,
+                                                "black",    /* header_foreground */
+                                                "#88a2b4",  /* header_background */
+                                                "#7f96a4",  /* header_line_background */
+                                                "brown4",   /* action_foreground */
+                                                "darkgrey", /* time_foreground */
+                                                "#7f96a4",  /* event_foreground */
+                                                "#49789e",  /* link_foreground */
+                                                "black",    /* text_foreground */
+                                                "#adbdc8",  /* text_background */
+                                                "black");   /* highlight_foreground */
+       }
 }
 
 EmpathyChatView *
 empathy_theme_manager_create_view (EmpathyThemeManager *manager)
 {
        EmpathyThemeManagerPriv *priv = GET_PRIV (manager);
+       EmpathyThemeBoxes       *theme;
 
        g_return_val_if_fail (EMPATHY_IS_THEME_MANAGER (manager), NULL);
 
        DEBUG ("Using theme %s", priv->name);
 
        if (strcmp (priv->name, "classic") == 0)  {
-               return theme_manager_create_irc_view (manager);
-       }
-       else if (strcmp (priv->name, "simple") == 0) {
-               return theme_manager_create_simple_view (manager);
-       }
-       else if (strcmp (priv->name, "clean") == 0) {
-               return theme_manager_create_boxes_view (manager,
-                                                       "black",    /* header_foreground */
-                                                       "#efefdf",  /* header_background */
-                                                       "#e3e3d3",  /* header_line_background */
-                                                       "brown4",   /* action_foreground */
-                                                       "darkgrey", /* time_foreground */
-                                                       "darkgrey", /* event_foreground */
-                                                       "#49789e",  /* link_foreground */
-                                                       NULL,       /* text_foreground */
-                                                       NULL,       /* text_background */
-                                                       NULL);      /* highlight_foreground */
-       }
-       else if (strcmp (priv->name, "blue") == 0) {
-               return theme_manager_create_boxes_view (manager,
-                                                       "black",    /* header_foreground */
-                                                       "#88a2b4",  /* header_background */
-                                                       "#7f96a4",  /* header_line_background */
-                                                       "brown4",   /* action_foreground */
-                                                       "darkgrey", /* time_foreground */
-                                                       "#7f96a4",  /* event_foreground */
-                                                       "#49789e",  /* link_foreground */
-                                                       "black",    /* text_foreground */
-                                                       "#adbdc8",  /* text_background */
-                                                       "black");   /* highlight_foreground */
+               return EMPATHY_CHAT_VIEW (theme_manager_create_irc_view (manager));
        }
 
-       return NULL;
+       theme = theme_manager_create_boxes_view (manager);
+       theme_manager_update_boxes_theme (manager, theme);
+
+       return EMPATHY_CHAT_VIEW (theme);
 }
 
-EmpathyThemeManager *
-empathy_theme_manager_get (void)
+static void
+theme_manager_color_hash_notify_cb (EmpathyThemeManager *manager)
 {
-       static EmpathyThemeManager *manager = NULL;
+       EmpathyThemeManagerPriv *priv = GET_PRIV (manager);
 
-       if (!manager) {
-               manager = g_object_new (EMPATHY_TYPE_THEME_MANAGER, NULL);
-       }
+       /* FIXME: Make that work, it should update color when theme changes but
+        * it doesnt seems to work with all themes. */
 
-       return manager;
-}
+       if (strcmp (priv->name, "simple") == 0) {
+               GList *l;
 
-const gchar **
-empathy_theme_manager_get_themes (void)
-{
-       return themes;
+               /* We are using the simple theme which use the GTK theme color,
+                * Update views to use the new color. */
+               for (l = priv->boxes_views; l; l = l->next) {
+                       theme_manager_update_simple_tags (EMPATHY_THEME_BOXES (l->data));
+               }
+       }
 }
 
+static gboolean
+theme_manager_ensure_theme_exists (const gchar *name)
+{
+       gint i;
 
-#if 0
-// theme boxes
-       empathy_text_buffer_tag_set (buffer, "fancy-spacing",
-                                    "size", 3000,
-                                    "pixels-above-lines", 8,
-                                    NULL);
-
-       tag = empathy_text_buffer_tag_set (buffer, "fancy-header",
-                                          "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);
+       if (EMP_STR_EMPTY (name)) {
+               return FALSE;
        }
 
-       tag = empathy_text_buffer_tag_set (buffer, "fancy-header-line",
-                                          "size", 1,
-                                          NULL);
-       if (priv->header_line_background) {
-               g_object_set (tag,
-                             "paragraph-background", priv->header_line_background,
-                             NULL);
+       for (i = 0; themes[i]; i += 2) {
+               if (strcmp (themes[i], name) == 0) {
+                       return TRUE;
+               }
        }
 
-       tag = empathy_text_buffer_tag_set (buffer, "fancy-body",
-                                          "pixels-above-lines", 4,
-                                          NULL);
-       if (priv->text_background) {
-               g_object_set (tag,
-                             "paragraph-background", priv->text_background,
-                             NULL);
-       }
+       return FALSE;
+}
 
-       if (priv->text_foreground) {
-               g_object_set (tag,
-                             "foreground", priv->text_foreground,
-                             NULL);
-       }
+static void
+theme_manager_notify_name_cb (EmpathyConf *conf,
+                             const gchar *key,
+                             gpointer     user_data)
+{
+       EmpathyThemeManager     *manager = EMPATHY_THEME_MANAGER (user_data);
+       EmpathyThemeManagerPriv *priv = GET_PRIV (manager);
+       gchar                   *name = NULL;
 
-       tag = empathy_text_buffer_tag_set (buffer, "fancy-action",
-                                          "style", PANGO_STYLE_ITALIC,
-                                          "pixels-above-lines", 4,
-                                          NULL);
+       if (!empathy_conf_get_string (conf, key, &name) ||
+           !theme_manager_ensure_theme_exists (name) ||
+           !tp_strdiff (priv->name, name)) {
+               if (!priv->name) {
+                       priv->name = g_strdup ("classic");
+               }
 
-       if (priv->text_background) {
-               g_object_set (tag,
-                             "paragraph-background", priv->text_background,
-                             NULL);
+               g_free (name);
+               return;
        }
 
-       if (priv->action_foreground) {
-               g_object_set (tag,
-                             "foreground", priv->action_foreground,
-                             NULL);
-       }
+       g_free (priv->name);
+       priv->name = name;
 
-       tag = empathy_text_buffer_tag_set (buffer, "fancy-highlight",
-                                          "weight", PANGO_WEIGHT_BOLD,
-                                          "pixels-above-lines", 4,
-                                          NULL);
-       if (priv->text_background) {
-               g_object_set (tag,
-                             "paragraph-background", priv->text_background,
-                             NULL);
+       if (!tp_strdiff (priv->name, "simple") ||
+           !tp_strdiff (priv->name, "clean") ||
+           !tp_strdiff (priv->name, "blue")) {
+               GList *l;
+
+               /* The theme changes to a boxed one, we can update boxed views */
+               for (l = priv->boxes_views; l; l = l->next) {
+                       theme_manager_update_boxes_theme (manager,
+                                                         EMPATHY_THEME_BOXES (l->data));
+               }
        }
 
+       g_signal_emit (manager, signals[THEME_CHANGED], 0, NULL);
+}
 
-       if (priv->highlight_foreground) {
-               g_object_set (tag,
-                             "foreground", priv->highlight_foreground,
-                             NULL);
-       }
+static void
+theme_manager_finalize (GObject *object)
+{
+       EmpathyThemeManagerPriv *priv = GET_PRIV (object);
+       GList                   *l;
 
-       tag = empathy_text_buffer_tag_set (buffer, "fancy-time",
-                                          "justification", GTK_JUSTIFY_CENTER,
-                                          NULL);
-       if (priv->time_foreground) {
-               g_object_set (tag,
-                             "foreground", priv->time_foreground,
-                             NULL);
-       }
+       empathy_conf_notify_remove (empathy_conf_get (), priv->name_notify_id);
+       g_free (priv->name);
 
-       tag = empathy_text_buffer_tag_set (buffer, "fancy-event",
-                                          "justification", GTK_JUSTIFY_LEFT,
-                                          NULL);
-       if (priv->event_foreground) {
-               g_object_set (tag,
-                             "foreground", priv->event_foreground,
-                             NULL);
+       for (l = priv->boxes_views; l; l = l->next) {
+               g_object_weak_unref (G_OBJECT (l->data),
+                                    theme_manager_boxes_weak_notify_cb,
+                                    object);
        }
+       g_list_free (priv->boxes_views);
 
-       tag = empathy_text_buffer_tag_set (buffer, "invite", NULL);
-       if (priv->invite_foreground) {
-               g_object_set (tag,
-                             "foreground", priv->invite_foreground,
-                             NULL);
-       }
+       G_OBJECT_CLASS (empathy_theme_manager_parent_class)->finalize (object);
+}
+
+static void
+empathy_theme_manager_class_init (EmpathyThemeManagerClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+       signals[THEME_CHANGED] =
+               g_signal_new ("theme-changed",
+                             G_OBJECT_CLASS_TYPE (object_class),
+                             G_SIGNAL_RUN_LAST,
+                             0,
+                             NULL, NULL,
+                             g_cclosure_marshal_VOID__VOID,
+                             G_TYPE_NONE,
+                             0);
+
+       g_type_class_add_private (object_class, sizeof (EmpathyThemeManagerPriv));
 
-       tag = empathy_text_buffer_tag_set (buffer, "fancy-link",
-                                          "underline", PANGO_UNDERLINE_SINGLE,
-                                          NULL);
-       if (priv->link_foreground) {
-               g_object_set (tag,
-                             "foreground", priv->link_foreground,
-                             NULL);
-       } 
-       empathy_chat_view_set_margin (view, MARGIN);
+       object_class->finalize = theme_manager_finalize;
+}
+
+static void
+empathy_theme_manager_init (EmpathyThemeManager *manager)
+{
+       EmpathyThemeManagerPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (manager,
+               EMPATHY_TYPE_THEME_MANAGER, EmpathyThemeManagerPriv);
 
+       manager->priv = priv;
 
+       /* Take the theme name and track changes */
+       priv->name_notify_id =
+               empathy_conf_notify_add (empathy_conf_get (),
+                                        EMPATHY_PREFS_CHAT_THEME,
+                                        theme_manager_notify_name_cb,
+                                        manager);
+       theme_manager_notify_name_cb (empathy_conf_get (),
+                                     EMPATHY_PREFS_CHAT_THEME,
+                                     manager);
+
+       /* Track GTK color changes */
+       priv->settings = gtk_settings_get_default ();
+       g_signal_connect_swapped (priv->settings, "notify::color-hash",
+                                 G_CALLBACK (theme_manager_color_hash_notify_cb),
+                                 manager);
+}
+
+EmpathyThemeManager *
+empathy_theme_manager_get (void)
+{
+       static EmpathyThemeManager *manager = NULL;
+
+       if (!manager) {
+               manager = g_object_new (EMPATHY_TYPE_THEME_MANAGER, NULL);
+       }
+
+       return manager;
+}
+
+const gchar **
+empathy_theme_manager_get_themes (void)
+{
+       return themes;
+}
 
-       priv->simple_theme = g_object_new (EMPATHY_TYPE_THEME_BOXES, NULL);
-       theme_manager_color_hash_notify_cb (manager);
-#endif