Mercurial > pidgin
annotate src/themes.c @ 9460:eae7e049d639
[gaim-migrate @ 10285]
" This patch completely eliminates the use of the old
numeric prpl identifiers.
I've noticed that some plugins (both in gaim's cvs and
external) continue to use the constants even though
they are essentially no longer valid - code that relies
on them being unique will fail - the new built-in prpls
(SILC and novell) ,and any recent external prpls don't
have numeric values.
The once side effect that the removal causes is that
the code for importing of the old .gaimrc and *.blist
files is a little more kludgy (using magic numbers
instead of the old constants). IMHO this isn't a big
deal as the code will go away eventually anyway.
**This patch also fixes the raw plugin so that i
compiles once again.
**Someone should make sure that the gaim-remote and raw
plugins still work. (If the raw doesn't work, it may be
unrelated as it hasn't been updated since the latest
significant MSN changes - i just made a minor change to
make it compile)" --Daniel Atallah
(13:44:44) Me: what think you of getting rid of prpl numbers?
(13:45:05) Sean: what do you mean?
(13:45:27) Me: right now they are listed as deprecated, but still used in a
few of our own plugins as well as in some 3rd party stuff
(13:45:32) Me: and the enum still exists in the core
(13:45:44) Me: and the newwer prpls such as novell don't use them
(13:45:59) Me: datallah has submitted a patch to get rid of them entirely
(13:46:31) Me: the only thing it would break would be the old blist import,
which he hacked into working with magic numbers, but which i tend to think
we could remove entirely anyway
(13:50:03) Sean: Let's get rid of them, then.
(13:50:10) Sean: and take out old .blist code too
(13:50:14) Me: cool
(13:52:37) Sean: we should get rid of .gaimrc code too, sometime.
(13:53:02) Sean: If anyone's seriously just now upgrading from 0.59.x, or
whatever, they deserve to lose their preferences.
(12:27:56) LSchiere: Paco-Paco: what do you think of getting rid of the
deprecated prpl numbers?
(12:28:14) Paco-Paco: LSchiere: I think it shouldh ave happened long ago
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Tue, 06 Jul 2004 18:06:43 +0000 |
parents | ed62fb44aa30 |
children | 4d05b6e9e9cd |
rev | line source |
---|---|
4263 | 1 /* |
2 * Themes for Gaim | |
3 * | |
8046 | 4 * Gaim is the legal property of its developers, whose names are too numerous |
5 * to list here. Please refer to the COPYRIGHT file distributed with this | |
6 * source distribution. | |
4263 | 7 * |
8 * This program is free software; you can redistribute it and/or modify | |
9 * it under the terms of the GNU General Public License as published by | |
10 * the Free Software Foundation; either version 2 of the License, or | |
11 * (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 * GNU General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program; if not, write to the Free Software | |
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 * | |
22 */ | |
6371
8f94cce8faa5
[gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
23 #include "gtkinternal.h" |
4263 | 24 |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5676
diff
changeset
|
25 #include "conversation.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5676
diff
changeset
|
26 #include "debug.h" |
4667 | 27 #include "prpl.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5676
diff
changeset
|
28 #include "util.h" |
4263 | 29 |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5676
diff
changeset
|
30 #include "gtkconv.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5676
diff
changeset
|
31 #include "gtkimhtml.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5676
diff
changeset
|
32 |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5676
diff
changeset
|
33 #include "ui.h" |
4321
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); |
6478
338147ea6896
[gaim-migrate @ 6991]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
135 child->sml = g_strndup(i+1, strchr(i, ']') - i - 1); |
4816 | 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) { |
5676
dae79aefac8d
[gaim-migrate @ 6094]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
196 GaimConversation *conv = cnv->data; |
4630 | 197 |
7736 | 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); |
7736 | 200 smiley_themeize(GAIM_GTK_CONVERSATION(conv)->entry); |
201 } | |
4338
6c1230d15958
[gaim-migrate @ 4602]
Christian Hammond <chipx86@chipx86.com>
parents:
4323
diff
changeset
|
202 } |
4288 | 203 } |
204 | |
4263 | 205 g_free(dirname); |
4989 | 206 fclose(f); |
4263 | 207 } |
208 | |
209 void smiley_theme_probe() | |
210 { | |
211 GDir *dir; | |
212 const gchar *file; | |
213 gchar *path; | |
214 int l; | |
215 | |
216 char* probedirs[3]; | |
217 probedirs[0] = g_build_filename(DATADIR, "pixmaps", "gaim", "smileys", NULL); | |
218 probedirs[1] = g_build_filename(gaim_user_dir(), "smileys", NULL); | |
219 probedirs[2] = 0; | |
220 for (l=0; probedirs[l]; l++) { | |
221 dir = g_dir_open(probedirs[l], 0, NULL); | |
222 if (dir) { | |
223 while ((file = g_dir_read_name(dir))) { | |
4301 | 224 path = g_build_filename(probedirs[l], file, "theme", NULL); |
4892 | 225 |
4263 | 226 /* Here we check to see that the theme has proper syntax. |
227 * We set the second argument to FALSE so that it doesn't load | |
228 * the theme yet. | |
229 */ | |
4892 | 230 load_smiley_theme(path, FALSE); |
4263 | 231 g_free(path); |
232 } | |
233 g_dir_close(dir); | |
4341 | 234 } else if (l == 1) { |
235 mkdir(probedirs[l], S_IRUSR | S_IWUSR | S_IXUSR); | |
4892 | 236 } |
4263 | 237 g_free(probedirs[l]); |
238 } | |
239 } | |
4667 | 240 |
7956 | 241 GSList *get_proto_smileys(const char *id) { |
242 GaimPlugin *proto = gaim_find_prpl(id); | |
4667 | 243 struct smiley_list *list, *def; |
244 | |
245 if(!current_smiley_theme) | |
246 return NULL; | |
247 | |
8892 | 248 if(!current_smiley_theme->list) |
249 return NULL; | |
250 | |
4667 | 251 def = list = current_smiley_theme->list; |
252 | |
253 while(list) { | |
254 if(!strcmp(list->sml, "default")) | |
255 def = list; | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4989
diff
changeset
|
256 else if(proto && !strcmp(proto->info->name, list->sml)) |
4667 | 257 break; |
258 | |
259 list = list->next; | |
260 } | |
261 | |
262 return list ? list->smileys : def->smileys; | |
263 } |