summaryrefslogtreecommitdiff
path: root/libnautilus-private/nautilus-file.c
diff options
context:
space:
mode:
authorDarin Adler <darin@src.gnome.org>2002-02-28 17:38:53 +0000
committerDarin Adler <darin@src.gnome.org>2002-02-28 17:38:53 +0000
commita6734d303977aa312617c67c70b761a27b5193f6 (patch)
tree9a97bae67f48388309107cfaa6b868e41881bbe8 /libnautilus-private/nautilus-file.c
parent37917988f4b6f4e53bb67efe2cf0145a7c8cd091 (diff)
downloadnautilus-a6734d303977aa312617c67c70b761a27b5193f6.tar.gz
New. (rename_guts): Rename nautilus_file_rename to this.
* 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.
Diffstat (limited to 'libnautilus-private/nautilus-file.c')
-rw-r--r--libnautilus-private/nautilus-file.c61
1 files changed, 47 insertions, 14 deletions
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;
+ }
}
}
}