changeset 11040:3428ad6f5049

[gaim-migrate @ 12940] Patch #1224610 from Richard Laager "Buddy icon cache files are removed when replacing icons but not when unsetting the icon. This patch corrects that." committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Thu, 30 Jun 2005 04:33:21 +0000
parents 34d2aac7b34f
children 84dd837a4445
files src/blist.c src/buddyicon.c src/buddyicon.h
diffstat 3 files changed, 51 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/blist.c	Thu Jun 30 04:24:27 2005 +0000
+++ b/src/blist.c	Thu Jun 30 04:33:21 2005 +0000
@@ -1097,7 +1097,7 @@
 	if (buddy->icon)
 		gaim_buddy_icon_cache(icon, buddy);
 	else
-		gaim_blist_node_remove_setting((GaimBlistNode *)buddy, "buddy_icon");
+		gaim_buddy_icon_uncache(buddy);
 
 	gaim_blist_schedule_save();
 
--- a/src/buddyicon.c	Thu Jun 30 04:24:27 2005 +0000
+++ b/src/buddyicon.c	Thu Jun 30 04:33:21 2005 +0000
@@ -196,6 +196,25 @@
 		gaim_conv_im_set_icon(GAIM_CONV_IM(conv), icon);
 }
 
+static void
+delete_icon_cache_file(const char *dirname, const char *old_icon)
+{
+	struct stat st;
+
+	g_return_if_fail(dirname != NULL);
+	g_return_if_fail(old_icon != NULL);
+
+	if (g_stat(old_icon, &st) == 0)
+		g_unlink(old_icon);
+	else
+	{
+		char *filename = g_build_filename(dirname, old_icon, NULL);
+		if (g_stat(filename, &st) == 0)
+			g_unlink(filename);
+		g_free(filename);
+	}
+}
+
 void
 gaim_buddy_icon_cache(GaimBuddyIcon *icon, GaimBuddy *buddy)
 {
@@ -205,7 +224,6 @@
 	char *filename;
 	const char *old_icon;
 	size_t len;
-	struct stat st;
 	FILE *file = NULL;
 
 	g_return_if_fail(icon  != NULL);
@@ -250,16 +268,7 @@
 	g_free(filename);
 
 	if (old_icon != NULL)
-	{
-		if(!g_stat(old_icon, &st))
-			g_unlink(old_icon);
-		else {
-			filename = g_build_filename(dirname, old_icon, NULL);
-			if(!g_stat(filename, &st))
-				g_unlink(filename);
-			g_free(filename);
-		}
-	}
+		delete_icon_cache_file(dirname, old_icon);
 
 	gaim_blist_node_set_string((GaimBlistNode *)buddy, "buddy_icon", random);
 
@@ -267,6 +276,29 @@
 }
 
 void
+gaim_buddy_icon_uncache(GaimBuddy *buddy)
+{
+	const char *old_icon;
+
+	g_return_if_fail(buddy != NULL);
+
+	old_icon = gaim_blist_node_get_string((GaimBlistNode *)buddy, "buddy_icon");
+
+	if (old_icon != NULL)
+		delete_icon_cache_file(gaim_buddy_icons_get_cache_dir(), old_icon);
+
+	gaim_blist_node_remove_setting((GaimBlistNode *)buddy, "buddy_icon");
+
+	/* Unset the icon in case this function is called from
+	 * something other than gaim_buddy_set_icon(). */
+	if (buddy->icon != NULL)
+	{
+		gaim_buddy_icon_unref(buddy->icon);
+		buddy->icon = NULL;
+	}
+}
+
+void
 gaim_buddy_icon_set_account(GaimBuddyIcon *icon, GaimAccount *account)
 {
 	g_return_if_fail(icon    != NULL);
--- a/src/buddyicon.h	Thu Jun 30 04:24:27 2005 +0000
+++ b/src/buddyicon.h	Thu Jun 30 04:33:21 2005 +0000
@@ -106,6 +106,13 @@
 void gaim_buddy_icon_cache(GaimBuddyIcon *icon, GaimBuddy *buddy);
 
 /**
+ * Removes cached buddy icon for a specific buddy.
+ *
+ * @param buddy The buddy for which to remove the cached icon.
+ */
+void gaim_buddy_icon_uncache(GaimBuddy *buddy);
+
+/**
  * Sets the buddy icon's account.
  *
  * @param icon    The buddy icon.