comparison src/gtkthemes.c @ 13586:0cc7773b1d87

[gaim-migrate @ 15971] Don't load invalid smiley themes (i.e. themes missing the Name, Description or Author lines). I noticed that gtkprefs were being initialized twice, so that is fixed too (it took me forever to figure out why the callback was being called twice). committer: Tailor Script <tailor@pidgin.im>
author Daniel Atallah <daniel.atallah@gmail.com>
date Thu, 06 Apr 2006 02:03:20 +0000
parents 541486fde12b
children ff70d3009409
comparison
equal deleted inserted replaced
13585:ffb12e85473f 13586:0cc7773b1d87
70 char *i; 70 char *i;
71 struct smiley_theme *theme=NULL; 71 struct smiley_theme *theme=NULL;
72 struct smiley_list *list = NULL; 72 struct smiley_list *list = NULL;
73 GSList *lst = smiley_themes; 73 GSList *lst = smiley_themes;
74 char *dirname; 74 char *dirname;
75 gboolean new_theme = FALSE;
75 76
76 if (!f) 77 if (!f)
77 return; 78 return;
78 79
79 while (lst) { 80 while (lst) {
84 } 85 }
85 lst = lst->next; 86 lst = lst->next;
86 } 87 }
87 88
88 if (!theme) { 89 if (!theme) {
90 new_theme = TRUE;
89 theme = g_new0(struct smiley_theme, 1); 91 theme = g_new0(struct smiley_theme, 1);
90 theme->path = g_strdup(file); 92 theme->path = g_strdup(file);
91 smiley_themes = g_slist_append(smiley_themes, theme); 93 } else if (theme == current_smiley_theme) {
94 /* Don't reload the theme if it is already loaded */
95 fclose(f);
96 return;
92 } 97 }
93 98
94 dirname = g_path_get_dirname(file); 99 dirname = g_path_get_dirname(file);
95 if (load) {
96 if (current_smiley_theme) {
97 GSList *already_freed = NULL;
98 struct smiley_list *wer = current_smiley_theme->list, *wer2;
99 while (wer) {
100 while (wer->smileys) {
101 GtkIMHtmlSmiley *uio = wer->smileys->data;
102 if (uio->icon)
103 g_object_unref(uio->icon);
104 if (!g_slist_find(already_freed, uio->file)) {
105 g_free(uio->file);
106 already_freed = g_slist_append(already_freed, uio->file);
107 }
108 g_free(uio->smile);
109 g_free(uio);
110 wer->smileys=g_slist_remove(wer->smileys, uio);
111 }
112 wer2 = wer->next;
113 g_free(wer->sml);
114 g_free(wer);
115 wer = wer2;
116 }
117 current_smiley_theme->list = NULL;
118 g_slist_free(already_freed);
119 }
120 current_smiley_theme = theme;
121 }
122
123 100
124 while (!feof(f)) { 101 while (!feof(f)) {
125 if (!fgets(buf, sizeof(buf), f)) { 102 if (!fgets(buf, sizeof(buf), f)) {
126 break; 103 break;
127 } 104 }
193 170
194 } 171 }
195 } 172 }
196 } 173 }
197 174
175 g_free(dirname);
176 fclose(f);
177
178 if (!theme->name || !theme->desc || !theme->author) {
179 GSList *already_freed = NULL;
180 struct smiley_list *wer = theme->list, *wer2;
181
182 gaim_debug_error("gtkthemes", "Invalid file format, not loading smiley theme from '%s'\n", file);
183
184 while (wer) {
185 while (wer->smileys) {
186 GtkIMHtmlSmiley *uio = wer->smileys->data;
187 if (uio->icon)
188 g_object_unref(uio->icon);
189 if (!g_slist_find(already_freed, uio->file)) {
190 g_free(uio->file);
191 already_freed = g_slist_append(already_freed, uio->file);
192 }
193 g_free(uio->smile);
194 g_free(uio);
195 wer->smileys = g_slist_remove(wer->smileys, uio);
196 }
197 wer2 = wer->next;
198 g_free(wer->sml);
199 g_free(wer);
200 wer = wer2;
201 }
202 theme->list = NULL;
203 g_slist_free(already_freed);
204
205 g_free(theme->path);
206 g_free(theme);
207
208 return;
209 }
210
211 if (new_theme) {
212 smiley_themes = g_slist_append(smiley_themes, theme);
213 }
214
198 if (load) { 215 if (load) {
199 GList *cnv; 216 GList *cnv;
217
218 if (current_smiley_theme) {
219 GSList *already_freed = NULL;
220 struct smiley_list *wer = current_smiley_theme->list, *wer2;
221 while (wer) {
222 while (wer->smileys) {
223 GtkIMHtmlSmiley *uio = wer->smileys->data;
224 if (uio->icon)
225 g_object_unref(uio->icon);
226 if (!g_slist_find(already_freed, uio->file)) {
227 g_free(uio->file);
228 already_freed = g_slist_append(already_freed, uio->file);
229 }
230 g_free(uio->smile);
231 g_free(uio);
232 wer->smileys = g_slist_remove(wer->smileys, uio);
233 }
234 wer2 = wer->next;
235 g_free(wer->sml);
236 g_free(wer);
237 wer = wer2;
238 }
239 current_smiley_theme->list = NULL;
240 g_slist_free(already_freed);
241 }
242 current_smiley_theme = theme;
200 243
201 for (cnv = gaim_get_conversations(); cnv != NULL; cnv = cnv->next) { 244 for (cnv = gaim_get_conversations(); cnv != NULL; cnv = cnv->next) {
202 GaimConversation *conv = cnv->data; 245 GaimConversation *conv = cnv->data;
203 246
204 if (GAIM_IS_GTK_CONVERSATION(conv)) { 247 if (GAIM_IS_GTK_CONVERSATION(conv)) {
205 gaim_gtkthemes_smiley_themeize(GAIM_GTK_CONVERSATION(conv)->imhtml); 248 gaim_gtkthemes_smiley_themeize(GAIM_GTK_CONVERSATION(conv)->imhtml);
206 gaim_gtkthemes_smiley_themeize(GAIM_GTK_CONVERSATION(conv)->entry); 249 gaim_gtkthemes_smiley_themeize(GAIM_GTK_CONVERSATION(conv)->entry);
207 } 250 }
208 } 251 }
209 } 252 }
210
211 g_free(dirname);
212 fclose(f);
213 } 253 }
214 254
215 void gaim_gtkthemes_smiley_theme_probe() 255 void gaim_gtkthemes_smiley_theme_probe()
216 { 256 {
217 GDir *dir; 257 GDir *dir;