Thu, 28 Jun 2007 18:52:26 +0000
If the action-windows are already there, then bring them to front when
requested.
| 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; | |
|
17534
609ab183a700
Reverse the smiley list only after reading the whole list of smileys in.
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17474
diff
changeset
|
149 | /* Reverse the Smiley list since it was built in reverse order for efficiency reasons */ |
|
609ab183a700
Reverse the smiley list only after reading the whole list of smileys in.
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17474
diff
changeset
|
150 | if (list != NULL) |
|
609ab183a700
Reverse the smiley list only after reading the whole list of smileys in.
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17474
diff
changeset
|
151 | list->smileys = g_slist_reverse(list->smileys); |
| 10295 | 152 | list = child; |
| 153 | } else if (!g_ascii_strncasecmp(i, "Name=", strlen("Name="))) { | |
| 15338 | 154 | int len; |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
13625
diff
changeset
|
155 | 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
|
156 | theme->name = g_strdup(i + strlen("Name=")); |
| 15338 | 157 | len = strlen(theme->name); |
| 158 | theme->name[len-1] = 0; | |
| 159 | if(len > 2 && theme->name[len-2] == '\r') | |
| 160 | theme->name[len-2] = 0; | |
| 10295 | 161 | } else if (!g_ascii_strncasecmp(i, "Description=", strlen("Description="))) { |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
13625
diff
changeset
|
162 | g_free(theme->desc); |
| 10295 | 163 | theme->desc = g_strdup(i + strlen("Description=")); |
| 164 | theme->desc[strlen(theme->desc)-1] = 0; | |
| 165 | } else if (!g_ascii_strncasecmp(i, "Icon=", strlen("Icon="))) { | |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
13625
diff
changeset
|
166 | g_free(theme->icon); |
| 10295 | 167 | theme->icon = g_build_filename(dirname, i + strlen("Icon="), NULL); |
| 168 | theme->icon[strlen(theme->icon)-1] = 0; | |
| 169 | } else if (!g_ascii_strncasecmp(i, "Author=", strlen("Author="))) { | |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
13625
diff
changeset
|
170 | g_free(theme->author); |
| 10295 | 171 | theme->author = g_strdup(i + strlen("Author=")); |
| 172 | theme->author[strlen(theme->author)-1] = 0; | |
| 173 | } else if (load && list) { | |
| 174 | gboolean hidden = FALSE; | |
| 175 | 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
|
176 | gboolean have_used_sfile = FALSE; |
| 10295 | 177 | |
| 178 | if (*i == '!' && *(i + 1) == ' ') { | |
| 179 | hidden = TRUE; | |
| 180 | i = i + 2; | |
| 181 | } | |
| 182 | while (*i) { | |
| 183 | char l[64]; | |
| 184 | int li = 0; | |
|
13134
e5898f2191a4
[gaim-migrate @ 15495]
Christophe Chapuis <tofe2tofe@users.sourceforge.net>
parents:
12915
diff
changeset
|
185 | while (!isspace(*i) && li < sizeof(l) - 1) { |
|
e5898f2191a4
[gaim-migrate @ 15495]
Christophe Chapuis <tofe2tofe@users.sourceforge.net>
parents:
12915
diff
changeset
|
186 | 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
|
187 | i++; |
| 10295 | 188 | l[li++] = *(i++); |
|
12915
d3efd3201aec
[gaim-migrate @ 15268]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11557
diff
changeset
|
189 | } |
| 10295 | 190 | if (!sfile) { |
| 191 | l[li] = 0; | |
| 192 | sfile = g_build_filename(dirname, l, NULL); | |
| 193 | } else { | |
| 194 | GtkIMHtmlSmiley *smiley = g_new0(GtkIMHtmlSmiley, 1); | |
| 195 | l[li] = 0; | |
| 196 | smiley->file = sfile; | |
| 197 | smiley->smile = g_strdup(l); | |
| 198 | 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
|
199 | 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
|
200 | have_used_sfile = TRUE; |
| 10295 | 201 | } |
| 202 | while (isspace(*i)) | |
| 203 | i++; | |
| 204 | ||
| 205 | } | |
|
16458
e0e45bccd8e2
Fix #273 (Emoticons appearing in reverse order).
Daniel Atallah <datallah@pidgin.im>
parents:
16263
diff
changeset
|
206 | |
|
e0e45bccd8e2
Fix #273 (Emoticons appearing in reverse order).
Daniel Atallah <datallah@pidgin.im>
parents:
16263
diff
changeset
|
207 | |
|
16194
ca4861bb467f
Fix a memory leak that occurs when a smiley theme lists a filename,
Mark Doliner <markdoliner@pidgin.im>
parents:
16123
diff
changeset
|
208 | 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
|
209 | g_free(sfile); |
| 10295 | 210 | } |
| 211 | } | |
| 212 | ||
|
17535
5f2b75cc8b92
We also need to reverse the last protocol's smiley list instead of only
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17534
diff
changeset
|
213 | /* Reverse the Smiley list since it was built in reverse order for efficiency reasons */ |
|
5f2b75cc8b92
We also need to reverse the last protocol's smiley list instead of only
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17534
diff
changeset
|
214 | if (list != NULL) |
|
5f2b75cc8b92
We also need to reverse the last protocol's smiley list instead of only
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17534
diff
changeset
|
215 | list->smileys = g_slist_reverse(list->smileys); |
|
5f2b75cc8b92
We also need to reverse the last protocol's smiley list instead of only
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17534
diff
changeset
|
216 | |
|
13587
fb0245a7ccab
[gaim-migrate @ 15971]
Daniel Atallah <datallah@pidgin.im>
parents:
13134
diff
changeset
|
217 | g_free(dirname); |
|
fb0245a7ccab
[gaim-migrate @ 15971]
Daniel Atallah <datallah@pidgin.im>
parents:
13134
diff
changeset
|
218 | fclose(f); |
|
fb0245a7ccab
[gaim-migrate @ 15971]
Daniel Atallah <datallah@pidgin.im>
parents:
13134
diff
changeset
|
219 | |
|
fb0245a7ccab
[gaim-migrate @ 15971]
Daniel Atallah <datallah@pidgin.im>
parents:
13134
diff
changeset
|
220 | if (!theme->name || !theme->desc || !theme->author) { |
| 15884 | 221 | 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
|
222 | |
|
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
|
223 | pidgin_themes_destroy_smiley_theme(theme); |
|
13587
fb0245a7ccab
[gaim-migrate @ 15971]
Daniel Atallah <datallah@pidgin.im>
parents:
13134
diff
changeset
|
224 | |
|
13625
4768bf7afce2
[gaim-migrate @ 16011]
Daniel Atallah <datallah@pidgin.im>
parents:
13587
diff
changeset
|
225 | g_free(theme->name); |
|
4768bf7afce2
[gaim-migrate @ 16011]
Daniel Atallah <datallah@pidgin.im>
parents:
13587
diff
changeset
|
226 | g_free(theme->desc); |
|
4768bf7afce2
[gaim-migrate @ 16011]
Daniel Atallah <datallah@pidgin.im>
parents:
13587
diff
changeset
|
227 | g_free(theme->author); |
|
4768bf7afce2
[gaim-migrate @ 16011]
Daniel Atallah <datallah@pidgin.im>
parents:
13587
diff
changeset
|
228 | g_free(theme->icon); |
|
13587
fb0245a7ccab
[gaim-migrate @ 15971]
Daniel Atallah <datallah@pidgin.im>
parents:
13134
diff
changeset
|
229 | g_free(theme->path); |
|
fb0245a7ccab
[gaim-migrate @ 15971]
Daniel Atallah <datallah@pidgin.im>
parents:
13134
diff
changeset
|
230 | g_free(theme); |
|
fb0245a7ccab
[gaim-migrate @ 15971]
Daniel Atallah <datallah@pidgin.im>
parents:
13134
diff
changeset
|
231 | |
|
fb0245a7ccab
[gaim-migrate @ 15971]
Daniel Atallah <datallah@pidgin.im>
parents:
13134
diff
changeset
|
232 | return; |
|
fb0245a7ccab
[gaim-migrate @ 15971]
Daniel Atallah <datallah@pidgin.im>
parents:
13134
diff
changeset
|
233 | } |
|
fb0245a7ccab
[gaim-migrate @ 15971]
Daniel Atallah <datallah@pidgin.im>
parents:
13134
diff
changeset
|
234 | |
|
fb0245a7ccab
[gaim-migrate @ 15971]
Daniel Atallah <datallah@pidgin.im>
parents:
13134
diff
changeset
|
235 | 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
|
236 | smiley_themes = g_slist_prepend(smiley_themes, theme); |
|
13587
fb0245a7ccab
[gaim-migrate @ 15971]
Daniel Atallah <datallah@pidgin.im>
parents:
13134
diff
changeset
|
237 | } |
|
fb0245a7ccab
[gaim-migrate @ 15971]
Daniel Atallah <datallah@pidgin.im>
parents:
13134
diff
changeset
|
238 | |
| 10295 | 239 | if (load) { |
|
18122
9bf9970c1b6a
disapproval of revision '2d8ea56b90971e7851442d96b7d74ecb4f052126'
Richard Laager <rlaager@pidgin.im>
parents:
18121
diff
changeset
|
240 | GList *cnv; |
| 10295 | 241 | |
|
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
|
242 | 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
|
243 | pidgin_themes_destroy_smiley_theme(current_smiley_theme); |
|
13587
fb0245a7ccab
[gaim-migrate @ 15971]
Daniel Atallah <datallah@pidgin.im>
parents:
13134
diff
changeset
|
244 | current_smiley_theme = theme; |
|
fb0245a7ccab
[gaim-migrate @ 15971]
Daniel Atallah <datallah@pidgin.im>
parents:
13134
diff
changeset
|
245 | |
| 15884 | 246 | for (cnv = purple_get_conversations(); cnv != NULL; cnv = cnv->next) { |
| 247 | PurpleConversation *conv = cnv->data; | |
| 10295 | 248 | |
|
15692
ecda27df58b9
Some more pidgininfication
Daniel Atallah <datallah@pidgin.im>
parents:
15577
diff
changeset
|
249 | 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
|
250 | 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
|
251 | pidgin_themes_smiley_themeize(PIDGIN_CONVERSATION(conv)->entry); |
| 10295 | 252 | } |
| 253 | } | |
| 254 | } | |
| 255 | } | |
| 256 | ||
|
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
|
257 | void pidgin_themes_smiley_theme_probe() |
| 10295 | 258 | { |
| 259 | GDir *dir; | |
| 260 | const gchar *file; | |
| 261 | gchar *path; | |
| 262 | int l; | |
| 263 | ||
| 264 | char* probedirs[3]; | |
| 15918 | 265 | probedirs[0] = g_build_filename(DATADIR, "pixmaps", "pidgin", "emotes", NULL); |
| 15884 | 266 | probedirs[1] = g_build_filename(purple_user_dir(), "smileys", NULL); |
| 10295 | 267 | probedirs[2] = 0; |
| 268 | for (l=0; probedirs[l]; l++) { | |
| 269 | dir = g_dir_open(probedirs[l], 0, NULL); | |
| 270 | if (dir) { | |
| 271 | while ((file = g_dir_read_name(dir))) { | |
| 272 | path = g_build_filename(probedirs[l], file, "theme", NULL); | |
| 273 | ||
| 274 | /* Here we check to see that the theme has proper syntax. | |
| 275 | * We set the second argument to FALSE so that it doesn't load | |
| 276 | * the theme yet. | |
| 277 | */ | |
|
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
|
278 | pidgin_themes_load_smiley_theme(path, FALSE); |
| 10295 | 279 | g_free(path); |
| 280 | } | |
| 281 | g_dir_close(dir); | |
| 282 | } else if (l == 1) { | |
|
10589
4e10236e06d4
[gaim-migrate @ 11994]
Daniel Atallah <datallah@pidgin.im>
parents:
10295
diff
changeset
|
283 | g_mkdir(probedirs[l], S_IRUSR | S_IWUSR | S_IXUSR); |
| 10295 | 284 | } |
| 285 | g_free(probedirs[l]); | |
| 286 | } | |
| 287 | } | |
| 288 | ||
|
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
|
289 | GSList *pidgin_themes_get_proto_smileys(const char *id) { |
| 15884 | 290 | PurplePlugin *proto; |
| 10295 | 291 | struct smiley_list *list, *def; |
| 292 | ||
| 293 | if ((current_smiley_theme == NULL) || (current_smiley_theme->list == NULL)) | |
| 294 | return NULL; | |
| 295 | ||
| 296 | def = list = current_smiley_theme->list; | |
| 297 | ||
| 298 | if (id == NULL) | |
| 299 | return def->smileys; | |
| 300 | ||
| 15884 | 301 | proto = purple_find_prpl(id); |
| 10295 | 302 | |
| 303 | while (list) { | |
| 304 | if (!strcmp(list->sml, "default")) | |
| 305 | def = list; | |
| 306 | else if (proto && !strcmp(proto->info->name, list->sml)) | |
| 307 | break; | |
| 308 | ||
| 309 | list = list->next; | |
| 310 | } | |
| 311 | ||
| 312 | return list ? list->smileys : def->smileys; | |
| 313 | } | |
|
11525
1d06283bdcc9
[gaim-migrate @ 13773]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
10589
diff
changeset
|
314 | |
|
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
|
315 | void pidgin_themes_init() |
|
11525
1d06283bdcc9
[gaim-migrate @ 13773]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
10589
diff
changeset
|
316 | { |
|
11557
7a20e7fb7915
[gaim-migrate @ 13819]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
317 | GSList *l; |
|
7a20e7fb7915
[gaim-migrate @ 13819]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
318 | 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
|
319 | purple_prefs_get_string(PIDGIN_PREFS_ROOT "/smileys/theme"); |
|
11557
7a20e7fb7915
[gaim-migrate @ 13819]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
320 | |
|
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_smiley_theme_probe(); |
|
11557
7a20e7fb7915
[gaim-migrate @ 13819]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
322 | |
|
7a20e7fb7915
[gaim-migrate @ 13819]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
323 | for (l = smiley_themes; l; l = l->next) { |
|
7a20e7fb7915
[gaim-migrate @ 13819]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
324 | struct smiley_theme *smile = l->data; |
|
7a20e7fb7915
[gaim-migrate @ 13819]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
325 | 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
|
326 | pidgin_themes_load_smiley_theme(smile->path, TRUE); |
|
11557
7a20e7fb7915
[gaim-migrate @ 13819]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
327 | break; |
|
11525
1d06283bdcc9
[gaim-migrate @ 13773]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
10589
diff
changeset
|
328 | } |
|
1d06283bdcc9
[gaim-migrate @ 13773]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
10589
diff
changeset
|
329 | } |
|
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 | /* 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
|
332 | if (!current_smiley_theme && smiley_themes) { |
|
7a20e7fb7915
[gaim-migrate @ 13819]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
333 | 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
|
334 | pidgin_themes_load_smiley_theme(smile->path, TRUE); |
|
11557
7a20e7fb7915
[gaim-migrate @ 13819]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
335 | } |
|
7a20e7fb7915
[gaim-migrate @ 13819]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
336 | |
|
11525
1d06283bdcc9
[gaim-migrate @ 13773]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
10589
diff
changeset
|
337 | } |