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