Re: [Nautilus-list] Using drag and drop to copy files in Nautilus?



Take two -- this patch applies a little better, and it fixes a problem
with dragging files to the desktop.  (It would create a link file first
and then try to copy the file.  This would popup a warning dialog during
every drag.) 

On 25 Jul 2001 11:15:43 -0400, Jonathan Blandford wrote:
> Benjamin Kahn <xkahn ximian com> writes:
> 
> > I'm writing a small panel applet which allows you to browse your home
> > directory as a panel menu.  
> > 
> > <plug> it's in gnome cvs in module file_menu_applet if you want to check
> > it out.</plug>
> > 
> > Anyway, I've been hooking up drag and drop and it's working okay. Except
> > in Nautilus. I'm trying to make Nautilus copy or move the file, but it
> > isn't working. I'm using text/uri-list as my mime type and Nautilus treats
> > that as a URL link. Reading through the nautilus drag and drop source
> > code, it looks like that's all it will ever do with that mime type.  (I
> > tested it with the panel and with gmc just to be sure.)  
> > 
> > So does this mean that I have to use Nautilus's internal mime
> > type: x-special/gnome-icon-list to perform a move and copy?  Is there any
> > other way to do it?  What risks should I look out for if I use a type is
> > seems obviously internal?
> 
> Surprisingly enough, I just ran into this bug yesterday, and tried to
> fix it a bit (in the redhat-outstanding-patches branch).  It seems like
> the handling of text/uri-list is sort of poor.  I'd like this to be
> improved at some point -- maybe I'll have time today.  If you want to
> look at it, I can tell you where the code is handled.
> 
> Thanks,
> -Jonathan


Index: nautilus/libnautilus-private/nautilus-icon-container.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-icon-container.c,v
retrieving revision 1.216
diff -u -r1.216 nautilus-icon-container.c
--- nautilus/libnautilus-private/nautilus-icon-container.c	2001/07/19 21:35:13	1.216
+++ nautilus/libnautilus-private/nautilus-icon-container.c	2001/07/31 03:27:46
@@ -3224,9 +3224,10 @@
 				  object_class->type,
 				  GTK_SIGNAL_OFFSET (NautilusIconContainerClass, 
 						     handle_uri_list),
-				  gtk_marshal_NONE__POINTER_INT_INT,
-				  GTK_TYPE_NONE, 3,
+				  eel_gtk_marshal_NONE__POINTER_INT_INT_INT,
+				  GTK_TYPE_NONE, 4,
 				  GTK_TYPE_POINTER,
+				  GTK_TYPE_INT,
 				  GTK_TYPE_INT,
 				  GTK_TYPE_INT);
 
Index: nautilus/libnautilus-private/nautilus-icon-dnd.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-icon-dnd.c,v
retrieving revision 1.91
diff -u -r1.91 nautilus-icon-dnd.c
--- nautilus/libnautilus-private/nautilus-icon-dnd.c	2001/07/20 17:36:33	1.91
+++ nautilus/libnautilus-private/nautilus-icon-dnd.c	2001/07/31 03:27:46
@@ -84,6 +84,7 @@
 								  int y);
 static void     receive_dropped_uri_list                          (NautilusIconContainer *container, 
 								  char* keyword, 
+								  GdkDragAction action,
 								  int x, 
 								  int y);
 static void     nautilus_icon_container_free_drag_data           (NautilusIconContainer *container);
@@ -461,7 +462,7 @@
 		case EEL_ICON_DND_URL:
 			receive_dropped_uri_list
 				(NAUTILUS_ICON_CONTAINER (widget),
-				 (char*) data->data, x, y);
+				 (char*) data->data, context->action, x, y);
 			gtk_drag_finish (context, TRUE, FALSE, time);
 			break;
 
@@ -660,7 +661,7 @@
 
 /* handle dropped uri list */
 static void
