Re: [patch] [bug 432510] samba filename encoding on none UTF-8 locales
- From: Takao Fujiwara - Tokyo S/W Center <Takao Fujiwara Sun COM>
- To: Alexander Larsson <alexl redhat com>
- Cc: nautilus-list gnome org
- Subject: Re: [patch] [bug 432510] samba filename encoding on none UTF-8 locales
- Date: Tue, 22 May 2007 23:21:49 +0900
Alexander Larsson wrote:
> Eh, this looks even worse. It never looks at G_BROKEN_FILENAMES_SMB.
Sorry, I misunderstood your request.
I updated the patch. Could you review the attachment?
I noticed the copy progress dialog also has the same problem so I modified nautilus-file-operations.c, too.
Could you also review this?
I may not understand the process. Should I use this alias before I update the bugzilla report?
--- nautilus-2.18.1/libnautilus-private/nautilus-file-operations-progress.c.orig 2007-05-21 21:10:10.455052000 +0900
+++ nautilus-2.18.1/libnautilus-private/nautilus-file-operations-progress.c 2007-05-21 21:12:18.814140000 +0900
@@ -180,9 +180,8 @@ nautilus_file_operations_progress_update
}
static void
-set_text_unescaped_trimmed (GtkLabel *label, const char *text)
+set_text_trimmed (GtkLabel *label, const char *text)
{
- char *unescaped_text;
char *unescaped_utf8;
if (text == NULL || text[0] == '\0') {
@@ -190,11 +189,9 @@ set_text_unescaped_trimmed (GtkLabel *la
return;
}
- unescaped_text = gnome_vfs_unescape_string_for_display (text);
- unescaped_utf8 = eel_make_valid_utf8 (unescaped_text);
+ unescaped_utf8 = eel_make_valid_utf8 (text);
gtk_label_set_text (label, unescaped_utf8);
g_free (unescaped_utf8);
- g_free (unescaped_text);
}
/* This is just to make sure the dialog is not closed without explicit
@@ -588,12 +585,12 @@ nautilus_file_operations_progress_new_fi
progress->details->file_index = file_index;
gtk_label_set_text (GTK_LABEL (progress->details->from_label), from_prefix);
- set_text_unescaped_trimmed
+ set_text_trimmed
(GTK_LABEL (progress->details->from_path_label), from_path);
if (progress->details->to_prefix != NULL && progress->details->to_path_label != NULL) {
gtk_label_set_text (GTK_LABEL (progress->details->to_label), to_prefix);
- set_text_unescaped_trimmed
+ set_text_trimmed
(GTK_LABEL (progress->details->to_path_label), to_path);
}
--- nautilus-2.18.1/libnautilus-private/nautilus-file-operations.c.orig 2007-05-21 18:26:53.526101000 +0900
+++ nautilus-2.18.1/libnautilus-private/nautilus-file-operations.c 2007-05-21 21:55:10.109576000 +0900
@@ -419,10 +419,13 @@ progress_dialog_set_to_from_item_text (N
char *from_text;
char *to_path;
char *to_text;
+ char *unescaped_path;
+ char *utf8_path;
char *progress_label_text;
const char *hostname;
const char *from_prefix;
const char *to_prefix;
+ const char *filename_charset;
GnomeVFSURI *uri;
int length;
@@ -445,6 +448,31 @@ progress_dialog_set_to_from_item_text (N
from_path [length - 1] = '\0';
}
+ unescaped_path = gnome_vfs_unescape_string_for_display (from_path);
+ g_free (from_path);
+ from_path = unescaped_path;
+
+ if (strcmp (uri->method_string, "file") == 0) {
+ utf8_path = g_filename_to_utf8 (from_path, -1,
+ NULL, NULL, NULL);
+ g_free (from_path);
+ from_path = utf8_path;
+ } else if (nautilus_use_local_charset_from_path (from_uri) &&
+ !eel_get_filename_charset (&filename_charset)) {
+ utf8_path = g_convert (from_path, -1,
+ "UTF-8", filename_charset,
+ NULL, NULL, NULL);
+ if (utf8_path) {
+ g_free (from_path);
+ from_path = utf8_path;
+ } else {
+ g_warning (_(NAUTILUS_FILE_NAMES_SMB_WARING));
+ }
+ }
+ utf8_path = eel_make_valid_utf8 (from_path);
+ g_free (from_path);
+ from_path = utf8_path;
+
if (strcmp (uri->method_string, "file") != 0) {
hostname = gnome_vfs_uri_get_host_name (uri);
}
@@ -474,6 +502,31 @@ progress_dialog_set_to_from_item_text (N
to_path [length - 1] = '\0';
}
+ unescaped_path = gnome_vfs_unescape_string_for_display (to_path);
+ g_free (to_path);
+ to_path = unescaped_path;
+
+ if (strcmp (uri->method_string, "file") == 0) {
+ utf8_path = g_filename_to_utf8 (to_path, -1,
+ NULL, NULL, NULL);
+ g_free (to_path);
+ to_path = utf8_path;
+ } else if (nautilus_use_local_charset_from_path (to_uri) &&
+ !eel_get_filename_charset (&filename_charset)) {
+ utf8_path = g_convert (to_path, -1,
+ "UTF-8", filename_charset,
+ NULL, NULL, NULL);
+ if (utf8_path) {
+ g_free (to_path);
+ to_path = utf8_path;
+ } else {
+ g_warning (_(NAUTILUS_FILE_NAMES_SMB_WARING));
+ }
+ }
+ utf8_path = eel_make_valid_utf8 (to_path);
+ g_free (to_path);
+ to_path = utf8_path;
+
if (strcmp (uri->method_string, "file") != 0) {
hostname = gnome_vfs_uri_get_host_name (uri);
}
--- nautilus-2.18.1/libnautilus-private/nautilus-file-utilities.c.orig 2007-05-21 19:02:32.657656000 +0900
+++ nautilus-2.18.1/libnautilus-private/nautilus-file-utilities.c 2007-05-21 20:34:55.147066000 +0900
@@ -873,6 +873,7 @@ nautilus_get_uri_shortname_for_display (
char *text_uri, *local_file;
gboolean validated;
const char *method;
+ const char *filename_charset;
validated = FALSE;
@@ -903,6 +904,15 @@ nautilus_get_uri_shortname_for_display (
name = g_strdup_printf ("%s: %s", method, name);
g_free (tmp);
}
+ } else if (nautilus_use_local_charset_from_uri (uri) &&
+ !eel_get_filename_charset (&filename_charset)) {
+ utf8_name = g_convert (name, -1, "UTF-8", filename_charset, NULL, NULL, NULL);
+ if (utf8_name) {
+ g_free (name);
+ name = utf8_name;
+ } else {
+ g_warning (_(NAUTILUS_FILE_NAMES_SMB_WARING));
+ }
}
if (!validated && !g_utf8_validate (name, -1, NULL)) {
@@ -922,3 +932,35 @@ nautilus_self_check_file_utilities (void
}
#endif /* !NAUTILUS_OMIT_SELF_CHECK */
+
+gboolean
+nautilus_use_local_charset_from_path (const char *text_uri)
+{
+ static gboolean done = FALSE;
+ static gboolean broken_filenames_smb = FALSE;
+
+ g_return_val_if_fail (text_uri != NULL, FALSE);
+
+ if (!done) {
+ broken_filenames_smb = g_getenv ("G_BROKEN_FILENAMES_SMB") != NULL;
+ done = TRUE;
+ }
+ return broken_filenames_smb &&
+ eel_str_has_prefix (text_uri, "smb:");
+}
+
+gboolean
+nautilus_use_local_charset_from_uri (const GnomeVFSURI *uri)
+{
+ char *text_uri = NULL;
+ gboolean retval = FALSE;
+
+ g_return_val_if_fail (uri != NULL, FALSE);
+
+ text_uri = gnome_vfs_uri_to_string (uri, GNOME_VFS_URI_HIDE_PASSWORD);
+ retval = nautilus_use_local_charset_from_path (text_uri);
+ g_free (text_uri);
+
+ return retval;
+}
+
--- nautilus-2.18.1/libnautilus-private/nautilus-file-utilities.h.orig 2007-05-21 19:48:01.852002000 +0900
+++ nautilus-2.18.1/libnautilus-private/nautilus-file-utilities.h 2007-05-21 20:33:50.082145000 +0900
@@ -25,10 +25,13 @@
#ifndef NAUTILUS_FILE_UTILITIES_H
#define NAUTILUS_FILE_UTILITIES_H
+#include <glib/gi18n.h>
#include <libgnomevfs/gnome-vfs-types.h>
#define NAUTILUS_SAVED_SEARCH_EXTENSION ".savedSearch"
#define NAUTILUS_SAVED_SEARCH_MIMETYPE "application/x-gnome-saved-search"
+#define NAUTILUS_FILE_NAMES_SMB_WARING \
+ N_("Your smb.conf or G_BROKEN_FILE_NAMES is not configured correctly.")
/* Recognizing special file names. */
gboolean nautilus_file_name_matches_hidden_pattern (const char *name_or_relative_uri);
@@ -90,4 +93,8 @@ char * nautilus_find_existing_uri_in_h
const char *nautilus_get_vfs_method_display_name (char *method);
char * nautilus_get_uri_shortname_for_display (GnomeVFSURI *uri);
+/* Whether use local charset for remote filesystem or not */
+gboolean nautilus_use_local_charset_from_path (const char *text_uri);
+gboolean nautilus_use_local_charset_from_uri (const GnomeVFSURI *uri);
+
#endif /* NAUTILUS_FILE_UTILITIES_H */
--- nautilus-2.18.1/libnautilus-private/nautilus-file.c.orig 2007-04-20 17:59:54.000000000 +0900
+++ nautilus-2.18.1/libnautilus-private/nautilus-file.c 2007-05-21 20:38:54.402345000 +0900
@@ -1034,6 +1034,12 @@ has_local_path (NautilusFile *file)
return eel_str_has_prefix (file->details->directory->details->uri, "file:");
}
+static gboolean
+use_local_charset (NautilusFile *file)
+{
+ return nautilus_use_local_charset_from_path (file->details->directory->details->uri);
+}
+
static void
rename_callback (GnomeVFSAsyncHandle *handle,
GnomeVFSResult result,
@@ -1260,9 +1266,10 @@ nautilus_file_rename (NautilusFile *file
utf8_filenames = eel_get_filename_charset (&filename_charset);
/* Note: Desktop file renaming wants utf8, even with G_BROKEN_FILENAMES */
- if (has_local_path (file) && !utf8_filenames &&
+ if ((has_local_path (file) || use_local_charset (file)) &&
+ !utf8_filenames &&
!is_desktop_file (file)) {
- locale_name = g_filename_from_utf8 (new_name, -1, NULL, NULL, NULL);
+ locale_name = g_convert (new_name, -1, filename_charset, "UTF-8", NULL, NULL, NULL);
if (locale_name == NULL) {
(* callback) (file, GNOME_VFS_ERROR_NOT_PERMITTED, callback_data);
return;
@@ -2642,6 +2649,7 @@ static char *
nautilus_file_get_display_name_nocopy (NautilusFile *file)
{
char *name, *utf8_name, *short_name;
+ const char *filename_charset;
gboolean validated;
GnomeVFSURI *vfs_uri;
const char *method;
@@ -2659,6 +2667,16 @@ nautilus_file_get_display_name_nocopy (N
if (file->details->got_link_info && file->details->display_name != NULL) {
name = g_strdup (file->details->display_name);
+ if (use_local_charset (file) &&
+ !eel_get_filename_charset (&filename_charset)) {
+ utf8_name = g_convert (name, -1, "UTF-8", filename_charset, NULL, NULL, NULL);
+ if (utf8_name) {
+ g_free (name);
+ name = utf8_name;
+ } else {
+ g_warning (_(NAUTILUS_FILE_NAMES_SMB_WARING));
+ }
+ }
} else {
name = nautilus_file_get_name (file);
if (name == NULL) {
@@ -2703,6 +2721,15 @@ nautilus_file_get_display_name_nocopy (N
g_free (short_name);
gnome_vfs_uri_unref (vfs_uri);
+ } else if (use_local_charset (file) &&
+ !eel_get_filename_charset (&filename_charset)) {
+ utf8_name = g_convert (name, -1, "UTF-8", filename_charset, NULL, NULL, NULL);
+ if (utf8_name) {
+ g_free (name);
+ name = utf8_name;
+ } else {
+ g_warning (_(NAUTILUS_FILE_NAMES_SMB_WARING));
+ }
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]