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.
This commit is contained in:
Alexander Larsson 2004-10-28 14:00:38 +00:00 committed by Alexander Larsson
parent 14704c0966
commit 1fd8052fa7
5 changed files with 69 additions and 39 deletions

View file

@ -1,3 +1,14 @@
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:

View file

@ -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 */

View file

@ -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 */

View file

@ -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 */

View file

@ -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;
}