-receive_dropped_uri_list (NautilusIconContainer *container, char *uri_list, int x, int y)
+receive_dropped_uri_list (NautilusIconContainer *container, char *uri_list, GdkDragAction action, int x, int y)
 {	
 	if (uri_list == NULL) {
 		return;
@@ -668,6 +669,7 @@
 	
 	gtk_signal_emit_by_name (GTK_OBJECT (container), "handle_uri_list",
 				 uri_list,
+				 action,
 				 x, y);
 }
 
Index: nautilus/src/file-manager/fm-desktop-icon-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-desktop-icon-view.c,v
retrieving revision 1.139
diff -u -r1.139 fm-desktop-icon-view.c
--- nautilus/src/file-manager/fm-desktop-icon-view.c	2001/07/23 10:42:36	1.139
+++ nautilus/src/file-manager/fm-desktop-icon-view.c	2001/07/31 03:27:46
@@ -114,6 +114,7 @@
 								   FMDesktopIconView      *icon_view);
 static void     icon_view_handle_uri_list                   	  (NautilusIconContainer  *container,
 								   const char             *item_uris,
+								   GdkDragAction           action,
 								   int                     x,
 								   int                     y,
 								   FMDirectoryView        *view);
@@ -649,11 +650,6 @@
 					desktop_icon_view,
 					GTK_OBJECT (desktop_icon_view));
 	
-	gtk_signal_connect (GTK_OBJECT (icon_container),
-			    "handle_uri_list",
-			    GTK_SIGNAL_FUNC (icon_view_handle_uri_list),
-			    desktop_icon_view);
-
 	eel_preferences_add_callback (NAUTILUS_PREFERENCES_HOME_URI,
 					   home_uri_changed,
 				  	   desktop_icon_view);
@@ -865,7 +861,7 @@
 
 static void
 icon_view_handle_uri_list (NautilusIconContainer *container, const char *item_uris,
-			   int x, int y, FMDirectoryView *view)
+			   GdkDragAction action, int x, int y, FMDirectoryView *view)
 {
 	GList *uri_list, *node;
 	GnomeDesktopEntry *entry;
Index: nautilus/src/file-manager/fm-icon-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-icon-view.c,v
retrieving revision 1.208
diff -u -r1.208 fm-icon-view.c
--- nautilus/src/file-manager/fm-icon-view.c	2001/07/15 09:00:44	1.208
+++ nautilus/src/file-manager/fm-icon-view.c	2001/07/31 03:27:47
@@ -34,6 +34,7 @@
 #include <eel/eel-gtk-extensions.h>
 #include <eel/eel-gtk-macros.h>
 #include <eel/eel-string.h>
+#include <eel/eel-vfs-extensions.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <gtk/gtkmain.h>
@@ -45,10 +46,12 @@
 #include <libgnome/gnome-i18n.h>
 #include <libgnome/gnome-config.h>
 #include <libgnome/gnome-metadata.h>
+#include <libgnome/gnome-mime.h>
 #include <libgnomevfs/gnome-vfs-async-ops.h>
 #include <libgnomevfs/gnome-vfs-uri.h>
 #include <libgnomevfs/gnome-vfs-utils.h>
 #include <libgnomevfs/gnome-vfs-xfer.h>
+#include <libgnomevfs/gnome-vfs-mime.h>
 #include <libnautilus-private/nautilus-audio-player.h>
 #include <libnautilus-private/nautilus-bonobo-extensions.h>
 #include <libnautilus-private/nautilus-directory-background.h>
@@ -115,49 +118,56 @@
 } MenuItemType;
 
 /* forward declarations */
