[empathy] theme-manager: make it possible to look up theme by name



commit 518d54667e1934f0e339e3368d77cfc953a34314
Author: Danielle Madeley <danielle madeley collabora co uk>
Date:   Fri Jun 29 14:12:14 2012 +1000

    theme-manager: make it possible to look up theme by name

 libempathy-gtk/empathy-theme-adium.c   |    3 +
 libempathy-gtk/empathy-theme-manager.c |   67 +++++++++++++++++++++++++++++++-
 libempathy-gtk/empathy-theme-manager.h |    1 +
 3 files changed, 69 insertions(+), 2 deletions(-)
---
diff --git a/libempathy-gtk/empathy-theme-adium.c b/libempathy-gtk/empathy-theme-adium.c
index 485d361..f1aad6e 100644
--- a/libempathy-gtk/empathy-theme-adium.c
+++ b/libempathy-gtk/empathy-theme-adium.c
@@ -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);
diff --git a/libempathy-gtk/empathy-theme-manager.c b/libempathy-gtk/empathy-theme-manager.c
index bb0b3f7..81b15d5 100644
--- a/libempathy-gtk/empathy-theme-manager.c
+++ b/libempathy-gtk/empathy-theme-manager.c
@@ -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;
+}
diff --git a/libempathy-gtk/empathy-theme-manager.h b/libempathy-gtk/empathy-theme-manager.h
index c60dc0c..4d51945 100644
--- a/libempathy-gtk/empathy-theme-manager.h
+++ b/libempathy-gtk/empathy-theme-manager.h
@@ -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
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]