comparison libpurple/ft.c @ 29807:d0730ad1c7df

propagate from branch 'im.pidgin.pidgin' (head cd4ab1e30725817663f30bcb4d6cbe22879b271f) to branch 'im.pidgin.cpw.malu.ft_thumbnails' (head f009319a480177e111738b76e2b2efd7da2b1dfc)
author Marcus Lundblad <ml@update.uu.se>
date Mon, 26 Oct 2009 22:16:32 +0000
parents 56b67321b7c6
children b0f1698c52f8
comparison
equal deleted inserted replaced
28443:342c05db42dd 29807:d0730ad1c7df
134 g_free(xfer->filename); 134 g_free(xfer->filename);
135 g_free(xfer->remote_ip); 135 g_free(xfer->remote_ip);
136 g_free(xfer->local_filename); 136 g_free(xfer->local_filename);
137 137
138 g_hash_table_remove(xfers_data, xfer); 138 g_hash_table_remove(xfers_data, xfer);
139 g_free(xfer->thumbnail_data);
139 140
140 PURPLE_DBUS_UNREGISTER_POINTER(xfer); 141 PURPLE_DBUS_UNREGISTER_POINTER(xfer);
141 xfers = g_list_remove(xfers, xfer); 142 xfers = g_list_remove(xfers, xfer);
142 g_free(xfer); 143 g_free(xfer);
143 } 144 }
209 break; 210 break;
210 } 211 }
211 } 212 }
212 } 213 }
213 214
214 void purple_xfer_conversation_write(PurpleXfer *xfer, char *message, gboolean is_error) 215 static void
216 purple_xfer_conversation_write_internal(PurpleXfer *xfer,
217 const char *message, gboolean is_error, gboolean print_thumbnail)
215 { 218 {
216 PurpleConversation *conv = NULL; 219 PurpleConversation *conv = NULL;
217 PurpleMessageFlags flags = PURPLE_MESSAGE_SYSTEM; 220 PurpleMessageFlags flags = PURPLE_MESSAGE_SYSTEM;
218 char *escaped; 221 char *escaped;
222 const gpointer *thumbnail_data = purple_xfer_get_thumbnail_data(xfer);
219 223
220 g_return_if_fail(xfer != NULL); 224 g_return_if_fail(xfer != NULL);
221 g_return_if_fail(message != NULL); 225 g_return_if_fail(message != NULL);
222 226
223 conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, xfer->who, 227 conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, xfer->who,
229 escaped = g_markup_escape_text(message, -1); 233 escaped = g_markup_escape_text(message, -1);
230 234
231 if (is_error) 235 if (is_error)
232 flags = PURPLE_MESSAGE_ERROR; 236 flags = PURPLE_MESSAGE_ERROR;
233 237
234 purple_conversation_write(conv, NULL, escaped, flags, time(NULL)); 238 if (print_thumbnail && thumbnail_data) {
239 gchar *message_with_img;
240 gsize size = purple_xfer_get_thumbnail_size(xfer);
241 gpointer data = g_memdup(thumbnail_data, size);
242 int id = purple_imgstore_add_with_id(data, size, NULL);
243
244 message_with_img =
245 g_strdup_printf("<img id='%d'/> %s", id, escaped);
246 purple_conversation_write(conv, NULL, message_with_img, flags,
247 time(NULL));
248 purple_imgstore_unref_by_id(id);
249 g_free(message_with_img);
250 } else {
251 purple_conversation_write(conv, NULL, escaped, flags, time(NULL));
252 }
235 g_free(escaped); 253 g_free(escaped);
236 } 254 }
255
256 void
257 purple_xfer_conversation_write(PurpleXfer *xfer, gchar *message,
258 gboolean is_error)
259 {
260 purple_xfer_conversation_write_internal(xfer, message, is_error, FALSE);
261 }
262
263 /* maybe this one should be exported puplically? */
264 static void
265 purple_xfer_conversation_write_with_thumbnail(PurpleXfer *xfer,
266 const gchar *message)
267 {
268 purple_xfer_conversation_write_internal(xfer, message, FALSE, TRUE);
269 }
270
237 271
238 static void purple_xfer_show_file_error(PurpleXfer *xfer, const char *filename) 272 static void purple_xfer_show_file_error(PurpleXfer *xfer, const char *filename)
239 { 273 {
240 int err = errno; 274 int err = errno;
241 gchar *msg = NULL, *utf8; 275 gchar *msg = NULL, *utf8;
396 430
397 if (xfer->message != NULL) 431 if (xfer->message != NULL)
398 serv_got_im(purple_account_get_connection(xfer->account), 432 serv_got_im(purple_account_get_connection(xfer->account),
399 xfer->who, xfer->message, 0, time(NULL)); 433 xfer->who, xfer->message, 0, time(NULL));
400 434
401 purple_request_accept_cancel(xfer, NULL, buf, NULL, 435 if (purple_xfer_get_thumbnail_data(xfer)) {
402 PURPLE_DEFAULT_ACTION_NONE, 436 purple_request_accept_cancel_with_icon(xfer, NULL, buf, NULL,
403 xfer->account, xfer->who, NULL, 437 PURPLE_DEFAULT_ACTION_NONE, xfer->account, xfer->who, NULL,
404 xfer, 438 purple_xfer_get_thumbnail_data(xfer),
405 G_CALLBACK(purple_xfer_choose_file), 439 purple_xfer_get_thumbnail_size(xfer), xfer,
406 G_CALLBACK(cancel_recv_cb)); 440 G_CALLBACK(purple_xfer_choose_file),
407 441 G_CALLBACK(cancel_recv_cb));
442 } else {
443 purple_request_accept_cancel(xfer, NULL, buf, NULL,
444 PURPLE_DEFAULT_ACTION_NONE, xfer->account, xfer->who, NULL,
445 xfer, G_CALLBACK(purple_xfer_choose_file),
446 G_CALLBACK(cancel_recv_cb));
447 }
448
408 g_free(buf); 449 g_free(buf);
409 } else 450 } else
410 purple_xfer_choose_file(xfer); 451 purple_xfer_choose_file(xfer);
411 } 452 }
412 453
470 else if (purple_xfer_get_filename(xfer) || 511 else if (purple_xfer_get_filename(xfer) ||
471 purple_xfer_get_status(xfer) == PURPLE_XFER_STATUS_ACCEPTED) 512 purple_xfer_get_status(xfer) == PURPLE_XFER_STATUS_ACCEPTED)
472 { 513 {
473 gchar* message = NULL; 514 gchar* message = NULL;
474 PurpleBuddy *buddy = purple_find_buddy(xfer->account, xfer->who); 515 PurpleBuddy *buddy = purple_find_buddy(xfer->account, xfer->who);
516
475 message = g_strdup_printf(_("%s is offering to send file %s"), 517 message = g_strdup_printf(_("%s is offering to send file %s"),
476 buddy ? purple_buddy_get_alias(buddy) : xfer->who, purple_xfer_get_filename(xfer)); 518 buddy ? purple_buddy_get_alias(buddy) : xfer->who, purple_xfer_get_filename(xfer));
477 purple_xfer_conversation_write(xfer, message, FALSE); 519 purple_xfer_conversation_write_with_thumbnail(xfer, message);
478 g_free(message); 520 g_free(message);
521
479 /* Ask for a filename to save to if it's not already given by a plugin */ 522 /* Ask for a filename to save to if it's not already given by a plugin */
480 if (xfer->local_filename == NULL) 523 if (xfer->local_filename == NULL)
481 purple_xfer_ask_recv(xfer); 524 purple_xfer_ask_recv(xfer);
482 } 525 }
483 else 526 else
1457 ui_ops = purple_xfer_get_ui_ops(xfer); 1500 ui_ops = purple_xfer_get_ui_ops(xfer);
1458 if (ui_ops != NULL && ui_ops->update_progress != NULL) 1501 if (ui_ops != NULL && ui_ops->update_progress != NULL)
1459 ui_ops->update_progress(xfer, purple_xfer_get_progress(xfer)); 1502 ui_ops->update_progress(xfer, purple_xfer_get_progress(xfer));
1460 } 1503 }
1461 1504
1505 const void *
1506 purple_xfer_get_thumbnail_data(const PurpleXfer *xfer)
1507 {
1508 return xfer->thumbnail_data;
1509 }
1510
1511 gsize
1512 purple_xfer_get_thumbnail_size(const PurpleXfer *xfer)
1513 {
1514 return xfer->thumbnail_size;
1515 }
1516
1517 void
1518 purple_xfer_set_thumbnail(PurpleXfer *xfer, gconstpointer thumbnail,
1519 gsize size)
1520 {
1521 if (thumbnail && size > 0) {
1522 xfer->thumbnail_data = g_memdup(thumbnail, size);
1523 xfer->thumbnail_size = size;
1524 }
1525 }
1526
1527 void
1528 purple_xfer_prepare_thumbnail(PurpleXfer *xfer)
1529 {
1530 if (xfer->ui_ops->add_thumbnail) {
1531 xfer->ui_ops->add_thumbnail(xfer);
1532 }
1533 }
1462 1534
1463 /************************************************************************** 1535 /**************************************************************************
1464 * File Transfer Subsystem API 1536 * File Transfer Subsystem API
1465 **************************************************************************/ 1537 **************************************************************************/
1466 void * 1538 void *