]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-theme-manager.c
Change Finnish translation team web page to l10n.gnome.org
[empathy.git] / libempathy-gtk / empathy-theme-manager.c
index 1bcb4204fed3028668e7b42033942222f185e2bf..81361c1ef87c25505ed6d16e4c2936415f4149a1 100644 (file)
@@ -1,6 +1,6 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
 /*
  * Copyright (C) 2005-2007 Imendio AB
+ * Copyright (C) 2008-2012 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
  *
  * 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>
  */
 
 #include "config.h"
+#include "empathy-theme-manager.h"
 
-#include <string.h>
-
-#include <glib/gi18n.h>
-#include <gtk/gtk.h>
+#include "empathy-gsettings.h"
 
-#include <libempathy/empathy-utils.h>
+#define DEBUG_FLAG EMPATHY_DEBUG_OTHER
+#include "empathy-debug.h"
 
-#include "empathy-chat-view.h"
-#include "empathy-conf.h"
-#include "empathy-theme.h"
-#include "empathy-theme-boxes.h"
-#include "empathy-theme-irc.h"
-#include "empathy-theme-manager.h"
+struct _EmpathyThemeManagerPriv
+{
+  GSettings   *gsettings_chat;
+  guint        emit_changed_idle;
+  gboolean     in_constructor;
+
+  EmpathyAdiumData *adium_data;
+  gchar *adium_variant;
+  /* list of weakref to EmpathyThemeAdium objects */
+  GList *adium_views;
+};
 
-#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyThemeManager)
-typedef struct {
-       gchar       *name;
-       guint        name_notify_id;
-
-       gboolean     show_avatars;
-       guint        show_avatars_notify_id;
-
-       EmpathyTheme *clean_theme;
-       EmpathyTheme *simple_theme;
-       EmpathyTheme *blue_theme;
-       EmpathyTheme *classic_theme;
-
-       GtkSettings  *settings;
-} EmpathyThemeManagerPriv;
-
-static void        theme_manager_finalize                 (GObject            *object);
-static void        theme_manager_notify_name_cb           (EmpathyConf         *conf,
-                                                          const gchar        *key,
-                                                          gpointer            user_data);
-
-static void        theme_manager_notify_show_avatars_cb   (EmpathyConf         *conf,
-                                                          const gchar        *key,
-                                                          gpointer            user_data);
-static void        theme_manager_apply_theme              (EmpathyThemeManager *manager,
-                                                          EmpathyChatView     *view,
-                                                          const gchar        *name);
-
-enum {
-       THEME_CHANGED,
-       LAST_SIGNAL
+enum
+{
+  THEME_CHANGED,
+  LAST_SIGNAL
 };
 
 static guint signals[LAST_SIGNAL] = { 0 };
 
-static const gchar *themes[] = {
-       "classic", N_("Classic"),
-       "simple", N_("Simple"),
-       "clean", N_("Clean"),
-       "blue", N_("Blue"),
-       NULL
-};
-
 G_DEFINE_TYPE (EmpathyThemeManager, empathy_theme_manager, G_TYPE_OBJECT);
 
-static void
-theme_manager_gdk_color_to_hex (GdkColor *gdk_color, gchar *str_color)
+static gboolean
+theme_manager_emit_changed_idle_cb (gpointer manager)
 {
-       g_snprintf (str_color, 10, 
-                   "#%02x%02x%02x", 
-                   gdk_color->red >> 8,
-                   gdk_color->green >> 8,
-                   gdk_color->blue >> 8);
+  EmpathyThemeManager *self = manager;
+  const gchar *adium_path = NULL;
+
+  if (self->priv->adium_data)
+    adium_path = empathy_adium_data_get_path (self->priv->adium_data);
+
+  DEBUG ("Emit theme-changed with: adium_path='%s' "
+      "adium_variant='%s'", adium_path, self->priv->adium_variant);
+
+  g_signal_emit (self, signals[THEME_CHANGED], 0, NULL);
+  self->priv->emit_changed_idle = 0;
+
+  return FALSE;
 }
- static void
-theme_manager_color_hash_notify_cb (EmpathyThemeManager *manager)
+
+static void
+theme_manager_emit_changed (EmpathyThemeManager *self)
 {
-       EmpathyThemeManagerPriv *priv;
-       GtkStyle                *style;
-       gchar                    color[10];
-
-       priv = GET_PRIV (manager);
-
-       style = gtk_widget_get_default_style ();
-
-       g_object_freeze_notify (G_OBJECT (priv->simple_theme));
-
-       theme_manager_gdk_color_to_hex (&style->base[GTK_STATE_SELECTED], color);
-       g_object_set (priv->simple_theme,
-                     "action-foreground", color,
-                     "link-foreground", color,
-                     NULL);
-       theme_manager_gdk_color_to_hex (&style->bg[GTK_STATE_SELECTED], color);
-       g_object_set (priv->simple_theme,
-                     "header-background", color,
-                     NULL);
-
-       theme_manager_gdk_color_to_hex (&style->dark[GTK_STATE_SELECTED], color);
-       g_object_set (priv->simple_theme,
-                     "header-line-background", color,
-                     NULL);
-
-       theme_manager_gdk_color_to_hex (&style->fg[GTK_STATE_SELECTED], color);
-       g_object_set (priv->simple_theme,
-                     "header-foreground", color,
-                     NULL);
-
-       g_object_thaw_notify (G_OBJECT (priv->simple_theme));
-
-#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
+  /* We emit the signal in idle callback to be sure we emit it only once
+   * in the case both the name and adium_path changed */
+  if (self->priv->emit_changed_idle == 0 && !self->priv->in_constructor)
+    {
+      self->priv->emit_changed_idle = g_idle_add (
+        theme_manager_emit_changed_idle_cb, self);
+    }
 }
 
 static void
-empathy_theme_manager_class_init (EmpathyThemeManagerClass *klass)
+theme_manager_view_weak_notify_cb (gpointer data,
+    GObject *where_the_object_was)
 {
-       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));
+  GList **list = data;
 
