Re: [PATCH] Nautilus location bar



В Чтв, 18/01/2007 в 11:32 +0100, Alexander Larsson пишет:
> Yes, this looks like the right approach. However, I don't think you
> should add a copy of gnome_vfs_make_uri_from_input_internal. Just make
> it take a base argument and then pass NULL for base in the other uses of
> it.

Yeah I really did a stupid thing :)
diff -urN gnome-vfs-2.16.3.old/libgnomevfs/gnome-vfs-utils.c gnome-vfs-2.16.3/libgnomevfs/gnome-vfs-utils.c
--- gnome-vfs-2.16.3.old/libgnomevfs/gnome-vfs-utils.c	2006-07-21 21:13:28.000000000 +0400
+++ gnome-vfs-2.16.3/libgnomevfs/gnome-vfs-utils.c	2007-01-29 19:48:03.000000000 +0300
@@ -1359,14 +1359,18 @@
 /* The strip_trailing_whitespace option is intended to make copy/paste of
  * URIs less error-prone when it is known that trailing whitespace isn't
  * part of the uri.
+ *
+ * Try to merge base and text (user input)
+ * base should be valid uri
  */
 static char *
 gnome_vfs_make_uri_from_input_internal (const char *text,
+					const char *base,
 					gboolean filenames_are_utf8,
 					const char *filename_charset,
 					gboolean strip_trailing_whitespace)
 {
-	char *stripped, *uri, *locale_path, *escaped;
+	char *stripped, *uri, *escaped;
 
 	g_return_val_if_fail (text != NULL, g_strdup (""));
 
@@ -1382,6 +1386,7 @@
 
 	if (g_path_is_absolute (stripped)) {
 		if (!filenames_are_utf8) {
+			char *locale_path;
 			locale_path = g_convert (stripped, -1, filename_charset, "UTF-8", NULL, NULL, NULL);
 			if (locale_path != NULL) {
 				uri = gnome_vfs_get_uri_from_local_path (locale_path);
@@ -1400,16 +1405,16 @@
 		break;
 #ifndef G_OS_WIN32
 	case '~': {
-		char *path, *filesystem_path;
+		char *path, *locale_path;
 		if (!filenames_are_utf8) {
-			filesystem_path = g_convert (stripped, -1, filename_charset, "UTF-8", NULL, NULL, NULL);
+			locale_path = g_convert (stripped, -1, filename_charset, "UTF-8", NULL, NULL, NULL);
 		} else {
-			filesystem_path = g_strdup (stripped);
+			locale_path = g_strdup (stripped);
 		}
-                /* deliberately falling into default case on fail */
-		if (filesystem_path != NULL) {
-			path = gnome_vfs_expand_initial_tilde (filesystem_path);
-			g_free (filesystem_path);
+		/* deliberately falling into default case on fail */
+		if (locale_path != NULL) {
+			path = gnome_vfs_expand_initial_tilde (locale_path);
+			g_free (locale_path);
 			if (*path == '/') {
 				uri = gnome_vfs_get_uri_from_local_path (path);
 				g_free (path);
@@ -1417,7 +1422,7 @@
 			}
 			g_free (path);
 		}
-                /* don't insert break here, read above comment */
+		/* don't insert break here, read above comment */
 	}
 #endif
 	default:
@@ -1428,8 +1433,37 @@
 			uri = g_strconcat ("http://";, escaped, NULL);
 			g_free (escaped);
 		} else {
+			char *resolved_relative_uri, *path, *base_scheme;
+			int resolved_relative_uri_offset;
+
 			escaped = gnome_vfs_escape_high_chars ((guchar *)stripped);
-			uri = g_strconcat ("file:///", escaped, NULL);
+
+			if (base == NULL) {
+				uri = g_strconcat ("file:///", escaped, NULL);
+			} else {
+				base_scheme = gnome_vfs_get_uri_scheme (base);
+
+				g_return_val_if_fail (base_scheme != NULL, g_strconcat ("file:///", escaped, NULL));
+
+				path = g_strconcat (base + strlen(base_scheme) + 1 + 2, "/", escaped, NULL);
+				resolved_relative_uri = gnome_vfs_make_path_name_canonical (path);
+				/* gnome_vfs_make_path_name_canonical
+				 * can leave '..' at the beginning
+				 * of resolved_relative_uri */
+				resolved_relative_uri_offset = 0;
+				if (resolved_relative_uri[0] == '.')
+					if (resolved_relative_uri[1] == '.')
+						resolved_relative_uri_offset = 2;
+				/* After all transformations, we get
+				 * empty string, return base_scheme + ':///' */
+				if (resolved_relative_uri[resolved_relative_uri_offset] == '\0')
+					uri = g_strconcat (base_scheme, ":///", NULL);
+				else
+					uri = g_strconcat (base_scheme, "://", resolved_relative_uri + resolved_relative_uri_offset, NULL);
+				g_free (resolved_relative_uri);
+				g_free (path);
+				g_free (base_scheme);
+			}
 			g_free (escaped);
 		}
 	}
@@ -1437,7 +1471,6 @@
 	g_free (stripped);
 
 	return uri;
-	
 }
 
 /**
@@ -1462,7 +1495,33 @@
 
 	utf8 = vfs_get_filename_charset (&charset);
 
-	return gnome_vfs_make_uri_from_input_internal (location, utf8, charset, TRUE);
+	return gnome_vfs_make_uri_from_input_internal (location, NULL, utf8, charset, TRUE);
+}
+
+/**
+ * gnome_vfs_make_uri_from_input_with_base:
+ * @location: a possibly mangled "uri", in UTF-8.
+ * @base: ___
+ *
+ * Takes a user input path/uri and makes a valid uri out of it.
+ *
+ * This function is the reverse of gnome_vfs_format_uri_for_display()
+ * but it also handles the fact that the user could have typed
+ * arbitrary UTF-8 in the entry showing the string.
+ *
+ * Returns: a newly allocated uri.
+ *
+ * Since: 2.?
+ */
+char *
+gnome_vfs_make_uri_from_input_with_base (const char *location, const char *base)
+{
+	gboolean utf8;
+	const char *charset;
+
+	utf8 = vfs_get_filename_charset (&charset);
+
+	return gnome_vfs_make_uri_from_input_internal (location, base, utf8, charset, TRUE);
 }
 
 /**
@@ -1486,7 +1545,32 @@
 
 	utf8 = vfs_get_filename_charset (&charset);
 
-	return gnome_vfs_make_uri_from_input_internal (location, utf8, charset, FALSE);	
+	return gnome_vfs_make_uri_from_input_internal (location, NULL, utf8, charset, FALSE);	
+}
+
+/**
+ * gnome_vfs_make_uri_from_input_with_base_with_trailing_ws:
+ * @location: a possibly mangled uri, in UTF-8.
+ * @base: ___
+ *
+ * Takes a user input path/uri and makes a valid uri out of it.
+ *
+ * This function is indentical to gnome_vfs_make_uri_from_input() except
+ * that this version won't strip any trailing slashes.
+ *
+ * Returns: a newly allocated uri.
+ *
+ * Since: 2.??
+ */
+char *
+gnome_vfs_make_uri_from_input_with_base_with_trailing_ws (const char *location, const char *base)
+{
+	gboolean utf8;
+	const char *charset;
+
+	utf8 = vfs_get_filename_charset (&charset);
+
+	return gnome_vfs_make_uri_from_input_internal (location, base, utf8, charset, FALSE);
 }
 
 /**
diff -urN gnome-vfs-2.16.3.old/libgnomevfs/gnome-vfs-utils.h gnome-vfs-2.16.3/libgnomevfs/gnome-vfs-utils.h
--- gnome-vfs-2.16.3.old/libgnomevfs/gnome-vfs-utils.h	2005-04-12 12:44:39.000000000 +0400
+++ gnome-vfs-2.16.3/libgnomevfs/gnome-vfs-utils.h	2007-01-29 19:43:04.000000000 +0300
@@ -163,13 +163,18 @@
 
 char *   gnome_vfs_format_uri_for_display            (const char          *uri);
 char *   gnome_vfs_make_uri_from_input               (const char     *location);
+char *   gnome_vfs_make_uri_from_input_with_base     (const char     *location,
+                                                     const char          *base);
 char *   gnome_vfs_make_uri_from_input_with_trailing_ws 
                                                      (const char     *location);
+char *   gnome_vfs_make_uri_from_input_with_base_with_trailing_ws 
+                                                     (const char      *location,
+                                                     const char          *base);
 char *   gnome_vfs_make_uri_from_input_with_dirs     (const char     *location,
-						      GnomeVFSMakeURIDirs  dirs);
+                                                     GnomeVFSMakeURIDirs  dirs);
 char *   gnome_vfs_make_uri_canonical_strip_fragment (const char          *uri);
-gboolean gnome_vfs_uris_match                        (const char          *uri_1,
-						      const char          *uri_2);
+gboolean gnome_vfs_uris_match                        (const char         *uri_1,
+                                                     const char         *uri_2);
 char *   gnome_vfs_get_uri_scheme                    (const char          *uri);
 char *   gnome_vfs_make_uri_from_shell_arg           (const char          *uri);
 


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