diff src/prpl.c @ 6846:8ab95f4c9800

[gaim-migrate @ 7391] Added new buddy icon caching code. Each GaimBuddy has its own icon, and the complete list of all icons is now stored in a set of hashtables for quick retrieval. Buddy icons now live much happier in the core, with the magma and tooth fairies (that's where they really live). committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Mon, 15 Sep 2003 07:35:49 +0000
parents 636b5215552e
children dece74f05509
line wrap: on
line diff
--- a/src/prpl.c	Mon Sep 15 02:23:58 2003 +0000
+++ b/src/prpl.c	Mon Sep 15 07:35:49 2003 +0000
@@ -102,158 +102,6 @@
 	return NULL;
 }
 
-struct icon_data {
-	GaimConnection *gc;
-	char *who;
-	void *data;
-	int len;
-};
-
-static GList *icons = NULL;
-
-static gint find_icon_data(gconstpointer a, gconstpointer b)
-{
-	const struct icon_data *x = a;
-	const struct icon_data *y = b;
-
-	return ((x->gc != y->gc) || gaim_utf8_strcasecmp(x->who, y->who));
-}
-
-void set_icon_data(GaimConnection *gc, const char *who, void *data, int len)
-{
-	GaimConversation *conv;
-	struct icon_data tmp;
-	GList *l;
-	struct icon_data *id;
-	GaimBuddy *b;
-	/* i'm going to vent here a little bit about normalize().  normalize()
-	 * uses a static buffer, so when we call functions that use normalize() from
-	 * functions that use normalize(), whose parameters are the result of running
-	 * normalize(), bad things happen.  To prevent some of this, we're going
-	 * to make a copy of what we get from normalize(), so we know nothing else
-	 * touches it, and buddy icons don't go to the wrong person.  Some day I
-	 * will kill normalize(), and dance on its grave.  That will be a very happy
-	 * day for everyone.
-	 *                                    --ndw
-	 */
-	char *realwho = g_strdup(normalize(who));
-	tmp.gc = gc;
-	tmp.who = realwho;
-	tmp.data=NULL;
-	tmp.len = 0;
-	l = g_list_find_custom(icons, &tmp, find_icon_data);
-	id = l ? l->data : NULL;
-
-	if (id) {
-		g_free(id->data);
-		if (!data) {
-			icons = g_list_remove(icons, id);
-			g_free(id->who);
-			g_free(id);
-			g_free(realwho);
-			return;
-		}
-	} else if (data) {
-		id = g_new0(struct icon_data, 1);
-		icons = g_list_append(icons, id);
-		id->gc = gc;
-		id->who = g_strdup(realwho);
-	} else {
-		g_free(realwho);
-		return;
-	}
-
-	gaim_debug(GAIM_DEBUG_MISC, "prpl", "Got icon for %s (length %d)\n",
-			   realwho, len);
-
-	id->data = g_memdup(data, len);
-	id->len = len;
-
-	/* Update the buddy icon for this user. */
-	conv = gaim_find_conversation_with_account(realwho, gc->account);
-
-	/* XXX Buddy Icon should probalby be part of struct buddy instead of this weird global
-	 * linked list stuff. */
-
-	if ((b = gaim_find_buddy(gc->account, realwho)) != NULL) {
-		char *random = g_strdup_printf("%x", g_random_int());
-		char *filename = g_build_filename(gaim_user_dir(), "icons", random,
-				NULL);
-		char *dirname = g_build_filename(gaim_user_dir(), "icons", NULL);
-		char *old_icon = gaim_buddy_get_setting(b, "buddy_icon");
-		FILE *file = NULL;
-
-		g_free(random);
-
-		if(!g_file_test(dirname, G_FILE_TEST_IS_DIR)) {
-			gaim_debug(GAIM_DEBUG_INFO, "buddy icons",
-					   "Creating icon cache directory.\n");
-
-			if(mkdir(dirname, S_IRUSR | S_IWUSR | S_IXUSR) < 0)
-				gaim_debug(GAIM_DEBUG_ERROR, "buddy icons",
-						   "Unable to create directory %s: %s\n",
-						   dirname, strerror(errno));
-		}
-
-		g_free(dirname);
-
-		file = fopen(filename, "wb");
-		if (file) {
-			fwrite(data, 1, len, file);
-			fclose(file);
-		}
-
-		if(old_icon) {
-			unlink(old_icon);
-			g_free(old_icon);
-		}
-
-		gaim_buddy_set_setting(b, "buddy_icon", filename);
-		gaim_blist_save();
-
-		g_free(filename);
-
-		gaim_blist_update_buddy_icon(b);
-	}
-
-	if (conv != NULL && gaim_conversation_get_gc(conv) == gc)
-		gaim_gtkconv_update_buddy_icon(conv);
-
-	g_free(realwho);
-}
-
-void remove_icon_data(GaimConnection *gc)
-{
-	GList *list = icons;
-	struct icon_data *id;
-
-	while (list) {
-		id = list->data;
-		if (id->gc == gc) {
-			g_free(id->data);
-			g_free(id->who);
-			list = icons = g_list_remove(icons, id);
-			g_free(id);
-		} else
-			list = list->next;
-	}
-}
-
-void *get_icon_data(GaimConnection *gc, const char *who, int *len)
-{
-	struct icon_data tmp = { gc, normalize(who), NULL, 0 };
-	GList *l = g_list_find_custom(icons, &tmp, find_icon_data);
-	struct icon_data *id = l ? l->data : NULL;
-
-	if (id) {
-		*len = id->len;
-		return id->data;
-	}
-
-	*len = 0;
-	return NULL;
-}
-
 struct got_add {
 	GaimConnection *gc;
 	char *who;