aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/misc
diff options
context:
space:
mode:
authorMilan Crha <mcrha@redhat.com>2011-02-23 00:00:10 +0800
committerMilan Crha <mcrha@redhat.com>2011-02-23 00:00:10 +0800
commitcb2362dee06e672ddc4b300ba677188ae4a6dc42 (patch)
treeb1aa2d580bf2c4c9413d70fb4ee58c2086c1a897 /widgets/misc
parent3c516cb10a9ec929143b7b806bcdc5be491c0924 (diff)
downloadgsoc2013-evolution-cb2362dee06e672ddc4b300ba677188ae4a6dc42.tar.gz
gsoc2013-evolution-cb2362dee06e672ddc4b300ba677188ae4a6dc42.tar.zst
gsoc2013-evolution-cb2362dee06e672ddc4b300ba677188ae4a6dc42.zip
Bug #623593 - Cannot drag&drop attached messages from mails
Diffstat (limited to 'widgets/misc')
-rw-r--r--widgets/misc/e-attachment-button.c80
-rw-r--r--widgets/misc/e-attachment.c37
-rw-r--r--widgets/misc/e-attachment.h1
3 files changed, 111 insertions, 7 deletions
diff --git a/widgets/misc/e-attachment-button.c b/widgets/misc/e-attachment-button.c
index 7cadf574f7..16ddaab063 100644
--- a/widgets/misc/e-attachment-button.c
+++ b/widgets/misc/e-attachment-button.c
@@ -268,6 +268,50 @@ attachment_button_expand_drag_data_get_cb (EAttachmentButton *button,
{
EAttachmentView *view;
+ if (button->priv->attachment) {
+ gchar *mime_type;
+
+ mime_type = e_attachment_get_mime_type (button->priv->attachment);
+
+ if (mime_type) {
+ gboolean processed = FALSE;
+ GdkAtom atom;
+ gchar *atom_name;
+
+ atom = gtk_selection_data_get_target (selection);
+ atom_name = gdk_atom_name (atom);
+
+ if (g_strcmp0 (atom_name, mime_type) == 0) {
+ CamelMimePart *mime_part;
+
+ mime_part = e_attachment_get_mime_part (button->priv->attachment);
+ if (CAMEL_IS_MIME_PART (mime_part)) {
+ CamelDataWrapper *wrapper;
+ CamelStream *stream;
+ GByteArray *buffer;
+
+ buffer = g_byte_array_new ();
+ stream = camel_stream_mem_new ();
+ camel_stream_mem_set_byte_array (CAMEL_STREAM_MEM (stream), buffer);
+ wrapper = camel_medium_get_content (CAMEL_MEDIUM (mime_part));
+ camel_data_wrapper_decode_to_stream_sync (wrapper, stream, NULL, NULL);
+ g_object_unref (stream);
+
+ gtk_selection_data_set (selection, atom, 8, buffer->data, buffer->len);
+ processed = TRUE;
+
+ g_byte_array_free (buffer, TRUE);
+ }
+ }
+
+ g_free (atom_name);
+ g_free (mime_type);
+
+ if (processed)
+ return;
+ }
+ }
+
view = e_attachment_button_get_view (button);
e_attachment_view_drag_data_get (
@@ -670,6 +714,10 @@ void
e_attachment_button_set_attachment (EAttachmentButton *button,
EAttachment *attachment)
{
+ GtkTargetEntry *targets;
+ GtkTargetList *list;
+ gint n_targets;
+
g_return_if_fail (E_IS_ATTACHMENT_BUTTON (button));
if (attachment != NULL) {
@@ -718,6 +766,38 @@ e_attachment_button_set_attachment (EAttachmentButton *button,
attachment_button_update_pixbufs (button);
}
+ /* update drag sources */
+ list = gtk_target_list_new (NULL, 0);
+ gtk_target_list_add_uri_targets (list, 0);
+
+ if (attachment) {
+ gchar *simple_type;
+
+ simple_type = e_attachment_get_mime_type (attachment);
+ if (simple_type) {
+ GtkTargetEntry attach_entry[] = { { NULL, 0, 2 } };
+
+ attach_entry[0].target = simple_type;
+
+ gtk_target_list_add_table (list, attach_entry, G_N_ELEMENTS (attach_entry));
+
+ g_free (simple_type);
+ }
+ }
+
+ targets = gtk_target_table_new_from_list (list, &n_targets);
+
+ gtk_drag_source_set (
+ button->priv->expand_button, GDK_BUTTON1_MASK,
+ targets, n_targets, GDK_ACTION_COPY);
+
+ gtk_drag_source_set (
+ button->priv->toggle_button, GDK_BUTTON1_MASK,
+ targets, n_targets, GDK_ACTION_COPY);
+
+ gtk_target_table_free (targets, n_targets);
+ gtk_target_list_unref (list);
+
g_object_notify (G_OBJECT (button), "attachment");
}
diff --git a/widgets/misc/e-attachment.c b/widgets/misc/e-attachment.c
index 0a3bfabb05..a96f7ed4ad 100644
--- a/widgets/misc/e-attachment.c
+++ b/widgets/misc/e-attachment.c
@@ -1358,26 +1358,49 @@ e_attachment_get_thumbnail_path (EAttachment *attachment)
return g_file_info_get_attribute_byte_string (file_info, attribute);
}
-gboolean
-e_attachment_is_rfc822 (EAttachment *attachment)
+/**
+ * e_attachment_get_mime_type:
+ *
+ * Returns mime_type part of the file_info as a newly allocated string,
+ * which should be freed with g_free().
+ * Returns NULL, if mime_type not found or set on the attachment.
+ **/
+gchar *
+e_attachment_get_mime_type (EAttachment *attachment)
{
GFileInfo *file_info;
const gchar *content_type;
gchar *mime_type;
- gboolean is_rfc822;
- g_return_val_if_fail (E_IS_ATTACHMENT (attachment), FALSE);
+ g_return_val_if_fail (E_IS_ATTACHMENT (attachment), NULL);
file_info = e_attachment_get_file_info (attachment);
if (file_info == NULL)
- return FALSE;
+ return NULL;
content_type = g_file_info_get_content_type (file_info);
if (content_type == NULL)
- return FALSE;
+ return NULL;
mime_type = g_content_type_get_mime_type (content_type);
- is_rfc822 = (g_ascii_strcasecmp (mime_type, "message/rfc822") == 0);
+ if (!mime_type)
+ return NULL;
+
+ camel_strdown (mime_type);
+
+ return mime_type;
+}
+
+gboolean
+e_attachment_is_rfc822 (EAttachment *attachment)
+{
+ gchar *mime_type;
+ gboolean is_rfc822;
+
+ g_return_val_if_fail (E_IS_ATTACHMENT (attachment), FALSE);
+
+ mime_type = e_attachment_get_mime_type (attachment);
+ is_rfc822 = mime_type && g_ascii_strcasecmp (mime_type, "message/rfc822") == 0;
g_free (mime_type);
return is_rfc822;
diff --git a/widgets/misc/e-attachment.h b/widgets/misc/e-attachment.h
index 8b9edc988d..26eceeb830 100644
--- a/widgets/misc/e-attachment.h
+++ b/widgets/misc/e-attachment.h
@@ -80,6 +80,7 @@ void e_attachment_set_file (EAttachment *attachment,
GFileInfo * e_attachment_get_file_info (EAttachment *attachment);
void e_attachment_set_file_info (EAttachment *attachment,
GFileInfo *file_info);
+gchar * e_attachment_get_mime_type (EAttachment *attachment);
GIcon * e_attachment_get_icon (EAttachment *attachment);
gboolean e_attachment_get_loading (EAttachment *attachment);
CamelMimePart * e_attachment_get_mime_part (EAttachment *attachment);