Mercurial > pidgin
comparison src/themes.c @ 4263:74f65a3d2a1f
[gaim-migrate @ 4514]
I wanted to get this into cvs before I went to bed. Now proto-specific
themes will work. The code's a bit crude at parts and it's not as fast
as I'd like, but I can work some more on it tomorrow. Just figured you'd
want to get a look at this.
8 penguin points to whoever finds out why gtk_smiley_tree_destroy (commented
out right now, causing leakage) segfaults on me now.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Thu, 09 Jan 2003 09:41:49 +0000 |
parents | |
children | 9ccb6c521cb2 |
comparison
equal
deleted
inserted
replaced
4262:7103653dd34e | 4263:74f65a3d2a1f |
---|---|
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 | |
22 #include "gtkimhtml.h" | |
23 #include <stdio.h> | |
24 | |
25 struct smiley_list { | |
26 char *sml; | |
27 GSList *smileys; | |
28 struct smiley_list *next; | |
29 }; | |
30 | |
31 struct smiley_theme { | |
32 char *path; | |
33 char *name; | |
34 char *desc; | |
35 char *icon; | |
36 char *author; | |
37 | |
38 struct smiley_list *list; | |
39 }; | |
40 | |
41 GSList *smiley_themes; | |
42 static struct smiley_theme *current_smiley_theme; | |
43 | |
44 void smiley_themeize(GtkWidget *imhtml) | |
45 { | |
46 struct smiley_list *list; | |
47 if (!current_smiley_theme) | |
48 return; | |
49 | |
50 | |
51 | |
52 gtk_imhtml_remove_smileys(GTK_IMHTML(imhtml)); | |
53 list = current_smiley_theme->list; | |
54 while (list) { | |
55 char *sml = !strcmp(list->sml, "default") ? NULL : list->sml; | |
56 GSList *icons = list->smileys; | |
57 while (icons) { | |
58 gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), sml, icons->data); | |
59 icons = icons->next; | |
60 } | |
61 list = list->next; | |
62 } | |
63 } | |
64 | |
65 struct smiley_theme *load_smiley_theme(char *file, gboolean load) | |
66 { | |
67 FILE *f = fopen(file, "r"); | |
68 char buf[256]; | |
69 char sml[16]; | |
70 char *i; | |
71 struct smiley_theme *theme=NULL; | |
72 struct smiley_list *list = NULL; | |
73 GSList *lst = smiley_themes; | |
74 char *dirname; | |
75 | |
76 while (lst) { | |
77 struct smiley_theme *thm = lst->data; | |
78 if (!g_strcasecmp(thm->path, file)) { | |
79 theme = thm; | |
80 break; | |
81 } | |
82 lst = lst->next; | |
83 } | |
84 if (!theme) { | |
85 theme = g_new0(struct smiley_theme, 1); | |
86 theme->path = file; | |
87 } | |
88 if (!f) | |
89 return NULL; | |
90 | |
91 dirname = g_path_get_dirname(file); | |
92 if (load) { | |
93 if (current_smiley_theme) { | |
94 struct smiley_list *wer = current_smiley_theme->list; | |
95 while (wer) { | |
96 char *nds = !strcmp(wer->sml, "default") ? NULL : wer->sml; | |
97 GSList *dfg = wer->smileys; | |
98 while (dfg) { | |
99 GtkIMHtmlSmiley *uio = dfg->data; | |
100 if (uio->icon) | |
101 g_object_unref(uio->icon); | |
102 g_free(uio->file); | |
103 g_free(uio->smile); | |
104 dfg = dfg->next; | |
105 } | |
106 wer = wer->next; | |
107 } | |
108 } | |
109 current_smiley_theme = theme; | |
110 } | |
111 | |
112 | |
113 while (!feof(f)) { | |
114 if (!fgets(buf, sizeof(buf), f)) { | |
115 g_free(dirname); | |
116 return NULL; | |
117 } | |
118 | |
119 if (buf[0] == '#' || buf[0] == '\0') | |
120 continue; | |
121 | |
122 i = buf; | |
123 while (isspace(*i)) | |
124 i++; | |
125 | |
126 if (*i == '[' && strchr(i, ']') && load) { | |
127 struct smiley_list *child = g_new0(struct smiley_list, 1); | |
128 child->sml = g_strndup(i+1, (int)strchr(i, ']') - (int)i - 1); | |
129 if (theme->list) | |
130 list->next = child; | |
131 else | |
132 theme->list = child; | |
133 list = child; | |
134 } else if (!g_strncasecmp(i, "Name=", strlen("Name="))) { | |
135 theme->name = g_strdup(i+ strlen("Name=")); | |
136 } else if (!g_strncasecmp(i, "Description=", strlen("Description="))) { | |
137 theme->desc = g_strdup(i + strlen("Description=")); | |
138 } else if (!g_strncasecmp(i, "Icon=", strlen("Icon="))) { | |
139 theme->icon = g_build_filename(dirname, i + strlen("Icon="), NULL); | |
140 } else if (!g_strncasecmp(i, "Author=", strlen("Author"))) { | |
141 theme->desc = g_strdup(i + strlen("Author")); | |
142 } else if (load && list) { | |
143 gboolean hidden; | |
144 char *file = NULL; | |
145 GtkIMHtmlSmiley *smiley = g_new0(GtkIMHtmlSmiley, 1); | |
146 | |
147 if (*i == '!' && *i + 1 == ' ') { | |
148 hidden = TRUE; | |
149 i = i + 2; | |
150 } | |
151 while (*i) { | |
152 char l[64]; | |
153 int li = 0; | |
154 while (!isspace(*i)) | |
155 l[li++] = *(i++); | |
156 if (!file) { | |
157 l[li] = 0; | |
158 file = g_build_filename(dirname, l, NULL); | |
159 } else { | |
160 l[li] = 0; | |
161 smiley = g_new0(GtkIMHtmlSmiley, 1); | |
162 smiley->file = file; | |
163 smiley->smile = g_strdup(l); | |
164 list->smileys = g_slist_append(list->smileys, smiley); | |
165 } | |
166 while (isspace(*i)) | |
167 i++; | |
168 } | |
169 } | |
170 } | |
171 g_free(dirname); | |
172 return theme; | |
173 } | |
174 | |
175 void smiley_theme_probe() | |
176 { | |
177 GDir *dir; | |
178 const gchar *file; | |
179 gchar *path; | |
180 struct smiley_theme *smile; | |
181 int l; | |
182 | |
183 char* probedirs[3]; | |
184 probedirs[0] = g_build_filename(DATADIR, "pixmaps", "gaim", "smileys", NULL); | |
185 probedirs[1] = g_build_filename(gaim_user_dir(), "smileys", NULL); | |
186 probedirs[2] = 0; | |
187 for (l=0; probedirs[l]; l++) { | |
188 dir = g_dir_open(probedirs[l], 0, NULL); | |
189 if (dir) { | |
190 while ((file = g_dir_read_name(dir))) { | |
191 path = g_build_filename(probedirs[0], file, "theme", NULL); | |
192 | |
193 /* Here we check to see that the theme has proper syntax. | |
194 * We set the second argument to FALSE so that it doesn't load | |
195 * the theme yet. | |
196 */ | |
197 if (smile = load_smiley_theme(path, TRUE)) { | |
198 smiley_themes = g_slist_append(smiley_themes, smile); | |
199 } | |
200 g_free(path); | |
201 } | |
202 g_dir_close(dir); | |
203 } | |
204 g_free(probedirs[l]); | |
205 } | |
206 | |
207 | |
208 | |
209 } |