diff options
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | libnautilus-private/nautilus-file.c | 61 |
2 files changed, 57 insertions, 14 deletions
@@ -1,5 +1,15 @@ 2002-02-28 Darin Adler <darin@bentspoon.com> + * libnautilus-private/nautilus-file.c: (in_filesystem): New. + (rename_guts): Rename nautilus_file_rename to this. + (nautilus_file_rename): Convert name to locale encoding if + G_BROKEN_FILENAMES is set. + (nautilus_file_get_display_name): Convert name to UTF-8 + assuming the locale character set if it's not valid UTF-8. + It was already doing it when G_BROKEN_FILENAMES was set. + +2002-02-28 Darin Adler <darin@bentspoon.com> + * src/nautilus-sidebar.c: (add_command_buttons): Use eel_str_replace_substring to replace the %s rather than using g_strdup_printf. It's not safe to use a string from a data diff --git a/libnautilus-private/nautilus-file.c b/libnautilus-private/nautilus-file.c index ef1909e58..a657991aa 100644 --- a/libnautilus-private/nautilus-file.c +++ b/libnautilus-private/nautilus-file.c @@ -886,6 +886,12 @@ operation_cancel (Operation *op) operation_free (op); } +static gboolean +in_filesystem (NautilusFile *file) +{ + return eel_str_has_prefix (file->details->directory->details->uri, "file:"); +} + static void rename_callback (GnomeVFSAsyncHandle *handle, GnomeVFSResult result, @@ -950,11 +956,11 @@ name_is (NautilusFile *file, const char *new_name) return equal; } -void -nautilus_file_rename (NautilusFile *file, - const char *new_name, - NautilusFileOperationCallback callback, - gpointer callback_data) +static void +rename_guts (NautilusFile *file, + const char *new_name, + NautilusFileOperationCallback callback, + gpointer callback_data) { Operation *op; GnomeVFSFileInfo *partial_file_info; @@ -964,8 +970,8 @@ nautilus_file_rename (NautilusFile *file, g_return_if_fail (new_name != NULL); g_return_if_fail (callback != NULL); - /* Make return an error for incoming names containing path separators. */ - if (strstr (new_name, "/") != NULL) { + /* Return an error for incoming names containing path separators. */ + if (strstr (new_name, "/") != NULL) { (* callback) (file, GNOME_VFS_ERROR_NOT_PERMITTED, callback_data); return; } @@ -1013,7 +1019,6 @@ nautilus_file_rename (NautilusFile *file, /* Do the renaming. */ partial_file_info = gnome_vfs_file_info_new (); - /* FIXME: Handle G_BROKEN_FILENAMES here? */ partial_file_info->name = g_strdup (new_name); vfs_uri = nautilus_file_get_gnome_vfs_uri (file); gnome_vfs_async_set_file_info (&op->handle, @@ -1028,6 +1033,29 @@ nautilus_file_rename (NautilusFile *file, } void +nautilus_file_rename (NautilusFile *file, + const char *new_name, + NautilusFileOperationCallback callback, + gpointer callback_data) +{ + char *locale_name; + + if (!in_filesystem (file) || g_getenv ("G_BROKEN_FILENAMES") == NULL) { + rename_guts (file, new_name, callback, callback_data); + return; + } + + locale_name = g_filename_from_utf8 (new_name, -1, NULL, NULL, NULL); + if (locale_name == NULL) { + (* callback) (file, GNOME_VFS_ERROR_NOT_PERMITTED, callback_data); + return; + } + + rename_guts (file, locale_name, callback, callback_data); + g_free (locale_name); +} + +void nautilus_file_cancel (NautilusFile *file, NautilusFileOperationCallback callback, gpointer callback_data) @@ -2170,13 +2198,18 @@ nautilus_file_get_display_name (NautilusFile *file) } else { /* Support the G_BROKEN_FILENAMES feature of * glib by using g_filename_to_utf8 to convert - * local filenames to UTF-8. + * local filenames to UTF-8. Also do the same + * thing with any local filename that does not + * validate as good UTF-8. */ - if (g_getenv ("G_BROKEN_FILENAMES") != NULL && nautilus_file_is_local (file)) { - utf8_name = g_filename_to_utf8 (name, -1, NULL, NULL, NULL); - if (utf8_name != NULL) { - g_free (name); - name = utf8_name; + if (in_filesystem (file)) { + if (g_getenv ("G_BROKEN_FILENAMES") != NULL + || !g_utf8_validate (name, -1, NULL)) { + utf8_name = g_filename_to_utf8 (name, -1, NULL, NULL, NULL); + if (utf8_name != NULL) { + g_free (name); + name = utf8_name; + } } } } |