diff options
Diffstat (limited to 'widgets')
-rw-r--r-- | widgets/misc/e-attachment-button.c | 44 | ||||
-rw-r--r-- | widgets/misc/e-attachment-view.c | 45 | ||||
-rw-r--r-- | widgets/misc/e-attachment.c | 37 | ||||
-rw-r--r-- | widgets/misc/e-attachment.h | 1 |
4 files changed, 122 insertions, 5 deletions
diff --git a/widgets/misc/e-attachment-button.c b/widgets/misc/e-attachment-button.c index d1b02c09f3..a248cf6ca4 100644 --- a/widgets/misc/e-attachment-button.c +++ b/widgets/misc/e-attachment-button.c @@ -247,6 +247,18 @@ attachment_button_expand_clicked_cb (EAttachmentButton *button) } static void +attachment_button_expand_drag_begin_cb (EAttachmentButton *button, + GdkDragContext *context) +{ + EAttachmentView *view; + + view = e_attachment_button_get_view (button); + + attachment_button_select_path (button); + e_attachment_view_drag_begin (view, context); +} + +static void attachment_button_expand_drag_data_get_cb (EAttachmentButton *button, GdkDragContext *context, GtkSelectionData *selection, @@ -255,14 +267,23 @@ attachment_button_expand_drag_data_get_cb (EAttachmentButton *button, { EAttachmentView *view; - attachment_button_select_path (button); - view = e_attachment_button_get_view (button); e_attachment_view_drag_data_get ( view, context, selection, info, time); } +static void +attachment_button_expand_drag_end_cb (EAttachmentButton *button, + GdkDragContext *context) +{ + EAttachmentView *view; + + view = e_attachment_button_get_view (button); + + e_attachment_view_drag_end (view, context); +} + static gboolean attachment_button_toggle_button_press_event_cb (EAttachmentButton *button, GdkEventButton *event) @@ -579,20 +600,39 @@ attachment_button_init (EAttachmentButton *button) G_CALLBACK (attachment_button_expand_clicked_cb), button); g_signal_connect_swapped ( + button->priv->expand_button, "drag-begin", + G_CALLBACK (attachment_button_expand_drag_begin_cb), + button); + + g_signal_connect_swapped ( button->priv->expand_button, "drag-data-get", G_CALLBACK (attachment_button_expand_drag_data_get_cb), button); g_signal_connect_swapped ( + button->priv->expand_button, "drag-end", + G_CALLBACK (attachment_button_expand_drag_end_cb), + button); + + g_signal_connect_swapped ( button->priv->toggle_button, "button-press-event", G_CALLBACK (attachment_button_toggle_button_press_event_cb), button); g_signal_connect_swapped ( + button->priv->toggle_button, "drag-begin", + G_CALLBACK (attachment_button_expand_drag_begin_cb), + button); + + g_signal_connect_swapped ( button->priv->toggle_button, "drag-data-get", G_CALLBACK (attachment_button_expand_drag_data_get_cb), button); + g_signal_connect_swapped ( + button->priv->toggle_button, "drag-end", + G_CALLBACK (attachment_button_expand_drag_end_cb), + button); } GType diff --git a/widgets/misc/e-attachment-view.c b/widgets/misc/e-attachment-view.c index b810e402c4..36356e8724 100644 --- a/widgets/misc/e-attachment-view.c +++ b/widgets/misc/e-attachment-view.c @@ -1218,8 +1218,6 @@ e_attachment_view_motion_notify_event (EAttachmentView *view, context = gtk_drag_begin ( widget, targets, GDK_ACTION_COPY, 1, (GdkEvent *) event); - gtk_drag_set_icon_default (context); - return TRUE; } @@ -1408,6 +1406,7 @@ e_attachment_view_drag_begin (EAttachmentView *view, GdkDragContext *context) { EAttachmentViewPrivate *priv; + guint n_selected; g_return_if_fail (E_IS_ATTACHMENT_VIEW (view)); g_return_if_fail (GDK_IS_DRAG_CONTEXT (context)); @@ -1421,6 +1420,48 @@ e_attachment_view_drag_begin (EAttachmentView *view, g_warn_if_fail (priv->selected == NULL); priv->selected = e_attachment_view_get_selected_attachments (view); + n_selected = g_list_length (priv->selected); + + if (n_selected > 1) + gtk_drag_set_icon_stock ( + context, GTK_STOCK_DND_MULTIPLE, 0, 0); + + else if (n_selected == 1) { + EAttachment *attachment; + GtkIconTheme *icon_theme; + GtkIconInfo *icon_info; + GIcon *icon; + gint width, height; + + attachment = E_ATTACHMENT (priv->selected->data); + icon = e_attachment_get_icon (attachment); + g_return_if_fail (icon != NULL); + + icon_theme = gtk_icon_theme_get_default (); + gtk_icon_size_lookup (GTK_ICON_SIZE_DND, &width, &height); + + icon_info = gtk_icon_theme_lookup_by_gicon ( + icon_theme, icon, MIN (width, height), + GTK_ICON_LOOKUP_USE_BUILTIN); + + if (icon_info != NULL) { + GdkPixbuf *pixbuf; + GError *error = NULL; + + pixbuf = gtk_icon_info_load_icon (icon_info, &error); + + if (pixbuf != NULL) { + gtk_drag_set_icon_pixbuf ( + context, pixbuf, 0, 0); + g_object_unref (pixbuf); + } else if (error != NULL) { + g_warning ("%s", error->message); + g_error_free (error); + } + + gtk_icon_info_free (icon_info); + } + } } void diff --git a/widgets/misc/e-attachment.c b/widgets/misc/e-attachment.c index ba4e4004b3..1872de6b77 100644 --- a/widgets/misc/e-attachment.c +++ b/widgets/misc/e-attachment.c @@ -56,6 +56,7 @@ struct _EAttachmentPrivate { GFile *file; + GIcon *icon; GFileInfo *file_info; GCancellable *cancellable; CamelMimePart *mime_part; @@ -85,6 +86,7 @@ enum { PROP_ENCRYPTED, PROP_FILE, PROP_FILE_INFO, + PROP_ICON, PROP_LOADING, PROP_MIME_PART, PROP_PERCENT, @@ -357,7 +359,11 @@ attachment_update_icon_column (EAttachment *attachment) E_ATTACHMENT_STORE_COLUMN_ICON, icon, -1); - g_object_unref (icon); + /* Cache the icon to reuse for things like drag-n-drop. */ + if (attachment->priv->icon != NULL) + g_object_unref (attachment->priv->icon); + attachment->priv->icon = icon; + g_object_notify (G_OBJECT (attachment), "icon"); } static void @@ -601,6 +607,12 @@ attachment_get_property (GObject *object, E_ATTACHMENT (object))); return; + case PROP_ICON: + g_value_set_object ( + value, e_attachment_get_icon ( + E_ATTACHMENT (object))); + return; + case PROP_SHOWN: g_value_set_boolean ( value, e_attachment_get_shown ( @@ -659,6 +671,11 @@ attachment_dispose (GObject *object) priv->file = NULL; } + if (priv->icon != NULL) { + g_object_unref (priv->icon); + priv->icon = NULL; + } + if (priv->file_info != NULL) { g_object_unref (priv->file_info); priv->file_info = NULL; @@ -773,6 +790,16 @@ attachment_class_init (EAttachmentClass *class) g_object_class_install_property ( object_class, + PROP_ICON, + g_param_spec_object ( + "icon", + "Icon", + NULL, + G_TYPE_ICON, + G_PARAM_READABLE)); + + g_object_class_install_property ( + object_class, PROP_LOADING, g_param_spec_boolean ( "loading", @@ -1178,6 +1205,14 @@ e_attachment_get_file_info (EAttachment *attachment) return attachment->priv->file_info; } +GIcon * +e_attachment_get_icon (EAttachment *attachment) +{ + g_return_val_if_fail (E_IS_ATTACHMENT (attachment), NULL); + + return attachment->priv->icon; +} + gboolean e_attachment_get_loading (EAttachment *attachment) { diff --git a/widgets/misc/e-attachment.h b/widgets/misc/e-attachment.h index 7cd655c6ff..8b9edc988d 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); +GIcon * e_attachment_get_icon (EAttachment *attachment); gboolean e_attachment_get_loading (EAttachment *attachment); CamelMimePart * e_attachment_get_mime_part (EAttachment *attachment); void e_attachment_set_mime_part (EAttachment *attachment, |