diff options
-rw-r--r-- | ChangeLog | 23 | ||||
-rw-r--r-- | libnautilus-private/nautilus-file-utilities.c | 71 | ||||
-rw-r--r-- | libnautilus-private/nautilus-file-utilities.h | 2 | ||||
-rw-r--r-- | libnautilus-private/nautilus-file.c | 41 | ||||
-rw-r--r-- | src/nautilus-location-entry.c | 23 | ||||
-rw-r--r-- | src/nautilus-spatial-window.c | 30 | ||||
-rw-r--r-- | src/nautilus-window.c | 36 |
7 files changed, 125 insertions, 101 deletions
@@ -1,3 +1,26 @@ +2004-02-13 Alexander Larsson <alexl@redhat.com> + + * libnautilus-private/nautilus-file-utilities.[ch]: + (nautilus_have_broken_filenames), + (nautilus_get_uri_shortname_for_display): + New functions + + * libnautilus-private/nautilus-file.c: + Use the public nautilus_have_broken_filenames instead of private copy + Make display names for toplevel uris better. + + * src/nautilus-location-entry.c: (try_to_expand_path): + Use the public nautilus_have_broken_filenames instead of private copy + + * src/nautilus-spatial-window.c: + (location_button_clicked_callback), + (nautilus_spatial_window_set_location_button): + Use nautilus_get_uri_shortname_for_display() + + * src/nautilus-window.c: (compute_default_title): + Special casing toplevel stuff not needed, since this is + handled by the display name change. + 2004-02-12 Dave Camp <dave@ximian.com> * src/file-manager/fm-icon-view.c: (fm_icon_view_merge_menus): diff --git a/libnautilus-private/nautilus-file-utilities.c b/libnautilus-private/nautilus-file-utilities.c index 674b0aa14..3fcbf2ace 100644 --- a/libnautilus-private/nautilus-file-utilities.c +++ b/libnautilus-private/nautilus-file-utilities.c @@ -31,6 +31,7 @@ #include "nautilus-metafile.h" #include <eel/eel-glib-extensions.h> #include <eel/eel-string.h> +#include <eel/eel-vfs-extensions.h> #include <libgnome/gnome-util.h> #include <libgnome/gnome-i18n.h> #include <libgnomevfs/gnome-vfs-ops.h> @@ -380,6 +381,76 @@ nautilus_get_vfs_method_display_name (char *method) return NULL; } +gboolean +nautilus_have_broken_filenames (void) +{ + static gboolean initialized = FALSE; + static gboolean broken; + + if (initialized) { + return broken; + } + + broken = g_getenv ("G_BROKEN_FILENAMES") != NULL; + + initialized = TRUE; + + return broken; +} + +char * +nautilus_get_uri_shortname_for_display (GnomeVFSURI *uri) +{ + gboolean broken_filenames; + char *utf8_name, *name, *tmp; + gboolean validated; + const char *method; + + validated = FALSE; + name = gnome_vfs_uri_extract_short_name (uri); + if (name == NULL) { + name = gnome_vfs_uri_to_string (uri, GNOME_VFS_URI_HIDE_PASSWORD); + } else if (g_ascii_strcasecmp (uri->method_string, "file") == 0) { + broken_filenames = nautilus_have_broken_filenames (); + if (broken_filenames || !g_utf8_validate (name, -1, NULL)) { + utf8_name = g_locale_to_utf8 (name, -1, NULL, NULL, NULL); + if (utf8_name != NULL) { + g_free (name); + name = utf8_name; + /* Guaranteed to be correct utf8 here */ + validated = TRUE; + } + } else if (!broken_filenames) { + /* name was valid, no need to re-validate */ + validated = TRUE; + } + } else if (!gnome_vfs_uri_has_parent (uri)) { + /* Special-case the display name for roots that are not local files */ + method = nautilus_get_vfs_method_display_name (uri->method_string); + if (method == NULL) { + method = uri->method_string; + } + + if (name == NULL || + strcmp (name, GNOME_VFS_URI_PATH_STR) == 0) { + g_free (name); + name = g_strdup (method); + } else { + tmp = name; + name = g_strdup_printf ("%s: %s", method, name); + g_free (tmp); + } + } + + if (!validated && !g_utf8_validate (name, -1, NULL)) { + utf8_name = eel_make_valid_utf8 (name); + g_free (name); + name = utf8_name; + } + + return name; +} + #if !defined (NAUTILUS_OMIT_SELF_CHECK) void diff --git a/libnautilus-private/nautilus-file-utilities.h b/libnautilus-private/nautilus-file-utilities.h index 5a2db8666..d4f1077b1 100644 --- a/libnautilus-private/nautilus-file-utilities.h +++ b/libnautilus-private/nautilus-file-utilities.h @@ -70,5 +70,7 @@ char * nautilus_find_file_in_gnome_path (char *file); GList * nautilus_find_all_files_in_gnome_path (char *file); const char *nautilus_get_vfs_method_display_name (char *method); +gboolean nautilus_have_broken_filenames (void); +char * nautilus_get_uri_shortname_for_display (GnomeVFSURI *uri); #endif /* NAUTILUS_FILE_UTILITIES_H */ diff --git a/libnautilus-private/nautilus-file.c b/libnautilus-private/nautilus-file.c index 82cdf71f0..7bf61fb3e 100644 --- a/libnautilus-private/nautilus-file.c +++ b/libnautilus-private/nautilus-file.c @@ -1261,23 +1261,6 @@ rename_guts (NautilusFile *file, gnome_vfs_uri_unref (vfs_uri); } -static gboolean -have_broken_filenames (void) -{ - static gboolean initialized = FALSE; - static gboolean broken; - - if (initialized) { - return broken; - } - - broken = g_getenv ("G_BROKEN_FILENAMES") != NULL; - - initialized = TRUE; - - return broken; -} - void nautilus_file_rename (NautilusFile *file, const char *new_name, @@ -1287,7 +1270,7 @@ nautilus_file_rename (NautilusFile *file, char *locale_name; /* Note: Desktop file renaming wants utf8, even with G_BROKEN_FILENAMES */ - if (has_local_path (file) && have_broken_filenames () && + if (has_local_path (file) && nautilus_have_broken_filenames () && !is_desktop_file (file)) { locale_name = g_filename_from_utf8 (new_name, -1, NULL, NULL, NULL); if (locale_name == NULL) { @@ -2639,10 +2622,11 @@ nautilus_file_get_display_name_collation_key (NautilusFile *file) static char * nautilus_file_get_display_name_nocopy (NautilusFile *file) { - char *name, *utf8_name; + char *name, *utf8_name, *short_name; gboolean broken_filenames; gboolean validated; GnomeVFSURI *vfs_uri; + const char *method; if (file == NULL) { return NULL; @@ -2671,8 +2655,9 @@ nautilus_file_get_display_name_nocopy (NautilusFile *file) * thing with any local filename that does not * validate as good UTF-8. */ + /* Keep in sync with nautilus_get_uri_shortname_for_display */ if (has_local_path (file)) { - broken_filenames = have_broken_filenames (); + broken_filenames = nautilus_have_broken_filenames (); if (broken_filenames || !g_utf8_validate (name, -1, NULL)) { utf8_name = g_locale_to_utf8 (name, -1, NULL, NULL, NULL); if (utf8_name != NULL) { @@ -2688,8 +2673,22 @@ nautilus_file_get_display_name_nocopy (NautilusFile *file) } else if (strcmp (name, "/") == 0) { /* Special-case the display name for roots that are not local files */ g_free (name); + vfs_uri = gnome_vfs_uri_new (file->details->directory->details->uri); - name = gnome_vfs_uri_to_string (vfs_uri, GNOME_VFS_URI_HIDE_PASSWORD); + method = nautilus_get_vfs_method_display_name (vfs_uri->method_string); + if (method == NULL) { + method = vfs_uri->method_string; + } + + short_name = gnome_vfs_uri_extract_short_name (vfs_uri); + if (short_name == NULL || + strcmp (short_name, GNOME_VFS_URI_PATH_STR) == 0) { + name = g_strdup (method); + } else { + name = g_strdup_printf ("%s: %s", method, short_name); + } + g_free (short_name); + gnome_vfs_uri_unref (vfs_uri); } } diff --git a/src/nautilus-location-entry.c b/src/nautilus-location-entry.c index f7e4a4463..06bf1de48 100644 --- a/src/nautilus-location-entry.c +++ b/src/nautilus-location-entry.c @@ -46,6 +46,7 @@ #include <libgnomeui/gnome-stock-icons.h> #include <libgnomeui/gnome-uidefs.h> #include <libgnomevfs/gnome-vfs.h> +#include <libnautilus-private/nautilus-file-utilities.h> #include <libnautilus-private/nautilus-entry.h> #include <libnautilus-private/nautilus-icon-dnd.h> #include <libnautilus/nautilus-clipboard.h> @@ -68,24 +69,6 @@ EEL_CLASS_BOILERPLATE (NautilusLocationEntry, nautilus_location_entry, NAUTILUS_TYPE_ENTRY) -static gboolean -have_broken_filenames (void) -{ - static gboolean initialized = FALSE; - static gboolean broken; - - if (initialized) { - return broken; - } - - broken = g_getenv ("G_BROKEN_FILENAMES") != NULL; - - initialized = TRUE; - - return broken; -} - - /* utility routine to determine the string to expand to. If we don't have anything yet, accept the whole string, otherwise accept the largest part common to both */ @@ -268,7 +251,7 @@ try_to_expand_path (gpointer callback_data) } else { expand_name = g_strdup (current_file_info->name); } - if (have_broken_filenames()) { + if (nautilus_have_broken_filenames()) { expand_text = accumulate_name_locale (expand_text, expand_name); } else { expand_text = accumulate_name_utf8 (expand_text, expand_name); @@ -277,7 +260,7 @@ try_to_expand_path (gpointer callback_data) } } - if (have_broken_filenames ()) { + if (nautilus_have_broken_filenames ()) { if (expand_text) { expand_text_utf8 = g_locale_to_utf8 (expand_text, -1, NULL, NULL, NULL); g_free (expand_text); diff --git a/src/nautilus-spatial-window.c b/src/nautilus-spatial-window.c index ca454da9d..20ab205a6 100644 --- a/src/nautilus-spatial-window.c +++ b/src/nautilus-spatial-window.c @@ -444,32 +444,6 @@ menu_popup_pos (GtkMenu *menu, *push_in = TRUE; } -static char * -get_uri_name (GnomeVFSURI *uri) -{ - char *name, *short_name; - const char *method; - - if (!gnome_vfs_uri_has_parent (uri) && - g_ascii_strcasecmp (uri->method_string, "file") != 0) { - method = nautilus_get_vfs_method_display_name (uri->method_string); - if (method == NULL) { - method = uri->method_string; - } - - short_name = gnome_vfs_uri_extract_short_name (uri); - if (short_name == NULL || - strcmp (short_name, GNOME_VFS_URI_PATH_STR) == 0) { - return g_strdup (method); - } - name = g_strdup_printf ("%s: %s", method, short_name); - g_free (short_name); - } else { - name = gnome_vfs_uri_extract_short_name (uri); - } - return name; -} - static void location_button_clicked_callback (GtkWidget *widget, NautilusSpatialWindow *window) { @@ -484,7 +458,7 @@ location_button_clicked_callback (GtkWidget *widget, NautilusSpatialWindow *wind uri = gnome_vfs_uri_ref (window->details->location); while (uri != NULL) { - name = get_uri_name (uri); + name = nautilus_get_uri_shortname_for_display (uri); menu_item = gtk_image_menu_item_new_with_label (name); g_free (name); gtk_widget_show (menu_item); @@ -525,7 +499,7 @@ nautilus_spatial_window_set_location_button (NautilusSpatialWindow *window, uri = gnome_vfs_uri_new (location); } if (uri != NULL) { - name = get_uri_name (uri); + name = nautilus_get_uri_shortname_for_display (uri); gtk_button_set_label (GTK_BUTTON (window->details->location_button), name); g_free (name); diff --git a/src/nautilus-window.c b/src/nautilus-window.c index 331ee075a..76ab780b1 100644 --- a/src/nautilus-window.c +++ b/src/nautilus-window.c @@ -1128,48 +1128,20 @@ nautilus_window_display_error (NautilusWindow *window, const char *error_msg) gtk_widget_show (dialog); } -static gboolean -is_method_root (char *uri) -{ - while (*uri != 0) { - if (*uri == ':') { - break; - } - if (!g_ascii_isalpha (*uri)) { - return FALSE; - } - uri++; - } - return (strcmp (uri, "://") == 0 || - strcmp (uri, ":///") == 0); -} - static char * compute_default_title (const char *text_uri) { NautilusFile *file; char *title; - char *canonical_uri; - char *colon; - - canonical_uri = eel_make_uri_canonical (text_uri); - - title = NULL; - if (canonical_uri == NULL) { - title = g_strdup (""); - } else if (is_method_root (canonical_uri)) { - colon = strchr (canonical_uri, ':'); - g_assert (colon != NULL); - *colon = 0; - title = g_strdup (nautilus_get_vfs_method_display_name (canonical_uri)); - } - if (title == NULL) { + + if (text_uri) { file = nautilus_file_get (text_uri); title = nautilus_file_get_display_name (file); nautilus_file_unref (file); + } else { + title = g_strdup (""); } - g_free (canonical_uri); return title; } |