Mercurial > pidgin.yaz
annotate src/buddyicon.c @ 9323:59bca4e8678c
[gaim-migrate @ 10131]
This should help make buddy icons get destroyed right and stuff.
Except the UI doesn't seem to care. I'll work on that.
committer: Tailor Script <tailor@pidgin.im>
author | Tim Ringenbach <marv@pidgin.im> |
---|---|
date | Sun, 20 Jun 2004 05:39:21 +0000 |
parents | 0c201a2386c7 |
children | ef8e4740254d |
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 | |
9323 | 72 /* We don't take a reference here. In fact we may want to check if we have |
73 * a reference (gaim_buddy_icon_set_data should have added one or more) | |
74 * and destroy ourselves if we don't. | |
75 */ | |
6846 | 76 return icon; |
77 } | |
78 | |
79 void | |
80 gaim_buddy_icon_destroy(GaimBuddyIcon *icon) | |
81 { | |
7311
1c8830db0189
[gaim-migrate @ 7895]
Christian Hammond <chipx86@chipx86.com>
parents:
7125
diff
changeset
|
82 GaimConversation *conv; |
1c8830db0189
[gaim-migrate @ 7895]
Christian Hammond <chipx86@chipx86.com>
parents:
7125
diff
changeset
|
83 GaimAccount *account; |
6846 | 84 GHashTable *icon_cache; |
7311
1c8830db0189
[gaim-migrate @ 7895]
Christian Hammond <chipx86@chipx86.com>
parents:
7125
diff
changeset
|
85 const char *username; |
9305
0c201a2386c7
[gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents:
9285
diff
changeset
|
86 GSList *sl, *list; |
6846 | 87 |
88 g_return_if_fail(icon != NULL); | |
89 | |
90 if (icon->ref_count > 0) | |
91 { | |
9323 | 92 /* If the ref count is greater than 0, then we weren't called from |
93 * gaim_buddy_icon_unref(). So we go through and ask everyone to | |
94 * unref us. Then we return, since we know somewhere along the | |
95 * line we got called recursively by one of the unrefs, and the | |
96 * icon is already destroyed. | |
97 */ | |
98 account = gaim_buddy_icon_get_account(icon); | |
99 username = gaim_buddy_icon_get_username(icon); | |
100 | |
101 conv = gaim_find_conversation_with_account(username, account); | |
102 if (conv != NULL && gaim_conversation_get_type(conv) == GAIM_CONV_IM) | |
103 gaim_conv_im_set_icon(GAIM_CONV_IM(conv), NULL); | |
104 | |
105 for (list = sl = gaim_find_buddies(account, username); sl != NULL; | |
106 sl = sl->next) | |
107 { | |
108 GaimBuddy *buddy = (GaimBuddy *)sl->data; | |
109 | |
110 gaim_buddy_set_icon(buddy, NULL); | |
111 } | |
112 | |
113 g_slist_free(list); | |
6846 | 114 |
115 return; | |
116 } | |
117 | |
118 icon_cache = g_hash_table_lookup(account_cache, | |
119 gaim_buddy_icon_get_account(icon)); | |
120 | |
121 if (icon_cache != NULL) | |
122 g_hash_table_remove(icon_cache, gaim_buddy_icon_get_username(icon)); | |
123 | |
124 if (icon->username != NULL) | |
125 g_free(icon->username); | |
126 | |
127 if (icon->data != NULL) | |
128 g_free(icon->data); | |
129 | |
130 g_free(icon); | |
131 } | |
132 | |
133 GaimBuddyIcon * | |
134 gaim_buddy_icon_ref(GaimBuddyIcon *icon) | |
135 { | |
136 g_return_val_if_fail(icon != NULL, NULL); | |
137 | |
138 icon->ref_count++; | |
139 | |
140 return icon; | |
141 } | |
142 | |
143 GaimBuddyIcon * | |
144 gaim_buddy_icon_unref(GaimBuddyIcon *icon) | |
145 { | |
146 g_return_val_if_fail(icon != NULL, NULL); | |
147 | |
148 if (icon->ref_count <= 0) | |
149 return NULL; | |
150 | |
151 icon->ref_count--; | |
152 | |
153 if (icon->ref_count == 0) | |
154 { | |
155 gaim_buddy_icon_destroy(icon); | |
156 | |
157 return NULL; | |
158 } | |
159 | |
160 return icon; | |
161 } | |
162 | |
163 void | |
164 gaim_buddy_icon_update(GaimBuddyIcon *icon) | |
165 { | |
166 GaimConversation *conv; | |
167 GaimAccount *account; | |
168 const char *username; | |
8550 | 169 GSList *sl, *list; |
6846 | 170 |
171 g_return_if_fail(icon != NULL); | |
172 | |
173 account = gaim_buddy_icon_get_account(icon); | |
174 username = gaim_buddy_icon_get_username(icon); | |
175 | |
9305
0c201a2386c7
[gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents:
9285
diff
changeset
|
176 for (list = sl = gaim_find_buddies(account, username); sl != NULL; |
0c201a2386c7
[gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents:
9285
diff
changeset
|
177 sl = sl->next) |
6846 | 178 { |
179 GaimBuddy *buddy = (GaimBuddy *)sl->data; | |
180 | |
181 gaim_buddy_set_icon(buddy, icon); | |
182 } | |
183 | |
8550 | 184 g_slist_free(list); |
185 | |
6846 | 186 conv = gaim_find_conversation_with_account(username, account); |
187 | |
188 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
|
189 gaim_conv_im_set_icon(GAIM_CONV_IM(conv), icon); |
6846 | 190 } |
191 | |
192 void | |
6886
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
193 gaim_buddy_icon_cache(GaimBuddyIcon *icon, GaimBuddy *buddy) |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
194 { |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
195 const void *data; |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
196 const char *dirname; |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
197 char *random; |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
198 char *filename; |
7125 | 199 const char *old_icon; |
6886
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
200 size_t len; |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
201 FILE *file = NULL; |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
202 |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
203 g_return_if_fail(icon != NULL); |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
204 g_return_if_fail(buddy != NULL); |
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 if (!gaim_buddy_icons_is_caching()) |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
207 return; |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
208 |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
209 data = gaim_buddy_icon_get_data(icon, &len); |
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 random = g_strdup_printf("%x", g_random_int()); |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
212 dirname = gaim_buddy_icons_get_cache_dir(); |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
213 filename = g_build_filename(dirname, random, NULL); |
7721 | 214 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
|
215 |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
216 g_free(random); |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
217 |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
218 if (!g_file_test(dirname, G_FILE_TEST_IS_DIR)) |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
219 { |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
220 gaim_debug_info("buddy icons", "Creating icon cache directory.\n"); |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
221 |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
222 if (mkdir(dirname, S_IRUSR | S_IWUSR | S_IXUSR) < 0) |
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 gaim_debug_error("buddy icons", |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
225 "Unable to create directory %s: %s\n", |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
226 dirname, strerror(errno)); |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
227 } |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
228 } |
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 if ((file = fopen(filename, "wb")) != NULL) |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
231 { |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
232 fwrite(data, 1, len, file); |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
233 fclose(file); |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
234 } |
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 if (old_icon != NULL) |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
237 unlink(old_icon); |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
238 |
9285 | 239 gaim_blist_node_set_string((GaimBlistNode *)buddy, "buddy_icon", filename); |
6886
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
240 |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
241 g_free(filename); |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
242 } |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
243 |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
244 void |
6846 | 245 gaim_buddy_icon_set_account(GaimBuddyIcon *icon, GaimAccount *account) |
246 { | |
247 g_return_if_fail(icon != NULL); | |
248 g_return_if_fail(account != NULL); | |
249 | |
250 icon->account = account; | |
251 } | |
252 | |
253 void | |
254 gaim_buddy_icon_set_username(GaimBuddyIcon *icon, const char *username) | |
255 { | |
256 g_return_if_fail(icon != NULL); | |
257 g_return_if_fail(username != NULL); | |
258 | |
259 if (icon->username != NULL) | |
260 g_free(icon->username); | |
261 | |
262 icon->username = g_strdup(username); | |
263 } | |
264 | |
265 void | |
266 gaim_buddy_icon_set_data(GaimBuddyIcon *icon, void *data, size_t len) | |
267 { | |
268 g_return_if_fail(icon != NULL); | |
269 | |
270 if (icon->data != NULL) | |
271 g_free(icon->data); | |
272 | |
273 if (data != NULL && len > 0) | |
274 { | |
275 icon->data = g_memdup(data, len); | |
276 icon->len = len; | |
277 } | |
278 else | |
279 { | |
280 icon->data = NULL; | |
281 icon->len = 0; | |
282 } | |
283 | |
284 gaim_buddy_icon_update(icon); | |
285 } | |
286 | |
287 GaimAccount * | |
288 gaim_buddy_icon_get_account(const GaimBuddyIcon *icon) | |
289 { | |
290 g_return_val_if_fail(icon != NULL, NULL); | |
291 | |
292 return icon->account; | |
293 } | |
294 | |
295 const char * | |
296 gaim_buddy_icon_get_username(const GaimBuddyIcon *icon) | |
297 { | |
298 g_return_val_if_fail(icon != NULL, NULL); | |
299 | |
300 return icon->username; | |
301 } | |
302 | |
303 const void * | |
304 gaim_buddy_icon_get_data(const GaimBuddyIcon *icon, size_t *len) | |
305 { | |
306 g_return_val_if_fail(icon != NULL, NULL); | |
307 | |
308 if (len != NULL) | |
309 *len = icon->len; | |
310 | |
311 return icon->data; | |
312 } | |
313 | |
314 void | |
315 gaim_buddy_icons_set_for_user(GaimAccount *account, const char *username, | |
316 void *icon_data, size_t icon_len) | |
317 { | |
318 g_return_if_fail(account != NULL); | |
319 g_return_if_fail(username != NULL); | |
320 | |
9305
0c201a2386c7
[gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents:
9285
diff
changeset
|
321 if (icon_data == NULL || icon_len == 0) |
0c201a2386c7
[gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents:
9285
diff
changeset
|
322 { |
0c201a2386c7
[gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents:
9285
diff
changeset
|
323 GaimBuddyIcon *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 buddy_icon = gaim_buddy_icons_find(account, username); |
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 if (buddy_icon != NULL) |
0c201a2386c7
[gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents:
9285
diff
changeset
|
328 gaim_buddy_icon_destroy(buddy_icon); |
0c201a2386c7
[gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents:
9285
diff
changeset
|
329 } |
0c201a2386c7
[gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents:
9285
diff
changeset
|
330 else |
0c201a2386c7
[gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents:
9285
diff
changeset
|
331 { |
0c201a2386c7
[gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents:
9285
diff
changeset
|
332 gaim_buddy_icon_new(account, username, icon_data, icon_len); |
0c201a2386c7
[gaim-migrate @ 10113]
Christian Hammond <chipx86@chipx86.com>
parents:
9285
diff
changeset
|
333 } |
6846 | 334 } |
335 | |
336 GaimBuddyIcon * | |
337 gaim_buddy_icons_find(const GaimAccount *account, const char *username) | |
338 { | |
339 GHashTable *icon_cache; | |
340 | |
341 g_return_val_if_fail(account != NULL, NULL); | |
342 g_return_val_if_fail(username != NULL, NULL); | |
343 | |
344 icon_cache = g_hash_table_lookup(account_cache, account); | |
345 | |
346 if (icon_cache == NULL) | |
347 return NULL; | |
348 | |
349 return g_hash_table_lookup(icon_cache, username); | |
350 } | |
351 | |
6886
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
352 void |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
353 gaim_buddy_icons_set_caching(gboolean caching) |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
354 { |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
355 icon_caching = caching; |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
356 } |
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 gboolean |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
359 gaim_buddy_icons_is_caching(void) |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
360 { |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
361 return icon_caching; |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
362 } |
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 void |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
365 gaim_buddy_icons_set_cache_dir(const char *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 g_return_if_fail(cache_dir != NULL); |
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 if (cache_dir != NULL) |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
370 g_free(cache_dir); |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
371 |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
372 cache_dir = g_strdup(dir); |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
373 } |
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 const char * |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
376 gaim_buddy_icons_get_cache_dir(void) |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
377 { |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
378 return cache_dir; |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
379 } |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
380 |
6846 | 381 void * |
382 gaim_buddy_icons_get_handle() | |
383 { | |
384 static int handle; | |
385 | |
386 return &handle; | |
387 } | |
388 | |
389 void | |
390 gaim_buddy_icons_init() | |
391 { | |
392 account_cache = g_hash_table_new_full( | |
393 g_direct_hash, g_direct_equal, | |
394 NULL, (GFreeFunc)g_hash_table_destroy); | |
6886
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
395 |
b5fb1d5282e5
[gaim-migrate @ 7432]
Christian Hammond <chipx86@chipx86.com>
parents:
6846
diff
changeset
|
396 cache_dir = g_build_filename(gaim_user_dir(), "icons", NULL); |
6846 | 397 } |
398 | |
399 void | |
400 gaim_buddy_icons_uninit() | |
401 { | |
402 g_hash_table_destroy(account_cache); | |
403 } |