cpw.malu.ft_thumbnails: 1a7d573c: Add code to generate a thumbnail (only f...
malu at pidgin.im
malu at pidgin.im
Thu Jun 25 16:50:36 EDT 2009
-----------------------------------------------------------------
Revision: 1a7d573c69fd6b6c59eb00cd0fb698b8b6d76363
Ancestor: e968dce6e9f1a0688dff7463f0b6ec5458fd7c42
Author: malu at pidgin.im
Date: 2009-06-25T20:46:11
Branch: im.pidgin.cpw.malu.ft_thumbnails
URL: http://d.pidgin.im/viewmtn/revision/info/1a7d573c69fd6b6c59eb00cd0fb698b8b6d76363
Modified files:
libpurple/protocols/jabber/si.c pidgin/gtkft.c
ChangeLog:
Add code to generate a thumbnail (only fully works with GDK 2.4+ so far)
-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/si.c d84149e9c34f10d65b45b45bf56e50ee3819ada0
+++ libpurple/protocols/jabber/si.c b80705ff08bf341a6d8821ceb988ef5ea2ddf8a5
@@ -1260,7 +1260,8 @@ static void jabber_si_xfer_send_request(
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");
============================================================
--- pidgin/gtkft.c 277b73dac5a654e69a564f3db7276253a4341297
+++ pidgin/gtkft.c 08e05022a60358ca607e3efd1ec4a34a94e66a12
@@ -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_cancel_remote(PurpleXfer *xf
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,9 +1235,9 @@ static PurpleXferUiOps ops =
pidgin_xfer_update_progress,
pidgin_xfer_cancel_local,
pidgin_xfer_cancel_remote,
+ pidgin_xfer_add_thumbnail,
NULL,
NULL,
- NULL,
NULL
};
More information about the Commits
mailing list