-static void                 create_icon_container                              (FMIconView           *icon_view);
-static void                 fm_icon_view_initialize                            (FMIconView           *icon_view);
-static void                 fm_icon_view_initialize_class                      (FMIconViewClass      *klass);
-static gboolean             fm_icon_view_is_empty                              (FMDirectoryView      *view);
-static void                 fm_icon_view_set_directory_sort_by                 (FMIconView           *icon_view,
-										NautilusFile         *file,
-										const char           *sort_by);
-static void                 fm_icon_view_set_zoom_level                        (FMIconView           *view,
-										NautilusZoomLevel     new_level,
-										gboolean              always_set_level);
-gboolean                    fm_icon_view_supports_auto_layout                  (FMIconView           *view);
-static void                 fm_icon_view_update_icon_container_fonts           (FMIconView           *icon_view);
-static void                 fm_icon_view_update_icon_container_smooth_font     (FMIconView           *icon_view);
-static void                 fm_icon_view_update_icon_container_font_size_table (FMIconView           *icon_view);
-static void                 fm_icon_view_update_click_mode                     (FMIconView           *icon_view);
-static void                 fm_icon_view_update_smooth_graphics_mode           (FMIconView           *icon_view);
-static gboolean             fm_icon_view_using_tighter_layout                  (FMIconView           *icon_view);
-static gboolean             fm_icon_view_get_directory_tighter_layout          (FMIconView           *icon_view,
-										NautilusFile         *file);
-static void                 fm_icon_view_set_directory_tighter_layout          (FMIconView           *icon_view,
-										NautilusFile         *file,
-										gboolean              tighter_layout);
-static gboolean             real_supports_auto_layout                          (FMIconView           *view);
-static const SortCriterion *get_sort_criterion_by_id                           (const char           *id);
-static const SortCriterion *get_sort_criterion_by_sort_type                    (NautilusFileSortType  sort_type);
-static void                 set_sort_criterion_by_id                           (FMIconView           *icon_view,
-										const char           *id);
-static gboolean             set_sort_reversed                                  (FMIconView           *icon_view,
-										gboolean              new_value);
-static void                 switch_to_manual_layout                            (FMIconView           *view);
-static void                 preview_audio                                      (FMIconView           *icon_view,
-										NautilusFile         *file,
-										gboolean              start_flag);
-static void                 update_layout_menus                                (FMIconView           *view);
-static void                 default_sort_in_reverse_order_changed_callback     (gpointer              callback_data);
-static void                 default_sort_order_changed_callback                (gpointer              callback_data);
-static void                 default_use_tighter_layout_changed_callback        (gpointer              callback_data);
-static void                 default_use_manual_layout_changed_callback         (gpointer              callback_data);
-static void                 default_zoom_level_changed_callback                (gpointer              callback_data);
-static void                 default_zoom_level_font_size_changed_callback      (gpointer              callback_data);
-static void                 font_changed_callback                              (gpointer              callback_data);
-static void                 smooth_font_changed_callback                       (gpointer              callback_data);
+static void                 create_icon_container                              (FMIconView            *icon_view);
+static void                 fm_icon_view_initialize                            (FMIconView            *icon_view);
+static void                 fm_icon_view_initialize_class                      (FMIconViewClass       *klass);
+static gboolean             fm_icon_view_is_empty                              (FMDirectoryView       *view);
+static void                 fm_icon_view_set_directory_sort_by                 (FMIconView            *icon_view,
+										NautilusFile          *file,
+										const char            *sort_by);
+static void                 fm_icon_view_set_zoom_level                        (FMIconView            *view,
+										NautilusZoomLevel      new_level,
+										gboolean               always_set_level);
+gboolean                    fm_icon_view_supports_auto_layout                  (FMIconView            *view);
+static void                 fm_icon_view_update_icon_container_fonts           (FMIconView            *icon_view);
+static void                 fm_icon_view_update_icon_container_smooth_font     (FMIconView            *icon_view);
+static void                 fm_icon_view_update_icon_container_font_size_table (FMIconView            *icon_view);
+static void                 fm_icon_view_update_click_mode                     (FMIconView            *icon_view);
+static void                 fm_icon_view_update_smooth_graphics_mode           (FMIconView            *icon_view);
+static gboolean             fm_icon_view_using_tighter_layout                  (FMIconView            *icon_view);
+static gboolean             fm_icon_view_get_directory_tighter_layout          (FMIconView            *icon_view,
+										NautilusFile          *file);
+static void                 fm_icon_view_set_directory_tighter_layout          (FMIconView            *icon_view,
+										NautilusFile          *file,
+										gboolean               tighter_layout);
+static gboolean             real_supports_auto_layout                          (FMIconView            *view);
+static const SortCriterion *get_sort_criterion_by_id                           (const char            *id);
+static const SortCriterion *get_sort_criterion_by_sort_type                    (NautilusFileSortType   sort_type);
+static void                 set_sort_criterion_by_id                           (FMIconView            *icon_view,
+										const char            *id);
+static gboolean             set_sort_reversed                                  (FMIconView            *icon_view,
+										gboolean               new_value);
+static void                 switch_to_manual_layout                            (FMIconView            *view);
+static void                 preview_audio                                      (FMIconView            *icon_view,
+										NautilusFile          *file,
+										gboolean               start_flag);
+static void                 update_layout_menus                                (FMIconView            *view);
+static void                 default_sort_in_reverse_order_changed_callback     (gpointer               callback_data);
+static void                 default_sort_order_changed_callback                (gpointer               callback_data);
+static void                 default_use_tighter_layout_changed_callback        (gpointer               callback_data);
+static void                 default_use_manual_layout_changed_callback         (gpointer               callback_data);
+static void                 default_zoom_level_changed_callback                (gpointer               callback_data);
+static void                 default_zoom_level_font_size_changed_callback      (gpointer               callback_data);
+static void                 font_changed_callback                              (gpointer               callback_data);
+static void                 smooth_font_changed_callback                       (gpointer               callback_data);
+static void                 icon_view_handle_uri_list                          (NautilusIconContainer *container,
+										const char            *item_uris,
+										GdkDragAction          action,
+										int                    x,
+										int                    y,
+										FMIconView            *view);
 
