Mercurial > pidgin
annotate src/themes.c @ 5162:b8eafeb874a1
[gaim-migrate @ 5526]
After my last commit, Nathan promptly asked me if I remembered to move
the declarations for gaim_new_item and gaim_new_item_stock from one .h
file to the next, and I promptly cracked on his mom.
Robot101, or anyone else cool, if you want to fix the comments in
gtkutils.h for these 2 functions, that'd be terrif.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Fri, 18 Apr 2003 03:40:54 +0000 |
parents | 0f8189301213 |
children | fefad67de2c7 |
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" |
4667 | 25 #include "prpl.h" |
4263 | 26 #include <stdio.h> |
4298 | 27 #include <string.h> |
28 #include <ctype.h> | |
4341 | 29 #include <sys/stat.h> |
4263 | 30 |
4321
1cfad48b7d93
[gaim-migrate @ 4576]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4301
diff
changeset
|
31 #ifdef _WIN32 |
1cfad48b7d93
[gaim-migrate @ 4576]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4301
diff
changeset
|
32 #include "win32dep.h" |
1cfad48b7d93
[gaim-migrate @ 4576]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4301
diff
changeset
|
33 #endif |
1cfad48b7d93
[gaim-migrate @ 4576]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4301
diff
changeset
|
34 |
4263 | 35 struct smiley_list { |
36 char *sml; | |
37 GSList *smileys; | |
38 struct smiley_list *next; | |
39 }; | |
40 | |
4892 | 41 GSList *smiley_themes = NULL; |
4288 | 42 struct smiley_theme *current_smiley_theme; |
4263 | 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 | |
4892 | 63 void load_smiley_theme(const char *file, gboolean load) |
4263 | 64 { |
65 FILE *f = fopen(file, "r"); | |
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; | |
4892 | 72 |
73 if (!f) | |
74 return; | |
4630 | 75 |
4263 | 76 while (lst) { |
77 struct smiley_theme *thm = lst->data; | |
4288 | 78 if (!strcmp(thm->path, file)) { |
4263 | 79 theme = thm; |
80 break; | |
81 } | |
82 lst = lst->next; | |
83 } | |
4630 | 84 |
4263 | 85 if (!theme) { |
86 theme = g_new0(struct smiley_theme, 1); | |
4288 | 87 theme->path = g_strdup(file); |
4892 | 88 smiley_themes = g_slist_append(smiley_themes, theme); |
4263 | 89 } |
4630 | 90 |
4263 | 91 dirname = g_path_get_dirname(file); |
92 if (load) { | |
93 if (current_smiley_theme) { | |
4288 | 94 GSList *already_freed = NULL; |
4892 | 95 struct smiley_list *wer = current_smiley_theme->list, *wer2; |
4263 | 96 while (wer) { |
4288 | 97 while (wer->smileys) { |
98 GtkIMHtmlSmiley *uio = wer->smileys->data; | |
4263 | 99 if (uio->icon) |
100 g_object_unref(uio->icon); | |
4288 | 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 } | |
4263 | 105 g_free(uio->smile); |
4288 | 106 g_free(uio); |
107 wer->smileys=g_slist_remove(wer->smileys, uio); | |
4263 | 108 } |
4892 | 109 wer2 = wer->next; |
110 g_free(wer->sml); | |
111 g_free(wer); | |
112 wer = wer2; | |
4263 | 113 } |
4288 | 114 current_smiley_theme->list = NULL; |
115 g_slist_free(already_freed); | |
4263 | 116 } |
4288 | 117 current_smiley_theme = theme; |
4263 | 118 } |
4816 | 119 |
120 | |
4263 | 121 while (!feof(f)) { |
122 if (!fgets(buf, sizeof(buf), f)) { | |
4288 | 123 break; |
4263 | 124 } |
4630 | 125 |
126 if (buf[0] == '#' || buf[0] == '\0') | |
4263 | 127 continue; |
4630 | 128 |
4263 | 129 i = buf; |
130 while (isspace(*i)) | |
131 i++; | |
4630 | 132 |
4816 | 133 if (*i == '[' && strchr(i, ']') && load) { |
4263 | 134 struct smiley_list *child = g_new0(struct smiley_list, 1); |
4816 | 135 child->sml = g_strndup(i+1, (int)strchr(i, ']') - (int)i - 1); |
136 if (theme->list) | |
4263 | 137 list->next = child; |
138 else | |
139 theme->list = child; | |
140 list = child; | |
4816 | 141 } else if (!g_ascii_strncasecmp(i, "Name=", strlen("Name="))) { |
4892 | 142 if(theme->name) |
143 g_free(theme->name); | |
4816 | 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="))) { | |
4892 | 147 if(theme->desc) |
148 g_free(theme->desc); | |
4816 | 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="))) { | |
4892 | 152 if(theme->icon) |
153 g_free(theme->icon); | |
4816 | 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="))) { | |
4892 | 157 if(theme->author) |
158 g_free(theme->author); | |
4816 | 159 theme->author = g_strdup(i + strlen("Author=")); |
160 theme->author[strlen(theme->author)-1] = 0; | |
161 } else if (load && list) { | |
4667 | 162 gboolean hidden = FALSE; |
4288 | 163 char *sfile = NULL; |
4630 | 164 |
4266 | 165 if (*i == '!' && *(i + 1) == ' ') { |
4263 | 166 hidden = TRUE; |
167 i = i + 2; | |
168 } | |
169 while (*i) { | |
170 char l[64]; | |
171 int li = 0; | |
4630 | 172 while (!isspace(*i)) |
4263 | 173 l[li++] = *(i++); |
4288 | 174 if (!sfile) { |
4263 | 175 l[li] = 0; |
4288 | 176 sfile = g_build_filename(dirname, l, NULL); |
4263 | 177 } else { |
4632 | 178 GtkIMHtmlSmiley *smiley = g_new0(GtkIMHtmlSmiley, 1); |
4263 | 179 l[li] = 0; |
4288 | 180 smiley->file = sfile; |
4263 | 181 smiley->smile = g_strdup(l); |
4667 | 182 smiley->hidden = hidden; |
4263 | 183 list->smileys = g_slist_append(list->smileys, smiley); |
184 } | |
4630 | 185 while (isspace(*i)) |
4263 | 186 i++; |
4630 | 187 |
4263 | 188 } |
189 } | |
190 } | |
4288 | 191 |
192 if (load) { | |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4341
diff
changeset
|
193 GList *cnv; |
4630 | 194 |
4375
90eaa3486949
[gaim-migrate @ 4641]
Christian Hammond <chipx86@chipx86.com>
parents:
4359
diff
changeset
|
195 for (cnv = gaim_get_conversations(); cnv != NULL; cnv = cnv->next) { |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4341
diff
changeset
|
196 struct gaim_conversation *conv = cnv->data; |
4630 | 197 |
4398
a8249a5250b6
[gaim-migrate @ 4667]
Christian Hammond <chipx86@chipx86.com>
parents:
4375
diff
changeset
|
198 if (GAIM_IS_GTK_CONVERSATION(conv)) |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4341
diff
changeset
|
199 smiley_themeize(GAIM_GTK_CONVERSATION(conv)->imhtml); |
4338
6c1230d15958
[gaim-migrate @ 4602]
Christian Hammond <chipx86@chipx86.com>
parents:
4323
diff
changeset
|
200 } |
4288 | 201 } |
202 | |
4263 | 203 g_free(dirname); |
4989 | 204 fclose(f); |
4263 | 205 } |
206 | |
207 void smiley_theme_probe() | |
208 { | |
209 GDir *dir; | |
210 const gchar *file; | |
211 gchar *path; | |
212 int l; | |
213 | |
214 char* probedirs[3]; | |
215 probedirs[0] = g_build_filename(DATADIR, "pixmaps", "gaim", "smileys", NULL); | |
216 probedirs[1] = g_build_filename(gaim_user_dir(), "smileys", NULL); | |
217 probedirs[2] = 0; | |
218 for (l=0; probedirs[l]; l++) { | |
219 dir = g_dir_open(probedirs[l], 0, NULL); | |
220 if (dir) { | |
221 while ((file = g_dir_read_name(dir))) { | |
4301 | 222 path = g_build_filename(probedirs[l], file, "theme", NULL); |
4892 | 223 |
4263 | 224 /* Here we check to see that the theme has proper syntax. |
225 * We set the second argument to FALSE so that it doesn't load | |
226 * the theme yet. | |
227 */ | |
4892 | 228 load_smiley_theme(path, FALSE); |
4263 | 229 g_free(path); |
230 } | |
231 g_dir_close(dir); | |
4341 | 232 } else if (l == 1) { |
233 mkdir(probedirs[l], S_IRUSR | S_IWUSR | S_IXUSR); | |
4892 | 234 } |
4263 | 235 g_free(probedirs[l]); |
236 } | |
237 } | |
4667 | 238 |
239 GSList *get_proto_smileys(int protocol) { | |
240 struct prpl *proto = find_prpl(protocol); | |
241 struct smiley_list *list, *def; | |
242 | |
243 if(!current_smiley_theme) | |
244 return NULL; | |
245 | |
246 def = list = current_smiley_theme->list; | |
247 | |
248 while(list) { | |
249 if(!strcmp(list->sml, "default")) | |
250 def = list; | |
251 else if(proto && !strcmp(proto->name, list->sml)) | |
252 break; | |
253 | |
254 list = list->next; | |
255 } | |
256 | |
257 return list ? list->smileys : def->smileys; | |
258 } |