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
|
|
30 struct smiley_list {
|
|
31 char *sml;
|
|
32 GSList *smileys;
|
|
33 struct smiley_list *next;
|
|
34 };
|
|
35
|
|
36 GSList *smiley_themes;
|
4288
|
37 struct smiley_theme *current_smiley_theme;
|
4263
|
38
|
|
39 void smiley_themeize(GtkWidget *imhtml)
|
|
40 {
|
|
41 struct smiley_list *list;
|
|
42 if (!current_smiley_theme)
|
|
43 return;
|
|
44
|
|
45 gtk_imhtml_remove_smileys(GTK_IMHTML(imhtml));
|
|
46 list = current_smiley_theme->list;
|
|
47 while (list) {
|
|
48 char *sml = !strcmp(list->sml, "default") ? NULL : list->sml;
|
|
49 GSList *icons = list->smileys;
|
|
50 while (icons) {
|
|
51 gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), sml, icons->data);
|
|
52 icons = icons->next;
|
|
53 }
|
|
54 list = list->next;
|
|
55 }
|
|
56 }
|
|
57
|
4298
|
58 struct smiley_theme *load_smiley_theme(const char *file, gboolean load)
|
4263
|
59 {
|
|
60 FILE *f = fopen(file, "r");
|
|
61 char buf[256];
|
|
62 char *i;
|
|
63 struct smiley_theme *theme=NULL;
|
|
64 struct smiley_list *list = NULL;
|
|
65 GSList *lst = smiley_themes;
|
|
66 char *dirname;
|
|
67
|
|
68 while (lst) {
|
|
69 struct smiley_theme *thm = lst->data;
|
4288
|
70 if (!strcmp(thm->path, file)) {
|
4263
|
71 theme = thm;
|
|
72 break;
|
|
73 }
|
|
74 lst = lst->next;
|
|
75 }
|
|
76 if (!theme) {
|
|
77 theme = g_new0(struct smiley_theme, 1);
|
4288
|
78 theme->path = g_strdup(file);
|
4263
|
79 }
|
|
80 if (!f)
|
|
81 return NULL;
|
|
82
|
|
83 dirname = g_path_get_dirname(file);
|
|
84 if (load) {
|
|
85 if (current_smiley_theme) {
|
4288
|
86 GSList *already_freed = NULL;
|
4263
|
87 struct smiley_list *wer = current_smiley_theme->list;
|
|
88 while (wer) {
|
4288
|
89 GSList *already_freed = NULL;
|
|
90 while (wer->smileys) {
|
|
91 GtkIMHtmlSmiley *uio = wer->smileys->data;
|
4263
|
92 if (uio->icon)
|
|
93 g_object_unref(uio->icon);
|
4288
|
94 if (!g_slist_find(already_freed, uio->file)) {
|
|
95 g_free(uio->file);
|
|
96 already_freed = g_slist_append(already_freed, uio->file);
|
|
97 }
|
4263
|
98 g_free(uio->smile);
|
4288
|
99 g_free(uio);
|
|
100 wer->smileys=g_slist_remove(wer->smileys, uio);
|
4263
|
101 }
|
|
102 wer = wer->next;
|
|
103 }
|
4288
|
104 current_smiley_theme->list = NULL;
|
|
105 g_slist_free(already_freed);
|
4263
|
106 }
|
4288
|
107 current_smiley_theme = theme;
|
4263
|
108 }
|
|
109
|
|
110
|
|
111 while (!feof(f)) {
|
|
112 if (!fgets(buf, sizeof(buf), f)) {
|
4288
|
113 break;
|
4263
|
114 }
|
|
115
|
|
116 if (buf[0] == '#' || buf[0] == '\0')
|
|
117 continue;
|
|
118
|
|
119 i = buf;
|
|
120 while (isspace(*i))
|
|
121 i++;
|
|
122
|
|
123 if (*i == '[' && strchr(i, ']') && load) {
|
|
124 struct smiley_list *child = g_new0(struct smiley_list, 1);
|
|
125 child->sml = g_strndup(i+1, (int)strchr(i, ']') - (int)i - 1);
|
|
126 if (theme->list)
|
|
127 list->next = child;
|
|
128 else
|
|
129 theme->list = child;
|
|
130 list = child;
|
|
131 } else if (!g_strncasecmp(i, "Name=", strlen("Name="))) {
|
|
132 theme->name = g_strdup(i+ strlen("Name="));
|
4288
|
133 theme->name[strlen(theme->name)-1] = 0;
|
4263
|
134 } else if (!g_strncasecmp(i, "Description=", strlen("Description="))) {
|
|
135 theme->desc = g_strdup(i + strlen("Description="));
|
4288
|
136 theme->desc[strlen(theme->desc)-1] = 0;
|
4263
|
137 } else if (!g_strncasecmp(i, "Icon=", strlen("Icon="))) {
|
|
138 theme->icon = g_build_filename(dirname, i + strlen("Icon="), NULL);
|
4288
|
139 theme->icon[strlen(theme->icon)-1] = 0;
|
|
140 } else if (!g_strncasecmp(i, "Author=", strlen("Author="))) {
|
|
141 theme->author = g_strdup(i + strlen("Author="));
|
|
142 theme->author[strlen(theme->author)-1] = 0;
|
4263
|
143 } else if (load && list) {
|
|
144 gboolean hidden;
|
4288
|
145 char *sfile = NULL;
|
4263
|
146 GtkIMHtmlSmiley *smiley = g_new0(GtkIMHtmlSmiley, 1);
|
|
147
|
4266
|
148 if (*i == '!' && *(i + 1) == ' ') {
|
4263
|
149 hidden = TRUE;
|
|
150 i = i + 2;
|
|
151 }
|
|
152 while (*i) {
|
|
153 char l[64];
|
|
154 int li = 0;
|
|
155 while (!isspace(*i))
|
|
156 l[li++] = *(i++);
|
4288
|
157 if (!sfile) {
|
4263
|
158 l[li] = 0;
|
4288
|
159 sfile = g_build_filename(dirname, l, NULL);
|
4263
|
160 } else {
|
|
161 l[li] = 0;
|
|
162 smiley = g_new0(GtkIMHtmlSmiley, 1);
|
4288
|
163 smiley->file = sfile;
|
4263
|
164 smiley->smile = g_strdup(l);
|
|
165 list->smileys = g_slist_append(list->smileys, smiley);
|
|
166 }
|
4288
|
167 while (isspace(*i))
|
4263
|
168 i++;
|
4288
|
169
|
4263
|
170 }
|
|
171 }
|
|
172 }
|
4288
|
173
|
|
174 if (load) {
|
|
175 GList *cnv = conversations;
|
|
176 while (cnv) {
|
|
177 struct conversation *c = cnv->data;
|
|
178 smiley_themeize(c->text);
|
|
179 cnv=cnv->next;
|
|
180 }
|
|
181 }
|
|
182
|
4263
|
183 g_free(dirname);
|
|
184 return theme;
|
|
185 }
|
|
186
|
|
187 void smiley_theme_probe()
|
|
188 {
|
|
189 GDir *dir;
|
|
190 const gchar *file;
|
|
191 gchar *path;
|
|
192 struct smiley_theme *smile;
|
|
193 int l;
|
|
194
|
|
195 char* probedirs[3];
|
|
196 probedirs[0] = g_build_filename(DATADIR, "pixmaps", "gaim", "smileys", NULL);
|
|
197 probedirs[1] = g_build_filename(gaim_user_dir(), "smileys", NULL);
|
|
198 probedirs[2] = 0;
|
|
199 for (l=0; probedirs[l]; l++) {
|
|
200 dir = g_dir_open(probedirs[l], 0, NULL);
|
|
201 if (dir) {
|
|
202 while ((file = g_dir_read_name(dir))) {
|
|
203 path = g_build_filename(probedirs[0], file, "theme", NULL);
|
|
204
|
|
205 /* Here we check to see that the theme has proper syntax.
|
|
206 * We set the second argument to FALSE so that it doesn't load
|
|
207 * the theme yet.
|
|
208 */
|
4298
|
209 if ((smile = load_smiley_theme(path, FALSE))) {
|
4263
|
210 smiley_themes = g_slist_append(smiley_themes, smile);
|
|
211 }
|
|
212 g_free(path);
|
|
213 }
|
|
214 g_dir_close(dir);
|
|
215 }
|
|
216 g_free(probedirs[l]);
|
|
217 }
|
|
218
|
|
219
|
|
220
|
|
221 }
|