Wed, 30 May 2007 09:02:05 +0000
A somewhat-Warmenhoved patch from tfujiwara to allow for the smiley theme
description data to be translated. I haven't tested my last set of changes
to make sure you can actually still see a translated name, but he's going
to check it for me, I hope.
Closes #1342
| 10295 | 1 | /* |
| 15918 | 2 | * Themes for Pidgin |
| 10295 | 3 | * |
| 15918 | 4 | * Pidgin is the legal property of its developers, whose names are too numerous |
| 10295 | 5 | * to list here. Please refer to the COPYRIGHT file distributed with this |
| 6 | * source distribution. | |
|
11525
1d06283bdcc9
[gaim-migrate @ 13773]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
10589
diff
changeset
|
7 | * |
| 10295 | 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 | */ | |
| 23 | #include "internal.h" | |
| 15577 | 24 | #include "pidgin.h" |
| 10295 | 25 | |
| 26 | #include "conversation.h" | |
| 27 | #include "debug.h" | |
| 28 | #include "prpl.h" | |
| 29 | #include "util.h" | |
| 30 | ||
| 31 | #include "gtkconv.h" | |
| 32 | #include "gtkdialogs.h" | |
| 33 | #include "gtkimhtml.h" | |
|
11525
1d06283bdcc9
[gaim-migrate @ 13773]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
10589
diff
changeset
|
34 | #include "gtkthemes.h" |
| 10295 | 35 | |
| 36 | GSList *smiley_themes = NULL; | |
| 37 | struct smiley_theme *current_smiley_theme; | |
| 38 | ||
|
16263
27e0ef0f38e6
Word on the street is that we don't want things named pidginfoo_bar(), but
Richard Laager <rlaager@pidgin.im>
parents:
16212
diff
changeset
|
39 | gboolean pidgin_themes_smileys_disabled() |
|
11525
1d06283bdcc9
[gaim-migrate @ 13773]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
10589
diff
changeset
|
40 | { |
|
1d06283bdcc9
[gaim-migrate @ 13773]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
10589
diff
changeset
|
41 | if (!current_smiley_theme) |
|
1d06283bdcc9
[gaim-migrate @ 13773]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
10589
diff
changeset
|
42 | return 1; |
|
1d06283bdcc9
[gaim-migrate @ 13773]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
10589
diff
changeset
|
43 | |
|
1d06283bdcc9
[gaim-migrate @ 13773]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
10589
diff
changeset
|
44 | return strcmp(current_smiley_theme->name, "none") == 0; |
|
1d06283bdcc9
[gaim-migrate @ 13773]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
10589
diff
changeset
|
45 | } |
|
1d06283bdcc9
[gaim-migrate @ 13773]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
10589
diff
changeset
|
46 | |
|
16263
27e0ef0f38e6
Word on the street is that we don't want things named pidginfoo_bar(), but
Richard Laager <rlaager@pidgin.im>
parents:
16212
diff
changeset
|
47 | void pidgin_themes_smiley_themeize(GtkWidget *imhtml) |
| 10295 | 48 | { |
| 49 | struct smiley_list *list; | |
| 50 | if (!current_smiley_theme) | |
| 51 | return; | |
|
11525
1d06283bdcc9
[gaim-migrate @ 13773]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
10589
diff
changeset
|
52 | |
| 10295 | 53 | gtk_imhtml_remove_smileys(GTK_IMHTML(imhtml)); |
| 54 | list = current_smiley_theme->list; | |
| 55 | while (list) { | |
| 56 | char *sml = !strcmp(list->sml, "default") ? NULL : list->sml; | |
| 57 | GSList *icons = list->smileys; | |
| 58 | while (icons) { | |
| 59 | gtk_imhtml_associate_smiley(GTK_IMHTML(imhtml), sml, icons->data); | |
| 60 | icons = icons->next; | |
| 61 | } | |
| 62 | list = list->next; | |
| 63 | } | |
| 64 | } | |
| 65 | ||
|
16195
4e158cbe65cd
Pull out the same block of code from two places and put it into
Mark Doliner <markdoliner@pidgin.im>
parents:
16194
diff
changeset
|
66 | static void |
|
16263
27e0ef0f38e6
Word on the street is that we don't want things named pidginfoo_bar(), but
Richard Laager <rlaager@pidgin.im>
parents:
16212
diff
changeset
|
67 | pidgin_themes_destroy_smiley_theme(struct smiley_theme *theme) |
|
16195
4e158cbe65cd
Pull out the same block of code from two places and put it into
Mark Doliner <markdoliner@pidgin.im>
parents:
16194
diff
changeset
|
68 | { |
|
16211
670c6b68f7c5
Change a g_slist_append() to a g_slist_prepend() in one place, and
Mark Doliner <markdoliner@pidgin.im>
parents:
16195
diff
changeset
|
69 | GHashTable *already_freed; |
|
670c6b68f7c5
Change a g_slist_append() to a g_slist_prepend() in one place, and
Mark Doliner <markdoliner@pidgin.im>
parents:
16195
diff
changeset
|
70 | struct smiley_list *wer; |
|
16195
4e158cbe65cd
Pull out the same block of code from two places and put it into
Mark Doliner <markdoliner@pidgin.im>
parents:
16194
diff
changeset
|
71 | |
|
16211
670c6b68f7c5
Change a g_slist_append() to a g_slist_prepend() in one place, and
Mark Doliner <markdoliner@pidgin.im>
parents:
16195
diff
changeset
|
72 | already_freed = g_hash_table_new(g_direct_hash, g_direct_equal); |
|
670c6b68f7c5
Change a g_slist_append() to a g_slist_prepend() in one place, and
Mark Doliner <markdoliner@pidgin.im>
parents:
16195
diff
changeset
|
73 | for (wer = theme->list; wer != NULL; wer = theme->list) { |
|
16195
4e158cbe65cd
Pull out the same block of code from two places and put it into
Mark Doliner <markdoliner@pidgin.im>
parents:
16194
diff
changeset
|
74 | while (wer->smileys) { |
|
4e158cbe65cd
Pull out the same block of code from two places and put it into
Mark Doliner <markdoliner@pidgin.im>
parents:
16194
diff
changeset
|
75 | GtkIMHtmlSmiley *uio = wer->smileys->data; |
|
4e158cbe65cd
Pull out the same block of code from two places and put it into
Mark Doliner <markdoliner@pidgin.im>
parents:
16194
diff
changeset
|
76 | if (uio->icon) |
|
4e158cbe65cd
Pull out the same block of code from two places and put it into
Mark Doliner <markdoliner@pidgin.im>
parents:
16194
diff
changeset
|
77 | g_object_unref(uio->icon); |
|
16211
670c6b68f7c5
Change a g_slist_append() to a g_slist_prepend() in one place, and
Mark Doliner <markdoliner@pidgin.im>
parents:
16195
diff
changeset
|
78 | if (g_hash_table_lookup(already_freed, uio->file) == NULL) { |
|
16195
4e158cbe65cd
Pull out the same block of code from two places and put it into
Mark Doliner <markdoliner@pidgin.im>
parents:
16194
diff
changeset
|
79 | g_free(uio->file); |
|
16211
670c6b68f7c5
Change a g_slist_append() to a g_slist_prepend() in one place, and
Mark Doliner <markdoliner@pidgin.im>
parents:
16195
diff
changeset
|
80 | g_hash_table_insert(already_freed, uio->file, GINT_TO_POINTER(1)); |
|
16195
4e158cbe65cd
Pull out the same block of code from two places and put it into
Mark Doliner <markdoliner@pidgin.im>
parents:
16194
diff
changeset
|
81 | } |
|
4e158cbe65cd
Pull out the same block of code from two places and put it into
Mark Doliner <markdoliner@pidgin.im>
parents:
16194
diff
changeset
|
82 | g_free(uio->smile); |
|
4e158cbe65cd
Pull out the same block of code from two places and put it into
Mark Doliner <markdoliner@pidgin.im>
parents:
16194
diff
changeset
|
83 | g_free(uio); |
|
4e158cbe65cd
Pull out the same block of code from two places and put it into
Mark Doliner <markdoliner@pidgin.im>
parents:
16194
diff
changeset
|
84 | wer->smileys = g_slist_remove(wer->smileys, uio); |
|
4e158cbe65cd
Pull out the same block of code from two places and put it into
Mark Doliner <markdoliner@pidgin.im>
parents:
16194
diff
changeset
|
85 | } |
|
16211
670c6b68f7c5
Change a g_slist_append() to a g_slist_prepend() in one place, and
Mark Doliner <markdoliner@pidgin.im>
parents:
16195
diff
changeset
|
86 | theme->list = wer->next; |
|
16195
4e158cbe65cd
Pull out the same block of code from two places and put it into
Mark Doliner <markdoliner@pidgin.im>
parents:
16194
diff
changeset
|
87 | g_free(wer->sml); |
|
4e158cbe65cd
Pull out the same block of code from two places and put it into
Mark Doliner <markdoliner@pidgin.im>
parents:
16194
diff
changeset
|
88 | g_free(wer); |
|
4e158cbe65cd
Pull out the same block of code from two places and put it into
Mark Doliner <markdoliner@pidgin.im>
parents:
16194
diff
changeset
|
89 | } |
|
16211
670c6b68f7c5
Change a g_slist_append() to a g_slist_prepend() in one place, and
Mark Doliner <markdoliner@pidgin.im>
parents:
16195
diff
changeset
|
90 | theme->list = NULL; |
|
16195
4e158cbe65cd
Pull out the same block of code from two places and put it into
Mark Doliner <markdoliner@pidgin.im>
parents:
16194
diff
changeset
|
91 | |
|
16211
670c6b68f7c5
Change a g_slist_append() to a g_slist_prepend() in one place, and
Mark Doliner <markdoliner@pidgin.im>
parents:
16195
diff
changeset
|
92 | g_hash_table_destroy(already_freed); |
|
16195
4e158cbe65cd
Pull out the same block of code from two places and put it into
Mark Doliner <markdoliner@pidgin.im>
parents:
16194
diff
changeset
|
93 | } |
|
4e158cbe65cd
Pull out the same block of code from two places and put it into
Mark Doliner <markdoliner@pidgin.im>
parents:
16194
diff
changeset
|
94 | |
|
16263
27e0ef0f38e6
Word on the street is that we don't want things named pidginfoo_bar(), but
Richard Laager <rlaager@pidgin.im>
parents:
16212
diff
changeset
|
95 | void pidgin_themes_load_smiley_theme(const char *file, gboolean load) |
| 10295 | 96 | { |
|
10589
4e10236e06d4
[gaim-migrate @ 11994]
Daniel Atallah <datallah@pidgin.im>
parents:
10295
diff
changeset
|
97 | FILE *f = g_fopen(file, "r"); |
| 10295 | 98 | char buf[256]; |
| 99 | char *i; | |
| 100 | struct smiley_theme *theme=NULL; | |
| 101 | struct smiley_list *list = NULL; | |
| 102 | GSList *lst = smiley_themes; | |
| 103 | char *dirname; | |
|
13587
fb0245a7ccab
[gaim-migrate @ 15971]
Daniel Atallah <datallah@pidgin.im>
parents:
13134
diff
changeset
|
104 | gboolean new_theme = FALSE; |
| 10295 | 105 | |
| 106 | if (!f) | |
| 107 | return; | |
| 108 | ||
| 109 | while (lst) { | |
| 110 | struct smiley_theme *thm = lst->data; | |
| 111 | if (!strcmp(thm->path, file)) { | |
| 112 | theme = thm; | |
| 113 | break; | |
| 114 | } | |
| 115 | lst = lst->next; | |
| 116 | } | |
| 117 | ||
| 118 | if (!theme) { | |
|
13587
fb0245a7ccab
[gaim-migrate @ 15971]
Daniel Atallah <datallah@pidgin.im>
parents:
13134
diff
changeset
|
119 | new_theme = TRUE; |
| 10295 | 120 | theme = g_new0(struct smiley_theme, 1); |
| 121 | theme->path = g_strdup(file); | |
|
13587
fb0245a7ccab
[gaim-migrate @ 15971]
Daniel Atallah <datallah@pidgin.im>
parents:
13134
diff
changeset
|
122 | } else if (theme == current_smiley_theme) { |
|
fb0245a7ccab
[gaim-migrate @ 15971]
Daniel Atallah <datallah@pidgin.im>
parents:
13134
diff
changeset
|
123 | /* Don't reload the theme if it is already loaded */ |
|
fb0245a7ccab
[gaim-migrate @ 15971]
Daniel Atallah <datallah@pidgin.im>
parents:
13134
diff
changeset
|
124 | fclose(f); |
|
fb0245a7ccab
[gaim-migrate @ 15971]
Daniel Atallah <datallah@pidgin.im>
parents:
13134
diff
changeset
|
125 | return; |
| 10295 | 126 | } |
| 127 | ||
| 128 | dirname = g_path_get_dirname(file); | |
| 129 | ||
| 130 | while (!feof(f)) { | |
| 131 | if (!fgets(buf, sizeof(buf), f)) { | |
| 132 | break; | |
| 133 | } | |
| 134 | ||
| 135 | if (buf[0] == '#' || buf[0] == '\0') | |
| 136 | continue; | |
| 137 | ||
| 138 | i = buf; | |
| 139 | while (isspace(*i)) | |
| 140 | i++; | |
| 141 | ||
| 142 | if (*i == '[' && strchr(i, ']') && load) { | |
| 143 | struct smiley_list *child = g_new0(struct smiley_list, 1); | |
| 144 | child->sml = g_strndup(i+1, strchr(i, ']') - i - 1); | |
| 145 | if (theme->list) | |
| 146 | list->next = child; | |
| 147 | else | |
| 148 | theme->list = child; | |
| 149 | list = child; | |
| 150 | } else if (!g_ascii_strncasecmp(i, "Name=", strlen("Name="))) { | |
| 15338 | 151 | int len; |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
13625
diff
changeset
|
152 | g_free(theme->name); |
|
17474
a7f61acc10f6
A somewhat-Warmenhoved patch from tfujiwara to allow for the smiley theme
Richard Laager <rlaager@pidgin.im>
parents:
16458
diff
changeset
|
153 | theme->name = g_strdup(i + strlen("Name=")); |
| 15338 | 154 | len = strlen(theme->name); |
| 155 | theme->name[len-1] = 0; | |
| 156 | if(len > 2 && theme->name[len-2] == '\r') | |
| 157 | theme->name[len-2] = 0; | |
| 10295 | 158 | } else if (!g_ascii_strncasecmp(i, "Description=", strlen("Description="))) { |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
13625
diff
changeset
|
159 | g_free(theme->desc); |
| 10295 | 160 | theme->desc = g_strdup(i + strlen("Description=")); |
| 161 | theme->desc[strlen(theme->desc)-1] = 0; | |
| 162 | } else if (!g_ascii_strncasecmp(i, "Icon=", strlen("Icon="))) { | |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
13625
diff
changeset
|
163 | g_free(theme->icon); |
| 10295 | 164 | theme->icon = g_build_filename(dirname, i + strlen("Icon="), NULL); |
| 165 | theme->icon[strlen(theme->icon)-1] = 0; | |
| 166 | } else if (!g_ascii_strncasecmp(i, "Author=", strlen("Author="))) { | |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
13625
diff
changeset
|
167 | g_free(theme->author); |
| 10295 | 168 | theme->author = g_strdup(i + strlen("Author=")); |
| 169 | theme->author[strlen(theme->author)-1] = 0; | |
| 170 | } else if (load && list) { | |
| 171 | gboolean hidden = FALSE; | |
| 172 | char *sfile = NULL; | |
|
16194
ca4861bb467f
Fix a memory leak that occurs when a smiley theme lists a filename,
Mark Doliner <markdoliner@pidgin.im>
parents:
16123
diff
changeset
|
173 | gboolean have_used_sfile = FALSE; |
| 10295 | 174 | |
| 175 | if (*i == '!' && *(i + 1) == ' ') { | |
| 176 | hidden = TRUE; | |
| 177 | i = i + 2; | |
| 178 | } | |
| 179 | while (*i) { | |
| 180 | char l[64]; | |
| 181 | int li = 0; | |
|
13134
e5898f2191a4
[gaim-migrate @ 15495]
Christophe Chapuis <tofe2tofe@users.sourceforge.net>
parents:
12915
diff
changeset
|
182 | while (!isspace(*i) && li < sizeof(l) - 1) { |
|
e5898f2191a4
[gaim-migrate @ 15495]
Christophe Chapuis <tofe2tofe@users.sourceforge.net>
parents:
12915
diff
changeset
|
183 | if (*i == '\\' && *(i+1) != '\0' && *(i+1) != '\n' && *(i+1) != '\r') |
|
12915
d3efd3201aec
[gaim-migrate @ 15268]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11557
diff
changeset
|
184 | i++; |
| 10295 | 185 | l[li++] = *(i++); |
|
12915
d3efd3201aec
[gaim-migrate @ 15268]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11557
diff
changeset
|
186 | } |
| 10295 | 187 | if (!sfile) { |
| 188 | l[li] = 0; | |
| 189 | sfile = g_build_filename(dirname, l, NULL); | |
| 190 | } else { | |
| 191 | GtkIMHtmlSmiley *smiley = g_new0(GtkIMHtmlSmiley, 1); | |
| 192 | l[li] = 0; | |
| 193 | smiley->file = sfile; | |
| 194 | smiley->smile = g_strdup(l); | |
| 195 | smiley->hidden = hidden; | |
|
16211
670c6b68f7c5
Change a g_slist_append() to a g_slist_prepend() in one place, and
Mark Doliner <markdoliner@pidgin.im>
parents:
16195
diff
changeset
|
196 | list->smileys = g_slist_prepend(list->smileys, smiley); |
|
16194
ca4861bb467f
Fix a memory leak that occurs when a smiley theme lists a filename,
Mark Doliner <markdoliner@pidgin.im>
parents:
16123
diff
changeset
|
197 | have_used_sfile = TRUE; |
| 10295 | 198 | } |
| 199 | while (isspace(*i)) | |
| 200 | i++; | |
| 201 | ||
| 202 | } | |
|
16458
e0e45bccd8e2
Fix #273 (Emoticons appearing in reverse order).
Daniel Atallah <datallah@pidgin.im>
parents:
16263
diff
changeset
|
203 | |
|
e0e45bccd8e2
Fix #273 (Emoticons appearing in reverse order).
Daniel Atallah <datallah@pidgin.im>
parents:
16263
diff
changeset
|
204 | /* Reverse the Smiley list since it was built in reverse order for efficiency reasons */ |
|
e0e45bccd8e2
Fix #273 (Emoticons appearing in reverse order).
Daniel Atallah <datallah@pidgin.im>
parents:
16263
diff
changeset
|
205 | list->smileys = g_slist_reverse(list->smileys); |
|
e0e45bccd8e2
Fix #273 (Emoticons appearing in reverse order).
Daniel Atallah <datallah@pidgin.im>
parents:
16263
diff
changeset
|
206 | |
|
16194
ca4861bb467f
Fix a memory leak that occurs when a smiley theme lists a filename,
Mark Doliner <markdoliner@pidgin.im>
parents:
16123
diff
changeset
|
207 | if (!have_used_sfile) |
|
ca4861bb467f
Fix a memory leak that occurs when a smiley theme lists a filename,
Mark Doliner <markdoliner@pidgin.im>
parents:
16123
diff
changeset
|
208 | g_free(sfile); |
| 10295 | 209 | } |
| 210 | } | |
| 211 | ||
|
13587
fb0245a7ccab
[gaim-migrate @ 15971]
Daniel Atallah <datallah@pidgin.im>
parents:
13134
diff
changeset
|
212 | g_free(dirname); |
|
fb0245a7ccab
[gaim-migrate @ 15971]
Daniel Atallah <datallah@pidgin.im>
parents:
13134
diff
changeset
|
213 | fclose(f); |
|
fb0245a7ccab
[gaim-migrate @ 15971]
Daniel Atallah <datallah@pidgin.im>
parents:
13134
diff
changeset
|
214 | |
|
fb0245a7ccab
[gaim-migrate @ 15971]
Daniel Atallah <datallah@pidgin.im>
parents:
13134
diff
changeset
|
215 | if (!theme->name || !theme->desc || !theme->author) { |
| 15884 | 216 | purple_debug_error("gtkthemes", "Invalid file format, not loading smiley theme from '%s'\n", file); |
|
13587
fb0245a7ccab
[gaim-migrate @ 15971]
Daniel Atallah <datallah@pidgin.im>
parents:
13134
diff
changeset
|
217 | |
|
16263
27e0ef0f38e6
Word on the street is that we don't want things named pidginfoo_bar(), but
Richard Laager <rlaager@pidgin.im>
parents:
16212
diff
changeset
|
218 | pidgin_themes_destroy_smiley_theme(theme); |
|
13587
fb0245a7ccab
[gaim-migrate @ 15971]
Daniel Atallah <datallah@pidgin.im>
parents:
13134
diff
changeset
|
219 | |
|
13625
4768bf7afce2
[gaim-migrate @ 16011]
Daniel Atallah <datallah@pidgin.im>
parents:
13587
diff
changeset
|
220 | g_free(theme->name); |
|
4768bf7afce2
[gaim-migrate @ 16011]
Daniel Atallah <datallah@pidgin.im>
parents:
13587
diff
changeset
|
221 | g_free(theme->desc); |
|
4768bf7afce2
[gaim-migrate @ 16011]
Daniel Atallah <datallah@pidgin.im>
parents:
13587
diff
changeset
|
222 | g_free(theme->author); |
|
4768bf7afce2
[gaim-migrate @ 16011]
Daniel Atallah <datallah@pidgin.im>
parents:
13587
diff
changeset
|
223 | g_free(theme->icon); |
|
13587
fb0245a7ccab
[gaim-migrate @ 15971]
Daniel Atallah <datallah@pidgin.im>
parents:
13134
diff
changeset
|
224 | g_free(theme->path); |
|
fb0245a7ccab
[gaim-migrate @ 15971]
Daniel Atallah <datallah@pidgin.im>
parents:
13134
diff
changeset
|
225 | g_free(theme); |
|
fb0245a7ccab
[gaim-migrate @ 15971]
Daniel Atallah <datallah@pidgin.im>
parents:
13134
diff
changeset
|
226 | |
|
fb0245a7ccab
[gaim-migrate @ 15971]
Daniel Atallah <datallah@pidgin.im>
parents:
13134
diff
changeset
|
227 | return; |
|
fb0245a7ccab
[gaim-migrate @ 15971]
Daniel Atallah <datallah@pidgin.im>
parents:
13134
diff
changeset
|
228 | } |
|
fb0245a7ccab
[gaim-migrate @ 15971]
Daniel Atallah <datallah@pidgin.im>
parents:
13134
diff
changeset
|
229 | |
|
fb0245a7ccab
[gaim-migrate @ 15971]
Daniel Atallah <datallah@pidgin.im>
parents:
13134
diff
changeset
|
230 | if (new_theme) { |
|
16212
50ef047fed38
Change another 'append' to 'prepend', since the ordering doesn't matter
Mark Doliner <markdoliner@pidgin.im>
parents:
16211
diff
changeset
|
231 | smiley_themes = g_slist_prepend(smiley_themes, theme); |
|
13587
fb0245a7ccab
[gaim-migrate @ 15971]
Daniel Atallah <datallah@pidgin.im>
parents:
13134
diff
changeset
|
232 | } |
|
fb0245a7ccab
[gaim-migrate @ 15971]
Daniel Atallah <datallah@pidgin.im>
parents:
13134
diff
changeset
|
233 | |
| 10295 | 234 | if (load) { |
| 235 | GList *cnv; | |
| 236 | ||
|
16195
4e158cbe65cd
Pull out the same block of code from two places and put it into
Mark Doliner <markdoliner@pidgin.im>
parents:
16194
diff
changeset
|
237 | if (current_smiley_theme) |
|
16263
27e0ef0f38e6
Word on the street is that we don't want things named pidginfoo_bar(), but
Richard Laager <rlaager@pidgin.im>
parents:
16212
diff
changeset
|
238 | pidgin_themes_destroy_smiley_theme(current_smiley_theme); |
|
13587
fb0245a7ccab
[gaim-migrate @ 15971]
Daniel Atallah <datallah@pidgin.im>
parents:
13134
diff
changeset
|
239 | current_smiley_theme = theme; |
|
fb0245a7ccab
[gaim-migrate @ 15971]
Daniel Atallah <datallah@pidgin.im>
parents:
13134
diff
changeset
|
240 | |
| 15884 | 241 | for (cnv = purple_get_conversations(); cnv != NULL; cnv = cnv->next) { |
| 242 | PurpleConversation *conv = cnv->data; | |
| 10295 | 243 | |
|
15692
ecda27df58b9
Some more pidgininfication
Daniel Atallah <datallah@pidgin.im>
parents:
15577
diff
changeset
|
244 | if (PIDGIN_IS_PIDGIN_CONVERSATION(conv)) { |
|
16263
27e0ef0f38e6
Word on the street is that we don't want things named pidginfoo_bar(), but
Richard Laager <rlaager@pidgin.im>
parents:
16212
diff
changeset
|
245 | pidgin_themes_smiley_themeize(PIDGIN_CONVERSATION(conv)->imhtml); |
|
27e0ef0f38e6
Word on the street is that we don't want things named pidginfoo_bar(), but
Richard Laager <rlaager@pidgin.im>
parents:
16212
diff
changeset
|
246 | pidgin_themes_smiley_themeize(PIDGIN_CONVERSATION(conv)->entry); |
| 10295 | 247 | } |
| 248 | } | |
| 249 | } | |
| 250 | } | |
| 251 | ||
|
16263
27e0ef0f38e6
Word on the street is that we don't want things named pidginfoo_bar(), but
Richard Laager <rlaager@pidgin.im>
parents:
16212
diff
changeset
|
252 | void pidgin_themes_smiley_theme_probe() |
| 10295 | 253 | { |
| 254 | GDir *dir; | |
| 255 | const gchar *file; | |
| 256 | gchar *path; | |
| 257 | int l; | |
| 258 | ||
| 259 | char* probedirs[3]; | |
| 15918 | 260 | probedirs[0] = g_build_filename(DATADIR, "pixmaps", "pidgin", "emotes", NULL); |
| 15884 | 261 | probedirs[1] = g_build_filename(purple_user_dir(), "smileys", NULL); |
| 10295 | 262 | probedirs[2] = 0; |
| 263 | for (l=0; probedirs[l]; l++) { | |
| 264 | dir = g_dir_open(probedirs[l], 0, NULL); | |
| 265 | if (dir) { | |
| 266 | while ((file = g_dir_read_name(dir))) { | |
| 267 | path = g_build_filename(probedirs[l], file, "theme", NULL); | |
| 268 | ||
| 269 | /* Here we check to see that the theme has proper syntax. | |
| 270 | * We set the second argument to FALSE so that it doesn't load | |
| 271 | * the theme yet. | |
| 272 | */ | |
|
16263
27e0ef0f38e6
Word on the street is that we don't want things named pidginfoo_bar(), but
Richard Laager <rlaager@pidgin.im>
parents:
16212
diff
changeset
|
273 | pidgin_themes_load_smiley_theme(path, FALSE); |
| 10295 | 274 | g_free(path); |
| 275 | } | |
| 276 | g_dir_close(dir); | |
| 277 | } else if (l == 1) { | |
|
10589
4e10236e06d4
[gaim-migrate @ 11994]
Daniel Atallah <datallah@pidgin.im>
parents:
10295
diff
changeset
|
278 | g_mkdir(probedirs[l], S_IRUSR | S_IWUSR | S_IXUSR); |
| 10295 | 279 | } |
| 280 | g_free(probedirs[l]); | |
| 281 | } | |
| 282 | } | |
| 283 | ||
|
16263
27e0ef0f38e6
Word on the street is that we don't want things named pidginfoo_bar(), but
Richard Laager <rlaager@pidgin.im>
parents:
16212
diff
changeset
|
284 | GSList *pidgin_themes_get_proto_smileys(const char *id) { |
| 15884 | 285 | PurplePlugin *proto; |
| 10295 | 286 | struct smiley_list *list, *def; |
| 287 | ||
| 288 | if ((current_smiley_theme == NULL) || (current_smiley_theme->list == NULL)) | |
| 289 | return NULL; | |
| 290 | ||
| 291 | def = list = current_smiley_theme->list; | |
| 292 | ||
| 293 | if (id == NULL) | |
| 294 | return def->smileys; | |
| 295 | ||
| 15884 | 296 | proto = purple_find_prpl(id); |
| 10295 | 297 | |
| 298 | while (list) { | |
| 299 | if (!strcmp(list->sml, "default")) | |
| 300 | def = list; | |
| 301 | else if (proto && !strcmp(proto->info->name, list->sml)) | |
| 302 | break; | |
| 303 | ||
| 304 | list = list->next; | |
| 305 | } | |
| 306 | ||
| 307 | return list ? list->smileys : def->smileys; | |
| 308 | } | |
|
11525
1d06283bdcc9
[gaim-migrate @ 13773]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
10589
diff
changeset
|
309 | |
|
16263
27e0ef0f38e6
Word on the street is that we don't want things named pidginfoo_bar(), but
Richard Laager <rlaager@pidgin.im>
parents:
16212
diff
changeset
|
310 | void pidgin_themes_init() |
|
11525
1d06283bdcc9
[gaim-migrate @ 13773]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
10589
diff
changeset
|
311 | { |
|
11557
7a20e7fb7915
[gaim-migrate @ 13819]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
312 | GSList *l; |
|
7a20e7fb7915
[gaim-migrate @ 13819]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
313 | const char *current_theme = |
|
16123
8b98683319e7
Rename /purple/gtk preferences back to /gaim/gtk to allow for smooth upgrades
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15918
diff
changeset
|
314 | purple_prefs_get_string(PIDGIN_PREFS_ROOT "/smileys/theme"); |
|
11557
7a20e7fb7915
[gaim-migrate @ 13819]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
315 | |
|
16263
27e0ef0f38e6
Word on the street is that we don't want things named pidginfoo_bar(), but
Richard Laager <rlaager@pidgin.im>
parents:
16212
diff
changeset
|
316 | pidgin_themes_smiley_theme_probe(); |
|
11557
7a20e7fb7915
[gaim-migrate @ 13819]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
317 | |
|
7a20e7fb7915
[gaim-migrate @ 13819]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
318 | for (l = smiley_themes; l; l = l->next) { |
|
7a20e7fb7915
[gaim-migrate @ 13819]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
319 | struct smiley_theme *smile = l->data; |
|
7a20e7fb7915
[gaim-migrate @ 13819]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
320 | if (smile->name && strcmp(current_theme, smile->name) == 0) { |
|
16263
27e0ef0f38e6
Word on the street is that we don't want things named pidginfoo_bar(), but
Richard Laager <rlaager@pidgin.im>
parents:
16212
diff
changeset
|
321 | pidgin_themes_load_smiley_theme(smile->path, TRUE); |
|
11557
7a20e7fb7915
[gaim-migrate @ 13819]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
322 | break; |
|
11525
1d06283bdcc9
[gaim-migrate @ 13773]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
10589
diff
changeset
|
323 | } |
|
1d06283bdcc9
[gaim-migrate @ 13773]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
10589
diff
changeset
|
324 | } |
|
11557
7a20e7fb7915
[gaim-migrate @ 13819]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
325 | |
|
7a20e7fb7915
[gaim-migrate @ 13819]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
326 | /* If we still don't have a smiley theme, choose the first one */ |
|
7a20e7fb7915
[gaim-migrate @ 13819]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
327 | if (!current_smiley_theme && smiley_themes) { |
|
7a20e7fb7915
[gaim-migrate @ 13819]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
328 | struct smiley_theme *smile = smiley_themes->data; |
|
16263
27e0ef0f38e6
Word on the street is that we don't want things named pidginfoo_bar(), but
Richard Laager <rlaager@pidgin.im>
parents:
16212
diff
changeset
|
329 | pidgin_themes_load_smiley_theme(smile->path, TRUE); |
|
11557
7a20e7fb7915
[gaim-migrate @ 13819]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
330 | } |
|
7a20e7fb7915
[gaim-migrate @ 13819]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
331 | |
|
11525
1d06283bdcc9
[gaim-migrate @ 13773]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
10589
diff
changeset
|
332 | } |