From c876eb6b4bff1b10cc56bfd11c6244f779914794 Mon Sep 17 00:00:00 2001 From: Larry Ewing Date: Tue, 1 Oct 2002 20:22:11 +0000 Subject: add support for dragging the content type directly. 2002-10-01 Larry Ewing * mail-display.c (drag_data_get_cb): add support for dragging the content type directly. (do_attachment_header): add the target for the mime type to the drag source. svn path=/trunk/; revision=18288 --- mail/mail-display.c | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) (limited to 'mail/mail-display.c') diff --git a/mail/mail-display.c b/mail/mail-display.c index 4865c11909..3cfb5bf4e7 100644 --- a/mail/mail-display.c +++ b/mail/mail-display.c @@ -149,10 +149,12 @@ static GHashTable *thumbnail_cache = NULL; enum DndTargetType { DND_TARGET_TYPE_TEXT_URI_LIST, + DND_TARGET_TYPE_PART_MIME_TYPE }; static GtkTargetEntry drag_types[] = { { TEXT_URI_LIST_TYPE, 0, DND_TARGET_TYPE_TEXT_URI_LIST }, + { NULL, 0, DND_TARGET_TYPE_PART_MIME_TYPE } }; static const int num_drag_types = sizeof (drag_types) / sizeof (drag_types[0]); @@ -868,7 +870,7 @@ drag_data_get_cb (GtkWidget *widget, CamelMimePart *part = user_data; const char *filename, *tmpdir; char *uri_list; - + switch (info) { case DND_TARGET_TYPE_TEXT_URI_LIST: /* Kludge around Nautilus requesting the same data many times */ @@ -903,8 +905,34 @@ drag_data_get_cb (GtkWidget *widget, gtk_selection_data_set (selection_data, selection_data->target, 8, uri_list, strlen (uri_list)); - gtk_object_set_data_full (GTK_OBJECT (widget), "uri-list", uri_list, g_free); + gtk_object_set_data_full (GTK_OBJECT (widget), "uri-list", uri_list, g_free); + break; + case DND_TARGET_TYPE_PART_MIME_TYPE: + if (header_content_type_is (part->content_type, "text", "*")) { + GByteArray *ba; + + ba = mail_format_get_data_wrapper_text (part, NULL); + if (ba) { + gtk_selection_data_set (selection_data, selection_data->target, 8, + ba->data, ba->len); + g_byte_array_free (ba, TRUE); + } + } else { + CamelDataWrapper *wrapper; + CamelStream *cstream; + GByteArray *ba; + ba = g_byte_array_new (); + + cstream = camel_stream_mem_new_with_byte_array (ba); + wrapper = camel_medium_get_content_object (CAMEL_MEDIUM (part)); + camel_data_wrapper_write_to_stream (wrapper, cstream); + + gtk_selection_data_set (selection_data, selection_data->target, 8, + ba->data, ba->len); + + camel_object_unref (CAMEL_OBJECT (cstream)); + } break; default: g_assert_not_reached (); @@ -971,14 +999,20 @@ do_attachment_header (GtkHTML *html, GtkHTMLEmbedded *eb, gtk_widget_set_sensitive (button, FALSE); /* Drag & Drop */ + drag_types[DND_TARGET_TYPE_PART_MIME_TYPE].target = header_content_type_simple(part->content_type); + g_strdown (drag_types[DND_TARGET_TYPE_PART_MIME_TYPE].target); + gtk_drag_source_set (button, GDK_BUTTON1_MASK, drag_types, num_drag_types, - GDK_ACTION_MOVE); + GDK_ACTION_COPY); gtk_signal_connect (GTK_OBJECT (button), "drag-data-get", drag_data_get_cb, part); gtk_signal_connect (GTK_OBJECT (button), "drag-data-delete", drag_data_delete_cb, part); + g_free (drag_types[DND_TARGET_TYPE_PART_MIME_TYPE].target); + drag_types[DND_TARGET_TYPE_PART_MIME_TYPE].target = NULL; + hbox = gtk_hbox_new (FALSE, 2); gtk_container_set_border_width (GTK_CONTAINER (hbox), 2); -- cgit