| 1161 } |
1161 } |
| 1162 |
1162 |
| 1163 static void |
1163 static void |
| 1164 pidgin_xfer_add_thumbnail(PurpleXfer *xfer) |
1164 pidgin_xfer_add_thumbnail(PurpleXfer *xfer) |
| 1165 { |
1165 { |
| |
1166 PurpleAccount *account = purple_xfer_get_account(xfer); |
| |
1167 PurpleConnection *gc = purple_account_get_connection(account); |
| |
1168 PurplePluginProtocolInfo *prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl); |
| |
1169 const char *thumbnail_format = prpl_info->thumbnail_spec.format; |
| |
1170 |
| 1166 purple_debug_info("pidgin", "creating thumbnail for transfer\n"); |
1171 purple_debug_info("pidgin", "creating thumbnail for transfer\n"); |
| 1167 |
1172 |
| 1168 if (purple_xfer_get_size(xfer) <= PIDGIN_XFER_MAX_SIZE_IMAGE_THUMBNAIL) { |
1173 if (thumbnail_format != NULL && |
| |
1174 purple_xfer_get_size(xfer) <= PIDGIN_XFER_MAX_SIZE_IMAGE_THUMBNAIL) { |
| 1169 GdkPixbuf *thumbnail = |
1175 GdkPixbuf *thumbnail = |
| 1170 gdk_pixbuf_new_from_file_at_size( |
1176 gdk_pixbuf_new_from_file_at_size( |
| 1171 purple_xfer_get_local_filename(xfer), 128, 128, NULL); |
1177 purple_xfer_get_local_filename(xfer), 128, 128, NULL); |
| 1172 |
1178 |
| 1173 if (thumbnail) { |
1179 if (thumbnail) { |
| |
1180 gchar **formats = g_strsplit(thumbnail_format, ",", 0); |
| 1174 gchar *buffer = NULL; |
1181 gchar *buffer = NULL; |
| 1175 gsize size; |
1182 gsize size; |
| 1176 char *option_keys[2] = {"compression", NULL}; |
1183 char *option_keys[2] = {NULL, NULL}; |
| 1177 char *option_values[2] = {"9", NULL}; |
1184 char *option_values[2] = {NULL, NULL}; |
| 1178 gdk_pixbuf_save_to_bufferv(thumbnail, &buffer, &size, "png", |
1185 gboolean supports_jpeg = FALSE; |
| |
1186 gboolean supports_png = FALSE; |
| |
1187 int i; |
| |
1188 gchar *format = NULL; |
| |
1189 |
| |
1190 for (i = 0 ; formats[i] ; i++) { |
| |
1191 if (purple_strequal(formats[i], "jpeg")) { |
| |
1192 supports_jpeg = TRUE; |
| |
1193 } else if (purple_strequal(formats[i], "png")) { |
| |
1194 supports_png = TRUE; |
| |
1195 } |
| |
1196 } |
| |
1197 |
| |
1198 /* prefer JPEG, then PNG, otherwise try the first format given |
| |
1199 by the PRPL without options */ |
| |
1200 if (supports_jpeg) { |
| |
1201 purple_debug_info("pidgin", "creating JPEG thumbnail\n"); |
| |
1202 option_keys[0] = "quality"; |
| |
1203 option_keys[1] = NULL; |
| |
1204 option_values[0] = "90"; |
| |
1205 option_values[1] = NULL; |
| |
1206 format = "jpeg"; |
| |
1207 } else if (supports_png) { |
| |
1208 purple_debug_info("pidgin", "creating PNG thumbnail\n"); |
| |
1209 option_keys[0] = "compression"; |
| |
1210 option_keys[1] = NULL; |
| |
1211 option_values[0] = "9"; |
| |
1212 option_values[1] = NULL; |
| |
1213 format = "png"; |
| |
1214 } else { |
| |
1215 purple_debug_info("pidgin", |
| |
1216 "creating thumbnail of format %s as demanded by PRPL\n", |
| |
1217 formats[0]); |
| |
1218 format = formats[0]; |
| |
1219 } |
| |
1220 |
| |
1221 gdk_pixbuf_save_to_bufferv(thumbnail, &buffer, &size, format, |
| 1179 option_keys, option_values, NULL); |
1222 option_keys, option_values, NULL); |
| 1180 |
1223 |
| 1181 if (buffer) { |
1224 if (buffer) { |
| |
1225 const gchar *mimetype = g_strdup_printf("image/%s", format); |
| 1182 purple_debug_info("pidgin", |
1226 purple_debug_info("pidgin", |
| 1183 "created thumbnail of %" G_GSIZE_FORMAT " bytes\n", |
1227 "created thumbnail of %" G_GSIZE_FORMAT " bytes\n", |
| 1184 size); |
1228 size); |
| 1185 purple_xfer_set_thumbnail(xfer, buffer, size); |
1229 purple_xfer_set_thumbnail(xfer, buffer, size, mimetype); |
| 1186 g_free(buffer); |
1230 g_free(buffer); |
| |
1231 g_free(mimetype); |
| 1187 } |
1232 } |
| 1188 g_object_unref(thumbnail); |
1233 g_object_unref(thumbnail); |
| |
1234 g_strfreev(formats); |
| 1189 } |
1235 } |
| 1190 } |
1236 } |
| 1191 } |
1237 } |
| 1192 |
1238 |
| 1193 static PurpleXferUiOps ops = |
1239 static PurpleXferUiOps ops = |