summaryrefslogtreecommitdiff
path: root/libnautilus-private
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2004-10-28 14:00:38 +0000
committerAlexander Larsson <alexl@src.gnome.org>2004-10-28 14:00:38 +0000
commit1fd8052fa7d77b0b20eeaad5d8368947440db093 (patch)
treee0026f8dc28ec12f621a4b45ae5d4df86d1845a3 /libnautilus-private
parent14704c0966ac5c6d8ae65b0b62cd95d6fca8aa92 (diff)
downloadnautilus-1fd8052fa7d77b0b20eeaad5d8368947440db093.tar.gz
Use eel_get_filename_charset to handle the new filename charset env vars.
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.
Diffstat (limited to 'libnautilus-private')
-rw-r--r--libnautilus-private/nautilus-file-utilities.c46
-rw-r--r--libnautilus-private/nautilus-file-utilities.h1
-rw-r--r--libnautilus-private/nautilus-file.c34
3 files changed, 48 insertions, 33 deletions
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 */