-       object_class->finalize = theme_manager_finalize;
+  *list = g_list_remove (*list, where_the_object_was);
 }
 
 static void
-empathy_theme_manager_init (EmpathyThemeManager *manager)
+clear_list_of_views (GList **views)
 {
-       EmpathyThemeManagerPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (manager,
-               EMPATHY_TYPE_THEME_MANAGER, EmpathyThemeManagerPriv);
-
-       manager->priv = priv;
-       priv->name_notify_id =
-               empathy_conf_notify_add (empathy_conf_get (),
-                                       EMPATHY_PREFS_CHAT_THEME,
-                                       theme_manager_notify_name_cb,
-                                       manager);
-
-       empathy_conf_get_string (empathy_conf_get (),
-                               EMPATHY_PREFS_CHAT_THEME,
-                               &priv->name);
-
-       /* Unused right now, but will be used soon. */
-       priv->show_avatars_notify_id =
-               empathy_conf_notify_add (empathy_conf_get (),
-                                       EMPATHY_PREFS_UI_SHOW_AVATARS,
-                                       theme_manager_notify_show_avatars_cb,
-                                       manager);
-
-       empathy_conf_get_bool (empathy_conf_get (),
-                             EMPATHY_PREFS_UI_SHOW_AVATARS,
-                             &priv->show_avatars);
-
-       priv->settings = gtk_settings_get_default ();
-       g_signal_connect_swapped (priv->settings, "notify::color-hash",
-                                 G_CALLBACK (theme_manager_color_hash_notify_cb),
-                                 manager);
-
-       priv->simple_theme = g_object_new (EMPATHY_TYPE_THEME_BOXES, NULL);
-       theme_manager_color_hash_notify_cb (manager);
-
-       priv->clean_theme = g_object_new (EMPATHY_TYPE_THEME_BOXES,
-                                         "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);
-
-       priv->blue_theme = g_object_new (EMPATHY_TYPE_THEME_BOXES,
-                                        "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",
-                                        NULL);
-
-       priv->classic_theme = g_object_new (EMPATHY_TYPE_THEME_IRC, NULL);
+  while (*views)
+    {
+      g_object_weak_unref ((*views)->data,
+               theme_manager_view_weak_notify_cb,
+               views);
+
+      *views = g_list_delete_link (*views, *views);
+    }
+}
+
+static EmpathyThemeAdium *
+theme_manager_create_adium_view (EmpathyThemeManager *self)
+{
+  EmpathyThemeAdium *theme;
+
+  theme = empathy_theme_adium_new (self->priv->adium_data, self->priv->adium_variant);
+
+  self->priv->adium_views = g_list_prepend (self->priv->adium_views, theme);
+
+  g_object_weak_ref (G_OBJECT (theme),
+         theme_manager_view_weak_notify_cb,
+         &self->priv->adium_views);
+
+  return theme;
 }
 
 static void
-theme_manager_finalize (GObject *object)
+theme_manager_notify_theme_cb (GSettings *gsettings_chat,
+    const gchar *key,
+    gpointer user_data)
 {
-       EmpathyThemeManagerPriv *priv;
+  EmpathyThemeManager *self = EMPATHY_THEME_MANAGER (user_data);
+  gchar *theme, *path;
 
-       priv = GET_PRIV (object);
+  theme = g_settings_get_string (gsettings_chat, key);
 
-       empathy_conf_notify_remove (empathy_conf_get (), priv->name_notify_id);
-       empathy_conf_notify_remove (empathy_conf_get (), priv->show_avatars_notify_id);
+  path = empathy_theme_manager_find_theme (theme);
+  if (path == NULL)
+    {
+      DEBUG ("Can't find theme: %s; fallback to 'Classic'",
+          theme);
 
-       g_free (priv->name);
+      path = empathy_theme_manager_find_theme ("Classic");
+      if (path == NULL)
+        g_critical ("Can't find 'Classic theme");
+    }
 
-       g_object_unref (priv->clean_theme);
-       g_object_unref (priv->simple_theme);
-       g_object_unref (priv->blue_theme);
-       g_object_unref (priv->classic_theme);
+  /* Load new theme data, we can stop tracking existing views since we
+   * won't be able to change them live anymore */
+  clear_list_of_views (&self->priv->adium_views);
+  tp_clear_pointer (&self->priv->adium_data, empathy_adium_data_unref);
+  self->priv->adium_data = empathy_adium_data_new (path);
 
-       G_OBJECT_CLASS (empathy_theme_manager_parent_class)->finalize (object);
+  theme_manager_emit_changed (self);
+
+  g_free (path);
+  g_free (theme);
 }
 
 static void
-theme_manager_notify_name_cb (EmpathyConf  *conf,
-                             const gchar *key,
-                             gpointer     user_data)
+theme_manager_notify_adium_variant_cb (GSettings *gsettings_chat,
+    const gchar *key,
+    gpointer user_data)
 {
-       EmpathyThemeManager     *manager;
-       EmpathyThemeManagerPriv *priv;
-       gchar                  *name;
-
-       manager = user_data;
-       priv = GET_PRIV (manager);
+  EmpathyThemeManager *self = EMPATHY_THEME_MANAGER (user_data);
+  gchar *new_variant;
+  GList *l;
+
+  new_variant = g_settings_get_string (gsettings_chat, key);
+  if (!tp_strdiff (self->priv->adium_variant, new_variant))
+    {
+      g_free (new_variant);
+      return;
+    }
+
+  g_free (self->priv->adium_variant);
+  self->priv->adium_variant = new_variant;
+
+  for (l = self->priv->adium_views; l; l = l->next)
+    {
+      empathy_theme_adium_set_variant (EMPATHY_THEME_ADIUM (l->data),
+        self->priv->adium_variant);
+    }
+}
 
-       g_free (priv->name);
+EmpathyThemeAdium *
+empathy_theme_manager_create_view (EmpathyThemeManager *self)
+{
+  g_return_val_if_fail (EMPATHY_IS_THEME_MANAGER (self), NULL);
 
-       name = NULL;
-       if (!empathy_conf_get_string (conf, key, &name) ||
-           name == NULL || name[0] == 0) {
-               priv->name = g_strdup ("classic");
-               g_free (name);
-       } else {
-               priv->name = name;
-       }
+  if (self->priv->adium_data != NULL)
+    return theme_manager_create_adium_view (self);
 
-       g_signal_emit (manager, signals[THEME_CHANGED], 0, NULL);
+  g_return_val_if_reached (NULL);
 }
 
 static void
-theme_manager_notify_show_avatars_cb (EmpathyConf  *conf,
-                                     const gchar *key,
-                                     gpointer     user_data)
+theme_manager_finalize (GObject *object)
 {
-       EmpathyThemeManager     *manager;
-       EmpathyThemeManagerPriv *priv;
-       gboolean                value;
-
-       manager = user_data;
-       priv = GET_PRIV (manager);
-
-       if (!empathy_conf_get_bool (conf, key, &value)) {
-               priv->show_avatars = FALSE;
-       } else {
-               priv->show_avatars = value;
-       }
+  EmpathyThemeManager *self = (EmpathyThemeManager *) object;
+
+  g_object_unref (self->priv->gsettings_chat);
+
+  if (self->priv->emit_changed_idle != 0)
+    g_source_remove (self->priv->emit_changed_idle);
+
+  clear_list_of_views (&self->priv->adium_views);
+  g_free (self->priv->adium_variant);
+  tp_clear_pointer (&self->priv->adium_data, empathy_adium_data_unref);
+
+  G_OBJECT_CLASS (empathy_theme_manager_parent_class)->finalize (object);
 }
 
-static gboolean
-theme_manager_ensure_theme_exists (const gchar *name)
+static void
+empathy_theme_manager_class_init (EmpathyThemeManagerClass *klass)
 {
-       gint i;
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
-       if (G_STR_EMPTY (name)) {
-               return FALSE;
-       }
+  signals[THEME_CHANGED] = g_signal_new ("theme-changed",
+      G_OBJECT_CLASS_TYPE (object_class),
+      G_SIGNAL_RUN_LAST,
+      0,
+      NULL, NULL,
+      g_cclosure_marshal_generic,
+      G_TYPE_NONE,
+      0);
 
-       for (i = 0; themes[i]; i += 2) {
-               if (strcmp (themes[i], name) == 0) {
-                       return TRUE;
-               }
-       }
+  g_type_class_add_private (object_class, sizeof (EmpathyThemeManagerPriv));
 
-       return FALSE;
+  object_class->finalize = theme_manager_finalize;
 }
 
 static void
-theme_manager_apply_theme (EmpathyThemeManager *manager,
-                          EmpathyChatView     *view,
-                          const gchar        *name)
+empathy_theme_manager_init (EmpathyThemeManager *self)
 {
-       EmpathyThemeManagerPriv *priv;
-       EmpathyTheme            *theme;
-
-       priv = GET_PRIV (manager);
-
-       /* Make sure all tags are present. Note: not useful now but when we have
-        * user defined theme it will be.
-        */
-       if (theme_manager_ensure_theme_exists (name)) {
-               if (strcmp (name, "clean") == 0) {
-                       theme = priv->clean_theme;
-               }
-               else if (strcmp (name, "simple") == 0) {
-                       theme = priv->simple_theme;
-               }
-               else if (strcmp (name, "blue") == 0) {
-                       theme = priv->blue_theme;
-               } else {
-                       theme = priv->classic_theme;
-               }
-       } else {
-               theme = priv->classic_theme;
-       }
-
-       empathy_chat_view_set_theme (view, theme);
+  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
+    EMPATHY_TYPE_THEME_MANAGER, EmpathyThemeManagerPriv);
+
+  self->priv->in_constructor = TRUE;
+
+  self->priv->gsettings_chat = g_settings_new (EMPATHY_PREFS_CHAT_SCHEMA);
+
+  /* Take the adium path/variant and track changes */
+  g_signal_connect (self->priv->gsettings_chat,
+      "changed::" EMPATHY_PREFS_CHAT_THEME,
+      G_CALLBACK (theme_manager_notify_theme_cb), self);
+
+  theme_manager_notify_theme_cb (self->priv->gsettings_chat,
+      EMPATHY_PREFS_CHAT_THEME, self);
+
+  g_signal_connect (self->priv->gsettings_chat,
+      "changed::" EMPATHY_PREFS_CHAT_THEME_VARIANT,
+      G_CALLBACK (theme_manager_notify_adium_variant_cb), self);
+
+  theme_manager_notify_adium_variant_cb (self->priv->gsettings_chat,
+      EMPATHY_PREFS_CHAT_THEME_VARIANT, self);
+
+  self->priv->in_constructor = FALSE;
 }
 
 EmpathyThemeManager *
-empathy_theme_manager_get (void)
+empathy_theme_manager_dup_singleton (void)
 {
-       static EmpathyThemeManager *manager = NULL;
+  static EmpathyThemeManager *manager = NULL;
 
-       if (!manager) {
-               manager = g_object_new (EMPATHY_TYPE_THEME_MANAGER, NULL);
-       }
+  if (manager == NULL)
+    {
+      manager = g_object_new (EMPATHY_TYPE_THEME_MANAGER, NULL);
+      g_object_add_weak_pointer (G_OBJECT (manager), (gpointer *) &manager);
 
-       return manager;
+      return manager;
+    }
+
+  return g_object_ref (manager);
 }
 
-const gchar **
-empathy_theme_manager_get_themes (void)
+static void
+find_themes (GHashTable *hash,
+    const gchar *dirpath)
 {
-       return themes;
+  GDir *dir;
+  GError *error = NULL;
+  const gchar *name = NULL;
+  GHashTable *info = NULL;
+
+  dir = g_dir_open (dirpath, 0, &error);
+  if (dir != NULL)
+    {
+      name = g_dir_read_name (dir);
+
+      while (name != NULL)
+        {
+          gchar *path;
+
+          path = g_build_path (G_DIR_SEPARATOR_S, dirpath, name, NULL);
+          if (empathy_adium_path_is_valid (path))
+            {
+              info = empathy_adium_info_new (path);
+
+              if (info != NULL)
+                {
+                  g_hash_table_insert (hash,
+                      empathy_theme_manager_dup_theme_name_from_path (path),
+                      info);
+                }
+            }
+
+          g_free (path);
+          name = g_dir_read_name (dir);
+        }
+
+      g_dir_close (dir);
+    }
+  else
+    {
+      DEBUG ("Error opening %s: %s\n", dirpath, error->message);
+      g_error_free (error);
+    }
 }
 
