Commit ec8713a0 authored by Pavel Cisler's avatar Pavel Cisler Committed by Pavel Cisler

reviewed by: Darin Adler <darin@eazel.com>

2001-03-08  Pavel Cisler  <pavel@eazel.com>

	reviewed by: Darin Adler  <darin@eazel.com>

	Fixed 7500 (Dragging WebDAV file to Trash has no effect.)

	* libnautilus-extensions/nautilus-file-operations.c:
	* libnautilus-extensions/nautilus-file-operations.h:
	(nautilus_file_operations_move_to_trash):
	Got rid of the call.

	* src/file-manager/fm-directory-view.c: (trash_callback),
	(fm_directory_view_can_move_uri_to_trash),
	(trash_or_delete_files_common),
	(fm_directory_view_trash_or_delete_files),
	(report_broken_symbolic_link),
	Got rid of callers to the eliminated nautilus_file_operations_move_to_trash,
	Rework the trash and move calls to all operate on uri strings rather than
	NautilusFile objects.

	* src/file-manager/fm-directory-view.c:
	(fm_directory_view_move_copy_items):
	Detect a move to Trash, handle it with trash_or_delete_files_common.

	* libnautilus-extensions/nautilus-file-operations.c:
	(nautilus_file_operations_copy_move),
	Added a FIXME.
