Mercurial > pidgin.yaz
comparison pidgin/gtkft.c @ 30238:79bb2804a19e
Set desired image formats for thumbnails as a parameter to
purple_xfer_prepare_thumbnail instead of putting it in PrplInfo
author | Marcus Lundblad <ml@update.uu.se> |
---|---|
date | Tue, 16 Mar 2010 23:14:54 +0000 |
parents | 25a53c299713 |
children | 0bc8e250ae0d |
comparison
equal
deleted
inserted
replaced
30237:25a53c299713 | 30238:79bb2804a19e |
---|---|
1159 if (xfer_dialog) | 1159 if (xfer_dialog) |
1160 pidgin_xfer_dialog_cancel_xfer(xfer_dialog, xfer); | 1160 pidgin_xfer_dialog_cancel_xfer(xfer_dialog, xfer); |
1161 } | 1161 } |
1162 | 1162 |
1163 static void | 1163 static void |
1164 pidgin_xfer_add_thumbnail(PurpleXfer *xfer) | 1164 pidgin_xfer_add_thumbnail(PurpleXfer *xfer, const gchar *formats) |
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 | |
1171 purple_debug_info("pidgin", "creating thumbnail for transfer\n"); | 1166 purple_debug_info("pidgin", "creating thumbnail for transfer\n"); |
1172 | 1167 |
1173 if (thumbnail_format != NULL && | 1168 if (purple_xfer_get_size(xfer) <= PIDGIN_XFER_MAX_SIZE_IMAGE_THUMBNAIL) { |
1174 purple_xfer_get_size(xfer) <= PIDGIN_XFER_MAX_SIZE_IMAGE_THUMBNAIL) { | |
1175 GdkPixbuf *thumbnail = | 1169 GdkPixbuf *thumbnail = |
1176 gdk_pixbuf_new_from_file_at_size( | 1170 gdk_pixbuf_new_from_file_at_size( |
1177 purple_xfer_get_local_filename(xfer), 128, 128, NULL); | 1171 purple_xfer_get_local_filename(xfer), 128, 128, NULL); |
1178 | 1172 |
1179 if (thumbnail) { | 1173 if (thumbnail) { |
1180 gchar **formats = g_strsplit(thumbnail_format, ",", 0); | 1174 gchar **formats_split = g_strsplit(formats, ",", 0); |
1181 gchar *buffer = NULL; | 1175 gchar *buffer = NULL; |
1182 gsize size; | 1176 gsize size; |
1183 char *option_keys[2] = {NULL, NULL}; | 1177 char *option_keys[2] = {NULL, NULL}; |
1184 char *option_values[2] = {NULL, NULL}; | 1178 char *option_values[2] = {NULL, NULL}; |
1185 gboolean supports_jpeg = FALSE; | 1179 gboolean supports_jpeg = FALSE; |
1186 gboolean supports_png = FALSE; | 1180 gboolean supports_png = FALSE; |
1187 int i; | 1181 int i; |
1188 gchar *format = NULL; | 1182 gchar *format = NULL; |
1189 | 1183 |
1190 for (i = 0 ; formats[i] ; i++) { | 1184 for (i = 0 ; formats_split[i] ; i++) { |
1191 if (purple_strequal(formats[i], "jpeg")) { | 1185 if (purple_strequal(formats_split[i], "jpeg")) { |
1192 supports_jpeg = TRUE; | 1186 supports_jpeg = TRUE; |
1193 } else if (purple_strequal(formats[i], "png")) { | 1187 } else if (purple_strequal(formats_split[i], "png")) { |
1194 supports_png = TRUE; | 1188 supports_png = TRUE; |
1195 } | 1189 } |
1196 } | 1190 } |
1197 | 1191 |
1198 /* prefer JPEG, then PNG, otherwise try the first format given | 1192 /* prefer JPEG, then PNG, otherwise try the first format given |
1212 option_values[1] = NULL; | 1206 option_values[1] = NULL; |
1213 format = "png"; | 1207 format = "png"; |
1214 } else { | 1208 } else { |
1215 purple_debug_info("pidgin", | 1209 purple_debug_info("pidgin", |
1216 "creating thumbnail of format %s as demanded by PRPL\n", | 1210 "creating thumbnail of format %s as demanded by PRPL\n", |
1217 formats[0]); | 1211 formats_split[0]); |
1218 format = formats[0]; | 1212 format = formats_split[0]; |
1219 } | 1213 } |
1220 | 1214 |
1221 gdk_pixbuf_save_to_bufferv(thumbnail, &buffer, &size, format, | 1215 gdk_pixbuf_save_to_bufferv(thumbnail, &buffer, &size, format, |
1222 option_keys, option_values, NULL); | 1216 option_keys, option_values, NULL); |
1223 | 1217 |
1224 if (buffer) { | 1218 if (buffer) { |
1225 const gchar *mimetype = g_strdup_printf("image/%s", format); | 1219 const gchar *mimetype = g_strdup_printf("image/%s", format); |
1226 purple_debug_info("pidgin", | 1220 purple_debug_info("pidgin", |
1227 "created thumbnail of %" G_GSIZE_FORMAT " bytes\n", | 1221 "created thumbnail of %" G_GSIZE_FORMAT " bytes\n", |
1228 size); | 1222 size); |
1229 purple_xfer_set_thumbnail(xfer, buffer, size, mimetype); | 1223 purple_xfer_set_thumbnail(xfer, buffer, size, mimetype); |
1230 g_free(buffer); | 1224 g_free(buffer); |
1231 g_free(mimetype); | 1225 g_free(mimetype); |
1232 } | 1226 } |
1233 g_object_unref(thumbnail); | 1227 g_object_unref(thumbnail); |
1234 g_strfreev(formats); | 1228 g_strfreev(formats_split); |
1235 } | 1229 } |
1236 } | 1230 } |
1237 } | 1231 } |
1238 | 1232 |
1239 static PurpleXferUiOps ops = | 1233 static PurpleXferUiOps ops = |