diff options
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | libnautilus-private/nautilus-file-utilities.c | 46 | ||||
-rw-r--r-- | libnautilus-private/nautilus-file-utilities.h | 1 | ||||
-rw-r--r-- | libnautilus-private/nautilus-file.c | 34 | ||||
-rw-r--r-- | src/nautilus-location-entry.c | 16 |
5 files changed, 69 insertions, 39 deletions
@@ -1,5 +1,16 @@ 2004-10-28 Alexander Larsson <alexl@redhat.com> + * libnautilus-private/nautilus-file-utilities.c: + (nautilus_get_uri_shortname_for_display): + * libnautilus-private/nautilus-file-utilities.h: + * libnautilus-private/nautilus-file.c: (nautilus_file_rename), + (nautilus_file_get_display_name_nocopy): + * src/nautilus-location-entry.c: (try_to_expand_path): + Use eel_get_filename_charset to handle the new filename + charset env vars. + +2004-10-28 Alexander Larsson <alexl@redhat.com> + * libnautilus-private/nautilus-global-preferences.c: * src/nautilus-window-manage-views.c: Fix warning due to NULL default string. diff --git a/libnautilus-private/nautilus-file-utilities.c b/libnautilus-private/nautilus-file-utilities.c index e270c5bcb..578eaf8ce 100644 --- a/libnautilus-private/nautilus-file-utilities.c +++ b/libnautilus-private/nautilus-file-utilities.c @@ -407,48 +407,46 @@ 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; + gboolean utf8_filenames; + const char *filename_charset; 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); + utf8_filenames = eel_get_filename_charset (&filename_charset); + if (utf8_filenames) { + /* If not valid utf8, and filenames are utf8, test if converting + from the locale works */ + if (!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 { + /* name was valid, no need to re-validate */ + validated = TRUE; + } + } else { + /* Try to convert from filename charset to utf8 */ + utf8_name = g_convert (name, -1, "UTF-8", filename_charset, 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 */ diff --git a/libnautilus-private/nautilus-file-utilities.h b/libnautilus-private/nautilus-file-utilities.h index 4c6fd2873..5b71e461d 100644 --- a/libnautilus-private/nautilus-file-utilities.h +++ b/libnautilus-private/nautilus-file-utilities.h @@ -72,7 +72,6 @@ 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 a4da3cefe..ba5ab5506 100644 --- a/libnautilus-private/nautilus-file.c +++ b/libnautilus-private/nautilus-file.c @@ -1271,9 +1271,13 @@ nautilus_file_rename (NautilusFile *file, gpointer callback_data) { char *locale_name; + gboolean utf8_filenames; + const char *filename_charset; + + utf8_filenames = eel_get_filename_charset (&filename_charset); /* Note: Desktop file renaming wants utf8, even with G_BROKEN_FILENAMES */ - if (has_local_path (file) && nautilus_have_broken_filenames () && + if (has_local_path (file) && !utf8_filenames && !is_desktop_file (file)) { locale_name = g_filename_from_utf8 (new_name, -1, NULL, NULL, NULL); if (locale_name == NULL) { @@ -2673,10 +2677,11 @@ static char * nautilus_file_get_display_name_nocopy (NautilusFile *file) { char *name, *utf8_name, *short_name; - gboolean broken_filenames; gboolean validated; GnomeVFSURI *vfs_uri; const char *method; + gboolean utf8_filenames; + const char *filename_charset; if (file == NULL) { return NULL; @@ -2707,18 +2712,31 @@ nautilus_file_get_display_name_nocopy (NautilusFile *file) */ /* Keep in sync with nautilus_get_uri_shortname_for_display */ if (has_local_path (file)) { - 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); + utf8_filenames = eel_get_filename_charset (&filename_charset); + if (utf8_filenames) { + /* If not valid utf8, and filenames are utf8, test if converting + from the locale works */ + if (!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 { + /* name was valid, no need to re-validate */ + validated = TRUE; + } + } else { + /* Try to convert from filename charset to utf8 */ + utf8_name = g_convert (name, -1, "UTF-8", filename_charset, 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 (strcmp (name, "/") == 0) { /* Special-case the display name for roots that are not local files */ diff --git a/src/nautilus-location-entry.c b/src/nautilus-location-entry.c index 06bf1de48..b9b344942 100644 --- a/src/nautilus-location-entry.c +++ b/src/nautilus-location-entry.c @@ -162,6 +162,8 @@ try_to_expand_path (gpointer callback_data) GList *element; GnomeVFSURI *uri; GtkEditable *editable; + gboolean utf8_filenames; + const char *filename_charset; char *base_name_uri_escaped; char *base_name; @@ -240,6 +242,8 @@ try_to_expand_path (gpointer callback_data) return FALSE; } + utf8_filenames = eel_get_filename_charset (&filename_charset); + /* iterate through the directory, keeping the intersection of all the names that have the current basename as a prefix. */ expand_text = NULL; @@ -251,23 +255,23 @@ try_to_expand_path (gpointer callback_data) } else { expand_name = g_strdup (current_file_info->name); } - if (nautilus_have_broken_filenames()) { - expand_text = accumulate_name_locale (expand_text, expand_name); - } else { + if (utf8_filenames) { expand_text = accumulate_name_utf8 (expand_text, expand_name); + } else { + expand_text = accumulate_name_locale (expand_text, expand_name); } g_free (expand_name); } } - if (nautilus_have_broken_filenames ()) { + if (!utf8_filenames) { if (expand_text) { - expand_text_utf8 = g_locale_to_utf8 (expand_text, -1, NULL, NULL, NULL); + expand_text_utf8 = g_convert (expand_text, -1, "UTF-8", filename_charset, NULL, NULL, NULL); g_free (expand_text); expand_text = expand_text_utf8; } - base_name_utf8 = g_locale_to_utf8 (base_name, -1, NULL, NULL, NULL); + base_name_utf8 = g_convert (base_name, -1, "UTF-8", filename_charset, NULL, NULL, NULL); g_free (base_name); base_name = base_name_utf8; } |