diff options
author | Cosimo Cecchi <cosimoc@gnome.org> | 2010-12-21 14:48:59 +0100 |
---|---|---|
committer | Cosimo Cecchi <cosimoc@gnome.org> | 2011-01-11 11:43:17 +0100 |
commit | 97e67f49279ad87737541249ef09b99c4bc1d9fe (patch) | |
tree | 53de9fde101d4c2d6969c778ddf589656ba4b4e9 /libnautilus-private/nautilus-dnd.c | |
parent | cd976fa26099fb8c1f2084a6bae7ac0b05f5e29e (diff) | |
download | nautilus-97e67f49279ad87737541249ef09b99c4bc1d9fe.tar.gz |
dnd: move DnD slot proxying code to src/
Diffstat (limited to 'libnautilus-private/nautilus-dnd.c')
-rw-r--r-- | libnautilus-private/nautilus-dnd.c | 303 |
1 files changed, 0 insertions, 303 deletions
diff --git a/libnautilus-private/nautilus-dnd.c b/libnautilus-private/nautilus-dnd.c index ec6d0bfae..592c4387b 100644 --- a/libnautilus-private/nautilus-dnd.c +++ b/libnautilus-private/nautilus-dnd.c @@ -24,8 +24,6 @@ Ettore Perazzoli <ettore@gnu.org> */ -/* FIXME: This should really be back in Nautilus, not here in Eel. */ - #include <config.h> #include "nautilus-dnd.h" @@ -957,304 +955,3 @@ nautilus_drag_selection_includes_special_link (GList *selection_list) return FALSE; } - -static gboolean -slot_proxy_drag_motion (GtkWidget *widget, - GdkDragContext *context, - int x, - int y, - unsigned int time, - gpointer user_data) -{ - NautilusDragSlotProxyInfo *drag_info; - NautilusWindowSlotInfo *target_slot; - GtkWidget *window; - GdkAtom target; - int action; - char *target_uri; - - drag_info = user_data; - - action = 0; - - if (gtk_drag_get_source_widget (context) == widget) { - goto out; - } - - window = gtk_widget_get_toplevel (widget); - g_assert (NAUTILUS_IS_WINDOW_INFO (window)); - - if (!drag_info->have_data) { - target = gtk_drag_dest_find_target (widget, context, NULL); - - if (target == GDK_NONE) { - goto out; - } - - gtk_drag_get_data (widget, context, target, time); - } - - target_uri = NULL; - if (drag_info->target_location != NULL) { - target_uri = g_file_get_uri (drag_info->target_location); - } else { - if (drag_info->target_slot != NULL) { - target_slot = drag_info->target_slot; - } else { - target_slot = nautilus_window_info_get_active_slot (NAUTILUS_WINDOW_INFO (window)); - } - - if (target_slot != NULL) { - target_uri = nautilus_window_slot_info_get_current_location (target_slot); - } - } - - if (drag_info->have_data && - drag_info->have_valid_data) { - if (drag_info->info == NAUTILUS_ICON_DND_GNOME_ICON_LIST) { - nautilus_drag_default_drop_action_for_icons (context, target_uri, - drag_info->data.selection_list, - &action); - } else if (drag_info->info == NAUTILUS_ICON_DND_URI_LIST) { - action = nautilus_drag_default_drop_action_for_uri_list (context, target_uri); - } else if (drag_info->info == NAUTILUS_ICON_DND_NETSCAPE_URL) { - action = nautilus_drag_default_drop_action_for_netscape_url (context); - } - } - - g_free (target_uri); - -out: - if (action != 0) { - gtk_drag_highlight (widget); - } else { - gtk_drag_unhighlight (widget); - } - - gdk_drag_status (context, action, time); - - return TRUE; -} - -static void -drag_info_clear (NautilusDragSlotProxyInfo *drag_info) -{ - if (!drag_info->have_data) { - goto out; - } - - if (drag_info->info == NAUTILUS_ICON_DND_GNOME_ICON_LIST) { - nautilus_drag_destroy_selection_list (drag_info->data.selection_list); - } else if (drag_info->info == NAUTILUS_ICON_DND_URI_LIST) { - g_list_free (drag_info->data.uri_list); - } else if (drag_info->info == NAUTILUS_ICON_DND_NETSCAPE_URL) { - g_free (drag_info->data.netscape_url); - } - -out: - drag_info->have_data = FALSE; - drag_info->have_valid_data = FALSE; - - drag_info->drop_occured = FALSE; -} - -static void -slot_proxy_drag_leave (GtkWidget *widget, - GdkDragContext *context, - unsigned int time, - gpointer user_data) -{ - NautilusDragSlotProxyInfo *drag_info; - - drag_info = user_data; - - gtk_drag_unhighlight (widget); - drag_info_clear (drag_info); -} - -static gboolean -slot_proxy_drag_drop (GtkWidget *widget, - GdkDragContext *context, - int x, - int y, - unsigned int time, - gpointer user_data) -{ - GdkAtom target; - NautilusDragSlotProxyInfo *drag_info; - - drag_info = user_data; - g_assert (!drag_info->have_data); - - drag_info->drop_occured = TRUE; - - target = gtk_drag_dest_find_target (widget, context, NULL); - gtk_drag_get_data (widget, context, target, time); - - return TRUE; -} - - -static void -slot_proxy_handle_drop (GtkWidget *widget, - GdkDragContext *context, - unsigned int time, - NautilusDragSlotProxyInfo *drag_info) -{ - GtkWidget *window; - NautilusWindowSlotInfo *target_slot; - NautilusView *target_view; - char *target_uri; - GList *uri_list; - - if (!drag_info->have_data || - !drag_info->have_valid_data) { - gtk_drag_finish (context, FALSE, FALSE, time); - drag_info_clear (drag_info); - return; - } - - window = gtk_widget_get_toplevel (widget); - g_assert (NAUTILUS_IS_WINDOW_INFO (window)); - - if (drag_info->target_slot != NULL) { - target_slot = drag_info->target_slot; - } else { - target_slot = nautilus_window_info_get_active_slot (NAUTILUS_WINDOW_INFO (window)); - } - - target_uri = NULL; - if (drag_info->target_location != NULL) { - target_uri = g_file_get_uri (drag_info->target_location); - } else if (target_slot != NULL) { - target_uri = nautilus_window_slot_info_get_current_location (target_slot); - } - - target_view = NULL; - if (target_slot != NULL) { - target_view = nautilus_window_slot_info_get_current_view (target_slot); - } - - if (target_slot != NULL && target_view != NULL) { - if (drag_info->info == NAUTILUS_ICON_DND_GNOME_ICON_LIST) { - uri_list = nautilus_drag_uri_list_from_selection_list (drag_info->data.selection_list); - g_assert (uri_list != NULL); - - nautilus_view_drop_proxy_received_uris (target_view, - uri_list, - target_uri, - gdk_drag_context_get_selected_action (context)); - g_list_free_full (uri_list, g_free); - } else if (drag_info->info == NAUTILUS_ICON_DND_URI_LIST) { - nautilus_view_drop_proxy_received_uris (target_view, - drag_info->data.uri_list, - target_uri, - gdk_drag_context_get_selected_action (context)); - } if (drag_info->info == NAUTILUS_ICON_DND_NETSCAPE_URL) { - nautilus_view_drop_proxy_received_netscape_url (target_view, - drag_info->data.netscape_url, - target_uri, - gdk_drag_context_get_selected_action (context)); - } - - - gtk_drag_finish (context, TRUE, FALSE, time); - } else { - gtk_drag_finish (context, FALSE, FALSE, time); - } - - if (target_view != NULL) { - g_object_unref (target_view); - } - - g_free (target_uri); - - drag_info_clear (drag_info); -} - -static void -slot_proxy_drag_data_received (GtkWidget *widget, - GdkDragContext *context, - int x, - int y, - GtkSelectionData *data, - unsigned int info, - unsigned int time, - gpointer user_data) -{ - NautilusDragSlotProxyInfo *drag_info; - char **uris; - - drag_info = user_data; - - g_assert (!drag_info->have_data); - - drag_info->have_data = TRUE; - drag_info->info = info; - - if (gtk_selection_data_get_length (data) < 0) { - drag_info->have_valid_data = FALSE; - return; - } - - if (info == NAUTILUS_ICON_DND_GNOME_ICON_LIST) { - drag_info->data.selection_list = nautilus_drag_build_selection_list (data); - - drag_info->have_valid_data = drag_info->data.selection_list != NULL; - } else if (info == NAUTILUS_ICON_DND_URI_LIST) { - uris = gtk_selection_data_get_uris (data); - drag_info->data.uri_list = nautilus_drag_uri_list_from_array ((const char **) uris); - g_strfreev (uris); - - drag_info->have_valid_data = drag_info->data.uri_list != NULL; - } else if (info == NAUTILUS_ICON_DND_NETSCAPE_URL) { - drag_info->data.netscape_url = g_strdup ((char *) gtk_selection_data_get_data (data)); - - drag_info->have_valid_data = drag_info->data.netscape_url != NULL; - } - - if (drag_info->drop_occured) { - slot_proxy_handle_drop (widget, context, time, drag_info); - } -} - -void -nautilus_drag_slot_proxy_init (GtkWidget *widget, - NautilusDragSlotProxyInfo *drag_info) -{ - const GtkTargetEntry targets[] = { - { NAUTILUS_ICON_DND_GNOME_ICON_LIST_TYPE, 0, NAUTILUS_ICON_DND_GNOME_ICON_LIST }, - { NAUTILUS_ICON_DND_NETSCAPE_URL_TYPE, 0, NAUTILUS_ICON_DND_NETSCAPE_URL } - }; - GtkTargetList *target_list; - - g_assert (GTK_IS_WIDGET (widget)); - g_assert (drag_info != NULL); - - gtk_drag_dest_set (widget, 0, - NULL, 0, - GDK_ACTION_MOVE | - GDK_ACTION_COPY | - GDK_ACTION_LINK | - GDK_ACTION_ASK); - - target_list = gtk_target_list_new (targets, G_N_ELEMENTS (targets)); - gtk_target_list_add_uri_targets (target_list, NAUTILUS_ICON_DND_URI_LIST); - gtk_drag_dest_set_target_list (widget, target_list); - gtk_target_list_unref (target_list); - - g_signal_connect (widget, "drag-motion", - G_CALLBACK (slot_proxy_drag_motion), - drag_info); - g_signal_connect (widget, "drag-drop", - G_CALLBACK (slot_proxy_drag_drop), - drag_info); - g_signal_connect (widget, "drag-data-received", - G_CALLBACK (slot_proxy_drag_data_received), - drag_info); - g_signal_connect (widget, "drag-leave", - G_CALLBACK (slot_proxy_drag_leave), - drag_info); -} - - |