comparison libpurple/theme-manager.c @ 25127:4575b578a54b

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...
author Gary Kramlich <grim@reaperworld.com>
date Thu, 21 Aug 2008 08:01:08 +0000
parents 748308865dbf
children 0de17531e9f2
comparison
equal deleted inserted replaced
25126:78b43f9c741b 25127:4575b578a54b
22 */ 22 */
23 23
24 #include <string.h> 24 #include <string.h>
25 25
26 #include "theme-manager.h" 26 #include "theme-manager.h"
27 #include "util.h"
27 28
28 /****************************************************************************** 29 /******************************************************************************
29 * Globals 30 * Globals
30 *****************************************************************************/ 31 *****************************************************************************/
31 32
99 100
100 static void 101 static void
101 purple_theme_manager_build_dir(const gchar *root) 102 purple_theme_manager_build_dir(const gchar *root)
102 { 103 {
103 104
104 GDir *rdir; 105 gchar *purple_dir, *theme_dir;
105 gchar *name, *type, *purple_dir, *theme_dir; 106 const gchar *name = NULL, *type = NULL;
106 GDir *dir; 107 GDir *rdir, *tdir;
107 PurpleThemeLoader *loader; 108 PurpleThemeLoader *loader;
108 109
109 rdir = g_dir_open(root, 0, NULL); 110 rdir = g_dir_open(root, 0, NULL);
110 111
111 g_return_if_fail(rdir); 112 g_return_if_fail(rdir);
112 113
113 /* Parses directory by root/name/purple/type */ 114 /* Parses directory by root/name/purple/type */
114 while ((name = g_strdup(g_dir_read_name (rdir)))){ 115 while((name = g_dir_read_name(rdir))) {
115
116 purple_dir = g_build_filename(root, name, "purple", NULL); 116 purple_dir = g_build_filename(root, name, "purple", NULL);
117 dir = g_dir_open(purple_dir, 0, NULL); 117 tdir = g_dir_open(purple_dir, 0, NULL);
118 118
119 if (dir) { 119 if(!tdir) {
120 while ((type = g_strdup(g_dir_read_name (dir)))) { 120 g_free(purple_dir);
121 if ((loader = g_hash_table_lookup (theme_table, type))){ 121
122 122 continue;
123 theme_dir = g_build_filename(purple_dir, type, NULL); 123 }
124 purple_theme_manager_add_theme(purple_theme_loader_build(loader, theme_dir)); 124
125 125 while((type = g_dir_read_name(tdir))) {
126 } 126 if((loader = g_hash_table_lookup(theme_table, type))) {
127 g_free(type); 127 PurpleTheme *theme = NULL;
128 128
129 theme_dir = g_build_filename(purple_dir, type, NULL);
130
131 theme = purple_theme_loader_build(loader, theme_dir);
132
133 if(PURPLE_IS_THEME(theme))
134 purple_theme_manager_add_theme(theme);
129 } 135 }
130 g_dir_close(dir);
131
132 } 136 }
137
138 g_dir_close(tdir);
133 g_free(purple_dir); 139 g_free(purple_dir);
134 g_free(name);
135
136 } 140 }
141
137 g_dir_close(rdir); 142 g_dir_close(rdir);
138
139 } 143 }
140 144
141 /***************************************************************************** 145 /*****************************************************************************
142 * Public API functions * 146 * Public API functions *
143 *****************************************************************************/ 147 *****************************************************************************/
152 } 156 }
153 157
154 void 158 void
155 purple_theme_manager_refresh() 159 purple_theme_manager_refresh()
156 { 160 {
157 g_hash_table_foreach_remove (theme_table, 161 gchar *path = NULL;
158 (GHRFunc) purple_theme_manager_is_theme, 162 const gchar *xdg = NULL;
159 NULL); 163 gint i = 0;
160 164
161 /* TODO: add correct directories to parse */ 165 g_hash_table_foreach_remove(theme_table,
162 purple_theme_manager_build_dir("/usr/share/themes"); 166 (GHRFunc) purple_theme_manager_is_theme,
163 167 NULL);
168
169 /* Add themes from ~/.purple */
170 path = g_build_filename(purple_user_dir(), "themes", NULL);
171 purple_theme_manager_build_dir(path);
172 g_free(path);
173
174 /* look for XDG_DATA_HOME. If we don't have it use ~/.local, and add it */
175 if((xdg = g_getenv("XDG_DATA_HOME")) != NULL)
176 path = g_build_filename(xdg, "themes", NULL);
177 else
178 path = g_build_filename(purple_home_dir(), ".local", "themes", NULL);
179
180 purple_theme_manager_build_dir(path);
181 g_free(path);
182
183 /* now dig through XDG_DATA_DIRS and add those too */
184 xdg = g_getenv("XDG_DATA_DIRS");
185 if(xdg) {
186 gchar **xdg_dirs = g_strsplit(xdg, G_SEARCHPATH_SEPARATOR_S, 0);
187
188 for(i = 0; xdg_dirs[i]; i++) {
189 path = g_build_filename(xdg_dirs[i], "themes", NULL);
190 purple_theme_manager_build_dir(path);
191 g_free(path);
192 }
193
194 g_strfreev(xdg_dirs);
195 }
164 } 196 }
165 197
166 void 198 void
167 purple_theme_manager_uninit () 199 purple_theme_manager_uninit ()
168 { 200 {