nautilus-3.6.3/libnautilus-private/nautilus-file-dnd.c

No issues found

  1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
  2 
  3 /* nautilus-file-drag.c - Drag & drop handling code that operated on 
  4    NautilusFile objects.
  5 
  6    Copyright (C) 2000 Eazel, Inc.
  7 
  8    The Gnome Library is free software; you can redistribute it and/or
  9    modify it under the terms of the GNU Library General Public License as
 10    published by the Free Software Foundation; either version 2 of the
 11    License, or (at your option) any later version.
 12 
 13    The Gnome Library is distributed in the hope that it will be useful,
 14    but WITHOUT ANY WARRANTY; without even the implied warranty of
 15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 16    Library General Public License for more details.
 17 
 18    You should have received a copy of the GNU Library General Public
 19    License along with the Gnome Library; see the file COPYING.LIB.  If not,
 20    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 21    Boston, MA 02111-1307, USA.
 22 
 23    Authors: Pavel Cisler <pavel@eazel.com>,
 24 */
 25 
 26 #include <config.h>
 27 #include "nautilus-file-dnd.h"
 28 #include "nautilus-desktop-icon-file.h"
 29 
 30 #include "nautilus-dnd.h"
 31 #include "nautilus-directory.h"
 32 #include "nautilus-file-utilities.h"
 33 #include <string.h>
 34 
 35 static gboolean
 36 nautilus_drag_can_accept_files (NautilusFile *drop_target_item)
 37 {
 38 	if (nautilus_file_is_directory (drop_target_item)) {
 39 		NautilusDirectory *directory;
 40 		gboolean res;
 41 
 42 		/* target is a directory, accept if editable */
 43 		directory = nautilus_directory_get_for_file (drop_target_item);
 44 		res = nautilus_directory_is_editable (directory) &&
 45 			nautilus_file_can_write (drop_target_item);
 46 		nautilus_directory_unref (directory);
 47 		return res;
 48 	}
 49 	
 50 	if (NAUTILUS_IS_DESKTOP_ICON_FILE (drop_target_item)) {
 51 		return TRUE;
 52 	}
 53 	
 54 	/* Launchers are an acceptable drop target */
 55 	if (nautilus_file_is_launcher (drop_target_item)) {
 56 		return TRUE;
 57 	}
 58 
 59 	if (nautilus_is_file_roller_installed () &&
 60 	    nautilus_file_is_archive (drop_target_item)) {
 61 		return TRUE;
 62 	}
 63 	
 64 	return FALSE;
 65 }
 66 
 67 gboolean
 68 nautilus_drag_can_accept_item (NautilusFile *drop_target_item,
 69 			       const char *item_uri)
 70 {
 71 	if (nautilus_file_matches_uri (drop_target_item, item_uri)) {
 72 		/* can't accept itself */
 73 		return FALSE;
 74 	}
 75 
 76 	return nautilus_drag_can_accept_files (drop_target_item);
 77 }
 78 				       
 79 gboolean
 80 nautilus_drag_can_accept_items (NautilusFile *drop_target_item,
 81 				const GList *items)
 82 {
 83 	int max;
 84 
 85 	if (drop_target_item == NULL)
 86 		return FALSE;
 87 
 88 	g_assert (NAUTILUS_IS_FILE (drop_target_item));
 89 
 90 	/* Iterate through selection checking if item will get accepted by the
 91 	 * drop target. If more than 100 items selected, return an over-optimisic
 92 	 * result
 93 	 */
 94 	for (max = 100; items != NULL && max >= 0; items = items->next, max--) {
 95 		if (!nautilus_drag_can_accept_item (drop_target_item, 
 96 			((NautilusDragSelectionItem *)items->data)->uri)) {
 97 			return FALSE;
 98 		}
 99 	}
100 	
101 	return TRUE;
102 }
103 
104 gboolean
105 nautilus_drag_can_accept_info (NautilusFile *drop_target_item,
106 			       NautilusIconDndTargetType drag_type,
107 			       const GList *items)
108 {
109 	switch (drag_type) {
110 		case NAUTILUS_ICON_DND_GNOME_ICON_LIST:
111 			return nautilus_drag_can_accept_items (drop_target_item, items);
112 
113 		case NAUTILUS_ICON_DND_URI_LIST:
114 		case NAUTILUS_ICON_DND_NETSCAPE_URL:
115 		case NAUTILUS_ICON_DND_TEXT:
116 			return nautilus_drag_can_accept_files (drop_target_item);
117 
118 		case NAUTILUS_ICON_DND_XDNDDIRECTSAVE:
119 		case NAUTILUS_ICON_DND_RAW:
120 			return nautilus_drag_can_accept_files (drop_target_item); /* Check if we can accept files at this location */
121 
122 		case NAUTILUS_ICON_DND_ROOTWINDOW_DROP:
123 			return FALSE;
124 
125 		default:
126 			g_assert_not_reached ();
127 			return FALSE;
128 	}
129 }