annotate src/gtkthemes.c @ 11231:64e2c65ef650

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