changeset 4757:c4ebe1a8484b

[gaim-migrate @ 5074] this fixes a bunch of little things, as well as a few big things, plugs a few leaks, and makes the new buddy icon cache stuff much cooler. enjoy! committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Fri, 14 Mar 2003 01:14:24 +0000
parents 85637881b342
children 2202f056a1c9
files src/buddy.c src/gtkconv.c src/html.c src/list.c src/list.h src/prpl.c
diffstat 6 files changed, 109 insertions(+), 51 deletions(-) [+]
line wrap: on
line diff
--- a/src/buddy.c	Thu Mar 13 23:28:25 2003 +0000
+++ b/src/buddy.c	Fri Mar 14 01:14:24 2003 +0000
@@ -735,7 +735,9 @@
 	if (!(blist_options & OPT_BLIST_SHOW_ICONS))
 		return NULL;
 
-	file = g_build_filename(gaim_user_dir(), "icons", normalize(b->name), NULL);
+	if ((file = gaim_buddy_get_setting(b, "buddy_icon")) == NULL)
+		return NULL;
+
 	buf = gdk_pixbuf_new_from_file(file, NULL);
 	g_free(file);
 
@@ -783,31 +785,31 @@
 
 		if(tmp) {
 			if(strlen(tmp) > 20)
-				statustext = g_strdup_printf("%.16s...", tmp);
+				statustext = g_strdup_printf("%.20s... ", tmp);
 			else
-				statustext = g_strdup(tmp);
+				statustext = g_strdup_printf("%s ", tmp);
 			g_free(tmp);
 		}
 	}
 
 	if (b->idle) {
 		if (ihrs)
-			idletime = g_strdup_printf(_("Idle (%dh%02dm)"), ihrs, imin);
+			idletime = g_strdup_printf(_("Idle (%dh%02dm) "), ihrs, imin);
 		else
-			idletime = g_strdup_printf(_("Idle (%dm)"), imin);
+			idletime = g_strdup_printf(_("Idle (%dm) "), imin);
 	}
-	
+
 	if (b->evil > 0)
-		warning = g_strdup_printf(_("Warned (%d%%)"), b->evil);
-	
+		warning = g_strdup_printf(_("Warned (%d%%) "), b->evil);
+
 	if (b->idle && blist_options & OPT_BLIST_GREY_IDLERS)