parent 43f38730
2001-03-08 Pavel Cisler <pavel@eazel.com>
reviewed by: Darin Adler <darin@eazel.com>
Fixed 7500 (Dragging WebDAV file to Trash has no effect.)
* libnautilus-extensions/nautilus-file-operations.c:
* libnautilus-extensions/nautilus-file-operations.h:
(nautilus_file_operations_move_to_trash):
Got rid of the call.
* src/file-manager/fm-directory-view.c: (trash_callback),
(fm_directory_view_can_move_uri_to_trash),
(trash_or_delete_files_common),
(fm_directory_view_trash_or_delete_files),
(report_broken_symbolic_link),
Got rid of callers to the eliminated nautilus_file_operations_move_to_trash,
Rework the trash and move calls to all operate on uri strings rather than
NautilusFile objects.
* src/file-manager/fm-directory-view.c:
(fm_directory_view_move_copy_items):
Detect a move to Trash, handle it with trash_or_delete_files_common.
* libnautilus-extensions/nautilus-file-operations.c:
(nautilus_file_operations_copy_move),
Added a FIXME.
2001-03-08 Maciej Stachowiak <mjs@eazel.com>
reviewed by: Adam Elman <aelman@eazel.com>
......
......@@ -1909,6 +1909,12 @@ nautilus_file_operations_copy_move (const GList *item_uris,
result = GNOME_VFS_ERROR_NOT_PERMITTED;
break;
}
/* FIXME:
* We should not have the case where a folder containing trash is moved into
* the trash give a generic "cannot move into itself" message, rather,
* we should have a trash specific message here.
*/
/* Don't allow recursive move/copy into itself.
* (We would get a file system error if we proceeded but it is nicer to
......@@ -2103,121 +2109,6 @@ nautilus_file_operations_new_folder (GtkWidget *parent_view,
gnome_vfs_uri_unref (parent_uri);
}
void
nautilus_file_operations_move_to_trash (const GList *item_uris,
GtkWidget *parent_view)
{
const GList *p;
GnomeVFSURI *trash_dir_uri;
GnomeVFSURI *source_uri;
GList *source_uri_list, *target_uri_list;
GnomeVFSResult result;
TransferInfo *transfer_info;
gboolean bail;
char *text;
char *item_name;
const char *source_uri_text;
g_assert (item_uris != NULL);
trash_dir_uri = NULL;
source_uri_list = NULL;
target_uri_list = NULL;
result = GNOME_VFS_OK;
/* build the source and uri list, checking if any of the delete itmes are Trash */
for (p = item_uris; p != NULL; p = p->next) {
bail = FALSE;
source_uri_text = (const char *) p->data;
source_uri = gnome_vfs_uri_new (source_uri_text);
source_uri_list = g_list_prepend (source_uri_list, source_uri);
if (trash_dir_uri == NULL) {
GnomeVFSURI *source_dir_uri;
source_dir_uri = gnome_vfs_uri_get_parent (source_uri);
result = gnome_vfs_find_directory (source_dir_uri, GNOME_VFS_DIRECTORY_KIND_TRASH,
&trash_dir_uri, FALSE, FALSE, 0777);
gnome_vfs_uri_unref (source_dir_uri);
}
if (result != GNOME_VFS_OK) {
break;
}
g_assert (trash_dir_uri != NULL);
target_uri_list = g_list_prepend (target_uri_list, append_basename (trash_dir_uri, source_uri));
if (gnome_vfs_uri_equal (source_uri, trash_dir_uri)) {
nautilus_run_simple_dialog
(parent_view,
FALSE,
_("The Trash must remain on the desktop."),
_("Can't Change Trash Location"),
GNOME_STOCK_BUTTON_OK, NULL, NULL);
bail = TRUE;
} else if (gnome_vfs_uri_is_parent (source_uri, trash_dir_uri, TRUE)) {
item_name = extract_and_ellipsize_file_name_for_dialog (source_uri_text);
text = g_strdup_printf
(_("You cannot throw \"%s\" into the Trash."),
item_name);
nautilus_run_simple_dialog
(parent_view, FALSE, text,
_("Error Moving to Trash"),
GNOME_STOCK_BUTTON_OK, NULL, NULL);
bail = TRUE;
g_free (text);
g_free (item_name);
}
if (bail) {
result = GNOME_VFS_ERROR_NOT_PERMITTED;
break;
}
}
source_uri_list = g_list_reverse (source_uri_list);
target_uri_list = g_list_reverse (target_uri_list);
if (result == GNOME_VFS_OK) {
g_assert (trash_dir_uri != NULL);
/* set up the move parameters */
transfer_info = transfer_info_new (parent_view);
/* Do an arbitrary guess that an operation will take very little
* time and the progress shouldn't be shown.
*/
transfer_info->show_progress_dialog = g_list_length ((GList *)item_uris) > 20;
/* localizers: progress dialog title */
transfer_info->operation_title = _("Moving files to the Trash");
/* localizers: label prepended to the progress count */
transfer_info->action_label =_("Files thrown out:");
/* localizers: label prepended to the name of the current file moved */
transfer_info->progress_verb =_("Moving");
transfer_info->preparation_name =_("Preparing to Move to Trash...");
transfer_info->cleanup_name ="";
transfer_info->error_mode = GNOME_VFS_XFER_ERROR_MODE_QUERY;
transfer_info->overwrite_mode = GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE;
transfer_info->kind = TRANSFER_MOVE_TO_TRASH;
gnome_vfs_async_xfer (&transfer_info->handle, source_uri_list, target_uri_list,
GNOME_VFS_XFER_REMOVESOURCE | GNOME_VFS_XFER_USE_UNIQUE_NAMES,
GNOME_VFS_XFER_ERROR_MODE_QUERY,
GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE,
update_transfer_callback, transfer_info,
sync_transfer_callback, NULL);
}
gnome_vfs_uri_list_free (source_uri_list);
gnome_vfs_uri_list_free (target_uri_list);
gnome_vfs_uri_unref (trash_dir_uri);
}
void
nautilus_file_operations_delete (const GList *item_uris,
GtkWidget *parent_view)
......
......@@ -42,8 +42,6 @@ void nautilus_file_operations_copy_move (const GList
GtkWidget *parent_view,
NautilusCopyCallback done_callback,
gpointer done_callback_data);
void nautilus_file_operations_move_to_trash (const GList *item_uris,
GtkWidget *parent_view);
void nautilus_file_operations_empty_trash (GtkWidget *parent_view);
void nautilus_file_operations_new_folder (GtkWidget *parent_view,
const char *parent_dir_uri,
......
......@@ -1909,6 +1909,12 @@ nautilus_file_operations_copy_move (const GList *item_uris,
result = GNOME_VFS_ERROR_NOT_PERMITTED;
break;
}
/* FIXME:
* We should not have the case where a folder containing trash is moved into
* the trash give a generic "cannot move into itself" message, rather,
* we should have a trash specific message here.
*/
/* Don't allow recursive move/copy into itself.
* (We would get a file system error if we proceeded but it is nicer to
......@@ -2103,121 +2109,6 @@ nautilus_file_operations_new_folder (GtkWidget *parent_view,
gnome_vfs_uri_unref (parent_uri);
}
void
nautilus_file_operations_move_to_trash (const GList *item_uris,
GtkWidget *parent_view)
{
const GList *p;
GnomeVFSURI *trash_dir_uri;
GnomeVFSURI *source_uri;
GList *source_uri_list, *target_uri_list;
GnomeVFSResult result;
TransferInfo *transfer_info;
gboolean bail;
char *text;
char *item_name;
const char *source_uri_text;
g_assert (item_uris != NULL);
trash_dir_uri = NULL;
source_uri_list = NULL;
target_uri_list = NULL;
result = GNOME_VFS_OK;
/* build the source and uri list, checking if any of the delete itmes are Trash */
for (p = item_uris; p != NULL; p = p->next) {
bail = FALSE;
source_uri_text = (const char *) p->data;
source_uri = gnome_vfs_uri_new (source_uri_text);
source_uri_list = g_list_prepend (source_uri_list, source_uri);
if (trash_dir_uri == NULL) {
GnomeVFSURI *source_dir_uri;
source_dir_uri = gnome_vfs_uri_get_parent (source_uri);
result = gnome_vfs_find_directory (source_dir_uri, GNOME_VFS_DIRECTORY_KIND_TRASH,
&trash_dir_uri, FALSE, FALSE, 0777);
gnome_vfs_uri_unref (source_dir_uri);
}
if (result != GNOME_VFS_OK) {
break;
}
g_assert (trash_dir_uri != NULL);
target_uri_list = g_list_prepend (target_uri_list, append_basename (trash_dir_uri, source_uri));
if (gnome_vfs_uri_equal (source_uri, trash_dir_uri)) {
nautilus_run_simple_dialog
(parent_view,
FALSE,
_("The Trash must remain on the desktop."),
_("Can't Change Trash Location"),
GNOME_STOCK_BUTTON_OK, NULL, NULL);
bail = TRUE;
} else if (gnome_vfs_uri_is_parent (source_uri, trash_dir_uri, TRUE)) {
item_name = extract_and_ellipsize_file_name_for_dialog (source_uri_text);
text = g_strdup_printf
(_("You cannot throw \"%s\" into the Trash."),
item_name);
nautilus_run_simple_dialog
(parent_view, FALSE, text,
_("Error Moving to Trash"),
GNOME_STOCK_BUTTON_OK, NULL, NULL);
bail = TRUE;
g_free (text);
g_free (item_name);
}
if (bail) {
result = GNOME_VFS_ERROR_NOT_PERMITTED;
break;
}
}
source_uri_list = g_list_reverse (source_uri_list);
target_uri_list = g_list_reverse (target_uri_list);
if (result == GNOME_VFS_OK) {
g_assert (trash_dir_uri != NULL);
/* set up the move parameters */
transfer_info = transfer_info_new (parent_view);
/* Do an arbitrary guess that an operation will take very little
* time and the progress shouldn't be shown.
*/
transfer_info->show_progress_dialog = g_list_length ((GList *)item_uris) > 20;
/* localizers: progress dialog title */
transfer_info->operation_title = _("Moving files to the Trash");
/* localizers: label prepended to the progress count */
transfer_info->action_label =_("Files thrown out:");
/* localizers: label prepended to the name of the current file moved */
transfer_info->progress_verb =_("Moving");
transfer_info->preparation_name =_("Preparing to Move to Trash...");
transfer_info->cleanup_name ="";
transfer_info->error_mode = GNOME_VFS_XFER_ERROR_MODE_QUERY;
transfer_info->overwrite_mode = GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE;
transfer_info->kind = TRANSFER_MOVE_TO_TRASH;
gnome_vfs_async_xfer (&transfer_info->handle, source_uri_list, target_uri_list,
GNOME_VFS_XFER_REMOVESOURCE | GNOME_VFS_XFER_USE_UNIQUE_NAMES,
GNOME_VFS_XFER_ERROR_MODE_QUERY,
GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE,
update_transfer_callback, transfer_info,
sync_transfer_callback, NULL);
}
gnome_vfs_uri_list_free (source_uri_list);
gnome_vfs_uri_list_free (target_uri_list);
gnome_vfs_uri_unref (trash_dir_uri);
}
void
nautilus_file_operations_delete (const GList *item_uris,
GtkWidget *parent_view)
......
......@@ -42,8 +42,6 @@ void nautilus_file_operations_copy_move (const GList
GtkWidget *parent_view,
NautilusCopyCallback done_callback,
gpointer done_callback_data);
void nautilus_file_operations_move_to_trash (const GList *item_uris,
GtkWidget *parent_view);
void nautilus_file_operations_empty_trash (GtkWidget *parent_view);
void nautilus_file_operations_new_folder (GtkWidget *parent_view,
const char *parent_dir_uri,
......
......@@ -190,8 +190,8 @@ static void fm_directory_view_duplicate_selection
static void fm_directory_view_create_links_for_files (FMDirectoryView *view,
GList *files,
GArray *item_locations);
static void fm_directory_view_trash_or_delete_files (FMDirectoryView *view,
GList *files);
static void fm_directory_view_trash_or_delete_files (const GList *files,
FMDirectoryView *view);
static void fm_directory_view_destroy (GtkObject *object);
static void fm_directory_view_activate_file (FMDirectoryView *view,
NautilusFile *file,
......@@ -750,7 +750,7 @@ trash_callback (BonoboUIComponent *component, gpointer callback_data, const char
view = FM_DIRECTORY_VIEW (callback_data);
selection = fm_directory_view_get_selection (view);
if (selection_not_empty_in_menu_callback (view, selection)) {
fm_directory_view_trash_or_delete_files (view, selection);
fm_directory_view_trash_or_delete_files (selection, view);
}
nautilus_file_list_free (selection);
......@@ -2552,19 +2552,27 @@ special_link_in_selection (FMDirectoryView *view)
}
static gboolean
fm_directory_view_can_move_file_to_trash (FMDirectoryView *view, NautilusFile *file)
fm_directory_view_can_move_uri_to_trash (FMDirectoryView *view, const char *file_uri_string)
{
/* Return TRUE if we can get a trash directory on the same volume as this file. */
char *directory;
GnomeVFSURI *file_uri;
GnomeVFSURI *directory_uri;
GnomeVFSURI *trash_dir_uri;
gboolean result;
directory = nautilus_file_get_parent_uri (file);
if (directory == NULL) {
g_return_val_if_fail (FM_IS_DIRECTORY_VIEW (view), FALSE);
g_return_val_if_fail (file_uri_string != NULL, FALSE);
file_uri = gnome_vfs_uri_new (file_uri_string);
g_return_val_if_fail (file_uri != NULL, FALSE);
directory_uri = gnome_vfs_uri_get_parent (file_uri);
gnome_vfs_uri_unref (file_uri);
if (directory_uri == NULL) {
return FALSE;
}
directory_uri = gnome_vfs_uri_new (directory);
/* Create a new trash if needed but don't go looking for an old Trash.
*/
......@@ -2579,7 +2587,6 @@ fm_directory_view_can_move_file_to_trash (FMDirectoryView *view, NautilusFile *f
gnome_vfs_uri_unref (trash_dir_uri);
}
gnome_vfs_uri_unref (directory_uri);
g_free (directory);
return result;
}
......@@ -2682,17 +2689,21 @@ confirm_delete_from_trash (FMDirectoryView *view, GList *uris)
}
static void
fm_directory_view_trash_or_delete_files (FMDirectoryView *view, GList *files)
{
GList *file_node;
NautilusFile *file;
trash_or_delete_files_common (const GList *file_uris,
GArray *relative_item_points,
const char *target_uri,
int copy_action,
int x, int y,
FMDirectoryView *view)
{
const GList *file_node;
char *file_uri;
GList *moveable_uris;
GList *unmoveable_uris;
GList *in_trash_uris;
g_assert (FM_IS_DIRECTORY_VIEW (view));
g_assert (files != NULL);
g_assert (file_uris != NULL);
/* Collect three lists: (1) items that can be moved to trash,
* (2) items that can only be deleted in place, and (3) items that
......@@ -2706,21 +2717,22 @@ fm_directory_view_trash_or_delete_files (FMDirectoryView *view, GList *files)
unmoveable_uris = NULL;
in_trash_uris = NULL;
for (file_node = files; file_node != NULL; file_node = file_node->next) {
file = NAUTILUS_FILE (file_node->data);
file_uri = nautilus_file_get_uri (file);
for (file_node = file_uris; file_node != NULL; file_node = file_node->next) {
file_uri = (char *)file_node->data;
if (fm_directory_view_can_move_file_to_trash (view, file)) {
moveable_uris = g_list_prepend (moveable_uris, file_uri);
} else if (nautilus_file_is_in_trash (file)) {
in_trash_uris = g_list_prepend (in_trash_uris, file_uri);
if (fm_directory_view_can_move_uri_to_trash (view, file_uri)) {
moveable_uris = g_list_prepend (moveable_uris, g_strdup (file_uri));
} else if (nautilus_uri_is_in_trash (file_uri)) {
in_trash_uris = g_list_prepend (in_trash_uris, g_strdup (file_uri));
} else {
unmoveable_uris = g_list_prepend (unmoveable_uris, file_uri);
unmoveable_uris = g_list_prepend (unmoveable_uris, g_strdup (file_uri));
}
}
if (moveable_uris != NULL) {
nautilus_file_operations_move_to_trash (moveable_uris, GTK_WIDGET (view));
nautilus_file_operations_copy_move (moveable_uris, relative_item_points,
target_uri, copy_action, GTK_WIDGET (view),
copy_move_done_callback, pre_copy_move (view));
}
if (in_trash_uris != NULL && moveable_uris == NULL && unmoveable_uris == NULL) {
......@@ -2743,6 +2755,25 @@ fm_directory_view_trash_or_delete_files (FMDirectoryView *view, GList *files)
nautilus_g_list_free_deep (in_trash_uris);
}
static void
fm_directory_view_trash_or_delete_files (const GList *files,
FMDirectoryView *view)
{
GList *file_uris;
const GList *node;
file_uris = NULL;
for (node = files; node != NULL; node = node->next) {
file_uris = g_list_prepend (file_uris,
nautilus_file_get_uri ((NautilusFile *) node->data));
}
file_uris = g_list_reverse (file_uris);
trash_or_delete_files_common (file_uris, NULL, NAUTILUS_TRASH_URI,
GDK_ACTION_MOVE, 0, 0, view);
nautilus_g_list_free_deep (file_uris);
}
static void
start_renaming_item (FMDirectoryView *view, const char *uri)
{
......@@ -3471,7 +3502,7 @@ report_broken_symbolic_link (FMDirectoryView *view, NautilusFile *file)
file_as_list.data = file;
file_as_list.next = NULL;
file_as_list.prev = NULL;
fm_directory_view_trash_or_delete_files (view, &file_as_list);
fm_directory_view_trash_or_delete_files (&file_as_list, view);
}
g_free (target_path);
......@@ -4333,7 +4364,6 @@ fm_directory_view_move_copy_items (const GList *item_uris,
int x, int y,
FMDirectoryView *view)
{
CopyMoveDoneData *copy_move_done_data;
char *command_string, *scanner;
int length;
const GList *p;
......@@ -4377,11 +4407,16 @@ fm_directory_view_move_copy_items (const GList *item_uris,
return;
}
copy_move_done_data = pre_copy_move (view);
nautilus_file_operations_copy_move
(item_uris, relative_item_points,
target_uri, copy_action, GTK_WIDGET (view),
copy_move_done_callback, copy_move_done_data);
if (nautilus_uri_is_trash (target_uri)) {
trash_or_delete_files_common (item_uris, relative_item_points,
target_uri, copy_action,
x, y, view);
} else {
nautilus_file_operations_copy_move
(item_uris, relative_item_points,
target_uri, copy_action, GTK_WIDGET (view),
copy_move_done_callback, pre_copy_move (view));
}
}
gboolean
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment