]> git.0d.be Git - empathy.git/commitdiff
theme-manager: make it possible to look up theme by name
authorDanielle Madeley <danielle.madeley@collabora.co.uk>
Fri, 29 Jun 2012 04:12:14 +0000 (14:12 +1000)
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Mon, 2 Jul 2012 08:03:23 +0000 (10:03 +0200)
libempathy-gtk/empathy-theme-adium.c
libempathy-gtk/empathy-theme-manager.c
libempathy-gtk/empathy-theme-manager.h

index 485d361f615c2eaf984b58c7624a6aa5a2c3c82c..f1aad6eacd3b3700b7f534d6a0d2342286e07301 100644 (file)
@@ -1710,6 +1710,9 @@ empathy_adium_path_is_valid (const gchar *path)
        gboolean ret;
        gchar   *file;
 
+       if (path[0] != '/')
+               return FALSE;
+
        /* The theme is not valid if there is no Info.plist */
        file = g_build_filename (path, "Contents", "Info.plist",
                                 NULL);
index bb0b3f7844a98bf889c826fac08b1841d79f2176..81b15d5ca4c8b80b1154b0eb3744979317af439b 100644 (file)
@@ -165,8 +165,12 @@ theme_manager_notify_adium_path_cb (GSettings   *gsettings_chat,
        }
 
        /* If path does not really contains an adium path, ignore */
-       if (!empathy_adium_path_is_valid (new_path)) {
-               DEBUG ("Invalid theme path set: %s", new_path);
+       if (empathy_adium_path_is_valid (new_path)) {
+               /* pass */
+       } else if (empathy_theme_manager_find_theme (new_path) != NULL) {
+               new_path = empathy_theme_manager_find_theme (new_path);
+       } else {
+               g_warning ("Do not understand theme: %s", new_path);
                goto finally;
        }
 
@@ -406,3 +410,62 @@ empathy_theme_manager_get_adium_themes (void)
 
        return themes_list;
 }
+
+gchar *
+empathy_theme_manager_find_theme (const gchar *name)
+{
+       gchar *path;
+       const gchar * const *paths;
+       gint i;
+
+       /* 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;
+}
index c60dc0cd9441078121ce0a367b2f3c2332b816cf..4d519457088bdf1795385bad9d0d6d6538b8f9bd 100644 (file)
@@ -53,6 +53,7 @@ EmpathyThemeManager *   empathy_theme_manager_dup_singleton (void);
 const gchar **          empathy_theme_manager_get_themes  (void);
 GList *                 empathy_theme_manager_get_adium_themes (void);
 EmpathyChatView *       empathy_theme_manager_create_view (EmpathyThemeManager *manager);
+gchar *                 empathy_theme_manager_find_theme (const gchar *name);
 
 G_END_DECLS