-		text =  g_strdup_printf("<span color='dim grey'>%s</span>\n<span color='dim grey' size='smaller'>%s %s %s</span>",
+		text =  g_strdup_printf("<span color='dim grey'>%s</span>\n<span color='dim grey' size='smaller'>%s%s%s</span>",
 					esc,
 					statustext != NULL ? statustext : "",
 					idletime != NULL ? idletime : "", 
 					warning != NULL ? warning : "");
 	else
-		text = g_strdup_printf("%s\n<span color='dim grey' size='smaller'>%s %s %s</span>", esc, 
+		text = g_strdup_printf("%s\n<span color='dim grey' size='smaller'>%s%s%s</span>", esc,
 				       statustext != NULL ? statustext :  "",
 				       idletime != NULL ? idletime : "", 
 				       warning != NULL ? warning : "");
@@ -1096,6 +1098,8 @@
 
 				if(node->parent && !get_iter_from_node(node->parent, &groupiter)) {
 					/* This buddy's group has not yet been added.  We do that here */
+					GdkPixbuf *groupicon = gtk_widget_render_icon(gtkblist->treeview,
+							GTK_STOCK_OPEN, GTK_ICON_SIZE_SMALL_TOOLBAR, NULL);
 					char *mark = g_strdup_printf("<span weight='bold'>%s</span>",  ((struct group*)node->parent)->name);
 					oldersibling = node->parent->prev;
 
@@ -1106,13 +1110,13 @@
 					/* This is where we create the node and add it. */
 					gtk_tree_store_insert_after(gtkblist->treemodel, &groupiter, NULL, oldersibling ? &oldersiblingiter : NULL);
 					gtk_tree_store_set(gtkblist->treemodel, &groupiter,
-							   STATUS_ICON_COLUMN, gtk_widget_render_icon
-							   (gtkblist->treeview,GTK_STOCK_OPEN,GTK_ICON_SIZE_SMALL_TOOLBAR,NULL),
+							   STATUS_ICON_COLUMN, groupicon,
 							   NAME_COLUMN, mark,
 							   NODE_COLUMN, node->parent,
 							   -1);
 
 					g_free(mark);
+					g_object_unref(G_OBJECT(groupicon));
 
 					expand = TRUE;
 				}
--- a/src/gtkconv.c	Thu Mar 13 23:28:25 2003 +0000
+++ b/src/gtkconv.c	Fri Mar 14 01:14:24 2003 +0000
@@ -1914,6 +1914,7 @@
 {
 	struct gaim_gtk_window *gtkwin;
 	struct gaim_im *im = NULL;
+	struct gaim_gtk_conversation *gtkconv = GAIM_GTK_CONVERSATION(conv);
 
 	gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(conv));
 
@@ -1930,7 +1931,7 @@
 				GTK_IMAGE_MENU_ITEM(gtkwin->menu.typing_icon),
 				gtk_image_new_from_stock(GAIM_STOCK_TYPING,
 					GTK_ICON_SIZE_MENU));
-		gtk_tooltips_set_tip(gtk_tooltips_new(), gtkwin->menu.typing_icon,
+		gtk_tooltips_set_tip(gtkconv->tooltips, gtkwin->menu.typing_icon,
 				_("User is typing..."), NULL);
 	} else if(im && gaim_im_get_typing_state(im) == TYPED) {
 		gtkwin->menu.typing_icon = gtk_image_menu_item_new();
@@ -1938,7 +1939,7 @@
 				GTK_IMAGE_MENU_ITEM(gtkwin->menu.typing_icon),
 				gtk_image_new_from_stock(GAIM_STOCK_TYPED,
 					GTK_ICON_SIZE_MENU));
-		gtk_tooltips_set_tip(gtk_tooltips_new(), gtkwin->menu.typing_icon,
+		gtk_tooltips_set_tip(gtkconv->tooltips, gtkwin->menu.typing_icon,
 				_("User has typed something and paused"), NULL);
 	}
 
@@ -4277,6 +4278,7 @@
 		if (!GTK_WIDGET_REALIZED(gtkconv->tab_label))
 			gtk_widget_realize(gtkconv->tab_label);
 
+		pango_font_description_free(style->font_desc);
 		style->font_desc = pango_font_description_copy(
 				gtk_widget_get_style(gtkconv->tab_label)->font_desc);
 
@@ -4615,6 +4617,8 @@
 	FILE *file;
 	GError *err = NULL;
 
+	struct buddy *buddy;
+
 	void *data;
 	int len, delay;
 
@@ -4643,34 +4647,43 @@
 	if (gaim_conversation_get_gc(conv) == NULL)
 		return;
 
-	data = get_icon_data(gaim_conversation_get_gc(conv),
-						 normalize(gaim_conversation_get_name(conv)),
-						 &len);
-
-	if (!data)
-		return;
-
-	/* this is such an evil hack, i don't know why i'm even considering it.
-	 * we'll do it differently when gdk-pixbuf-loader isn't leaky anymore. */
-	g_snprintf(filename, sizeof(filename),
-			   "%s" G_DIR_SEPARATOR_S "gaimicon-%s.%d",
-			   g_get_tmp_dir(), gaim_conversation_get_name(conv), getpid());
-
-	if (!(file = fopen(filename, "wb")))
-		return;
-
-	fwrite(data, 1, len, file);
-	fclose(file);
-
-	gtkconv->u.im->anim = gdk_pixbuf_animation_new_from_file(filename, &err);
+	if((buddy = gaim_find_buddy(gaim_conversation_get_account(conv),
+					gaim_conversation_get_name(conv))) != NULL) {
+		char *file = gaim_buddy_get_setting(buddy, "buddy_icon");
+		if(file) {
+			gtkconv->u.im->anim = gdk_pixbuf_animation_new_from_file(file, &err);
+			g_free(file);
+		}
+	} else {
+		data = get_icon_data(gaim_conversation_get_gc(conv),
+				normalize(gaim_conversation_get_name(conv)),
+				&len);
+
+		if (!data)
+			return;
+
+		/* this is such an evil hack, i don't know why i'm even considering it.
+		 * we'll do it differently when gdk-pixbuf-loader isn't leaky anymore. */
+		g_snprintf(filename, sizeof(filename),
+				"%s" G_DIR_SEPARATOR_S "gaimicon-%s.%d",
+				g_get_tmp_dir(), gaim_conversation_get_name(conv), getpid());
+
+		if (!(file = fopen(filename, "wb")))
+			return;
+
+		fwrite(data, 1, len, file);
+		fclose(file);
+
+		gtkconv->u.im->anim = gdk_pixbuf_animation_new_from_file(filename, &err);
+		/* make sure we remove the file as soon as possible */
+		unlink(filename);
+	}
 
 	if (err) {
 		debug_printf("Buddy icon error: %s\n", err->message);
 		g_error_free(err);
 	}
 
-	/* make sure we remove the file as soon as possible */
-	unlink(filename);
 
 	if (!gtkconv->u.im->anim)
 		return;
--- a/src/html.c	Thu Mar 13 23:28:25 2003 +0000
+++ b/src/html.c	Fri Mar 14 01:14:24 2003 +0000
@@ -50,7 +50,8 @@
 	int visible = 1;
 	gchar *text2 = g_strdup(text);
 
-	g_return_val_if_fail(text != NULL, NULL);
+	if(!text)
+		return NULL;
 
 	for (i = 0, j = 0; text2[i]; i++) {
 		if (text2[i] == '<') {
--- a/src/list.c	Thu Mar 13 23:28:25 2003 +0000
+++ b/src/list.c	Fri Mar 14 01:14:24 2003 +0000
@@ -164,6 +164,11 @@
 	if (ops)
 		ops->update(gaimbuddylist,(GaimBlistNode*)buddy);
 }
+void gaim_blist_update_buddy_icon(struct buddy *buddy) {
+	struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops;
+	if(ops)
+		ops->update(gaimbuddylist, (GaimBlistNode*)buddy);
+}
 void  gaim_blist_rename_buddy (struct buddy *buddy, const char *name)
 {
 	struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops;
@@ -353,19 +358,26 @@
 
 struct buddy *gaim_find_buddy(struct gaim_account *account, const char *name)
 {
-	GaimBlistNode *group = gaimbuddylist->root;
+	GaimBlistNode *group;
 	GaimBlistNode *buddy;
+	char *norm_name = g_strdup(normalize(name));
+
 	if (!gaimbuddylist)
 		return NULL;
+
+	group = gaimbuddylist->root;
 	while (group) {
 		buddy = group->child;
 		while (buddy) {
-			if (!g_strcasecmp(((struct buddy*)buddy)->name, name) && account == ((struct buddy*)buddy)->account)
+			if (!g_strcasecmp(normalize(((struct buddy*)buddy)->name), norm_name) && account == ((struct buddy*)buddy)->account) {
+				g_free(norm_name);
 				return (struct buddy*)buddy;
+			}
 			buddy = buddy->next;
 		}
 		group = group->next;
 	}
+	g_free(norm_name);
 	return NULL;
 }
 
--- a/src/list.h	Thu Mar 13 23:28:25 2003 +0000
+++ b/src/list.h	Fri Mar 14 01:14:24 2003 +0000
@@ -192,12 +192,20 @@
 
 /**
  * Updates a buddy's warning level.
- * 
+ *
  * @param buddy  The buddy whose warning level has changed
  * @param evil   The warning level as an int from 0 to 100 (or higher, I guess... but that'd be weird)
  */
 void gaim_blist_update_buddy_evil(struct buddy *buddy, int warning);
 
+/**
+ * Updates a buddy's warning level.
+ *
+ * @param buddy  The buddy whose buddy icon has changed
+ */
+void gaim_blist_update_buddy_icon(struct buddy *buddy);
+
+
 
 /**
  * Renames a buddy in the buddy list.
--- a/src/prpl.c	Thu Mar 13 23:28:25 2003 +0000
+++ b/src/prpl.c	Fri Mar 14 01:14:24 2003 +0000
@@ -559,6 +559,7 @@
 	struct icon_data tmp;
 	GList *l;
 	struct icon_data *id;
+	struct buddy *b;
 	tmp.gc = gc;
 	tmp.who = normalize(who);
 	tmp.data=NULL;
@@ -594,21 +595,40 @@
 	/* XXX Buddy Icon should probalby be part of struct buddy instead of this weird global
 	 * linked list stuff. */
 
-	if (gaim_find_buddy(gc->account, who)) { 
-		/* This is one of our buddies, so we'll cache this icon for our buddy list */
-		
-		/* Because only OSCAR does buddy icons right now, I don't feel so bad doing nothing to
-		   save what protocol this is from. */
-		char *filename = g_build_filename(gaim_user_dir(), "icons", normalize(who), NULL);
+	if ((b = gaim_find_buddy(gc->account, who)) != 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))
+			mkdir(dirname, S_IRUSR | S_IWUSR | S_IXUSR);
+
+		g_free(dirname);
+
 		file = fopen(filename, "wb");
-		if (!file)
-			return;
-		fwrite(data, 1, len, file);
-		fclose(file);
+		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);
 }