comparison libpurple/buddyicon.c @ 16376:dd47fa8ba3e4

Bug fixes! From my preliminary testing, the standard buddy icon stuff is working.
author Richard Laager <rlaager@wiktel.com>
date Tue, 24 Apr 2007 04:35:38 +0000
parents 391a79778f89
children 44489a2123e7
comparison
equal deleted inserted replaced
16375:391a79778f89 16376:dd47fa8ba3e4
60 int refs; 60 int refs;
61 61
62 g_return_if_fail(filename != NULL); 62 g_return_if_fail(filename != NULL);
63 63
64 refs = GPOINTER_TO_INT(g_hash_table_lookup(icon_file_cache, filename)); 64 refs = GPOINTER_TO_INT(g_hash_table_lookup(icon_file_cache, filename));
65 printf("refs before increment = %d\n", refs);
65 66
66 g_hash_table_insert(icon_file_cache, g_strdup(filename), 67 g_hash_table_insert(icon_file_cache, g_strdup(filename),
67 GINT_TO_POINTER(refs + 1)); 68 GINT_TO_POINTER(refs + 1));
68 } 69 }
69 70
74 75
75 if (filename == NULL) 76 if (filename == NULL)
76 return; 77 return;
77 78
78 refs = GPOINTER_TO_INT(g_hash_table_lookup(icon_file_cache, filename)); 79 refs = GPOINTER_TO_INT(g_hash_table_lookup(icon_file_cache, filename));
80 printf("refs before decrement = %d\n", refs);
79 81
80 if (refs == 1) 82 if (refs == 1)
81 { 83 {
82 g_hash_table_remove(icon_file_cache, filename); 84 g_hash_table_remove(icon_file_cache, filename);
83 } 85 }
172 174
173 g_return_if_fail(filename != NULL); 175 g_return_if_fail(filename != NULL);
174 176
175 /* It's possible that there are other references to this icon 177 /* It's possible that there are other references to this icon
176 * cache file that are not currently loaded into memory. */ 178 * cache file that are not currently loaded into memory. */
177 if (g_hash_table_lookup(icon_file_cache, filename)) 179 printf("file has %d refs\n", GPOINTER_TO_INT(g_hash_table_lookup(icon_file_cache, filename)));
180 if (GPOINTER_TO_INT(g_hash_table_lookup(icon_file_cache, filename)))
178 return; 181 return;
179 182
180 dirname = purple_buddy_icons_get_cache_dir(); 183 dirname = purple_buddy_icons_get_cache_dir();
181 path = g_build_filename(dirname, filename, NULL); 184 path = g_build_filename(dirname, filename, NULL);
182 185
186 printf("Going to unlink %s\n", path);
183 if (g_file_test(path, G_FILE_TEST_EXISTS)) 187 if (g_file_test(path, G_FILE_TEST_EXISTS))
184 { 188 {
185 if (g_unlink(path)) 189 if (g_unlink(path))
186 { 190 {
191 printf("Failed to unlink %s\n", path);
192
187 purple_debug_error("buddyicon", "Failed to delete %s: %s\n", 193 purple_debug_error("buddyicon", "Failed to delete %s: %s\n",
188 path, strerror(errno)); 194 path, strerror(errno));
189 } 195 }
190 else 196 else
197 {
198 printf("Unlinked %s\n", path);
191 purple_debug_info("buddyicon", "Deleted cache file: %s\n", path); 199 purple_debug_info("buddyicon", "Deleted cache file: %s\n", path);
200 }
192 } 201 }
193 202
194 g_free(path); 203 g_free(path);
195 } 204 }
196 205
277 g_return_val_if_fail(account != NULL, NULL); 286 g_return_val_if_fail(account != NULL, NULL);
278 g_return_val_if_fail(username != NULL, NULL); 287 g_return_val_if_fail(username != NULL, NULL);
279 g_return_val_if_fail(icon_data != NULL, NULL); 288 g_return_val_if_fail(icon_data != NULL, NULL);
280 g_return_val_if_fail(icon_len > 0, NULL); 289 g_return_val_if_fail(icon_len > 0, NULL);
281 290
291 /* purple_buddy_icons_find() does allocation, so be
292 * sure to update it as well when members are added. */
282 icon = purple_buddy_icons_find(account, username); 293 icon = purple_buddy_icons_find(account, username);
283 294
284 /* purple_buddy_icon_create() sets account & username */ 295 /* purple_buddy_icon_create() sets account & username */
285 if (icon == NULL) 296 if (icon == NULL)
286 icon = purple_buddy_icon_create(account, username); 297 icon = purple_buddy_icon_create(account, username);
287 298
288 /* Take a reference for the caller of this function. */ 299 /* Take a reference for the caller of this function. */
289 icon->ref_count = 1; 300 icon->ref_count = 1;
290 301
291 /* purple_buddy_icon_set_data() sets img */ 302 /* purple_buddy_icon_set_data() sets img, but it
303 * references img first, so we need to initialize it */
304 icon->img = NULL;
292 purple_buddy_icon_set_data(icon, icon_data, icon_len); 305 purple_buddy_icon_set_data(icon, icon_data, icon_len);
293 306
294 return icon; 307 return icon;
295 } 308 }
296 309
370 { 383 {
371 const char *filename = purple_imgstore_get_filename(icon->img); 384 const char *filename = purple_imgstore_get_filename(icon->img);
372 purple_blist_node_set_string((PurpleBlistNode *)buddy, 385 purple_blist_node_set_string((PurpleBlistNode *)buddy,
373 "buddy_icon", 386 "buddy_icon",
374 filename); 387 filename);
388 printf("Calling ref_filename(%s)\n", filename);
375 ref_filename(filename); 389 ref_filename(filename);
376 } 390 }
377 else 391 else
378 { 392 {
379 purple_blist_node_remove_setting((PurpleBlistNode *)buddy, "buddy_icon"); 393 purple_blist_node_remove_setting((PurpleBlistNode *)buddy, "buddy_icon");
380 } 394 }
395 printf("Calling unref_filename(%s)\n", old_icon);
381 unref_filename(old_icon); 396 unref_filename(old_icon);
382 g_free(old_icon); 397 g_free(old_icon);
383 } 398 }
384 399
385 g_slist_free(list); 400 g_slist_free(list);
401 icon->img = NULL; 416 icon->img = NULL;
402 417
403 if (data != NULL && len > 0) 418 if (data != NULL && len > 0)
404 icon->img = purple_buddy_icon_data_new(data, len, NULL); 419 icon->img = purple_buddy_icon_data_new(data, len, NULL);
405 420
421 printf("Calling purple_buddy_icon_update\n");
406 purple_buddy_icon_update(icon); 422 purple_buddy_icon_update(icon);
407 423
424 printf("Calling purple_imgstore_unref\n");
408 purple_imgstore_unref(old_img); 425 purple_imgstore_unref(old_img);
409 } 426 }
410 427
411 PurpleAccount * 428 PurpleAccount *
412 purple_buddy_icon_get_account(const PurpleBuddyIcon *icon) 429 purple_buddy_icon_get_account(const PurpleBuddyIcon *icon)
454 void *icon_data, size_t icon_len) 471 void *icon_data, size_t icon_len)
455 { 472 {
456 g_return_if_fail(account != NULL); 473 g_return_if_fail(account != NULL);
457 g_return_if_fail(username != NULL); 474 g_return_if_fail(username != NULL);
458 475
459 if (icon_data == NULL || icon_len == 0) 476 if (icon_data != NULL && icon_len > 0)
460 { 477 {
461 PurpleBuddyIcon *icon; 478 PurpleBuddyIcon *icon;
462 479
463 icon = purple_buddy_icons_find(account, username); 480 icon = purple_buddy_icons_find(account, username);
464 481
545 char *path = g_build_filename(dirname, protocol_icon_file, NULL); 562 char *path = g_build_filename(dirname, protocol_icon_file, NULL);
546 if (read_icon_file(path, &data, &len)) 563 if (read_icon_file(path, &data, &len))
547 { 564 {
548 if (icon == NULL) 565 if (icon == NULL)
549 icon = purple_buddy_icon_create(account, username); 566 icon = purple_buddy_icon_create(account, username);
567 icon->ref_count = 0;
568 icon->img = NULL;
550 purple_buddy_icon_set_data(icon, data, len); 569 purple_buddy_icon_set_data(icon, data, len);
551 } 570 }
552 g_free(path); 571 g_free(path);
553 } 572 }
554 573