Re: [PATCH] Nautilus location bar



В Вск, 14/01/2007 в 20:45 +0300, Виталий Ищенко пишет:
> Slightly reworked GnomeVFS patch.
> Now base == NULL checks are done later, when we actually start using it
> So new function gnome_vfs_make_uri_from_input_with_base_internal behaves
> absolutely the same way, as gnome_vfs_make_uri_from_input_internal,
> except default case.

Forgot the patch
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-14 20:35:33.000000000 +0300
@@ -1440,6 +1440,118 @@
 	
 }
 
+/*
+ * Try to merge base and text (user input)
+ * base should be valid uri
+ */
+static char *
+gnome_vfs_make_uri_from_input_with_base_internal (const char *text,
+					const char *base,
+					gboolean filenames_are_utf8,
+					const char *filename_charset,
+					gboolean strip_trailing_whitespace)
+{
+	char *stripped, *uri, *escaped;
+
+	g_return_val_if_fail (text != NULL, g_strdup (""));
+
+	/* Strip off leading whitespaces (since they can't be part of a valid
+	   uri).   Only strip off trailing whitespaces when requested since
+	   they might be part of a valid uri.
+	 */
+	if (strip_trailing_whitespace) {
+		stripped = g_strstrip (g_strdup (text));
+	} else {
+		stripped = g_strchug (g_strdup (text));
+	}
+
+	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);
+				g_free (locale_path);
+			} else {
+				/* We couldn't convert to the locale. */
+				/* FIXME: We should probably give a user-visible error here. */
+				uri = g_strdup("");
+			}
+		} else {
+			uri = gnome_vfs_get_uri_from_local_path (stripped);
+		}
+	} else switch (stripped[0]) {
+	case '\0':
+		uri = g_strdup ("");
+		break;
+#ifndef G_OS_WIN32
+	case '~': {
+		char *path, *locale_path;
+		if (!filenames_are_utf8) {
+			locale_path = g_convert (stripped, -1, filename_charset, "UTF-8", NULL, NULL, NULL);
+		} else {
+			locale_path = g_strdup (stripped);
+		}
+		/* 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);
+				break;
+			}
+			g_free (path);
+		}
+		/* don't insert break here, read above comment */
+	}
+#endif
+	default:
+		if (has_valid_scheme (stripped)) {
+			uri = gnome_vfs_escape_high_chars ((guchar *)stripped);
+		} else if (looks_like_http_uri (stripped)) {
+			escaped = gnome_vfs_escape_high_chars ((guchar *)stripped);
+			uri = g_strconcat ("http://";, escaped, NULL);
+			g_free (escaped);
+		} else {
+			char *resolved_relative_uri, *path, *base_scheme;
+			int resolved_relative_uri_offset;
+
+			g_return_val_if_fail (base != NULL, g_strdup (""));
+
+			base_scheme = gnome_vfs_get_uri_scheme (base);
+
+			g_return_val_if_fail (base_scheme != NULL, g_strdup (""));
+
+			escaped = gnome_vfs_escape_high_chars ((guchar *)stripped);
+
+			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 (escaped);
+			g_free (base_scheme);
+		}
+	}
+
+	g_free (stripped);
+
+	return uri;
+}
+
 /**
  * gnome_vfs_make_uri_from_input:
  * @location: a possibly mangled "uri", in UTF-8.
@@ -1466,6 +1578,32 @@
 }
 
 /**
+ * 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_with_base_internal (location, base, utf8, charset, TRUE);
+}
+
+/**
  * gnome_vfs_make_uri_from_input_with_trailing_ws:
  * @location: a possibly mangled uri, in UTF-8.
  *
@@ -1490,6 +1628,31 @@
 }
 
 /**
+ * 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_with_base_internal (location, base, utf8, charset, FALSE);
+}
+
+/**
  * gnome_vfs_make_uri_from_input_with_dirs:
  * @location: a relative or absolute path.
  * @dirs: directory to use as a base directory if @location is a relative path.
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-13 23:45:25.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]