cpw.malu.xmpp.jingle_ft: 7a3603f1: Enable thumbnails for jingle file transf...

malu at pidgin.im malu at pidgin.im
Tue Jun 1 15:30:46 EDT 2010


-----------------------------------------------------------------
Revision: 7a3603f1fc7bfea83297655c01786ad6e23e8954
Ancestor: db7704ba8c1d93c5a9056eb4d2bef771ede2351d
Author: malu at pidgin.im
Date: 2010-06-01T19:26:25
Branch: im.pidgin.cpw.malu.xmpp.jingle_ft
URL: http://d.pidgin.im/viewmtn/revision/info/7a3603f1fc7bfea83297655c01786ad6e23e8954

Modified files:
        libpurple/protocols/jabber/jingle/file-transfer.c
        libpurple/protocols/jabber/si.c
        libpurple/protocols/jabber/xfer.c
        libpurple/protocols/jabber/xfer.h

ChangeLog: 

Enable thumbnails for jingle file transfers as well

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/jingle/file-transfer.c	4d623466022d3b6d48508a2d2faae858980dd31e
+++ libpurple/protocols/jabber/jingle/file-transfer.c	9247e81da9f81a439aa7a144721cc89ea6066730
@@ -29,6 +29,7 @@ struct _JingleFTPrivate {
 struct _JingleFTPrivate {
 	PurpleXfer *xfer;
 	PurpleCircBuffer *ibb_buffer;
+	gchar *thumbnail_cid;
 };
 
 #define JINGLE_FT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), \
@@ -517,6 +518,10 @@ jingle_file_transfer_xfer_init(PurpleXfe
 			/* start local listen on the S5B transport */
 			jingle_s5b_gather_candidates(session, JINGLE_S5B(transport));
 		}
+
+		/* ask UI to create a thumbnail */
+		JINGLE_FT_GET_PRIVATE(JINGLE_FT(content))->thumbnail_cid =
+			jabber_xfer_add_thumbnail(js, xfer);
 	} else if (xfer->data) {
 		JingleContent *content = (JingleContent *) xfer->data;
 		JingleSession *session = jingle_content_get_session(content);
@@ -686,8 +691,11 @@ jingle_file_transfer_to_xml_internal(Jin
 		const PurpleXfer *xfer = jingle_file_transfer_get_xfer(ft);
 		
 		/* if xfer is NULL, it means it has disconnected */
-		if (xfer)
-			xmlnode_insert_child(offer, jabber_xfer_create_file_element(xfer));
+		if (xfer) {
+			xmlnode_insert_child(offer,
+				jabber_xfer_create_file_element(xfer,
+					JINGLE_FT_GET_PRIVATE(JINGLE_FT(ft))->thumbnail_cid));
+		}
 	}
 	return node;
 }
@@ -757,7 +765,7 @@ jingle_file_transfer_handle_action_inter
 					purple_debug_info("jingle-ft", 
 					    "setting content %p on xfer %p\n", content, xfer);
 					xfer->data = content;
