changeset 30221:56b67321b7c6

Print the thumbnail along with the offer message in the conversation
author Marcus Lundblad <ml@update.uu.se>
date Thu, 22 Oct 2009 21:21:47 +0000
parents bc57ec419847
children d0730ad1c7df
files libpurple/ft.c
diffstat 1 files changed, 37 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/ft.c	Thu Oct 22 19:03:47 2009 +0000
+++ b/libpurple/ft.c	Thu Oct 22 21:21:47 2009 +0000
@@ -212,12 +212,15 @@
 	}
 }
 
-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 @@
 	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,33 +511,13 @@
 		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)