comparison pidgin/gtkthemes.c @ 17482:fcf61e3be189

propagate from branch 'im.pidgin.pidgin' (head 906d9e8b2315b314b956961566ef8062cd963241) to branch 'org.maemo.garage.pidgin.smiley-install' (head 9d93f1f0d77e5c7bc7fcf4baa9e8f0c026f09e20)
author Gabriel Schulhof <nix@go-nix.ca>
date Wed, 30 May 2007 21:05:04 +0000
parents 92821180bded 6caaf5eba4e7
children cf6b7aeae062
comparison
equal deleted inserted replaced
17481:deb035e6d748 17482:fcf61e3be189
88 g_free(wer); 88 g_free(wer);
89 } 89 }
90 theme->list = NULL; 90 theme->list = NULL;
91 91
92 g_hash_table_destroy(already_freed); 92 g_hash_table_destroy(already_freed);
93 }
94
95 static void smiley_theme_free(struct smiley_theme *theme)
96 {
97 pidgin_themes_destroy_smiley_theme(theme);
98
99 g_free(theme->name);
100 g_free(theme->desc);
101 g_free(theme->author);
102 g_free(theme->icon);
103 g_free(theme->path);
104 g_free(theme);
105 }
106
107 static void
108 pidgin_smiley_themes_remove_non_existing()
109 {
110 static struct smiley_theme *theme = NULL;
111 GSList *iter = NULL;
112
113 if (!smiley_themes) return ;
114
115 for (iter = smiley_themes ; iter ; iter = iter->next) {
116 theme = ((struct smiley_theme *)(iter->data));
117 if (!g_file_test(theme->path, G_FILE_TEST_EXISTS)) {
118 if (theme == current_smiley_theme)
119 current_smiley_theme = ((struct smiley_theme *)(NULL == iter->next ? NULL : iter->next->data));
120 smiley_theme_free(theme);
121 iter->data = NULL;
122 }
123 }
124 /* Remove all elements whose data is NULL */
125 smiley_themes = g_slist_remove_all(smiley_themes, NULL);
126
127 if (!current_smiley_theme && smiley_themes)
128 current_smiley_theme = ((struct smiley_theme *)(g_slist_last(smiley_themes)->data));
93 } 129 }
94 130
95 void pidgin_themes_load_smiley_theme(const char *file, gboolean load) 131 void pidgin_themes_load_smiley_theme(const char *file, gboolean load)
96 { 132 {
97 FILE *f = g_fopen(file, "r"); 133 FILE *f = g_fopen(file, "r");
213 fclose(f); 249 fclose(f);
214 250
215 if (!theme->name || !theme->desc || !theme->author) { 251 if (!theme->name || !theme->desc || !theme->author) {
216 purple_debug_error("gtkthemes", "Invalid file format, not loading smiley theme from '%s'\n", file); 252 purple_debug_error("gtkthemes", "Invalid file format, not loading smiley theme from '%s'\n", file);
217 253
218 pidgin_themes_destroy_smiley_theme(theme); 254 smiley_theme_free(theme);
219
220 g_free(theme->name);
221 g_free(theme->desc);
222 g_free(theme->author);
223 g_free(theme->icon);
224 g_free(theme->path);
225 g_free(theme);
226 255
227 return; 256 return;
228 } 257 }
229 258
230 if (new_theme) { 259 if (new_theme) {
251 280
252 void pidgin_themes_smiley_theme_probe() 281 void pidgin_themes_smiley_theme_probe()
253 { 282 {
254 GDir *dir; 283 GDir *dir;
255 const gchar *file; 284 const gchar *file;
256 gchar *path; 285 gchar *path, *test_path;
257 int l; 286 int l;
258
259 char* probedirs[3]; 287 char* probedirs[3];
288
289 pidgin_smiley_themes_remove_non_existing();
290
260 probedirs[0] = g_build_filename(DATADIR, "pixmaps", "pidgin", "emotes", NULL); 291 probedirs[0] = g_build_filename(DATADIR, "pixmaps", "pidgin", "emotes", NULL);
261 probedirs[1] = g_build_filename(purple_user_dir(), "smileys", NULL); 292 probedirs[1] = g_build_filename(purple_user_dir(), "smileys", NULL);
262 probedirs[2] = 0; 293 probedirs[2] = 0;
263 for (l=0; probedirs[l]; l++) { 294 for (l=0; probedirs[l]; l++) {
264 dir = g_dir_open(probedirs[l], 0, NULL); 295 dir = g_dir_open(probedirs[l], 0, NULL);
265 if (dir) { 296 if (dir) {
266 while ((file = g_dir_read_name(dir))) { 297 while ((file = g_dir_read_name(dir))) {
267 path = g_build_filename(probedirs[l], file, "theme", NULL); 298 test_path = g_build_filename(probedirs[l], file, NULL);
268 299 if (g_file_test(test_path, G_FILE_TEST_IS_DIR)) {
269 /* Here we check to see that the theme has proper syntax. 300 path = g_build_filename(probedirs[l], file, "theme", NULL);
270 * We set the second argument to FALSE so that it doesn't load 301
271 * the theme yet. 302 /* Here we check to see that the theme has proper syntax.
272 */ 303 * We set the second argument to FALSE so that it doesn't load
273 pidgin_themes_load_smiley_theme(path, FALSE); 304 * the theme yet.
274 g_free(path); 305 */
306 pidgin_themes_load_smiley_theme(path, FALSE);
307 g_free(path);
308 }
309 g_free(test_path);
275 } 310 }
276 g_dir_close(dir); 311 g_dir_close(dir);
277 } else if (l == 1) { 312 } else if (l == 1) {
278 g_mkdir(probedirs[l], S_IRUSR | S_IWUSR | S_IXUSR); 313 g_mkdir(probedirs[l], S_IRUSR | S_IWUSR | S_IXUSR);
279 } 314 }
280 g_free(probedirs[l]); 315 g_free(probedirs[l]);
281 } 316 }
317
318 if (!current_smiley_theme && smiley_themes)
319 current_smiley_theme = ((struct smiley_theme *)(smiley_themes->data));
282 } 320 }
283 321
284 GSList *pidgin_themes_get_proto_smileys(const char *id) { 322 GSList *pidgin_themes_get_proto_smileys(const char *id) {
285 PurplePlugin *proto; 323 PurplePlugin *proto;
286 struct smiley_list *list, *def; 324 struct smiley_list *list, *def;