cpw.malu.ft_thumbnails: f009319a: Print the thumbnail along with the offer...

malu at pidgin.im malu at pidgin.im
Thu Oct 22 17:25:41 EDT 2009


-----------------------------------------------------------------
Revision: f009319a480177e111738b76e2b2efd7da2b1dfc
Ancestor: a637b275d2a8a141f2d147d713040348fa01a6d6
Author: malu at pidgin.im
Date: 2009-10-22T21:21:47
Branch: im.pidgin.cpw.malu.ft_thumbnails
URL: http://d.pidgin.im/viewmtn/revision/info/f009319a480177e111738b76e2b2efd7da2b1dfc

Modified files:
        libpurple/ft.c

ChangeLog: 

Print the thumbnail along with the offer message in the conversation

-------------- next part --------------
============================================================
--- libpurple/ft.c	1d0fc28e1b0a37de6f7548a3d851a098a8af72f3
+++ libpurple/ft.c	e76b93a1329b9a66206dcba63d985b2fa85b4588
@@ -212,12 +212,15 @@ purple_xfer_set_status(PurpleXfer *xfer,
 	}
 }
 
-void purple_xfer_conversation_write(PurpleXfer *xfer, char *message, gboolean is_error)
+static void 
+purple_xfer_conversation_write_internal(PurpleXfer *xfer,
+	const char *message, gboolean is_error, gboolean print_thumbnail)
 {
 	PurpleConversation *conv = NULL;
 	PurpleMessageFlags flags = PURPLE_MESSAGE_SYSTEM;
 	char *escaped;
-	
+	const gpointer *thumbnail_data = purple_xfer_get_thumbnail_data(xfer);
+
 	g_return_if_fail(xfer != NULL);
 	g_return_if_fail(message != NULL);
 
@@ -232,10 +235,40 @@ void purple_xfer_conversation_write(Purp
 	if (is_error)
 		flags = PURPLE_MESSAGE_ERROR;
 
-	purple_conversation_write(conv, NULL, escaped, flags, time(NULL));
+	if (print_thumbnail && thumbnail_data) {
+		gchar *message_with_img;
+		gsize size = purple_xfer_get_thumbnail_size(xfer);
+		gpointer data = g_memdup(thumbnail_data, size); 
+		int id = purple_imgstore_add_with_id(data, size, NULL);
+
+		message_with_img = 
+			g_strdup_printf("<img id='%d'/> %s", id, escaped);
+		purple_conversation_write(conv, NULL, message_with_img, flags, 
+			time(NULL));
+		purple_imgstore_unref_by_id(id);
+		g_free(message_with_img);
+	} else {
+		purple_conversation_write(conv, NULL, escaped, flags, time(NULL));
+	}
 	g_free(escaped);
 }
 
+void
+purple_xfer_conversation_write(PurpleXfer *xfer, gchar *message,
+	gboolean is_error)
+{
+	purple_xfer_conversation_write_internal(xfer, message, is_error, FALSE);
+}
+
+/* maybe this one should be exported puplically? */
+static void
+purple_xfer_conversation_write_with_thumbnail(PurpleXfer *xfer,
+	const gchar *message)
+{
+	purple_xfer_conversation_write_internal(xfer, message, FALSE, TRUE);
+}
+
+
 static void purple_xfer_show_file_error(PurpleXfer *xfer, const char *filename)
 {
 	int err = errno;
@@ -478,34 +511,14 @@ purple_xfer_request(PurpleXfer *xfer)
 		else if (purple_xfer_get_filename(xfer) ||
 		           purple_xfer_get_status(xfer) == PURPLE_XFER_STATUS_ACCEPTED)
 		{
-			/* write thumbnail to the conversation, if there is one */
-			const gpointer *thumbnail_data = 
-				purple_xfer_get_thumbnail_data(xfer);
 			gchar* message = NULL;
 			PurpleBuddy *buddy = purple_find_buddy(xfer->account, xfer->who);
 
 			message = g_strdup_printf(_("%s is offering to send file %s"),
 				buddy ? purple_buddy_get_alias(buddy) : xfer->who, purple_xfer_get_filename(xfer));
-			purple_xfer_conversation_write(xfer, message, FALSE);
+			purple_xfer_conversation_write_with_thumbnail(xfer, message);
 			g_free(message);
-			if (thumbnail_data) {
-				PurpleConversation *conv =
-					purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM,
-						xfer->who, purple_xfer_get_account(xfer));
-				if (conv) {
-					gsize size = purple_xfer_get_thumbnail_size(xfer);
-					gpointer data = g_memdup(thumbnail_data, size); 
-					int id = purple_imgstore_add_with_id(data, size, NULL);
 
-					message = g_strdup_printf("<img id='%d'/>", id);
-					purple_conversation_write(conv, NULL, message,
-						PURPLE_MESSAGE_SYSTEM, time(NULL));
-					purple_imgstore_unref_by_id(id);
-					g_free(message);
-				}
-			}			
-
-
 			/* Ask for a filename to save to if it's not already given by a plugin */
 			if (xfer->local_filename == NULL)
 				purple_xfer_ask_recv(xfer);


More information about the Commits mailing list