PATCH: make link creation from dragged URIs work



Hi all,

right now link creation from dragged URIs in Nautilus doesn't work.
There are several easy ways to demonstrate this, my favourite example
follows:

- run gnome-about
- drag one of the link buttons onto your desktop
- you will notice nautilus freezing and your net connection working
- after a while nautilus comes back, but there is a weird "No name" link
on your desktop that does nothing

Another example is to drag the label from the location bar to create a
link. It wont work either.

The problem is caused by the fact that Nautilus tries to load a desktop
item from the URI, even if the URI doesn't represent a desktop item.
Even worse, it doesn't take non-local URIs into account - so in the case
of the gnome-about buttons it actually downloads the document from the
Gnome.org site!

The two attached patches, one for nautilus and one for
gnome-desktop-item fix this. Somebody please review them and commit if
ok.

Also, with these patches I don't pass in an icon for the link, so the
default gnome icon for desktop items is used. This doesn't look very
good because the default icon kinda sucks. A better solution might be to
use the default icon for the MIME type as the icon for the link. If this
patch is acceptable I will send a second patch implementing that.

Cheers,

- Frank
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/nautilus/ChangeLog,v
retrieving revision 1.5285
diff -u -r1.5285 ChangeLog
--- ChangeLog	2002/05/10 20:16:33	1.5285
+++ ChangeLog	2002/05/11 04:19:28
@@ -1,3 +1,11 @@
+2002-05-10  Frank Worsley  <fworsley shaw ca>
+
+	* libnautilus-private/nautilus-link-desktop-file.c:
+	allow NULL to be passed in for the nautilus icon
+	
+	* src/file-manager/fm-icon-view.c:
+	correctly create nautilus links from dropped URIs
+
 2002-05-10  Anders Carlsson  <andersca gnu org>
 
 	* src/nautilus-bookmark-list.c: (nautilus_bookmark_list_load_file):
Index: libnautilus-private/nautilus-link-desktop-file.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-link-desktop-file.c,v
retrieving revision 1.15
diff -u -r1.15 nautilus-link-desktop-file.c
--- libnautilus-private/nautilus-link-desktop-file.c	2002/05/02 20:38:41	1.15
+++ libnautilus-private/nautilus-link-desktop-file.c	2002/05/11 04:19:29
@@ -109,7 +109,6 @@
 
 	g_return_val_if_fail (directory_path != NULL, FALSE);
 	g_return_val_if_fail (name != NULL, FALSE);
-	g_return_val_if_fail (image != NULL, FALSE);
 	g_return_val_if_fail (target_uri != NULL, FALSE);
 
 	path = nautilus_make_path (directory_path, name);
@@ -126,8 +125,13 @@
 	fputs (name, file);
 	fputs ("\nType=", file);
 	fputs (get_tag (type), file);
-	fputs ("\nX-Nautilus-Icon=", file);
-	fputs (image, file);
+	
+	/* we don't always want a nautilus icon */
+	if (image != NULL) {
+		fputs ("\nX-Nautilus-Icon=", file);
+		fputs (image, file);
+	}
+	
 	fputs ("\nURL=", file);
 	fputs (target_uri, file);
 	fputs ("\n", file);
Index: src/file-manager/fm-icon-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-icon-view.c,v
retrieving revision 1.257
diff -u -r1.257 fm-icon-view.c
--- src/file-manager/fm-icon-view.c	2002/05/09 20:40:53	1.257
+++ src/file-manager/fm-icon-view.c	2002/05/11 04:19:29
@@ -2280,8 +2280,8 @@
 		eel_show_warning_dialog (_("An invalid drag type was used."),
 					 _("Drag and Drop error"),
 					 fm_directory_view_get_containing_window (FM_DIRECTORY_VIEW (view)));
-		g_free (container_uri);
 		gnome_vfs_uri_unref (container_uri);
+		g_free (container_uri_string);
 		return;
 	}
 