+
 static int preview_sound_auto_value;
 
 EEL_DEFINE_CLASS_BOILERPLATE (FMIconView,
@@ -2001,7 +2011,7 @@
 			char **additional_text,
 			FMIconView *icon_view)
 {
-	char *actual_uri, *path;
+	char *actual_uri;
 	char *attribute_names;
 	char **text_array;
 	int i , slot_index;
@@ -2025,15 +2035,13 @@
 	if (nautilus_file_is_nautilus_link (file)) {
 		/* FIXME bugzilla.eazel.com 2531: Does sync. I/O and works only locally. */
 		actual_uri = nautilus_file_get_uri (file);
-		path = gnome_vfs_get_local_path_from_uri (actual_uri);
-		g_free (actual_uri);
-		if (path != NULL) {
-			*additional_text = nautilus_link_local_get_additional_text (path);
-			g_free (path);
-			return;
-		}
+		*additional_text = NULL;
+		/* This looks pretty bad.  It would be nice to get the additional text to only appear if
+		 * you zoom in a lot */
+		/* *additional_text = nautilus_link_local_get_additional_text (actual_uri); */
+		return;
 	}
-	
+
 	/* Find out what attributes go below each icon. */
 	attribute_names = fm_icon_view_get_icon_text_attribute_names (icon_view);
 	text_array = g_strsplit (attribute_names, "|", 0);
@@ -2318,6 +2326,8 @@
 static void
 fm_icon_view_initialize (FMIconView *icon_view)
 {
+	NautilusIconContainer *icon_container;
+
         g_return_if_fail (GTK_BIN (icon_view)->child == NULL);
 
 	icon_view->details = g_new0 (FMIconViewDetails, 1);
@@ -2326,6 +2336,7 @@
 	icon_view->details->timeout = -1;
 	icon_view->details->audio_preview_file = NULL;
 	create_icon_container (icon_view);
+	icon_container = get_icon_container (icon_view);
 
 	eel_preferences_add_callback_while_alive (NAUTILUS_PREFERENCES_ICON_VIEW_FONT,
 						       font_changed_callback, 
@@ -2359,6 +2370,12 @@
 						       default_zoom_level_changed_callback,
 						       icon_view,
 						       GTK_OBJECT (icon_view));
+
+	gtk_signal_connect (GTK_OBJECT (icon_container),
+			    "handle_uri_list",
+			    GTK_SIGNAL_FUNC (icon_view_handle_uri_list),
+			    icon_view);
+
 }
 
 static gboolean
@@ -2647,4 +2664,135 @@
 	fm_icon_view_update_smooth_graphics_mode (icon_view);
 
 	gtk_widget_show (GTK_WIDGET (icon_container));
+}
+
+static void
+icon_view_handle_uri_list (NautilusIconContainer *container, const char *item_uris,
+			   GdkDragAction action, int x, int y, FMIconView *view)
+{
+
+	GList *uri_list, *node, *real_uri_list = NULL;
+	GnomeDesktopEntry *entry;
+	GdkPoint point;
+	char *uri, *local_path;
+	char *stripped_uri;
+	const char *last_slash, *link_name;
+	char *container_uri;
+	char *container_path;
+	
+	if (item_uris == NULL) {
+		return;
+	}
+	
+	container_uri = fm_directory_view_get_uri (FM_DIRECTORY_VIEW (view));
+	container_path = gnome_vfs_get_local_path_from_uri (container_uri);
+
+	/* If the container_path is bad at this point, 
+	 * we need to pop up an annoying warning.  
+	 * FIXME: What we should do
+	 * is not accept drags on this icon view.  To fix this, look in:
+	 * nautilus-icon-dnd.c:1218 the call to be blocked
+	 * nautilus-icon-container.c:3363 the call to that function
+	 */
+
+	if (


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]