Mercurial > pidgin.yaz
annotate src/themes.c @ 4321:1cfad48b7d93
[gaim-migrate @ 4576]
win32'ized
committer: Tailor Script <tailor@pidgin.im>
author | Herman Bloggs <hermanator12002@yahoo.com> |
---|---|
date | Thu, 16 Jan 2003 22:39:22 +0000 |
parents | a23ae74677a2 |
children | 8a932c488afc |
rev | line source |
---|---|
4263 | 1 /* |
2 * Themes for Gaim | |
3 * | |
4 * Copyright (C) 2003, Sean Egan <bj91704@binghamton.edu> | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 * | |
20 */ | |
21 | |
4288 | 22 #include "gaim.h" |
23 #include "ui.h" | |
4263 | 24 #include "gtkimhtml.h" |
25 #include <stdio.h> | |
4298 | 26 #include <string.h> |
27 #include <ctype.h> | |
28 #include "gaim.h" | |
4263 | 29 |
4321
1cfad48b7d93
[gaim-migrate @ 4576]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4301
diff
changeset
|
30 #ifdef _WIN32 |
1cfad48b7d93
[gaim-migrate @ 4576]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4301
diff
changeset
|
31 #include "win32dep.h" |
1cfad48b7d93
[gaim-migrate @ 4576]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4301
diff
changeset
|
32 #endif |
1cfad48b7d93
[gaim-migrate @ 4576]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4301
diff
changeset
|
33 |
4263 | 34 struct smiley_list { |
35 char *sml; | |
36 GSList *smileys; | |
37 struct smiley_list *next; | |
38 }; | |
39 | |
40 GSList *smiley_themes; | |
4288 | 41 struct smiley_theme *current_smiley_theme; |
4263 | 42 |
43 void smiley_themeize(GtkWidget *imhtml) | |
44 { | |
45 struct smiley_list *list; | |
46 if (!current_smiley_theme) | |
47 return; | |
48 | |
49 gtk_imhtml_remove_smileys(GTK_IMHTML(imhtml)); | |
50 list = current_smiley_theme->list; | |
51 while (list) { | |
52 char *sml = !strcmp(list->sml, "default") ? NULL : list->sml; | |
53 GSList *icons = list->smileys; | |
54 while (icons) { | |
55 gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), sml, icons->data); | |
56 icons = icons->next; | |
57 } | |
58 list = list->next; | |
59 } | |
60 } | |
61 | |
4298 | 62 struct smiley_theme *load_smiley_theme(const char *file, gboolean load) |
4263 | 63 { |
64 FILE *f = fopen(file, "r"); | |
65 char buf[256]; | |
66 char *i; | |
67 struct smiley_theme *theme=NULL; | |
68 struct smiley_list *list = NULL; | |
69 GSList *lst = smiley_themes; | |
70 char *dirname; | |
71 | |
72 while (lst) { | |
73 struct smiley_theme *thm = lst->data; | |
4288 | 74 if (!strcmp(thm->path, file)) { |
4263 | 75 theme = thm; |
76 break; | |
77 } | |
78 lst = lst->next; | |
79 } | |
80 if (!theme) { | |
81 theme = g_new0(struct smiley_theme, 1); | |
4288 | 82 theme->path = g_strdup(file); |
4263 | 83 } |
84 if (!f) | |
85 return NULL; | |
86 | |
87 dirname = g_path_get_dirname(file); | |
88 if (load) { | |
89 if (current_smiley_theme) { | |
4288 | 90 GSList *already_freed = NULL; |
4263 | 91 struct smiley_list *wer = current_smiley_theme->list; |
92 while (wer) { | |
4288 | 93 GSList *already_freed = NULL; |
94 while (wer->smileys) { | |
95 GtkIMHtmlSmiley *uio = wer->smileys->data; | |
4263 | 96 if (uio->icon) |
97 g_object_unref(uio->icon); | |
4288 | 98 if (!g_slist_find(already_freed, uio->file)) { |
99 g_free(uio->file); | |
100 already_freed = g_slist_append(already_freed, uio->file); | |
101 } | |
4263 | 102 g_free(uio->smile); |
4288 | 103 g_free(uio); |
104 wer->smileys=g_slist_remove(wer->smileys, uio); | |
4263 | 105 } |
106 wer = wer->next; | |
107 } | |
4288 | 108 current_smiley_theme->list = NULL; |
109 g_slist_free(already_freed); | |
4263 | 110 } |
4288 | 111 current_smiley_theme = theme; |
4263 | 112 } |
113 | |
114 | |
115 while (!feof(f)) { | |
116 if (!fgets(buf, sizeof(buf), f)) { | |
4288 | 117 break; |
4263 | 118 } |
119 | |
120 if (buf[0] == '#' || buf[0] == '\0') | |
121 continue; | |
122 | |
123 i = buf; | |
124 while (isspace(*i)) | |
125 i++; | |
126 | |
127 if (*i == '[' && strchr(i, ']') && load) { | |
128 struct smiley_list *child = g_new0(struct smiley_list, 1); | |
129 child->sml = g_strndup(i+1, (int)strchr(i, ']') - (int)i - 1); | |
130 if (theme->list) | |
131 list->next = child; | |
132 else | |
133 theme->list = child; | |
134 list = child; | |
135 } else if (!g_strncasecmp(i, "Name=", strlen("Name="))) { | |
136 theme->name = g_strdup(i+ strlen("Name=")); | |
4288 | 137 theme->name[strlen(theme->name)-1] = 0; |
4263 | 138 } else if (!g_strncasecmp(i, "Description=", strlen("Description="))) { |
139 theme->desc = g_strdup(i + strlen("Description=")); | |
4288 | 140 theme->desc[strlen(theme->desc)-1] = 0; |
4263 | 141 } else if (!g_strncasecmp(i, "Icon=", strlen("Icon="))) { |
142 theme->icon = g_build_filename(dirname, i + strlen("Icon="), NULL); | |
4288 | 143 theme->icon[strlen(theme->icon)-1] = 0; |
144 } else if (!g_strncasecmp(i, "Author=", strlen("Author="))) { | |
145 theme->author = g_strdup(i + strlen("Author=")); | |
146 theme->author[strlen(theme->author)-1] = 0; | |
4263 | 147 } else if (load && list) { |
148 gboolean hidden; | |
4288 | 149 char *sfile = NULL; |
4263 | 150 GtkIMHtmlSmiley *smiley = g_new0(GtkIMHtmlSmiley, 1); |
151 | |
4266 | 152 if (*i == '!' && *(i + 1) == ' ') { |
4263 | 153 hidden = TRUE; |
154 i = i + 2; | |
155 } | |
156 while (*i) { | |
157 char l[64]; | |
158 int li = 0; | |
159 while (!isspace(*i)) | |
160 l[li++] = *(i++); | |
4288 | 161 if (!sfile) { |
4263 | 162 l[li] = 0; |
4288 | 163 sfile = g_build_filename(dirname, l, NULL); |
4263 | 164 } else { |
165 l[li] = 0; | |
166 smiley = g_new0(GtkIMHtmlSmiley, 1); | |
4288 | 167 smiley->file = sfile; |
4263 | 168 smiley->smile = g_strdup(l); |
169 list->smileys = g_slist_append(list->smileys, smiley); | |
170 } | |
4288 | 171 while (isspace(*i)) |
4263 | 172 i++; |
4288 | 173 |
4263 | 174 } |
175 } | |
176 } | |
4288 | 177 |
178 if (load) { | |
179 GList *cnv = conversations; | |
180 while (cnv) { | |
181 struct conversation *c = cnv->data; | |
182 smiley_themeize(c->text); | |
183 cnv=cnv->next; | |
184 } | |
185 } | |
186 | |
4263 | 187 g_free(dirname); |
188 return theme; | |
189 } | |
190 | |
191 void smiley_theme_probe() | |
192 { | |
193 GDir *dir; | |
194 const gchar *file; | |
195 gchar *path; | |
196 struct smiley_theme *smile; | |
197 int l; | |
198 | |
199 char* probedirs[3]; | |
200 probedirs[0] = g_build_filename(DATADIR, "pixmaps", "gaim", "smileys", NULL); | |
201 probedirs[1] = g_build_filename(gaim_user_dir(), "smileys", NULL); | |
202 probedirs[2] = 0; | |
203 for (l=0; probedirs[l]; l++) { | |
204 dir = g_dir_open(probedirs[l], 0, NULL); | |
205 if (dir) { | |
206 while ((file = g_dir_read_name(dir))) { | |
4301 | 207 path = g_build_filename(probedirs[l], file, "theme", NULL); |
4263 | 208 |
209 /* Here we check to see that the theme has proper syntax. | |
210 * We set the second argument to FALSE so that it doesn't load | |
211 * the theme yet. | |
212 */ | |
4298 | 213 if ((smile = load_smiley_theme(path, FALSE))) { |
4263 | 214 smiley_themes = g_slist_append(smiley_themes, smile); |
215 } | |
216 g_free(path); | |
217 } | |
218 g_dir_close(dir); | |
219 } | |
220 g_free(probedirs[l]); | |
221 } | |
222 | |
223 | |
224 | |
225 } |