Mercurial > pidgin
annotate src/gtkthemes.c @ 11304:74e30ef571ce
[gaim-migrate @ 13504]
Wow, I need to get it together today. I can't write code.
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Thu, 18 Aug 2005 21:00:50 +0000 |
parents | 0f7452b1f777 |
children | b47708f46a38 |
rev | line source |
---|---|
10295 | 1 /* |
2 * Themes for Gaim | |
3 * | |
4 * Gaim is the legal property of its developers, whose names are too numerous | |
5 * to list here. Please refer to the COPYRIGHT file distributed with this | |
6 * source distribution. | |
7 * | |
8 * This program is free software; you can redistribute it and/or modify | |
9 * it under the terms of the GNU General Public License as published by | |
10 * the Free Software Foundation; either version 2 of the License, or | |
11 * (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 * GNU General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program; if not, write to the Free Software | |
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 * | |
22 */ | |
23 #include "internal.h" | |
24 #include "gtkgaim.h" | |
25 | |
26 #include "conversation.h" | |
27 #include "debug.h" | |
28 #include "prpl.h" | |
29 #include "util.h" | |
30 | |
31 #include "gtkconv.h" | |
32 #include "gtkdialogs.h" | |
33 #include "gtkimhtml.h" | |
34 | |
35 struct smiley_list { | |
36 char *sml; | |
37 GSList *smileys; | |
38 struct smiley_list *next; | |
39 }; | |
40 | |
41 GSList *smiley_themes = NULL; | |
42 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 gtk_imhtml_remove_smileys(GTK_IMHTML(imhtml)); | |
51 list = current_smiley_theme->list; | |
52 while (list) { | |
53 char *sml = !strcmp(list->sml, "default") ? NULL : list->sml; | |
54 GSList *icons = list->smileys; | |
55 while (icons) { | |
56 gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), sml, icons->data); | |
57 icons = icons->next; | |
58 } | |
59 list = list->next; | |
60 } | |
61 } | |
62 | |
63 void load_smiley_theme(const char *file, gboolean load) | |
64 { | |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10295
diff
changeset
|
65 FILE *f = g_fopen(file, "r"); |
10295 | 66 char buf[256]; |
67 char *i; | |
68 struct smiley_theme *theme=NULL; | |
69 struct smiley_list *list = NULL; | |
70 GSList *lst = smiley_themes; | |
71 char *dirname; | |
72 | |
73 if (!f) | |
74 return; | |
75 | |
76 while (lst) { | |
77 struct smiley_theme *thm = lst->data; | |
78 if (!strcmp(thm->path, file)) { | |
79 theme = thm; | |
80 break; | |
81 } | |
82 lst = lst->next; | |
83 } | |
84 | |
85 if (!theme) { | |
86 theme = g_new0(struct smiley_theme, 1); | |
87 theme->path = g_strdup(file); | |
88 smiley_themes = g_slist_append(smiley_themes, theme); | |
89 } | |
90 | |
91 dirname = g_path_get_dirname(file); | |
92 if (load) { | |
93 if (current_smiley_theme) { | |
94 GSList *already_freed = NULL; | |
95 struct smiley_list *wer = current_smiley_theme->list, *wer2; | |
96 while (wer) { | |
97 while (wer->smileys) { | |
98 GtkIMHtmlSmiley *uio = wer->smileys->data; | |
99 if (uio->icon) | |
100 g_object_unref(uio->icon); | |
101 if (!g_slist_find(already_freed, uio->file)) { | |
102 g_free(uio->file); | |
103 already_freed = g_slist_append(already_freed, uio->file); | |
104 } | |
105 g_free(uio->smile); | |
106 g_free(uio); | |
107 wer->smileys=g_slist_remove(wer->smileys, uio); | |
108 } | |
109 wer2 = wer->next; | |
110 g_free(wer->sml); | |
111 g_free(wer); | |
112 wer = wer2; | |
113 } | |
114 current_smiley_theme->list = NULL; | |
115 g_slist_free(already_freed); | |
116 } | |
117 current_smiley_theme = theme; | |
118 } | |
119 | |
120 | |
121 while (!feof(f)) { | |
122 if (!fgets(buf, sizeof(buf), f)) { | |
123 break; | |
124 } | |
125 | |
126 if (buf[0] == '#' || buf[0] == '\0') | |
127 continue; | |
128 | |
129 i = buf; | |
130 while (isspace(*i)) | |
131 i++; | |
132 | |
133 if (*i == '[' && strchr(i, ']') && load) { | |
134 struct smiley_list *child = g_new0(struct smiley_list, 1); | |
135 child->sml = g_strndup(i+1, strchr(i, ']') - i - 1); | |
136 if (theme->list) | |
137 list->next = child; | |
138 else | |
139 theme->list = child; | |
140 list = child; | |
141 } else if (!g_ascii_strncasecmp(i, "Name=", strlen("Name="))) { | |
142 if(theme->name) | |
143 g_free(theme->name); | |
144 theme->name = g_strdup(i+ strlen("Name=")); | |
145 theme->name[strlen(theme->name)-1] = 0; | |
146 } else if (!g_ascii_strncasecmp(i, "Description=", strlen("Description="))) { | |
147 if(theme->desc) | |
148 g_free(theme->desc); | |
149 theme->desc = g_strdup(i + strlen("Description=")); | |
150 theme->desc[strlen(theme->desc)-1] = 0; | |
151 } else if (!g_ascii_strncasecmp(i, "Icon=", strlen("Icon="))) { | |
152 if(theme->icon) | |
153 g_free(theme->icon); | |
154 theme->icon = g_build_filename(dirname, i + strlen("Icon="), NULL); | |
155 theme->icon[strlen(theme->icon)-1] = 0; | |
156 } else if (!g_ascii_strncasecmp(i, "Author=", strlen("Author="))) { | |
157 if(theme->author) | |
158 g_free(theme->author); | |
159 theme->author = g_strdup(i + strlen("Author=")); | |
160 theme->author[strlen(theme->author)-1] = 0; | |
161 } else if (load && list) { | |
162 gboolean hidden = FALSE; | |
163 char *sfile = NULL; | |
164 | |
165 if (*i == '!' && *(i + 1) == ' ') { | |
166 hidden = TRUE; | |
167 i = i + 2; | |
168 } | |
169 while (*i) { | |
170 char l[64]; | |
171 int li = 0; | |
172 while (!isspace(*i)) | |
173 l[li++] = *(i++); | |
174 if (!sfile) { | |
175 l[li] = 0; | |
176 sfile = g_build_filename(dirname, l, NULL); | |
177 } else { | |
178 GtkIMHtmlSmiley *smiley = g_new0(GtkIMHtmlSmiley, 1); | |
179 l[li] = 0; | |
180 smiley->file = sfile; | |
181 smiley->smile = g_strdup(l); | |
182 smiley->hidden = hidden; | |
183 list->smileys = g_slist_append(list->smileys, smiley); | |
184 } | |
185 while (isspace(*i)) | |
186 i++; | |
187 | |
188 } | |
189 } | |
190 } | |
191 | |
192 if (load) { | |
193 GList *cnv; | |
194 | |
195 for (cnv = gaim_get_conversations(); cnv != NULL; cnv = cnv->next) { | |
196 GaimConversation *conv = cnv->data; | |
197 | |
198 if (GAIM_IS_GTK_CONVERSATION(conv)) { | |
199 smiley_themeize(GAIM_GTK_CONVERSATION(conv)->imhtml); | |
200 smiley_themeize(GAIM_GTK_CONVERSATION(conv)->entry); | |
201 } | |
202 } | |
203 } | |
204 | |
205 g_free(dirname); | |
206 fclose(f); | |
207 } | |
208 | |
209 void smiley_theme_probe() | |
210 { | |
211 GDir *dir; | |
212 const gchar *file; | |
213 gchar *path; | |
214 int l; | |
215 | |
216 char* probedirs[3]; | |
217 probedirs[0] = g_build_filename(DATADIR, "pixmaps", "gaim", "smileys", NULL); | |
218 probedirs[1] = g_build_filename(gaim_user_dir(), "smileys", NULL); | |
219 probedirs[2] = 0; | |
220 for (l=0; probedirs[l]; l++) { | |
221 dir = g_dir_open(probedirs[l], 0, NULL); | |
222 if (dir) { | |
223 while ((file = g_dir_read_name(dir))) { | |
224 path = g_build_filename(probedirs[l], file, "theme", NULL); | |
225 | |
226 /* Here we check to see that the theme has proper syntax. | |
227 * We set the second argument to FALSE so that it doesn't load | |
228 * the theme yet. | |
229 */ | |
230 load_smiley_theme(path, FALSE); | |
231 g_free(path); | |
232 } | |
233 g_dir_close(dir); | |
234 } else if (l == 1) { | |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10295
diff
changeset
|
235 g_mkdir(probedirs[l], S_IRUSR | S_IWUSR | S_IXUSR); |
10295 | 236 } |
237 g_free(probedirs[l]); | |
238 } | |
239 } | |
240 | |
241 GSList *get_proto_smileys(const char *id) { | |
242 GaimPlugin *proto; | |
243 struct smiley_list *list, *def; | |
244 | |
245 if ((current_smiley_theme == NULL) || (current_smiley_theme->list == NULL)) | |
246 return NULL; | |
247 | |
248 def = list = current_smiley_theme->list; | |
249 | |
250 if (id == NULL) | |
251 return def->smileys; | |
252 | |
253 proto = gaim_find_prpl(id); | |
254 | |
255 while (list) { | |
256 if (!strcmp(list->sml, "default")) | |
257 def = list; | |
258 else if (proto && !strcmp(proto->info->name, list->sml)) | |
259 break; | |
260 | |
261 list = list->next; | |
262 } | |
263 | |
264 return list ? list->smileys : def->smileys; | |
265 } |