示例#1
0
static gboolean
nautilus_drag_can_accept_files (NautilusFile *drop_target_item)
{
	NautilusDirectory *directory;

	if (nautilus_file_is_directory (drop_target_item)) {
		gboolean res;

		/* target is a directory, accept if editable */
		directory = nautilus_directory_get_for_file (drop_target_item);
		res = nautilus_directory_is_editable (directory);
		nautilus_directory_unref (directory);
		return res;
	}
	
	if (NAUTILUS_IS_DESKTOP_ICON_FILE (drop_target_item)) {
		return TRUE;
	}
	
	/* Launchers are an acceptable drop target */
	if (nautilus_file_is_launcher (drop_target_item)) {
		return TRUE;
	}

	if (nautilus_is_file_roller_installed () &&
	    nautilus_file_is_archive (drop_target_item)) {
		return TRUE;
	}
	
	return FALSE;
}
示例#2
0
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);
	
}
示例#3
0
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);
	
}