-					purple_xfer_request(xfer);
+					jabber_xfer_request_thumbnail(js, file, xfer);
 				} else {
 					/* TODO: set a reason code */
 					jabber_iq_send(jingle_session_to_packet(session,
@@ -949,7 +957,7 @@ jingle_file_transfer_new_xfer(PurpleConn
 	if (xfer) {
 		purple_xfer_set_init_fnc(xfer, jingle_file_transfer_xfer_init);
 		purple_xfer_set_cancel_send_fnc(xfer, jingle_file_transfer_cancel_send);
-		purple_xfer_set_end_fnc(xfer, jingle_file_transfer_xfer_end);
+		purple_xfer_set_end_fnc(xfer, jingle_file_transfer_xfer_end);		
 	}
 
 	return xfer;
============================================================
--- libpurple/protocols/jabber/si.c	48d0679e2f34e8054eada9480d557ed7c613ba44
+++ libpurple/protocols/jabber/si.c	5b9a60008f2fe230051d80b7db1dcd68983b2033
@@ -953,10 +953,15 @@ static void jabber_si_xfer_send_request(
 {
 	JabberSIXfer *jsx = xfer->data;
 	JabberIq *iq;
-	xmlnode *si, *feature, *x, *field, *option, *value, *file;
+	xmlnode *si, *feature, *x, *field, *option, *value;
+	const gchar *thumbnail_cid = NULL;
 
 	xfer->filename = g_path_get_basename(xfer->local_filename);
 	
+#if ENABLE_FT_THUMBNAILS
+	thumbnail_cid = jabber_xfer_add_thumbnail(jsx->js, xfer);
+#endif
+
 	iq = jabber_iq_new(jsx->js, JABBER_IQ_SET);
 	xmlnode_set_attrib(iq->node, "to", xfer->who);
 	si = xmlnode_new_child(iq->node, "si");
@@ -965,14 +970,8 @@ static void jabber_si_xfer_send_request(
 	xmlnode_set_attrib(si, "id", jsx->stream_id);
 	xmlnode_set_attrib(si, "profile",
 			"http://jabber.org/protocol/si/profile/file-transfer");
-
-	file = jabber_xfer_create_file_element(xfer);
-	xmlnode_insert_child(si, file);
-
-#if ENABLE_FT_THUMBNAILS
-	jabber_xfer_add_thumbnail(jsx->js, file, xfer);
-#endif
-	    
+	xmlnode_insert_child(si,
+		jabber_xfer_create_file_element(xfer, thumbnail_cid));  
 	feature = xmlnode_new_child(si, "feature");
 	xmlnode_set_namespace(feature, "http://jabber.org/protocol/feature-neg");
 	x = xmlnode_new_child(feature, "x");
============================================================
--- libpurple/protocols/jabber/xfer.c	d5c71410896fc9c0a0fe6638c4f296c1ba485ee1
+++ libpurple/protocols/jabber/xfer.c	f0c7875618fd5c5171c44e32eab8df05ef259067
@@ -187,11 +187,11 @@ xmlnode *
 }
  
 xmlnode *
-jabber_xfer_create_file_element(const PurpleXfer *xfer)
+jabber_xfer_create_file_element(const PurpleXfer *xfer, const gchar *thumb_cid)
 {
 	xmlnode *file = xmlnode_new("file");
 	gchar buf[32];
-	
+
 	xmlnode_set_namespace(file,
 			"http://jabber.org/protocol/si/profile/file-transfer");
 	xmlnode_set_attrib(file, "name", xfer->filename);
@@ -200,6 +200,16 @@ jabber_xfer_create_file_element(const Pu
 	/* maybe later we'll do hash and date attribs */
 	/* ... and file transfer thumbnails :) */
 
+	/* add thumbnail, if appropriate */
+	if (thumb_cid) {
+		const gchar *mimetype = purple_xfer_get_thumbnail_mimetype(xfer);
+
+		xmlnode *thumbnail = xmlnode_new_child(file, "thumbnail");
+		xmlnode_set_namespace(thumbnail, NS_THUMBS);
+		xmlnode_set_attrib(thumbnail, "cid", thumb_cid);
+		xmlnode_set_attrib(thumbnail, "mime-type", mimetype);
+	}
+                     
 	return file;
 }
 
@@ -268,26 +278,25 @@ void jabber_xfer_request_thumbnail(Jabbe
 	}
 }
 
-void jabber_xfer_add_thumbnail(JabberStream *js, const xmlnode *file,
-	PurpleXfer *xfer)
+const gchar *
+jabber_xfer_add_thumbnail(JabberStream *js, PurpleXfer *xfer)
 {
 	gconstpointer thumb;
 	gsize thumb_size;
-
+	const gchar *cid = NULL;
+	
 	purple_xfer_prepare_thumbnail(xfer, "jpeg,png");
 
 	/* add thumbnail, if appropriate */
 	if ((thumb = purple_xfer_get_thumbnail(xfer, &thumb_size))) {
 		const gchar *mimetype = purple_xfer_get_thumbnail_mimetype(xfer);
 		JabberData *thumbnail_data =
-			jabber_data_create_from_data(thumb, thumb_size,
-				mimetype, TRUE, js);
-		xmlnode *thumbnail = xmlnode_new_child(file, "thumbnail");
-		xmlnode_set_namespace(thumbnail, NS_THUMBS);
-		xmlnode_set_attrib(thumbnail, "cid", 
-			jabber_data_get_cid(thumbnail_data));
-		xmlnode_set_attrib(thumbnail, "mime-type", mimetype);
+			jabber_data_create_from_data(thumb, thumb_size, mimetype, TRUE, js);		
+
+		cid = jabber_data_get_cid(thumbnail_data);
 		/* cache data */
 		jabber_data_associate_local(thumbnail_data, NULL);
 	}
+
+	return cid;
 }
============================================================
--- libpurple/protocols/jabber/xfer.h	2961f368261beb490b0878a84ae87d2813b01675
+++ libpurple/protocols/jabber/xfer.h	ef5e64ff47a18f752ef3d58149f6a0c24d9026c0
@@ -28,7 +28,8 @@ void jabber_xfer_send(PurpleConnection *
 PurpleXfer *jabber_xfer_new(PurpleConnection *gc, const char *who);
 void jabber_xfer_send(PurpleConnection *gc, const char *who, const char *file);
  
-xmlnode *jabber_xfer_create_file_element(const PurpleXfer *xfer);
+xmlnode *jabber_xfer_create_file_element(const PurpleXfer *xfer,
+	const gchar *thumbnail_cid);
 PurpleXfer *jabber_xfer_create_from_xml(PurpleAccount *account, xmlnode *file, 
 	const gchar *who, gpointer data);
 
@@ -37,8 +38,7 @@ void jabber_xfer_request_thumbnail(Jabbe
 void jabber_xfer_request_thumbnail(JabberStream *js, const xmlnode *file,
 	PurpleXfer *xfer);
 
-void jabber_xfer_add_thumbnail(JabberStream *js, const xmlnode *file,
-	PurpleXfer *xfer);
+const gchar *jabber_xfer_add_thumbnail(JabberStream *js, PurpleXfer *xfer);
 
 #endif /* JABBER_XFER_H */
  


More information about the Commits mailing list