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