@@ -2332,12 +2332,22 @@
 		container_path = gnome_vfs_get_local_path_from_uri (container_uri_string);
 		for (node = real_uri_list; node != NULL; node = node->next) {
 			/* Make a link using the desktop file contents? */
-			uri = node->data;
-			entry = gnome_desktop_item_new_from_uri (uri, 0, NULL);
+			uri = gnome_vfs_get_local_path_from_uri (node->data);
+
+			if (uri != NULL) {
+				entry = gnome_desktop_item_new_from_uri (uri,
+									 GNOME_DESKTOP_ITEM_LOAD_ONLY_IF_EXISTS,
+									 NULL);
+			} else {
+				entry = NULL;
+				uri = g_strdup (node->data);
+			}
+			
 			if (entry != NULL) {
 				/* FIXME: Handle name conflicts? */
 				nautilus_link_local_create_from_gnome_entry (entry, container_path, &point);
 
+				g_free (uri);
 				gnome_desktop_item_unref (entry);
 				continue;
 			}
@@ -2355,10 +2365,11 @@
 			if (!eel_str_is_empty (link_name)) {
 				/* FIXME: Handle name conflicts? */
 				nautilus_link_local_create (container_path, link_name,
-							    "gnome-http-url", uri,
+							    NULL, uri,
 							    &point, NAUTILUS_LINK_GENERIC);
 			}
 			
+			g_free (uri);
 			g_free (stripped_uri);
 			break;
 		}
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gnome-desktop/ChangeLog,v
retrieving revision 1.429
diff -u -r1.429 ChangeLog
--- ChangeLog	2002/04/29 10:27:35	1.429
+++ ChangeLog	2002/05/11 04:24:25
@@ -1,3 +1,12 @@
+2002-05-10  Frank Worsley  <fworsley shaw ca>
+
+	* libgnome-desktop/gnome-desktop-item.c:
+	(gnome_desktop_item_load_from_uri):
+	added a few more checks before loading a file as a
+	desktop item
+	fixed a bug where a .directory file was created even
+	when flag was passed in saying not to do so
+
 2002-04-29  Seth Nickell  <snickell stanford edu>
 
 	* pixmaps/gnome-audio2.png:
Index: libgnome-desktop/gnome-desktop-item.c
===================================================================
RCS file: /cvs/gnome/gnome-desktop/libgnome-desktop/gnome-desktop-item.c,v
retrieving revision 1.99
diff -u -r1.99 gnome-desktop-item.c
--- libgnome-desktop/gnome-desktop-item.c	2002/04/20 01:08:03	1.99
+++ libgnome-desktop/gnome-desktop-item.c	2002/05/11 04:24:26
@@ -551,7 +551,23 @@
 
 		return NULL;
 	}
+	
+	if (info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_TYPE &&
+	    info->type == GNOME_VFS_FILE_TYPE_REGULAR &&
+	    info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_MIME_TYPE &&
+	    strcmp (info->mime_type, "application/x-gnome-app-info") != 0) {
+		g_set_error (error,
+			     /* FIXME: better errors */
+			     GNOME_DESKTOP_ITEM_ERROR,
+			     GNOME_DESKTOP_ITEM_ERROR_INVALID_TYPE,
+			     _("File '%s' has invalid MIME type: %s"),
+			     uri, info->mime_type);
+
+		gnome_vfs_file_info_unref (info);
 
+		return NULL;
+	}		
+
 	if (info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_MTIME)
 		mtime = info->mtime;
 	else
@@ -565,7 +581,12 @@
 					     GNOME_VFS_FILE_INFO_DEFAULT) != GNOME_VFS_OK) {
 			gnome_vfs_file_info_unref (info);
 			g_free (subfn);
-			return make_fake_directory (uri);
+
+			if (flags & GNOME_DESKTOP_ITEM_LOAD_ONLY_IF_EXISTS) {
+				return NULL;
+			} else {
+				return make_fake_directory (uri);
+			}
 		}
 
 		if (info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_MTIME)
Index: libgnome-desktop/gnome-desktop-item.h
===================================================================
RCS file: /cvs/gnome/gnome-desktop/libgnome-desktop/gnome-desktop-item.h,v
retrieving revision 1.39
diff -u -r1.39 gnome-desktop-item.h
--- libgnome-desktop/gnome-desktop-item.h	2002/03/27 18:31:22	1.39
+++ libgnome-desktop/gnome-desktop-item.h	2002/05/11 04:24:26
@@ -123,7 +123,8 @@
 	GNOME_DESKTOP_ITEM_ERROR_NO_EXEC_STRING /* Cannot launch due to no execute string */,
 	GNOME_DESKTOP_ITEM_ERROR_BAD_EXEC_STRING /* Cannot launch due to bad execute string */,
 	GNOME_DESKTOP_ITEM_ERROR_NO_URL /* No URL on a url entry*/,
-	GNOME_DESKTOP_ITEM_ERROR_NOT_LAUNCHABLE /* Not a launchable type of item */
+	GNOME_DESKTOP_ITEM_ERROR_NOT_LAUNCHABLE /* Not a launchable type of item */,
+	GNOME_DESKTOP_ITEM_ERROR_INVALID_TYPE /* Not of type application/x-gnome-app-info */
 } GnomeDesktopItemError;
 
 /* Note that functions can also return the G_FILE_ERROR_* errors */


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