-void
-empathy_theme_manager_apply (EmpathyThemeManager *manager,
-                           EmpathyChatView     *view,
-                           const gchar        *name)
+GList *
+empathy_theme_manager_get_adium_themes (void)
 {
-       EmpathyThemeManagerPriv *priv;
+  /* Theme name -> GHashTable info */
+  GHashTable *hash;
+  GList *result;
+  gchar *path = NULL;
+  const gchar *const *paths = NULL;
+  gint i = 0;
+  const gchar *dir;
+
+  hash = g_hash_table_new_full (g_str_hash, g_str_equal,
+      g_free, (GDestroyNotify) g_hash_table_unref);
+
+  /* Start from the more general locations (the system) to the more specific
+   * ones ($HOME, EMPATHY_SRCDIR) so the more specific themes will override
+   * the more general ones.*/
+
+  /* System */
+  paths = g_get_system_data_dirs ();
+  for (i = 0; paths[i] != NULL; i++)
+    {
+      path = g_build_path (G_DIR_SEPARATOR_S, paths[i],
+        "adium/message-styles", NULL);
+
+      find_themes (hash, path);
+      g_free (path);
+    }
+
+  /* Home */
+  path = g_build_path (G_DIR_SEPARATOR_S, g_get_user_data_dir (),
+      "adium/message-styles", NULL);
+
+  find_themes (hash, path);
+  g_free (path);
+
+  /* EMPATHY_SRCDIR */
+  dir = g_getenv ("EMPATHY_SRCDIR");
+  if (dir != NULL)
+    {
+      path = g_build_path (G_DIR_SEPARATOR_S, dir, "data/themes/", NULL);
+
+      find_themes (hash, path);
+      g_free (path);
+    }
+
+  result = g_hash_table_get_values (hash);
+  /* Pass ownership of the info hash table to the list */
+  g_list_foreach (result, (GFunc) g_hash_table_ref, NULL);
+
+  g_hash_table_unref (hash);
+
+  return result;
+}
 
