soc.2008.themes: fc91075c: cleaned up purple_theme_manager_build_di...
grim at pidgin.im
grim at pidgin.im
Thu Aug 21 04:20:35 EDT 2008
-----------------------------------------------------------------
Revision: fc91075c8014936b08a61c91b00cb217eeef4b2b
Ancestor: 7d0b59f7f62367cb4d0c8d9e6a056130e5d63aea
Author: grim at pidgin.im
Date: 2008-08-21T08:01:08
Branch: im.pidgin.soc.2008.themes
URL: http://d.pidgin.im/viewmtn/revision/info/fc91075c8014936b08a61c91b00cb217eeef4b2b
Modified files:
libpurple/theme-manager.c
ChangeLog:
cleaned up purple_theme_manager_build_dir
added additional directories to purple_theme_manager_refresh. We should really be using the glib functions for the xdg data dir stuff, but this will work, for now, on !win32...
-------------- next part --------------
============================================================
--- libpurple/theme-manager.c ba2ca99f83e494a0c2775e268fc4906b46fd6374
+++ libpurple/theme-manager.c 4c94f63b6062eeab25be28c01563024dd3341378
@@ -24,6 +24,7 @@
#include <string.h>
#include "theme-manager.h"
+#include "util.h"
/******************************************************************************
* Globals
@@ -101,41 +102,44 @@ purple_theme_manager_build_dir(const gch
purple_theme_manager_build_dir(const gchar *root)
{
- GDir *rdir;
- gchar *name, *type, *purple_dir, *theme_dir;
- GDir *dir;
+ gchar *purple_dir, *theme_dir;
+ const gchar *name = NULL, *type = NULL;
+ GDir *rdir, *tdir;
PurpleThemeLoader *loader;
- rdir = g_dir_open(root, 0, NULL);
+ rdir = g_dir_open(root, 0, NULL);
g_return_if_fail(rdir);
/* Parses directory by root/name/purple/type */
- while ((name = g_strdup(g_dir_read_name (rdir)))){
-
+ while((name = g_dir_read_name(rdir))) {
purple_dir = g_build_filename(root, name, "purple", NULL);
- dir = g_dir_open(purple_dir, 0, NULL);
+ tdir = g_dir_open(purple_dir, 0, NULL);
- if (dir) {
- while ((type = g_strdup(g_dir_read_name (dir)))) {
- if ((loader = g_hash_table_lookup (theme_table, type))){
+ if(!tdir) {
+ g_free(purple_dir);
- theme_dir = g_build_filename(purple_dir, type, NULL);
- purple_theme_manager_add_theme(purple_theme_loader_build(loader, theme_dir));
+ continue;
+ }
- }
- g_free(type);
+ while((type = g_dir_read_name(tdir))) {
+ if((loader = g_hash_table_lookup(theme_table, type))) {
+ PurpleTheme *theme = NULL;
+ theme_dir = g_build_filename(purple_dir, type, NULL);
+
+ theme = purple_theme_loader_build(loader, theme_dir);
+
+ if(PURPLE_IS_THEME(theme))
+ purple_theme_manager_add_theme(theme);
}
- g_dir_close(dir);
+ }
- }
+ g_dir_close(tdir);
g_free(purple_dir);
- g_free(name);
-
}
+
g_dir_close(rdir);
-
}
/*****************************************************************************
@@ -154,13 +158,41 @@ purple_theme_manager_refresh()
void
purple_theme_manager_refresh()
{
- g_hash_table_foreach_remove (theme_table,
- (GHRFunc) purple_theme_manager_is_theme,
- NULL);
-
- /* TODO: add correct directories to parse */
- purple_theme_manager_build_dir("/usr/share/themes");
+ gchar *path = NULL;
+ const gchar *xdg = NULL;
+ gint i = 0;
+ g_hash_table_foreach_remove(theme_table,
+ (GHRFunc) purple_theme_manager_is_theme,
+ NULL);
+
+ /* Add themes from ~/.purple */
+ path = g_build_filename(purple_user_dir(), "themes", NULL);
+ purple_theme_manager_build_dir(path);
+ g_free(path);
+
+ /* look for XDG_DATA_HOME. If we don't have it use ~/.local, and add it */
+ if((xdg = g_getenv("XDG_DATA_HOME")) != NULL)
+ path = g_build_filename(xdg, "themes", NULL);
+ else
+ path = g_build_filename(purple_home_dir(), ".local", "themes", NULL);
+
+ purple_theme_manager_build_dir(path);
+ g_free(path);
+
+ /* now dig through XDG_DATA_DIRS and add those too */
+ xdg = g_getenv("XDG_DATA_DIRS");
+ if(xdg) {
+ gchar **xdg_dirs = g_strsplit(xdg, G_SEARCHPATH_SEPARATOR_S, 0);
+
+ for(i = 0; xdg_dirs[i]; i++) {
+ path = g_build_filename(xdg_dirs[i], "themes", NULL);
+ purple_theme_manager_build_dir(path);
+ g_free(path);
+ }
+
+ g_strfreev(xdg_dirs);
+ }
}
void
More information about the Commits
mailing list