/* Returns a reffed NautilusFile object for this directory, but only if the * NautilusFile object has already been created. */ NautilusFile * nautilus_directory_get_existing_corresponding_file (NautilusDirectory *directory) { NautilusFile *file; char *uri; file = directory->details->as_file; if (file != NULL) { nautilus_file_ref (file); return file; } uri = nautilus_directory_get_uri (directory); file = nautilus_file_get_existing_by_uri (uri); g_free (uri); return file; }
void nautilus_drag_default_drop_action_for_icons (GdkDragContext *context, const char *target_uri_string, const GList *items, int *action) { gboolean same_fs; gboolean target_is_source_parent; const char *dropped_uri; GFile *target, *dropped; GdkDragAction actions; NautilusFile *target_file; if (target_uri_string == NULL) { *action = 0; return; } actions = context->actions & (GDK_ACTION_MOVE | GDK_ACTION_COPY); if (actions == 0) { /* We can't use copy or move, just go with the suggested action. */ *action = context->suggested_action; return; } if (context->suggested_action == GDK_ACTION_ASK) { /* Don't override ask */ *action = context->suggested_action; return; } dropped_uri = ((NautilusDragSelectionItem *)items->data)->uri; target_file = nautilus_file_get_existing_by_uri (dropped_uri); /* * Check for trash URI. We do a find_directory for any Trash directory. * Passing 0 permissions as gnome-vfs would override the permissions * passed with 700 while creating .Trash directory */ if (eel_uri_is_trash (target_uri_string)) { /* Only move to Trash */ if (actions & GDK_ACTION_MOVE) { *action = GDK_ACTION_MOVE; } nautilus_file_unref (target_file); return; } else if (target_file != NULL && nautilus_file_is_launcher (target_file)) { if (actions & GDK_ACTION_MOVE) { *action = GDK_ACTION_MOVE; } nautilus_file_unref (target_file); return; } else if (eel_uri_is_desktop (target_uri_string)) { target = nautilus_get_desktop_location (); if (eel_uri_is_desktop (dropped_uri)) { /* Only move to Desktop icons */ if (actions & GDK_ACTION_MOVE) { *action = GDK_ACTION_MOVE; } nautilus_file_unref (target_file); return; } } else { target = g_file_new_for_uri (target_uri_string); } nautilus_file_unref (target_file); /* Compare the first dropped uri with the target uri for same fs match. */ dropped = g_file_new_for_uri (dropped_uri); same_fs = check_same_fs (target, dropped); target_is_source_parent = g_file_has_prefix (dropped, target); if (same_fs || target_is_source_parent || g_file_has_uri_scheme (dropped, "trash")) { if (actions & GDK_ACTION_MOVE) { *action = GDK_ACTION_MOVE; } else { *action = context->suggested_action; } } else { if (actions & GDK_ACTION_COPY) { *action = GDK_ACTION_COPY; } else { *action = context->suggested_action; } } g_object_unref (target); g_object_unref (dropped); }
static gboolean slot_proxy_drag_motion (GtkWidget *widget, GdkDragContext *context, int x, int y, unsigned int time, gpointer user_data) { NautilusDragSlotProxyInfo *drag_info; NautilusWindowSlot *target_slot; GtkWidget *window; GdkAtom target; int action; char *target_uri; GFile *location; gboolean valid_text_drag; gboolean valid_xds_drag; drag_info = user_data; action = 0; valid_text_drag = FALSE; valid_xds_drag = FALSE; if (gtk_drag_get_source_widget (context) == widget) { goto out; } window = gtk_widget_get_toplevel (widget); g_assert (NAUTILUS_IS_WINDOW (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_file != NULL) { target_uri = nautilus_file_get_uri (drag_info->target_file); } else { if (drag_info->target_slot != NULL) { target_slot = drag_info->target_slot; } else { target_slot = nautilus_window_get_active_slot (NAUTILUS_WINDOW (window)); } if (target_slot != NULL) { location = nautilus_window_slot_get_location (target_slot); target_uri = g_file_get_uri (location); } } if (target_uri != NULL) { NautilusFile *file; gboolean can; file = nautilus_file_get_existing_by_uri (target_uri); can = nautilus_file_can_write (file); g_object_unref (file); if (!can) { action = 0; goto out; } } 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, 0, &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); } else if (drag_info->info == NAUTILUS_ICON_DND_TEXT) { valid_text_drag = TRUE; } else if (drag_info->info == NAUTILUS_ICON_DND_XDNDDIRECTSAVE || drag_info->info == NAUTILUS_ICON_DND_RAW) { valid_xds_drag = TRUE; } } g_free (target_uri); out: if (action != 0 || valid_text_drag || valid_xds_drag) { gtk_drag_highlight (widget); slot_proxy_check_switch_location_timer (drag_info, widget); } else { gtk_drag_unhighlight (widget); slot_proxy_remove_switch_location_timer (drag_info); } gdk_drag_status (context, action, time); return TRUE; }
void nautilus_drag_default_drop_action_for_icons (GdkDragContext *context, const char *target_uri_string, const GList *items, int *action) { gboolean same_fs; gboolean target_is_source_parent; gboolean source_deletable; const char *dropped_uri; GFile *target, *dropped, *dropped_directory; GdkDragAction actions; NautilusFile *dropped_file, *target_file; if (target_uri_string == NULL) { *action = 0; return; } actions = gdk_drag_context_get_actions (context) & (GDK_ACTION_MOVE | GDK_ACTION_COPY); if (actions == 0) { /* We can't use copy or move, just go with the suggested action. */ *action = gdk_drag_context_get_suggested_action (context); return; } if (gdk_drag_context_get_suggested_action (context) == GDK_ACTION_ASK) { /* Don't override ask */ *action = gdk_drag_context_get_suggested_action (context); return; } dropped_uri = ((NautilusDragSelectionItem *)items->data)->uri; dropped_file = nautilus_file_get_existing_by_uri (dropped_uri); target_file = nautilus_file_get_existing_by_uri (target_uri_string); /* * Check for trash URI. We do a find_directory for any Trash directory. * Passing 0 permissions as gnome-vfs would override the permissions * passed with 700 while creating .Trash directory */ if (eel_uri_is_trash (target_uri_string)) { /* Only move to Trash */ if (actions & GDK_ACTION_MOVE) { *action = GDK_ACTION_MOVE; } nautilus_file_unref (dropped_file); nautilus_file_unref (target_file); return; } else if (dropped_file != NULL && nautilus_file_is_launcher (dropped_file)) { if (actions & GDK_ACTION_MOVE) { *action = GDK_ACTION_MOVE; } nautilus_file_unref (dropped_file); nautilus_file_unref (target_file); return; } else if (eel_uri_is_desktop (target_uri_string)) { target = nautilus_get_desktop_location (); nautilus_file_unref (target_file); target_file = nautilus_file_get (target); if (eel_uri_is_desktop (dropped_uri)) { /* Only move to Desktop icons */ if (actions & GDK_ACTION_MOVE) { *action = GDK_ACTION_MOVE; } g_object_unref (target); nautilus_file_unref (dropped_file); nautilus_file_unref (target_file); return; } } else if (target_file != NULL && nautilus_file_is_archive (target_file)) { *action = GDK_ACTION_COPY; nautilus_file_unref (dropped_file); nautilus_file_unref (target_file); return; } else { target = g_file_new_for_uri (target_uri_string); } same_fs = check_same_fs (target_file, dropped_file); nautilus_file_unref (dropped_file); nautilus_file_unref (target_file); /* Compare the first dropped uri with the target uri for same fs match. */ dropped = g_file_new_for_uri (dropped_uri); dropped_directory = g_file_get_parent (dropped); target_is_source_parent = FALSE; if (dropped_directory != NULL) { /* If the dropped file is already in the same directory but is in another filesystem we still want to move, not copy as this is then just a move of a mountpoint to another position in the dir */ target_is_source_parent = g_file_equal (dropped_directory, target); g_object_unref (dropped_directory); } source_deletable = source_is_deletable (dropped); if ((same_fs && source_deletable) || target_is_source_parent || g_file_has_uri_scheme (dropped, "trash")) { if (actions & GDK_ACTION_MOVE) { *action = GDK_ACTION_MOVE; } else { *action = gdk_drag_context_get_suggested_action (context); } } else { if (actions & GDK_ACTION_COPY) { *action = GDK_ACTION_COPY; } else { *action = gdk_drag_context_get_suggested_action (context); } } g_object_unref (target); g_object_unref (dropped); }