Mercurial > pidgin.yaz
comparison pidgin/gtkft.c @ 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 | 65a79c501f58 |
children | 399756f65c88 |
comparison
equal
deleted
inserted
replaced
30197:3882d419e628 | 30198:afe5c224f3e9 |
---|---|
40 #include "gtkutils.h" | 40 #include "gtkutils.h" |
41 | 41 |
42 #define PIDGINXFER(xfer) \ | 42 #define PIDGINXFER(xfer) \ |
43 (PidginXferUiData *)(xfer)->ui_data | 43 (PidginXferUiData *)(xfer)->ui_data |
44 | 44 |
45 /* the maximum size of files we will try to make a thumbnail for */ | |
46 #define PIDGIN_XFER_MAX_SIZE_IMAGE_THUMBNAIL 10 * 1024 * 1024 | |
47 | |
45 struct _PidginXferDialog | 48 struct _PidginXferDialog |
46 { | 49 { |
47 gboolean keep_open; | 50 gboolean keep_open; |
48 gboolean auto_clear; | 51 gboolean auto_clear; |
49 | 52 |
1179 { | 1182 { |
1180 if (xfer_dialog) | 1183 if (xfer_dialog) |
1181 pidgin_xfer_dialog_cancel_xfer(xfer_dialog, xfer); | 1184 pidgin_xfer_dialog_cancel_xfer(xfer_dialog, xfer); |
1182 } | 1185 } |
1183 | 1186 |
1187 static void | |
1188 pidgin_xfer_add_thumbnail(PurpleXfer *xfer) | |
1189 { | |
1190 purple_debug_info("pidgin", "creating thumbnail for transfer\n"); | |
1191 | |
1192 if (purple_xfer_get_size(xfer) <= PIDGIN_XFER_MAX_SIZE_IMAGE_THUMBNAIL) { | |
1193 #if GTK_CHECK_VERSION(2, 4, 0) | |
1194 GdkPixbuf *thumbnail = | |
1195 gdk_pixbuf_new_from_file_at_size( | |
1196 purple_xfer_get_local_filename(xfer), 128, 128, NULL); | |
1197 #else | |
1198 GdkPixbuf *full_size = | |
1199 gdk_pixbuf_from_file(purple_xfer_get_local_filename(xfer), NULL); | |
1200 GdkPixbuf *thumbnail = NULL; | |
1201 | |
1202 if (full_size) { | |
1203 thumbnail = gdk_pixbuf_scale_simple(full_size, 128, 128, | |
1204 GDK_INTERP_BILINEAR); | |
1205 g_object_unref(full_size); | |
1206 } | |
1207 #endif | |
1208 if (thumbnail) { | |
1209 gpointer *buffer = NULL; | |
1210 gsize size; | |
1211 #if GTK_CHECK_VERSION(2, 4, 0) | |
1212 char *option_keys[2] = {"quality", NULL}; | |
1213 char *option_values[2] = {"75", NULL}; | |
1214 gdk_pixbuf_save_to_bufferv(thumbnail, &buffer, &size, "jpeg", | |
1215 option_keys, option_values, NULL); | |
1216 #else | |
1217 /* TODO: */ | |
1218 #endif | |
1219 if (buffer) { | |
1220 purple_debug_info("pidgin", "created thumbnail of %d bytes\n", | |
1221 size); | |
1222 purple_xfer_set_thumbnail(xfer, buffer, size); | |
1223 g_free(buffer); | |
1224 } | |
1225 g_object_unref(thumbnail); | |
1226 } | |
1227 } | |
1228 } | |
1229 | |
1184 static PurpleXferUiOps ops = | 1230 static PurpleXferUiOps ops = |
1185 { | 1231 { |
1186 pidgin_xfer_new_xfer, | 1232 pidgin_xfer_new_xfer, |
1187 pidgin_xfer_destroy, | 1233 pidgin_xfer_destroy, |
1188 pidgin_xfer_add_xfer, | 1234 pidgin_xfer_add_xfer, |
1189 pidgin_xfer_update_progress, | 1235 pidgin_xfer_update_progress, |
1190 pidgin_xfer_cancel_local, | 1236 pidgin_xfer_cancel_local, |
1191 pidgin_xfer_cancel_remote, | 1237 pidgin_xfer_cancel_remote, |
1192 NULL, | 1238 pidgin_xfer_add_thumbnail, |
1193 NULL, | 1239 NULL, |
1194 NULL, | 1240 NULL, |
1195 NULL | 1241 NULL |
1196 }; | 1242 }; |
1197 | 1243 |