Mercurial > pidgin.yaz
annotate src/buddyicon.c @ 9308:b3bda982996b
[gaim-migrate @ 10116]
Yikes.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Sat, 19 Jun 2004 04:57:43 +0000 |
parents | 0c201a2386c7 |
children | 59bca4e8678c |
rev | line source |
---|---|
6846 | 1 /** |
2 * @file icon.c Buddy Icon API | |
3 * @ingroup core | |
4 * | |
5 * gaim | |
6 * | |
8046 | 7 * Gaim is the legal property of its developers, whose names are too numerous |
8 * to list here. Please refer to the COPYRIGHT file distributed with this | |
9 * source distribution. | |
6846 | 10 * |
11 * This program is free software; you can redistribute it and/or modify | |
12 * it under the terms of the GNU General Public License as published by | |
13 * the Free Software Foundation; either version 2 of the License, or | |
14 * (at your option) any later version. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU General Public License | |
22 * along with this program; if not, write to the Free Software | |
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
24 */ | |
25 #include "internal.h" | |
26 #include "buddyicon.h" | |
27 #include "conversation.h" | |
6886
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
28 #include "debug.h" |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
29 #include "util.h" |
6846 | 30 |
31 static GHashTable *account_cache = NULL; | |
6886
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
32 static char *cache_dir = NULL; |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
33 static gboolean icon_caching = TRUE; |
6846 | 34 |
35 GaimBuddyIcon * | |
36 gaim_buddy_icon_new(GaimAccount *account, const char *username, | |
37 void *icon_data, size_t icon_len) | |
38 { | |
39 GaimBuddyIcon *icon; | |
40 | |
41 g_return_val_if_fail(account != NULL, NULL); | |
42 g_return_val_if_fail(username != NULL, NULL); | |
43 g_return_val_if_fail(icon_data != NULL, NULL); | |
44 g_return_val_if_fail(icon_len > 0, NULL); | |
45 | |
46 icon = gaim_buddy_icons_find(account, username); | |
47 | |
48 if (icon == NULL) | |
49 { | |
50 GHashTable *icon_cache; | |
51 | |
52 icon = g_new0(GaimBuddyIcon, 1); | |
53 | |
54 gaim_buddy_icon_set_account(icon, account); | |
55 gaim_buddy_icon_set_username(icon, username); | |
56 | |
57 icon_cache = g_hash_table_lookup(account_cache, account); | |
58 | |
59 if (icon_cache == NULL) | |
60 { | |
61 icon_cache = g_hash_table_new(g_str_hash, g_str_equal); | |
62 | |
63 g_hash_table_insert(account_cache, account, icon_cache); | |
64 } | |
65 | |
66 g_hash_table_insert(icon_cache, | |
67 (char *)gaim_buddy_icon_get_username(icon), icon); | |
68 } | |
69 | |
70 gaim_buddy_icon_set_data(icon, icon_data, icon_len); | |
71 | |
72 gaim_buddy_icon_ref(icon); | |
73 | |
74 return icon; | |
75 } | |
76 | |
77 void | |
78 gaim_buddy_icon_destroy(GaimBuddyIcon *icon) | |
79 { | |
7311
1c8830db0189
[gaim-migrate @ 7895]
Christian Hammond <chipx86@chipx86.com>
parents:
7125
diff
changeset
|
80 GaimConversation *conv; |
1c8830db0189
[gaim-migrate @ 7895]
Christian Hammond <chipx86@chipx86.com>
parents:
7125
diff
changeset
|
81 GaimAccount *account; |
6846 | 82 GHashTable *icon_cache; |
7311
1c8830db0189
[gaim-migrate @ 7895]
Christian Hammond <chipx86@chipx86.com>
parents:
7125
diff
changeset
|
83 const char *username; |
9305
0c201a2386c7
[gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents:
9285
diff
changeset
|
84 GSList *sl, *list; |
6846 | 85 |
86 g_return_if_fail(icon != NULL); | |
87 | |
88 if (icon->ref_count > 0) | |
89 { | |
90 gaim_buddy_icon_unref(icon); | |
91 | |
92 return; | |
93 } | |
94 | |
7311
1c8830db0189
[gaim-migrate @ 7895]
Christian Hammond <chipx86@chipx86.com>
parents:
7125
diff
changeset
|
95 account = gaim_buddy_icon_get_account(icon); |
1c8830db0189
[gaim-migrate @ 7895]
Christian Hammond <chipx86@chipx86.com>
parents:
7125
diff
changeset
|
96 username = gaim_buddy_icon_get_username(icon); |
1c8830db0189
[gaim-migrate @ 7895]
Christian Hammond <chipx86@chipx86.com>
parents:
7125
diff
changeset
|
97 |
1c8830db0189
[gaim-migrate @ 7895]
Christian Hammond <chipx86@chipx86.com>
parents:
7125
diff
changeset
|
98 conv = gaim_find_conversation_with_account(username, account); |
1c8830db0189
[gaim-migrate @ 7895]
Christian Hammond <chipx86@chipx86.com>
parents:
7125
diff
changeset
|
99 |
9305
0c201a2386c7
[gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents:
9285
diff
changeset
|
100 for (list = sl = gaim_find_buddies(account, username); sl != NULL; |
0c201a2386c7
[gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents:
9285
diff
changeset
|
101 sl = sl->next) |
0c201a2386c7
[gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents:
9285
diff
changeset
|
102 { |
0c201a2386c7
[gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents:
9285
diff
changeset
|
103 GaimBuddy *buddy = (GaimBuddy *)sl->data; |
0c201a2386c7
[gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents:
9285
diff
changeset
|
104 |
0c201a2386c7
[gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents:
9285
diff
changeset
|
105 gaim_buddy_set_icon(buddy, NULL); |
0c201a2386c7
[gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents:
9285
diff
changeset
|
106 } |
0c201a2386c7
[gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents:
9285
diff
changeset
|
107 |
0c201a2386c7
[gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents:
9285
diff
changeset
|
108 g_slist_free(list); |
0c201a2386c7
[gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents:
9285
diff
changeset
|
109 |
7311
1c8830db0189
[gaim-migrate @ 7895]
Christian Hammond <chipx86@chipx86.com>
parents:
7125
diff
changeset
|
110 if (conv != NULL && gaim_conversation_get_type(conv) == GAIM_CONV_IM) |
1c8830db0189
[gaim-migrate @ 7895]
Christian Hammond <chipx86@chipx86.com>
parents:
7125
diff
changeset
|
111 gaim_conv_im_set_icon(GAIM_CONV_IM(conv), NULL); |
1c8830db0189
[gaim-migrate @ 7895]
Christian Hammond <chipx86@chipx86.com>
parents:
7125
diff
changeset
|
112 |
6846 | 113 icon_cache = g_hash_table_lookup(account_cache, |
114 gaim_buddy_icon_get_account(icon)); | |
115 | |
116 if (icon_cache != NULL) | |
117 g_hash_table_remove(icon_cache, gaim_buddy_icon_get_username(icon)); | |
118 | |
119 if (icon->username != NULL) | |
120 g_free(icon->username); | |
121 | |
122 if (icon->data != NULL) | |
123 g_free(icon->data); | |
124 | |
125 g_free(icon); | |
126 } | |
127 | |
128 GaimBuddyIcon * | |
129 gaim_buddy_icon_ref(GaimBuddyIcon *icon) | |
130 { | |
131 g_return_val_if_fail(icon != NULL, NULL); | |
132 | |
133 icon->ref_count++; | |
134 | |
135 return icon; | |
136 } | |
137 | |
138 GaimBuddyIcon * | |
139 gaim_buddy_icon_unref(GaimBuddyIcon *icon) | |
140 { | |
141 g_return_val_if_fail(icon != NULL, NULL); | |
142 | |
143 if (icon->ref_count <= 0) | |
144 return NULL; | |
145 | |
146 icon->ref_count--; | |
147 | |
148 if (icon->ref_count == 0) | |
149 { | |
150 gaim_buddy_icon_destroy(icon); | |
151 | |
152 return NULL; | |
153 } | |
154 | |
155 return icon; | |
156 } | |
157 | |
158 void | |
159 gaim_buddy_icon_update(GaimBuddyIcon *icon) | |
160 { | |
161 GaimConversation *conv; | |
162 GaimAccount *account; | |
163 const char *username; | |
8550 | 164 GSList *sl, *list; |
6846 | 165 |
166 g_return_if_fail(icon != NULL); | |
167 | |
168 account = gaim_buddy_icon_get_account(icon); | |
169 username = gaim_buddy_icon_get_username(icon); | |
170 | |
9305
0c201a2386c7
[gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents:
9285
diff
changeset
|
171 for (list = sl = gaim_find_buddies(account, username); sl != NULL; |
0c201a2386c7
[gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents:
9285
diff
changeset
|
172 sl = sl->next) |
6846 | 173 { |
174 GaimBuddy *buddy = (GaimBuddy *)sl->data; | |
175 | |
176 gaim_buddy_set_icon(buddy, icon); | |
177 } | |
178 | |
8550 | 179 g_slist_free(list); |
180 | |
6846 | 181 conv = gaim_find_conversation_with_account(username, account); |
182 | |
183 if (conv != NULL && gaim_conversation_get_type(conv) == GAIM_CONV_IM) | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6886
diff
changeset
|
184 gaim_conv_im_set_icon(GAIM_CONV_IM(conv), icon); |
6846 | 185 } |
186 | |
187 void | |
6886
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
188 gaim_buddy_icon_cache(GaimBuddyIcon *icon, GaimBuddy *buddy) |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
189 { |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
190 const void *data; |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
191 const char *dirname; |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
192 char *random; |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
193 char *filename; |
7125 | 194 const char *old_icon; |
6886
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
195 size_t len; |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
196 FILE *file = NULL; |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
197 |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
198 g_return_if_fail(icon != NULL); |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
199 g_return_if_fail(buddy != NULL); |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
200 |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
201 if (!gaim_buddy_icons_is_caching()) |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
202 return; |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
203 |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
204 data = gaim_buddy_icon_get_data(icon, &len); |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
205 |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
206 random = g_strdup_printf("%x", g_random_int()); |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
207 dirname = gaim_buddy_icons_get_cache_dir(); |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
208 filename = g_build_filename(dirname, random, NULL); |
7721 | 209 old_icon = gaim_blist_node_get_string((GaimBlistNode*)buddy, "buddy_icon"); |
6886
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
210 |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
211 g_free(random); |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
212 |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
213 if (!g_file_test(dirname, G_FILE_TEST_IS_DIR)) |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
214 { |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
215 gaim_debug_info("buddy icons", "Creating icon cache directory.\n"); |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
216 |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
217 if (mkdir(dirname, S_IRUSR | S_IWUSR | S_IXUSR) < 0) |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
218 { |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
219 gaim_debug_error("buddy icons", |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
220 "Unable to create directory %s: %s\n", |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
221 dirname, strerror(errno)); |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
222 } |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
223 } |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
224 |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
225 if ((file = fopen(filename, "wb")) != NULL) |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
226 { |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
227 fwrite(data, 1, len, file); |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
228 fclose(file); |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
229 } |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
230 |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
231 if (old_icon != NULL) |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
232 unlink(old_icon); |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
233 |
9285 | 234 gaim_blist_node_set_string((GaimBlistNode *)buddy, "buddy_icon", filename); |
6886
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
235 |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
236 g_free(filename); |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
237 } |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
238 |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
239 void |
6846 | 240 gaim_buddy_icon_set_account(GaimBuddyIcon *icon, GaimAccount *account) |
241 { | |
242 g_return_if_fail(icon != NULL); | |
243 g_return_if_fail(account != NULL); | |
244 | |
245 icon->account = account; | |
246 } | |
247 | |
248 void | |
249 gaim_buddy_icon_set_username(GaimBuddyIcon *icon, const char *username) | |
250 { | |
251 g_return_if_fail(icon != NULL); | |
252 g_return_if_fail(username != NULL); | |
253 | |
254 if (icon->username != NULL) | |
255 g_free(icon->username); | |
256 | |
257 icon->username = g_strdup(username); | |
258 } | |
259 | |
260 void | |
261 gaim_buddy_icon_set_data(GaimBuddyIcon *icon, void *data, size_t len) | |
262 { | |
263 g_return_if_fail(icon != NULL); | |
264 | |
265 if (icon->data != NULL) | |
266 g_free(icon->data); | |
267 | |
268 if (data != NULL && len > 0) | |
269 { | |
270 icon->data = g_memdup(data, len); | |
271 icon->len = len; | |
272 } | |
273 else | |
274 { | |
275 icon->data = NULL; | |
276 icon->len = 0; | |
277 } | |
278 | |
279 gaim_buddy_icon_update(icon); | |
280 } | |
281 | |
282 GaimAccount * | |
283 gaim_buddy_icon_get_account(const GaimBuddyIcon *icon) | |
284 { | |
285 g_return_val_if_fail(icon != NULL, NULL); | |
286 | |
287 return icon->account; | |
288 } | |
289 | |
290 const char * | |
291 gaim_buddy_icon_get_username(const GaimBuddyIcon *icon) | |
292 { | |
293 g_return_val_if_fail(icon != NULL, NULL); | |
294 | |
295 return icon->username; | |
296 } | |
297 | |
298 const void * | |
299 gaim_buddy_icon_get_data(const GaimBuddyIcon *icon, size_t *len) | |
300 { | |
301 g_return_val_if_fail(icon != NULL, NULL); | |
302 | |
303 if (len != NULL) | |
304 *len = icon->len; | |
305 | |
306 return icon->data; | |
307 } | |
308 | |
309 void | |
310 gaim_buddy_icons_set_for_user(GaimAccount *account, const char *username, | |
311 void *icon_data, size_t icon_len) | |
312 { | |
313 g_return_if_fail(account != NULL); | |
314 g_return_if_fail(username != NULL); | |
315 | |
9305
0c201a2386c7
[gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents:
9285
diff
changeset
|
316 if (icon_data == NULL || icon_len == 0) |
0c201a2386c7
[gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents:
9285
diff
changeset
|
317 { |
0c201a2386c7
[gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents:
9285
diff
changeset
|
318 GaimBuddyIcon *buddy_icon; |
0c201a2386c7
[gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents:
9285
diff
changeset
|
319 |
0c201a2386c7
[gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents:
9285
diff
changeset
|
320 buddy_icon = gaim_buddy_icons_find(account, username); |
0c201a2386c7
[gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents:
9285
diff
changeset
|
321 |
0c201a2386c7
[gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents:
9285
diff
changeset
|
322 if (buddy_icon != NULL) |
0c201a2386c7
[gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents:
9285
diff
changeset
|
323 gaim_buddy_icon_destroy(buddy_icon); |
0c201a2386c7
[gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents:
9285
diff
changeset
|
324 } |
0c201a2386c7
[gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents:
9285
diff
changeset
|
325 else |
0c201a2386c7
[gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents:
9285
diff
changeset
|
326 { |
0c201a2386c7
[gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents:
9285
diff
changeset
|
327 gaim_buddy_icon_new(account, username, icon_data, icon_len); |
0c201a2386c7
[gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents:
9285
diff
changeset
|
328 } |
6846 | 329 } |
330 | |
331 GaimBuddyIcon * | |
332 gaim_buddy_icons_find(const GaimAccount *account, const char *username) | |
333 { | |
334 GHashTable *icon_cache; | |
335 | |
336 g_return_val_if_fail(account != NULL, NULL); | |
337 g_return_val_if_fail(username != NULL, NULL); | |
338 | |
339 icon_cache = g_hash_table_lookup(account_cache, account); | |
340 | |
341 if (icon_cache == NULL) | |
342 return NULL; | |
343 | |
344 return g_hash_table_lookup(icon_cache, username); | |
345 } | |
346 | |
6886
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
347 void |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
348 gaim_buddy_icons_set_caching(gboolean caching) |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
349 { |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
350 icon_caching = caching; |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
351 } |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
352 |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
353 gboolean |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
354 gaim_buddy_icons_is_caching(void) |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
355 { |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
356 return icon_caching; |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
357 } |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
358 |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
359 void |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
360 gaim_buddy_icons_set_cache_dir(const char *dir) |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
361 { |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
362 g_return_if_fail(cache_dir != NULL); |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
363 |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
364 if (cache_dir != NULL) |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
365 g_free(cache_dir); |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
366 |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
367 cache_dir = g_strdup(dir); |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
368 } |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
369 |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
370 const char * |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
371 gaim_buddy_icons_get_cache_dir(void) |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
372 { |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
373 return cache_dir; |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
374 } |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
375 |
6846 | 376 void * |
377 gaim_buddy_icons_get_handle() | |
378 { | |
379 static int handle; | |
380 | |
381 return &handle; | |
382 } | |
383 | |
384 void | |
385 gaim_buddy_icons_init() | |
386 { | |
387 account_cache = g_hash_table_new_full( | |
388 g_direct_hash, g_direct_equal, | |
389 NULL, (GFreeFunc)g_hash_table_destroy); | |
6886
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
390 |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
391 cache_dir = g_build_filename(gaim_user_dir(), "icons", NULL); |
6846 | 392 } |
393 | |
394 void | |
395 gaim_buddy_icons_uninit() | |
396 { | |
397 g_hash_table_destroy(account_cache); | |
398 } |