comparison src/themes.c @ 4892:dc6de8ad81ae

[gaim-migrate @ 5222] memleak fixes in all kinds of places. mainly in smiley themes. committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Tue, 25 Mar 2003 06:37:45 +0000
parents 94e75b03c598
children 0f8189301213
comparison
equal deleted inserted replaced
4891:cfa045006bec 4892:dc6de8ad81ae
36 char *sml; 36 char *sml;
37 GSList *smileys; 37 GSList *smileys;
38 struct smiley_list *next; 38 struct smiley_list *next;
39 }; 39 };
40 40
41 GSList *smiley_themes; 41 GSList *smiley_themes = NULL;
42 struct smiley_theme *current_smiley_theme; 42 struct smiley_theme *current_smiley_theme;
43 43
44 void smiley_themeize(GtkWidget *imhtml) 44 void smiley_themeize(GtkWidget *imhtml)
45 { 45 {
46 struct smiley_list *list; 46 struct smiley_list *list;
58 } 58 }
59 list = list->next; 59 list = list->next;
60 } 60 }
61 } 61 }
62 62
63 struct smiley_theme *load_smiley_theme(const char *file, gboolean load) 63 void load_smiley_theme(const char *file, gboolean load)
64 { 64 {
65 FILE *f = fopen(file, "r"); 65 FILE *f = fopen(file, "r");
66 char buf[256]; 66 char buf[256];
67 char *i; 67 char *i;
68 struct smiley_theme *theme=NULL; 68 struct smiley_theme *theme=NULL;
69 struct smiley_list *list = NULL; 69 struct smiley_list *list = NULL;
70 GSList *lst = smiley_themes; 70 GSList *lst = smiley_themes;
71 char *dirname; 71 char *dirname;
72 gboolean old=FALSE; 72
73 if (!f)
74 return;
73 75
74 while (lst) { 76 while (lst) {
75 struct smiley_theme *thm = lst->data; 77 struct smiley_theme *thm = lst->data;
76 if (!strcmp(thm->path, file)) { 78 if (!strcmp(thm->path, file)) {
77 theme = thm; 79 theme = thm;
78 old = TRUE;
79 break; 80 break;
80 } 81 }
81 lst = lst->next; 82 lst = lst->next;
82 } 83 }
83 84
84 if (!f)
85 return NULL;
86 if (!theme) { 85 if (!theme) {
87 theme = g_new0(struct smiley_theme, 1); 86 theme = g_new0(struct smiley_theme, 1);
88 theme->path = g_strdup(file); 87 theme->path = g_strdup(file);
88 smiley_themes = g_slist_append(smiley_themes, theme);
89 } 89 }
90 90
91 dirname = g_path_get_dirname(file); 91 dirname = g_path_get_dirname(file);
92 if (load) { 92 if (load) {
93 if (current_smiley_theme) { 93 if (current_smiley_theme) {
94 GSList *already_freed = NULL; 94 GSList *already_freed = NULL;
95 struct smiley_list *wer = current_smiley_theme->list; 95 struct smiley_list *wer = current_smiley_theme->list, *wer2;
96 while (wer) { 96 while (wer) {
97 GSList *already_freed = NULL;
98 while (wer->smileys) { 97 while (wer->smileys) {
99 GtkIMHtmlSmiley *uio = wer->smileys->data; 98 GtkIMHtmlSmiley *uio = wer->smileys->data;
100 if (uio->icon) 99 if (uio->icon)
101 g_object_unref(uio->icon); 100 g_object_unref(uio->icon);
102 if (!g_slist_find(already_freed, uio->file)) { 101 if (!g_slist_find(already_freed, uio->file)) {
105 } 104 }
106 g_free(uio->smile); 105 g_free(uio->smile);
107 g_free(uio); 106 g_free(uio);
108 wer->smileys=g_slist_remove(wer->smileys, uio); 107 wer->smileys=g_slist_remove(wer->smileys, uio);
109 } 108 }
110 wer = wer->next; 109 wer2 = wer->next;
110 g_free(wer->sml);
111 g_free(wer);
112 wer = wer2;
111 } 113 }
112 current_smiley_theme->list = NULL; 114 current_smiley_theme->list = NULL;
113 g_slist_free(already_freed); 115 g_slist_free(already_freed);
114 } 116 }
115 current_smiley_theme = theme; 117 current_smiley_theme = theme;
135 list->next = child; 137 list->next = child;
136 else 138 else
137 theme->list = child; 139 theme->list = child;
138 list = child; 140 list = child;
139 } else if (!g_ascii_strncasecmp(i, "Name=", strlen("Name="))) { 141 } else if (!g_ascii_strncasecmp(i, "Name=", strlen("Name="))) {
142 if(theme->name)
143 g_free(theme->name);
140 theme->name = g_strdup(i+ strlen("Name=")); 144 theme->name = g_strdup(i+ strlen("Name="));
141 theme->name[strlen(theme->name)-1] = 0; 145 theme->name[strlen(theme->name)-1] = 0;
142 } else if (!g_ascii_strncasecmp(i, "Description=", strlen("Description="))) { 146 } else if (!g_ascii_strncasecmp(i, "Description=", strlen("Description="))) {
147 if(theme->desc)
148 g_free(theme->desc);
143 theme->desc = g_strdup(i + strlen("Description=")); 149 theme->desc = g_strdup(i + strlen("Description="));
144 theme->desc[strlen(theme->desc)-1] = 0; 150 theme->desc[strlen(theme->desc)-1] = 0;
145 } else if (!g_ascii_strncasecmp(i, "Icon=", strlen("Icon="))) { 151 } else if (!g_ascii_strncasecmp(i, "Icon=", strlen("Icon="))) {
152 if(theme->icon)
153 g_free(theme->icon);
146 theme->icon = g_build_filename(dirname, i + strlen("Icon="), NULL); 154 theme->icon = g_build_filename(dirname, i + strlen("Icon="), NULL);
147 theme->icon[strlen(theme->icon)-1] = 0; 155 theme->icon[strlen(theme->icon)-1] = 0;
148 } else if (!g_ascii_strncasecmp(i, "Author=", strlen("Author="))) { 156 } else if (!g_ascii_strncasecmp(i, "Author=", strlen("Author="))) {
157 if(theme->author)
158 g_free(theme->author);
149 theme->author = g_strdup(i + strlen("Author=")); 159 theme->author = g_strdup(i + strlen("Author="));
150 theme->author[strlen(theme->author)-1] = 0; 160 theme->author[strlen(theme->author)-1] = 0;
151 } else if (load && list) { 161 } else if (load && list) {
152 gboolean hidden = FALSE; 162 gboolean hidden = FALSE;
153 char *sfile = NULL; 163 char *sfile = NULL;
189 smiley_themeize(GAIM_GTK_CONVERSATION(conv)->imhtml); 199 smiley_themeize(GAIM_GTK_CONVERSATION(conv)->imhtml);
190 } 200 }
191 } 201 }
192 202
193 g_free(dirname); 203 g_free(dirname);
194 return old ? NULL : theme;
195 } 204 }
196 205
197 void smiley_theme_probe() 206 void smiley_theme_probe()
198 { 207 {
199 GDir *dir; 208 GDir *dir;
200 const gchar *file; 209 const gchar *file;
201 gchar *path; 210 gchar *path;
202 struct smiley_theme *smile;
203 int l; 211 int l;
204 212
205 char* probedirs[3]; 213 char* probedirs[3];
206 probedirs[0] = g_build_filename(DATADIR, "pixmaps", "gaim", "smileys", NULL); 214 probedirs[0] = g_build_filename(DATADIR, "pixmaps", "gaim", "smileys", NULL);
207 probedirs[1] = g_build_filename(gaim_user_dir(), "smileys", NULL); 215 probedirs[1] = g_build_filename(gaim_user_dir(), "smileys", NULL);
209 for (l=0; probedirs[l]; l++) { 217 for (l=0; probedirs[l]; l++) {
210 dir = g_dir_open(probedirs[l], 0, NULL); 218 dir = g_dir_open(probedirs[l], 0, NULL);
211 if (dir) { 219 if (dir) {
212 while ((file = g_dir_read_name(dir))) { 220 while ((file = g_dir_read_name(dir))) {
213 path = g_build_filename(probedirs[l], file, "theme", NULL); 221 path = g_build_filename(probedirs[l], file, "theme", NULL);
214 222
215 /* Here we check to see that the theme has proper syntax. 223 /* Here we check to see that the theme has proper syntax.
216 * We set the second argument to FALSE so that it doesn't load 224 * We set the second argument to FALSE so that it doesn't load
217 * the theme yet. 225 * the theme yet.
218 */ 226 */
219 if ((smile = load_smiley_theme(path, FALSE))) { 227 load_smiley_theme(path, FALSE);
220 smiley_themes = g_slist_append(smiley_themes, smile);
221 }
222 g_free(path); 228 g_free(path);
223 } 229 }
224 g_dir_close(dir); 230 g_dir_close(dir);
225 } else if (l == 1) { 231 } else if (l == 1) {
226 mkdir(probedirs[l], S_IRUSR | S_IWUSR | S_IXUSR); 232 mkdir(probedirs[l], S_IRUSR | S_IWUSR | S_IXUSR);
227 } 233 }
228 g_free(probedirs[l]); 234 g_free(probedirs[l]);
229 } 235 }
230 } 236 }
231 237
232 GSList *get_proto_smileys(int protocol) { 238 GSList *get_proto_smileys(int protocol) {