Mercurial > pidgin.yaz
annotate src/themes.c @ 4331:bbd7b12986a8
[gaim-migrate @ 4595]
Okay, a few new goodies in here!
HTTP redirect support! Sean wants to be able to drag-and-drop themes from
our new themes page, but they're hiding behind a script that redirects.
Rather than lose functionality in the script, I added redirects here. Works
like a charm.
Smarter memory reallocation! The buffer was being reallocated every byte.
That means 10,000,000 of data would cause 10,000,000 reallocations. Now
it starts off with a buffer of 4096 (for HTTP headers) or 8192 (for data)
and reads until it's full. When full, the buffer increases by half of the
previous size.
Content-Length support! The HTTP headers are scanned for a Content-Length
header. If found, it uses this for the buffer instead of 8192. This should
reduce the number of reallocations to 0.
Have fun draggening-and-droppening.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Sat, 18 Jan 2003 00:53:42 +0000 |
parents | 8a932c488afc |
children | 6c1230d15958 |
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; | |
4323 | 71 gboolean old=FALSE; |
4263 | 72 |
73 while (lst) { | |
74 struct smiley_theme *thm = lst->data; | |
4288 | 75 if (!strcmp(thm->path, file)) { |
4263 | 76 theme = thm; |
4323 | 77 old = TRUE; |
4263 | 78 break; |
79 } | |
80 lst = lst->next; | |
81 } | |
82 if (!theme) { | |
83 theme = g_new0(struct smiley_theme, 1); | |
4288 | 84 theme->path = g_strdup(file); |
4263 | 85 } |
86 if (!f) | |
87 return NULL; | |
88 | |
89 dirname = g_path_get_dirname(file); | |
90 if (load) { | |
91 if (current_smiley_theme) { | |
4288 | 92 GSList *already_freed = NULL; |
4263 | 93 struct smiley_list *wer = current_smiley_theme->list; |
94 while (wer) { | |
4288 | 95 GSList *already_freed = NULL; |
96 while (wer->smileys) { | |
97 GtkIMHtmlSmiley *uio = wer->smileys->data; | |
4263 | 98 if (uio->icon) |
99 g_object_unref(uio->icon); | |
4288 | 100 if (!g_slist_find(already_freed, uio->file)) { |
101 g_free(uio->file); | |
102 already_freed = g_slist_append(already_freed, uio->file); | |
103 } | |
4263 | 104 g_free(uio->smile); |
4288 | 105 g_free(uio); |
106 wer->smileys=g_slist_remove(wer->smileys, uio); | |
4263 | 107 } |
108 wer = wer->next; | |
109 } | |
4288 | 110 current_smiley_theme->list = NULL; |
111 g_slist_free(already_freed); | |
4263 | 112 } |
4288 | 113 current_smiley_theme = theme; |
4263 | 114 } |
115 | |
116 | |
117 while (!feof(f)) { | |
118 if (!fgets(buf, sizeof(buf), f)) { | |
4288 | 119 break; |
4263 | 120 } |
121 | |
122 if (buf[0] == '#' || buf[0] == '\0') | |
123 continue; | |
124 | |
125 i = buf; | |
126 while (isspace(*i)) | |
127 i++; | |
128 | |
129 if (*i == '[' && strchr(i, ']') && load) { | |
130 struct smiley_list *child = g_new0(struct smiley_list, 1); | |
131 child->sml = g_strndup(i+1, (int)strchr(i, ']') - (int)i - 1); | |
132 if (theme->list) | |
133 list->next = child; | |
134 else | |
135 theme->list = child; | |
136 list = child; | |
137 } else if (!g_strncasecmp(i, "Name=", strlen("Name="))) { | |
138 theme->name = g_strdup(i+ strlen("Name=")); | |
4288 | 139 theme->name[strlen(theme->name)-1] = 0; |
4263 | 140 } else if (!g_strncasecmp(i, "Description=", strlen("Description="))) { |
141 theme->desc = g_strdup(i + strlen("Description=")); | |
4288 | 142 theme->desc[strlen(theme->desc)-1] = 0; |
4263 | 143 } else if (!g_strncasecmp(i, "Icon=", strlen("Icon="))) { |
144 theme->icon = g_build_filename(dirname, i + strlen("Icon="), NULL); | |
4288 | 145 theme->icon[strlen(theme->icon)-1] = 0; |
146 } else if (!g_strncasecmp(i, "Author=", strlen("Author="))) { | |
147 theme->author = g_strdup(i + strlen("Author=")); | |
148 theme->author[strlen(theme->author)-1] = 0; | |
4263 | 149 } else if (load && list) { |
150 gboolean hidden; | |
4288 | 151 char *sfile = NULL; |
4263 | 152 GtkIMHtmlSmiley *smiley = g_new0(GtkIMHtmlSmiley, 1); |
153 | |
4266 | 154 if (*i == '!' && *(i + 1) == ' ') { |
4263 | 155 hidden = TRUE; |
156 i = i + 2; | |
157 } | |
158 while (*i) { | |
159 char l[64]; | |
160 int li = 0; | |
161 while (!isspace(*i)) | |
162 l[li++] = *(i++); | |
4288 | 163 if (!sfile) { |
4263 | 164 l[li] = 0; |
4288 | 165 sfile = g_build_filename(dirname, l, NULL); |
4263 | 166 } else { |
167 l[li] = 0; | |
168 smiley = g_new0(GtkIMHtmlSmiley, 1); | |
4288 | 169 smiley->file = sfile; |
4263 | 170 smiley->smile = g_strdup(l); |
171 list->smileys = g_slist_append(list->smileys, smiley); | |
172 } | |
4288 | 173 while (isspace(*i)) |
4263 | 174 i++; |
4288 | 175 |
4263 | 176 } |
177 } | |
178 } | |
4288 | 179 |
180 if (load) { | |
181 GList *cnv = conversations; | |
182 while (cnv) { | |
183 struct conversation *c = cnv->data; | |
184 smiley_themeize(c->text); | |
185 cnv=cnv->next; | |
186 } | |
187 } | |
188 | |
4263 | 189 g_free(dirname); |
4323 | 190 return old ? NULL : theme; |
4263 | 191 } |
192 | |
193 void smiley_theme_probe() | |
194 { | |
195 GDir *dir; | |
196 const gchar *file; | |
197 gchar *path; | |
198 struct smiley_theme *smile; | |
199 int l; | |
200 | |
201 char* probedirs[3]; | |
202 probedirs[0] = g_build_filename(DATADIR, "pixmaps", "gaim", "smileys", NULL); | |
203 probedirs[1] = g_build_filename(gaim_user_dir(), "smileys", NULL); | |
204 probedirs[2] = 0; | |
205 for (l=0; probedirs[l]; l++) { | |
206 dir = g_dir_open(probedirs[l], 0, NULL); | |
207 if (dir) { | |
208 while ((file = g_dir_read_name(dir))) { | |
4301 | 209 path = g_build_filename(probedirs[l], file, "theme", NULL); |
4263 | 210 |
211 /* Here we check to see that the theme has proper syntax. | |
212 * We set the second argument to FALSE so that it doesn't load | |
213 * the theme yet. | |
214 */ | |
4298 | 215 if ((smile = load_smiley_theme(path, FALSE))) { |
4263 | 216 smiley_themes = g_slist_append(smiley_themes, smile); |
217 } | |
218 g_free(path); | |
219 } | |
220 g_dir_close(dir); | |
221 } | |
222 g_free(probedirs[l]); | |
223 } | |
224 | |
225 | |
226 | |
227 } |