Mercurial > pidgin
comparison libpurple/ft.c @ 29833:834038426c38
Minor cleanup.
* g_free is NULL-safe.
* No need for an extra * on the gpointer.
* Adium doesn't like / in their <img> tags.
* purple_xfer_set_thumbnail should free previous data.
author | Elliott Sales de Andrade <qulogic@pidgin.im> |
---|---|
date | Sun, 25 Apr 2010 20:38:17 +0000 |
parents | 2ab17571bf42 |
children | afc9cec164e4 |
comparison
equal
deleted
inserted
replaced
29832:2ab17571bf42 | 29833:834038426c38 |
---|---|
74 PurpleXferPrivData *priv = data; | 74 PurpleXferPrivData *priv = data; |
75 | 75 |
76 if (priv->buffer) | 76 if (priv->buffer) |
77 g_byte_array_free(priv->buffer, TRUE); | 77 g_byte_array_free(priv->buffer, TRUE); |
78 | 78 |
79 if (priv->thumbnail_data) | 79 g_free(priv->thumbnail_data); |
80 g_free(priv->thumbnail_data); | 80 |
81 | 81 g_free(priv->thumbnail_mimetype); |
82 if (priv->thumbnail_mimetype) | |
83 g_free(priv->thumbnail_mimetype); | |
84 | 82 |
85 g_free(priv); | 83 g_free(priv); |
86 } | 84 } |
87 | 85 |
88 static const gchar * | 86 static const gchar * |
281 const char *message, gboolean is_error, gboolean print_thumbnail) | 279 const char *message, gboolean is_error, gboolean print_thumbnail) |
282 { | 280 { |
283 PurpleConversation *conv = NULL; | 281 PurpleConversation *conv = NULL; |
284 PurpleMessageFlags flags = PURPLE_MESSAGE_SYSTEM; | 282 PurpleMessageFlags flags = PURPLE_MESSAGE_SYSTEM; |
285 char *escaped; | 283 char *escaped; |
286 const gpointer *thumbnail_data = purple_xfer_get_thumbnail_data(xfer); | 284 gconstpointer thumbnail_data = purple_xfer_get_thumbnail_data(xfer); |
287 | 285 |
288 g_return_if_fail(xfer != NULL); | 286 g_return_if_fail(xfer != NULL); |
289 g_return_if_fail(message != NULL); | 287 g_return_if_fail(message != NULL); |
290 | 288 |
291 conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, xfer->who, | 289 conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, xfer->who, |
304 gsize size = purple_xfer_get_thumbnail_size(xfer); | 302 gsize size = purple_xfer_get_thumbnail_size(xfer); |
305 gpointer data = g_memdup(thumbnail_data, size); | 303 gpointer data = g_memdup(thumbnail_data, size); |
306 int id = purple_imgstore_add_with_id(data, size, NULL); | 304 int id = purple_imgstore_add_with_id(data, size, NULL); |
307 | 305 |
308 message_with_img = | 306 message_with_img = |
309 g_strdup_printf("<img id='%d'/> %s", id, escaped); | 307 g_strdup_printf("<img id='%d'> %s", id, escaped); |
310 purple_conversation_write(conv, NULL, message_with_img, flags, | 308 purple_conversation_write(conv, NULL, message_with_img, flags, |
311 time(NULL)); | 309 time(NULL)); |
312 purple_imgstore_unref_by_id(id); | 310 purple_imgstore_unref_by_id(id); |
313 g_free(message_with_img); | 311 g_free(message_with_img); |
314 } else { | 312 } else { |
322 gboolean is_error) | 320 gboolean is_error) |
323 { | 321 { |
324 purple_xfer_conversation_write_internal(xfer, message, is_error, FALSE); | 322 purple_xfer_conversation_write_internal(xfer, message, is_error, FALSE); |
325 } | 323 } |
326 | 324 |
327 /* maybe this one should be exported puplically? */ | 325 /* maybe this one should be exported publically? */ |
328 static void | 326 static void |
329 purple_xfer_conversation_write_with_thumbnail(PurpleXfer *xfer, | 327 purple_xfer_conversation_write_with_thumbnail(PurpleXfer *xfer, |
330 const gchar *message) | 328 const gchar *message) |
331 { | 329 { |
332 purple_xfer_conversation_write_internal(xfer, message, FALSE, TRUE); | 330 purple_xfer_conversation_write_internal(xfer, message, FALSE, TRUE); |
1660 purple_xfer_set_thumbnail(PurpleXfer *xfer, gconstpointer thumbnail, | 1658 purple_xfer_set_thumbnail(PurpleXfer *xfer, gconstpointer thumbnail, |
1661 gsize size, const gchar *mimetype) | 1659 gsize size, const gchar *mimetype) |
1662 { | 1660 { |
1663 PurpleXferPrivData *priv = g_hash_table_lookup(xfers_data, xfer); | 1661 PurpleXferPrivData *priv = g_hash_table_lookup(xfers_data, xfer); |
1664 | 1662 |
1663 g_free(priv->thumbnail_data); | |
1664 g_free(priv->thumbnail_mimetype); | |
1665 | |
1665 if (thumbnail && size > 0) { | 1666 if (thumbnail && size > 0) { |
1666 priv->thumbnail_data = g_memdup(thumbnail, size); | 1667 priv->thumbnail_data = g_memdup(thumbnail, size); |
1667 priv->thumbnail_size = size; | 1668 priv->thumbnail_size = size; |
1668 priv->thumbnail_mimetype = g_strdup(mimetype); | 1669 priv->thumbnail_mimetype = g_strdup(mimetype); |
1670 } else { | |
1671 priv->thumbnail_data = NULL; | |
1672 priv->thumbnail_size = 0; | |
1673 priv->thumbnail_mimetype = NULL; | |
1669 } | 1674 } |
1670 } | 1675 } |
1671 | 1676 |
1672 void | 1677 void |
1673 purple_xfer_prepare_thumbnail(PurpleXfer *xfer, const gchar *formats) | 1678 purple_xfer_prepare_thumbnail(PurpleXfer *xfer, const gchar *formats) |