-       priv = GET_PRIV (manager);
+gchar *
+empathy_theme_manager_find_theme (const gchar *name)
+{
+  gchar *path;
+  const gchar * const *paths;
+  gint i;
 
-       theme_manager_apply_theme (manager, view, name);
+  /* look in EMPATHY_SRCDIR */
+  path = g_strjoin (NULL,
+      g_getenv ("EMPATHY_SRCDIR"),
+      "/data/themes/",
+      name,
+      ".AdiumMessageStyle",
+      NULL);
+
+  DEBUG ("Trying '%s'", path);
+
+  if (empathy_adium_path_is_valid (path))
+    return path;
+
+  g_free (path);
+
+  /* look in user dir */
+  path = g_strjoin (NULL,
+      g_get_user_data_dir (),
+      "/adium/message-styles/",
+      name,
+      ".AdiumMessageStyle",
+      NULL);
+
+  DEBUG ("Trying '%s'", path);
+
+  if (empathy_adium_path_is_valid (path))
+    return path;
+
+  g_free (path);
+
+  /* look in system dirs */
+  paths = g_get_system_data_dirs ();
+
+  for (i = 0; paths[i] != NULL; i++)
+    {
+      path = g_strjoin (NULL,
+          paths[i],
+          "/adium/message-styles/",
+          name,
+          ".AdiumMessageStyle",
+          NULL);
+
+      DEBUG ("Trying '%s'", path);
+
+      if (empathy_adium_path_is_valid (path))
+        return path;
+
+      g_free (path);
+    }
+
+  return NULL;
 }
 
-void
-empathy_theme_manager_apply_saved (EmpathyThemeManager *manager,
-                                 EmpathyChatView     *view)
+gchar *
+empathy_theme_manager_dup_theme_name_from_path (const gchar *path)
 {
-       EmpathyThemeManagerPriv *priv;
+  gchar *fullname = NULL, *result = NULL;
+  gchar **tmp = NULL;
 
-       priv = GET_PRIV (manager);
+  if (path == NULL)
+    return NULL;
 
-       theme_manager_apply_theme (manager, view, priv->name);
-}
+  fullname = g_path_get_basename (path);
+  if (!g_str_has_suffix (fullname, ".AdiumMessageStyle"))
+    goto out;
 
+  tmp = g_strsplit (fullname, ".AdiumMessageStyle", 0);
+  result = g_strdup (tmp[0]);
+
+out:
+  g_strfreev (tmp);
+  g_free (fullname);
+  return result;
+}