diff gtk/gtkblist.c @ 14852:cf25420b074d

[gaim-migrate @ 17621] Allow custom buddy icons for people in the buddylist. It's done completely in the UI side. The custom icon does not overwrite the original icon, which is displayed in the tooltip. You can set the icon by dragging an image on the conv window, or on the buddy in the buddylist. You can also set/remove custom icon from the conversation window by right clicking on the icon in the conv window. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sun, 29 Oct 2006 23:35:57 +0000
parents 77c68f898389
children 41ced1c9ba29
line wrap: on
line diff
--- a/gtk/gtkblist.c	Sun Oct 29 23:28:37 2006 +0000
+++ b/gtk/gtkblist.c	Sun Oct 29 23:35:57 2006 +0000
@@ -1992,12 +1992,12 @@
 }
 
 static GdkPixbuf *gaim_gtk_blist_get_buddy_icon(GaimBlistNode *node,
-		gboolean scaled, gboolean greyed)
+		gboolean scaled, gboolean greyed, gboolean custom)
 {
 	GdkPixbuf *buf, *ret = NULL;
 	GdkPixbufLoader *loader;
 	GaimBuddyIcon *icon;
-	const guchar *data;
+	const guchar *data = NULL;
 	gsize len;
 	GaimBuddy *buddy = (GaimBuddy *)node;
 
@@ -2014,12 +2014,30 @@
 		return NULL;
 #endif
 
-	if (!(icon = gaim_buddy_get_icon(buddy)))
-		if (!(icon = gaim_buddy_icons_find(buddy->account, buddy->name))) /* Not sure I like this...*/
-			return NULL;
+	if (custom) {
+		const char *file = gaim_blist_node_get_string((GaimBlistNode*)gaim_buddy_get_contact(buddy),
+							"custom_buddy_icon");
+		if (file && *file) {
+			char *contents;
+			GError *err  = NULL;
+			if (!g_file_get_contents(file, &contents, &len, &err)) {
+				gaim_debug_info("custom -icon", "Could not open custom-icon %s for %s\n",
+							file, gaim_buddy_get_name(buddy), err->message);
+				g_error_free(err);
+			} else
+				data = (const guchar*)contents;
+		}
+	}
+
+	if (data == NULL) {
+		if (!(icon = gaim_buddy_get_icon(buddy)))
+			if (!(icon = gaim_buddy_icons_find(buddy->account, buddy->name))) /* Not sure I like this...*/
+				return NULL;
+		data = gaim_buddy_icon_get_data(icon, &len);
+		custom = FALSE;  /* We are not using the custom icon */
+	}
 
 	loader = gdk_pixbuf_loader_new();
-	data = gaim_buddy_icon_get_data(icon, &len);
 	gdk_pixbuf_loader_write(loader, data, len, NULL);
 	gdk_pixbuf_loader_close(loader, NULL);
 	buf = gdk_pixbuf_loader_get_pixbuf(loader);
@@ -2027,6 +2045,8 @@
 		g_object_ref(G_OBJECT(buf));
 	g_object_unref(G_OBJECT(loader));
 
+	if (custom)
+		g_free((void*)data);
 	if (buf) {
 		GaimAccount *account = gaim_buddy_get_account(buddy);
 		GaimPluginProtocolInfo *prpl_info = NULL;
@@ -2088,7 +2108,7 @@
 	struct tooltip_data *td = g_new0(struct tooltip_data, 1);
 
 	td->status_icon = gaim_gtk_blist_get_status_icon(node, GAIM_STATUS_ICON_LARGE);
-	td->avatar = gaim_gtk_blist_get_buddy_icon(node, !full, FALSE);
+	td->avatar = gaim_gtk_blist_get_buddy_icon(node, !full, FALSE, FALSE);
 	tooltip_text = gaim_get_tooltip_text(node, full);
 	td->layout = gtk_widget_create_pango_layout(gtkblist->tipwindow, NULL);
 	pango_layout_set_markup(td->layout, tooltip_text, -1);
@@ -4470,7 +4490,7 @@
 	status = gaim_gtk_blist_get_status_icon((GaimBlistNode*)buddy,
 						biglist ? GAIM_STATUS_ICON_LARGE : GAIM_STATUS_ICON_SMALL);
 
-	avatar = gaim_gtk_blist_get_buddy_icon((GaimBlistNode *)buddy, TRUE, TRUE);
+	avatar = gaim_gtk_blist_get_buddy_icon((GaimBlistNode *)buddy, TRUE, TRUE, TRUE);
 	mark = gaim_gtk_blist_get_name_markup(buddy, selected);
 
 	if (gaim_prefs_get_bool("/gaim/gtk/blist/show_idle_time") &&