Re: Nautilus location bar
- From: Виталий Ищенко <betalb gmail com>
- To: Alexander Larsson <alexl redhat com>
- Cc: nautilus-list gnome org
- Subject: Re: Nautilus location bar
- Date: Sun, 14 Jan 2007 01:07:51 +0300
Another try:
created patch for gnome-vfs. Added 3 functions
1 private -- gnome_vfs_make_uri_from_input_with_base_internal it is
slightly changed version of gnome_vfs_make_uri_from_input_internal
and 2 public.
And patch for nautilus - to use new public functions:
nautilus-location-bar.c - simply replaced calls to
gnome_vfs_make_uri_from_input with
gnome_vfs_make_uri_from_input_with_base
As base used bar->details->last_location
nautilus-location-entry.c - don't know where to get something similar to
bar->details->last_location. I've looked into
entry->details->current_directory, but it seems that this var keeps
something different
nautilus-location-dialog.c - same story, need var with current directory
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-13 23:45:03.000000000 +0300
@@ -1440,6 +1440,116 @@
}
+/*
+ * 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, *base_scheme, *escaped;
+
+ 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 (""));
+
+ g_return_val_if_fail (text != NULL, g_strdup (base));
+
+ /* 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 (base);
+ 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;
+ int resolved_relative_uri_offset;
+ 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 (stripped);
+ g_free (base_scheme);
+
+ return uri;
+}
+
/**
* gnome_vfs_make_uri_from_input:
* @location: a possibly mangled "uri", in UTF-8.
@@ -1466,6 +1576,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 +1626,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);
--- nautilus-2.16.3.old/src/nautilus-location-bar.c 2006-10-18 17:12:07.000000000 +0400
+++ nautilus-2.16.3/src/nautilus-location-bar.c 2007-01-14 00:11:32.000000000 +0300
@@ -530,7 +530,7 @@
* @bar: A NautilusLocationBar.
*
* returns a newly allocated "string" containing the mangled
- * (by gnome_vfs_make_uri_from_input) text that the user typed in...maybe a URI
+ * (by gnome_vfs_make_uri_from_input_with_base) text that the user typed in...maybe a URI
* but not guaranteed.
*
**/
@@ -541,9 +541,9 @@
char *user_location, *best_uri;
bar = NAUTILUS_LOCATION_BAR (navigation_bar);
-
+
user_location = gtk_editable_get_chars (GTK_EDITABLE (bar->details->entry), 0, -1);
- best_uri = gnome_vfs_make_uri_from_input (user_location);
+ best_uri = gnome_vfs_make_uri_from_input_with_base (user_location, bar->details->last_location);
g_free (user_location);
return best_uri;
}
@@ -559,10 +559,10 @@
{
const char *current_text;
char *current_location;
-
+
current_text = gtk_entry_get_text (GTK_ENTRY (bar->details->entry));
- current_location = gnome_vfs_make_uri_from_input (current_text);
-
+ current_location = gnome_vfs_make_uri_from_input_with_base (current_text, bar->details->last_location);
+
if (gnome_vfs_uris_match (bar->details->last_location, current_location)) {
gtk_label_set_text (GTK_LABEL (bar->details->label), LOCATION_LABEL);
} else {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]