changeset 30198:afe5c224f3e9

Add code to generate a thumbnail (only fully works with GDK 2.4+ so far)
author Marcus Lundblad <ml@update.uu.se>
date Thu, 25 Jun 2009 20:46:11 +0000
parents 3882d419e628
children bae447e1fa96
files libpurple/protocols/jabber/si.c pidgin/gtkft.c
diffstat 2 files changed, 49 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/si.c	Tue Jun 23 21:33:10 2009 +0000
+++ b/libpurple/protocols/jabber/si.c	Thu Jun 25 20:46:11 2009 +0000
@@ -1260,7 +1260,8 @@
 	char buf[32];
 
 	xfer->filename = g_path_get_basename(xfer->local_filename);
-
+	purple_xfer_prepare_thumbnail(xfer);
+	
 	iq = jabber_iq_new(jsx->js, JABBER_IQ_SET);
 	xmlnode_set_attrib(iq->node, "to", xfer->who);
 	si = xmlnode_new_child(iq->node, "si");
--- a/pidgin/gtkft.c	Tue Jun 23 21:33:10 2009 +0000
+++ b/pidgin/gtkft.c	Thu Jun 25 20:46:11 2009 +0000
@@ -42,6 +42,9 @@
 #define PIDGINXFER(xfer) \
 	(PidginXferUiData *)(xfer)->ui_data
 
+/* the maximum size of files we will try to make a thumbnail for */
+#define PIDGIN_XFER_MAX_SIZE_IMAGE_THUMBNAIL 10 * 1024 * 1024
+
 struct _PidginXferDialog
 {
 	gboolean keep_open;
@@ -1181,6 +1184,49 @@
 		pidgin_xfer_dialog_cancel_xfer(xfer_dialog, xfer);
 }
 
+static void
+pidgin_xfer_add_thumbnail(PurpleXfer *xfer)
+{
+	purple_debug_info("pidgin", "creating thumbnail for transfer\n");
+
+	if (purple_xfer_get_size(xfer) <= PIDGIN_XFER_MAX_SIZE_IMAGE_THUMBNAIL) {
+#if GTK_CHECK_VERSION(2, 4, 0)
+		GdkPixbuf *thumbnail = 
+			gdk_pixbuf_new_from_file_at_size(
+				purple_xfer_get_local_filename(xfer), 128, 128, NULL);
+#else
+		GdkPixbuf *full_size =
+			gdk_pixbuf_from_file(purple_xfer_get_local_filename(xfer), NULL);
+		GdkPixbuf *thumbnail = NULL;
+		
+		if (full_size) {
+			thumbnail = gdk_pixbuf_scale_simple(full_size, 128, 128, 
+				GDK_INTERP_BILINEAR);
+			g_object_unref(full_size);
+		}
+#endif
+		if (thumbnail) {
+			gpointer *buffer = NULL;
+			gsize size;
+#if GTK_CHECK_VERSION(2, 4, 0)
+			char *option_keys[2] = {"quality", NULL};
+			char *option_values[2] = {"75", NULL};
+			gdk_pixbuf_save_to_bufferv(thumbnail, &buffer, &size, "jpeg", 
+				option_keys, option_values, NULL);
+#else
+			/* TODO: */
+#endif
+			if (buffer) {
+				purple_debug_info("pidgin", "created thumbnail of %d bytes\n",
+					size);
+				purple_xfer_set_thumbnail(xfer, buffer, size);
+				g_free(buffer);
+			}
+			g_object_unref(thumbnail);
+		}
+	}
+}
+
 static PurpleXferUiOps ops =
 {
 	pidgin_xfer_new_xfer,
@@ -1189,7 +1235,7 @@
 	pidgin_xfer_update_progress,
 	pidgin_xfer_cancel_local,
 	pidgin_xfer_cancel_remote,
-	NULL,
+	pidgin_xfer_add_thumbnail,
 	NULL,
 	NULL,
 	NULL