[PATCH] Mozilla Drag/drop URL action by file type



This is a little patch that would change the default drag/drop behavior
for Mozilla URLs. Instead of always asking, it would default to linking
for HTML files, asking for plaintext, and downloading for everything
else. 

The reasoning behind this is that most arbitrary filetypes on the web
are intended to be downloaded locally before being used, and most often
the remote copy stays about the same. Conversely, HTML files are
intended to be viewed in-place, and are often updated without the
filename being changed.

Text files seemed to be a somewhat grey area, and could fall into either
of these categories, so they ask by default.

As a technical note, I had to change the ordering of the function a bit,
to extract the URL from the drag/drop packet before determining the
action.
? depcomp
? stamp-h1
? libnautilus-private/nautilus-directory-background.loT
Index: src/file-manager/fm-directory-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-directory-view.c,v
retrieving revision 1.675
diff -u -r1.675 fm-directory-view.c
--- src/file-manager/fm-directory-view.c	25 May 2005 21:45:26 -0000	1.675
+++ src/file-manager/fm-directory-view.c	26 May 2005 15:54:59 -0000
@@ -8182,6 +8182,8 @@
 	char *container_uri;
 	GArray *points;
 	char **bits;
+	GnomeVFSResult result;
+	GnomeVFSFileInfo *file_info;
 	GList *uri_list = NULL;
 
 	if (encoded_url == NULL) {
@@ -8201,8 +8203,39 @@
 		return;
 	}
 
+	/* _NETSCAPE_URL_ works like this: $URL\n$TITLE */
+	bits = g_strsplit (encoded_url, "\n", 0);
+	switch (g_strv_length (bits)) {
+	case 0:
+		g_strfreev (bits);
+		g_free (container_uri);
+		return;
+	case 1:
+		url = bits[0];
+		title = NULL;
+		break;
+	default:
+		url = bits[0];
+		title = bits[1];
+	}
+
 	if (action == GDK_ACTION_ASK) {
-		action = ask_link_action (view);
+		file_info = gnome_vfs_file_info_new ();
+		result = gnome_vfs_get_file_info (url, file_info,
+		    GNOME_VFS_FILE_INFO_GET_MIME_TYPE
+		    | GNOME_VFS_FILE_INFO_FOLLOW_LINKS);
+
+		if ( eel_strcasecmp (file_info->mime_type, "text/html") == 0 ||
+		    eel_strcasecmp (file_info->mime_type, "text/xml") == 0 ||
+		    eel_strcasecmp (file_info->mime_type, "application/xhtml+xml") == 0) {
+			action = GDK_ACTION_LINK;
+		} else if (eel_strcasecmp (file_info->mime_type, "text/plain") == 0) {
+			action = ask_link_action (view);
+		} else {
+			action = GDK_ACTION_COPY;
+		}
+		gnome_vfs_file_info_unref (file_info);
+		
 		if (action == 0) {
 			g_free (container_uri);
 			return;
@@ -8221,22 +8254,6 @@
 					 fm_directory_view_get_containing_window (view));
 		g_free (container_uri);
 		return;
-	}
-
-	/* _NETSCAPE_URL_ works like this: $URL\n$TITLE */
-	bits = g_strsplit (encoded_url, "\n", 0);
-	switch (g_strv_length (bits)) {
-	case 0:
-		g_strfreev (bits);
-		g_free (container_uri);
-		return;
-	case 1:
-		url = bits[0];
-		title = NULL;
-		break;
-	default:
-		url = bits[0];
-		title = bits[1];
 	}
 
 	if (action == GDK_ACTION_LINK) {

Attachment: signature.asc
Description: This is a digitally signed message part



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