4 * Copyright (C) 2003, Sean Egan <bj91704@binghamton.edu>
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.
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.
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
24 #include "gtkimhtml.h"
38 struct smiley_list
*next
;
41 GSList
*smiley_themes
= NULL
;
42 struct smiley_theme
*current_smiley_theme
;
44 void smiley_themeize(GtkWidget
*imhtml
)
46 struct smiley_list
*list
;
47 if (!current_smiley_theme
)
50 gtk_imhtml_remove_smileys(GTK_IMHTML(imhtml
));
51 list
= current_smiley_theme
->list
;
53 char *sml
= !strcmp(list
->sml
, "default") ? NULL
: list
->sml
;
54 GSList
*icons
= list
->smileys
;
56 gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml
), sml
, icons
->data
);
63 void load_smiley_theme(const char *file
, gboolean load
)
65 FILE *f
= fopen(file
, "r");
68 struct smiley_theme
*theme
=NULL
;
69 struct smiley_list
*list
= NULL
;
70 GSList
*lst
= smiley_themes
;
77 struct smiley_theme
*thm
= lst
->data
;
78 if (!strcmp(thm
->path
, file
)) {
86 theme
= g_new0(struct smiley_theme
, 1);
87 theme
->path
= g_strdup(file
);
88 smiley_themes
= g_slist_append(smiley_themes
, theme
);
91 dirname
= g_path_get_dirname(file
);
93 if (current_smiley_theme
) {
94 GSList
*already_freed
= NULL
;
95 struct smiley_list
*wer
= current_smiley_theme
->list
, *wer2
;
97 while (wer
->smileys
) {
98 GtkIMHtmlSmiley
*uio
= wer
->smileys
->data
;
100 g_object_unref(uio
->icon
);
101 if (!g_slist_find(already_freed
, uio
->file
)) {
103 already_freed
= g_slist_append(already_freed
, uio
->file
);
107 wer
->smileys
=g_slist_remove(wer
->smileys
, uio
);
114 current_smiley_theme
->list
= NULL
;
115 g_slist_free(already_freed
);
117 current_smiley_theme
= theme
;
122 if (!fgets(buf
, sizeof(buf
), f
)) {
126 if (buf
[0] == '#' || buf
[0] == '\0')
133 if (*i
== '[' && strchr(i
, ']') && load
) {
134 struct smiley_list
*child
= g_new0(struct smiley_list
, 1);
135 child
->sml
= g_strndup(i
+1, (int)strchr(i
, ']') - (int)i
- 1);
141 } else if (!g_ascii_strncasecmp(i
, "Name=", strlen("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="))) {
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="))) {
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="))) {
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
;
165 if (*i
== '!' && *(i
+ 1) == ' ') {
176 sfile
= g_build_filename(dirname
, l
, NULL
);
178 GtkIMHtmlSmiley
*smiley
= g_new0(GtkIMHtmlSmiley
, 1);
180 smiley
->file
= sfile
;
181 smiley
->smile
= g_strdup(l
);
182 smiley
->hidden
= hidden
;
183 list
->smileys
= g_slist_append(list
->smileys
, smiley
);
195 for (cnv
= gaim_get_conversations(); cnv
!= NULL
; cnv
= cnv
->next
) {
196 struct gaim_conversation
*conv
= cnv
->data
;
198 if (GAIM_IS_GTK_CONVERSATION(conv
))
199 smiley_themeize(GAIM_GTK_CONVERSATION(conv
)->imhtml
);
206 void smiley_theme_probe()
214 probedirs
[0] = g_build_filename(DATADIR
, "pixmaps", "gaim", "smileys", NULL
);
215 probedirs
[1] = g_build_filename(gaim_user_dir(), "smileys", NULL
);
217 for (l
=0; probedirs
[l
]; l
++) {
218 dir
= g_dir_open(probedirs
[l
], 0, NULL
);
220 while ((file
= g_dir_read_name(dir
))) {
221 path
= g_build_filename(probedirs
[l
], file
, "theme", NULL
);
223 /* Here we check to see that the theme has proper syntax.
224 * We set the second argument to FALSE so that it doesn't load
227 load_smiley_theme(path
, FALSE
);
232 mkdir(probedirs
[l
], S_IRUSR
| S_IWUSR
| S_IXUSR
);
234 g_free(probedirs
[l
]);
238 GSList
*get_proto_smileys(int protocol
) {
239 struct prpl
*proto
= find_prpl(protocol
);
240 struct smiley_list
*list
, *def
;
242 if(!current_smiley_theme
)
245 def
= list
= current_smiley_theme
->list
;
248 if(!strcmp(list
->sml
, "default"))
250 else if(proto
&& !strcmp(proto
->name
, list
->sml
))
256 return list
? list
->smileys
: def
->smileys
;