nautilus太笨重了; 新版本的xffm似乎比以前更难移至了; gnome-commander的gnome-1版本在没有FAM的情况下总需要手工刷新,gnome2也老是出问题。于是我开始沉下心来用rox。
但它似乎对于在中文文件名(应该是非ANSI字符)上有不少问题,比如对路径包含中文的话,加到书签里之后又无法跳过去,拷贝、移动、删除的时候老是报告路径找不到。
琢磨了一阵,基本上可以用了: rox对于文件名没有进行编码转换就直接交给了gtk2显示,但gtk2要求非ansi字符在显示时必须采用UTF-8编码。这个补丁可以修正这个问题,在Cygwin上和Linux都试过了,但在Cygwin上还不太稳定。
diff -Nurp rox-2.1.2.orig/ROX-Filer/src/action.c rox-2.1.2/ROX-Filer/src/action.c --- rox-2.1.2.orig/ROX-Filer/src/action.c 2004-01-22 04:03:16.000000000 +0800 +++ rox-2.1.2/ROX-Filer/src/action.c 2004-10-11 19:23:10.000000000 +0800 @@ -887,12 +887,14 @@ static void do_usage(const char *src_pat } /* dest_path is the dir containing src_path */ -static void do_delete(const char *src_path, const char *unused) +static void do_delete(const char *src_path_req, const char *unused) { struct stat info; gboolean write_prot; char *safe_path; + gchar *src_path = filename_from_utf8(src_path_req); + check_flags(); if (mc_lstat(src_path, &info)) @@ -994,10 +996,12 @@ static void do_eject(const char *path) /* path is the item to check. If is is a directory then we may recurse * (unless prune is used). */ -static void do_find(const char *path, const char *unused) +static void do_find(const char *path_req, const char *unused) { FindInfo info; + gchar *path = filename_from_utf8(path_req); + check_flags(); if (!quiet) @@ -1081,11 +1085,13 @@ static struct mode_change *nice_mode_com return retval; } -static void do_chmod(const char *path, const char *unused) +static void do_chmod(const char *path_req, const char *unused) { struct stat info; mode_t new_mode; + gchar *path = filename_from_utf8(path_req); + check_flags(); if (mc_lstat(path, &info)) @@ -1159,10 +1165,12 @@ static void do_chmod(const char *path, c } } -static void do_settype(const char *path, const char *unused) +static void do_settype(const char *path_req, const char *unused) { struct stat info; + gchar *path = filename_from_utf8(path_req); + check_flags(); if (mc_lstat(path, &info)) @@ -1257,8 +1265,9 @@ static const char *make_dest_path(const else leaf++; } + gchar *leaf_copy = filename_from_utf8(leaf); - return make_path(dir, leaf); + return make_path(dir, leaf_copy); } /* If action_leaf is not NULL it specifies the new leaf name */ @@ -1510,8 +1519,11 @@ static void do_move2(const char *path, c /* Copy path to dest. * Check that path not copied into itself. */ -static void do_copy(const char *path, const char *dest) +static void do_copy(const char *path_req, const char *dest_req) { + gchar *path = filename_from_utf8(path_req); + gchar *dest = filename_from_utf8(dest_req); + if (is_sub_dir(make_dest_path(path, dest), path)) printf_send(_("!ERROR: Can't copy object into itselfn")); else @@ -1524,8 +1536,11 @@ static void do_copy(const char *path, co /* Move path to dest. * Check that path not moved into itself. */ -static void do_move(const char *path, const char *dest) +static void do_move(const char *path_req, const char *dest_req) { + gchar *path = filename_from_utf8(path_req); + gchar *dest = filename_from_utf8(dest_req); + if (is_sub_dir(make_dest_path(path, dest), path)) printf_send( _("!ERROR: Can't move/rename object into itselfn")); @@ -1536,10 +1551,13 @@ static void do_move(const char *path, co } } -static void do_link(const char *path, const char *dest) +static void do_link(const char *path_req, const char *dest_req) { const char *dest_path; + gchar *path = filename_from_utf8(path_req); + gchar *dest = filename_from_utf8(dest_req); + check_flags(); dest_path = make_dest_path(path, dest); @@ -1566,6 +1584,7 @@ static void do_mount(const guchar *path, const char *argv[3] = {NULL, NULL, NULL}; char *err; + /* path = filename_from_utf8(path); */ check_flags(); argv[0] = mount ? "mount" : "umount"; diff -Nurp rox-2.1.2.orig/ROX-Filer/src/bookmarks.c rox-2.1.2/ROX-Filer/src/bookmarks.c --- rox-2.1.2.orig/ROX-Filer/src/bookmarks.c 2004-03-25 21:03:44.000000000 +0800 +++ rox-2.1.2/ROX-Filer/src/bookmarks.c 2004-10-11 16:58:26.000000000 +0800 @@ -380,8 +380,10 @@ static xmlNode *bookmark_find(const gcha same = strcmp(mark, path) == 0; xmlFree(path); - if (same) + if (same) { + printf("This path already in bookmark listn.", path); return node; + } } return NULL; @@ -410,10 +412,12 @@ static void bookmarks_add(GtkMenuItem *m bookmarks_add_dir(filer_window->sym_path); } -static void bookmarks_add_dir(const guchar *dir) +static void bookmarks_add_dir(const guchar *dir_req) { xmlNode *bookmark; + gchar *dir = filename_to_utf8(dir_req); + if (bookmark_find(dir)) return; @@ -439,8 +443,10 @@ static void bookmarks_activate(GtkMenuSh mark = gtk_label_get_text(label); } - if (strcmp(mark, filer_window->sym_path) != 0) - filer_change_to(filer_window, mark, NULL); + gchar *path = filename_from_utf8(mark); + + if (strcmp(path, filer_window->sym_path) != 0) + filer_change_to(filer_window, path, NULL); if (g_hash_table_lookup(fstab_mounts, filer_window->real_path) && !mount_is_mounted(filer_window->real_path, NULL, NULL)) { diff -Nurp rox-2.1.2.orig/ROX-Filer/src/display.c rox-2.1.2/ROX-Filer/src/display.c --- rox-2.1.2.orig/ROX-Filer/src/display.c 2004-04-27 18:34:30.000000000 +0800 +++ rox-2.1.2/ROX-Filer/src/display.c 2004-10-11 18:00:40.000000000 +0800 @@ -759,15 +759,24 @@ void display_update_view(FilerWindow *fi view->layout = NULL; } + gchar *u8 = filename_to_utf8(item->leafname); if (view->layout) { /* Do nothing */ } +#ifndef __CYGWIN__ else if (g_utf8_validate(item->leafname, -1, NULL)) { view->layout = gtk_widget_create_pango_layout( filer_window->window, item->leafname); } +#else /* on Cygwin(Windows), filenames should be in local charset, rather than UTF-8, */ + else if (g_utf8_validate(u8, -1, NULL)) + { + view->layout = gtk_widget_create_pango_layout( + filer_window->window, u8); + } +#endif else { PangoAttribute *attr; diff -Nurp rox-2.1.2.orig/ROX-Filer/src/dropbox.c rox-2.1.2/ROX-Filer/src/dropbox.c --- rox-2.1.2.orig/ROX-Filer/src/dropbox.c 2004-01-22 04:03:16.000000000 +0800 +++ rox-2.1.2/ROX-Filer/src/dropbox.c 2004-10-11 18:00:50.000000000 +0800 @@ -177,6 +177,7 @@ void drop_box_set_path(DropBox *drop_box gtk_widget_set_sensitive(drop_box->buttons, FALSE); } + ensure_utf8(©); gtk_label_set_text(GTK_LABEL(drop_box->label), copy); g_free(copy); } diff -Nurp rox-2.1.2.orig/ROX-Filer/src/filer.c rox-2.1.2/ROX-Filer/src/filer.c --- rox-2.1.2.orig/ROX-Filer/src/filer.c 2004-04-13 17:04:04.000000000 +0800 +++ rox-2.1.2/ROX-Filer/src/filer.c 2004-10-11 16:58:38.000000000 +0800 @@ -2102,10 +2102,12 @@ void filer_add_tip_details(FilerWindow * g_object_unref(info); } +#ifndef __CYGWIN__ /* TODO: use G_BROKEN_FILENAME/G_FILENAME_ENCODINGS ?? */ if (!g_utf8_validate(item->leafname, -1, NULL)) g_string_append(tip, _("This filename is not valid UTF-8. " "You should rename it.n")); +#endif } /* Return the selection as a text/uri-list. diff -Nurp rox-2.1.2.orig/ROX-Filer/src/menu.c rox-2.1.2/ROX-Filer/src/menu.c --- rox-2.1.2.orig/ROX-Filer/src/menu.c 2004-05-01 00:36:42.000000000 +0800 +++ rox-2.1.2/ROX-Filer/src/menu.c 2004-10-11 16:59:02.000000000 +0800 @@ -1024,7 +1024,7 @@ static void find(FilerWindow *filer_wind * both the current and new paths. * NOTE: This function unrefs 'image'! */ -static void savebox_show(const gchar *action, const gchar *path, +static void savebox_show(const gchar *action, const gchar *path_req, MaskedPixmap *image, SaveCb callback, GdkDragAction dnd_action) { @@ -1032,6 +1032,7 @@ static void savebox_show(const gchar *ac GtkWidget *check_relative = NULL; g_return_if_fail(image != NULL); + gchar *path = filename_to_utf8(path_req); savebox = gtk_savebox_new(action); gtk_savebox_set_action(GTK_SAVEBOX(savebox), dnd_action); @@ -1293,8 +1294,10 @@ void menu_show_options(gpointer data, gu } static gboolean new_directory_cb(GObject *savebox, - const gchar *initial, const gchar *path) + const gchar *initial, const gchar *path_req) { + gchar *path = filename_from_utf8(path_req); + if (mkdir(path, S_IRWXU | S_IRWXG | S_IRWXO)) { report_error("mkdir: %s", g_strerror(errno)); @@ -1325,9 +1328,11 @@ static void new_directory(gpointer data, } static gboolean new_file_cb(GObject *savebox, - const gchar *initial, const gchar *path) + const gchar *initial, const gchar *path_req) { int fd; + + gchar *path = filename_from_utf8(path_req); fd = open(path, O_CREAT | O_EXCL, 0666); diff -Nurp rox-2.1.2.orig/ROX-Filer/src/pinboard.c rox-2.1.2/ROX-Filer/src/pinboard.c --- rox-2.1.2.orig/ROX-Filer/src/pinboard.c 2004-03-07 02:50:48.000000000 +0800 +++ rox-2.1.2/ROX-Filer/src/pinboard.c 2004-10-11 19:23:38.000000000 +0800 @@ -753,6 +753,7 @@ static void drag_backdrop_dropped(GtkWid radios = g_object_get_data(G_OBJECT(dialog), "rox-radios"); g_return_if_fail(radios != NULL); + /*gchar *path = filename_from_utf8(path_req); */ if (mc_stat(path, &info)) { delayed_error( @@ -2088,12 +2089,13 @@ static void create_pinboard_window(Pinbo } /* Load image 'path' and scale according to 'style' */ -static GdkPixmap *load_backdrop(const gchar *path, BackdropStyle style) +static GdkPixmap *load_backdrop(const gchar *path_req, BackdropStyle style) { GdkPixmap *pixmap; GdkPixbuf *pixbuf; GError *error = NULL; + gchar *path = filename_from_utf8(path_req); pixbuf = gdk_pixbuf_new_from_file(path, &error); if (error) { diff -Nurp rox-2.1.2.orig/ROX-Filer/src/support.c rox-2.1.2/ROX-Filer/src/support.c --- rox-2.1.2.orig/ROX-Filer/src/support.c 2004-04-27 18:34:30.000000000 +0800 +++ rox-2.1.2/ROX-Filer/src/support.c 2004-10-11 17:20:42.000000000 +0800 @@ -1083,6 +1083,34 @@ void ensure_utf8(gchar **sp) } } +/* +void filename_from_utf8(gchar **pathp) +{ + gchar *foo = g_filename_from_utf8(*pathp, -1, NULL, NULL, NULL); + if (foo) { + *pathp = g_strdup(foo); + g_free(foo); + } +} */ + +gchar* filename_from_utf8(const gchar* path_u) +{ + gchar *foo = g_filename_from_utf8(path_u, -1, NULL, NULL, NULL); + if (foo) { + return foo; + } else + return g_strdup(path_u); +} + +gchar* filename_to_utf8(const gchar* path) +{
但它似乎对于在中文文件名(应该是非ANSI字符)上有不少问题,比如对路径包含中文的话,加到书签里之后又无法跳过去,拷贝、移动、删除的时候老是报告路径找不到。
琢磨了一阵,基本上可以用了: rox对于文件名没有进行编码转换就直接交给了gtk2显示,但gtk2要求非ansi字符在显示时必须采用UTF-8编码。这个补丁可以修正这个问题,在Cygwin上和Linux都试过了,但在Cygwin上还不太稳定。
diff -Nurp rox-2.1.2.orig/ROX-Filer/src/action.c rox-2.1.2/ROX-Filer/src/action.c --- rox-2.1.2.orig/ROX-Filer/src/action.c 2004-01-22 04:03:16.000000000 +0800 +++ rox-2.1.2/ROX-Filer/src/action.c 2004-10-11 19:23:10.000000000 +0800 @@ -887,12 +887,14 @@ static void do_usage(const char *src_pat } /* dest_path is the dir containing src_path */ -static void do_delete(const char *src_path, const char *unused) +static void do_delete(const char *src_path_req, const char *unused) { struct stat info; gboolean write_prot; char *safe_path; + gchar *src_path = filename_from_utf8(src_path_req); + check_flags(); if (mc_lstat(src_path, &info)) @@ -994,10 +996,12 @@ static void do_eject(const char *path) /* path is the item to check. If is is a directory then we may recurse * (unless prune is used). */ -static void do_find(const char *path, const char *unused) +static void do_find(const char *path_req, const char *unused) { FindInfo info; + gchar *path = filename_from_utf8(path_req); + check_flags(); if (!quiet) @@ -1081,11 +1085,13 @@ static struct mode_change *nice_mode_com return retval; } -static void do_chmod(const char *path, const char *unused) +static void do_chmod(const char *path_req, const char *unused) { struct stat info; mode_t new_mode; + gchar *path = filename_from_utf8(path_req); + check_flags(); if (mc_lstat(path, &info)) @@ -1159,10 +1165,12 @@ static void do_chmod(const char *path, c } } -static void do_settype(const char *path, const char *unused) +static void do_settype(const char *path_req, const char *unused) { struct stat info; + gchar *path = filename_from_utf8(path_req); + check_flags(); if (mc_lstat(path, &info)) @@ -1257,8 +1265,9 @@ static const char *make_dest_path(const else leaf++; } + gchar *leaf_copy = filename_from_utf8(leaf); - return make_path(dir, leaf); + return make_path(dir, leaf_copy); } /* If action_leaf is not NULL it specifies the new leaf name */ @@ -1510,8 +1519,11 @@ static void do_move2(const char *path, c /* Copy path to dest. * Check that path not copied into itself. */ -static void do_copy(const char *path, const char *dest) +static void do_copy(const char *path_req, const char *dest_req) { + gchar *path = filename_from_utf8(path_req); + gchar *dest = filename_from_utf8(dest_req); + if (is_sub_dir(make_dest_path(path, dest), path)) printf_send(_("!ERROR: Can't copy object into itselfn")); else @@ -1524,8 +1536,11 @@ static void do_copy(const char *path, co /* Move path to dest. * Check that path not moved into itself. */ -static void do_move(const char *path, const char *dest) +static void do_move(const char *path_req, const char *dest_req) { + gchar *path = filename_from_utf8(path_req); + gchar *dest = filename_from_utf8(dest_req); + if (is_sub_dir(make_dest_path(path, dest), path)) printf_send( _("!ERROR: Can't move/rename object into itselfn")); @@ -1536,10 +1551,13 @@ static void do_move(const char *path, co } } -static void do_link(const char *path, const char *dest) +static void do_link(const char *path_req, const char *dest_req) { const char *dest_path; + gchar *path = filename_from_utf8(path_req); + gchar *dest = filename_from_utf8(dest_req); + check_flags(); dest_path = make_dest_path(path, dest); @@ -1566,6 +1584,7 @@ static void do_mount(const guchar *path, const char *argv[3] = {NULL, NULL, NULL}; char *err; + /* path = filename_from_utf8(path); */ check_flags(); argv[0] = mount ? "mount" : "umount"; diff -Nurp rox-2.1.2.orig/ROX-Filer/src/bookmarks.c rox-2.1.2/ROX-Filer/src/bookmarks.c --- rox-2.1.2.orig/ROX-Filer/src/bookmarks.c 2004-03-25 21:03:44.000000000 +0800 +++ rox-2.1.2/ROX-Filer/src/bookmarks.c 2004-10-11 16:58:26.000000000 +0800 @@ -380,8 +380,10 @@ static xmlNode *bookmark_find(const gcha same = strcmp(mark, path) == 0; xmlFree(path); - if (same) + if (same) { + printf("This path already in bookmark listn.", path); return node; + } } return NULL; @@ -410,10 +412,12 @@ static void bookmarks_add(GtkMenuItem *m bookmarks_add_dir(filer_window->sym_path); } -static void bookmarks_add_dir(const guchar *dir) +static void bookmarks_add_dir(const guchar *dir_req) { xmlNode *bookmark; + gchar *dir = filename_to_utf8(dir_req); + if (bookmark_find(dir)) return; @@ -439,8 +443,10 @@ static void bookmarks_activate(GtkMenuSh mark = gtk_label_get_text(label); } - if (strcmp(mark, filer_window->sym_path) != 0) - filer_change_to(filer_window, mark, NULL); + gchar *path = filename_from_utf8(mark); + + if (strcmp(path, filer_window->sym_path) != 0) + filer_change_to(filer_window, path, NULL); if (g_hash_table_lookup(fstab_mounts, filer_window->real_path) && !mount_is_mounted(filer_window->real_path, NULL, NULL)) { diff -Nurp rox-2.1.2.orig/ROX-Filer/src/display.c rox-2.1.2/ROX-Filer/src/display.c --- rox-2.1.2.orig/ROX-Filer/src/display.c 2004-04-27 18:34:30.000000000 +0800 +++ rox-2.1.2/ROX-Filer/src/display.c 2004-10-11 18:00:40.000000000 +0800 @@ -759,15 +759,24 @@ void display_update_view(FilerWindow *fi view->layout = NULL; } + gchar *u8 = filename_to_utf8(item->leafname); if (view->layout) { /* Do nothing */ } +#ifndef __CYGWIN__ else if (g_utf8_validate(item->leafname, -1, NULL)) { view->layout = gtk_widget_create_pango_layout( filer_window->window, item->leafname); } +#else /* on Cygwin(Windows), filenames should be in local charset, rather than UTF-8, */ + else if (g_utf8_validate(u8, -1, NULL)) + { + view->layout = gtk_widget_create_pango_layout( + filer_window->window, u8); + } +#endif else { PangoAttribute *attr; diff -Nurp rox-2.1.2.orig/ROX-Filer/src/dropbox.c rox-2.1.2/ROX-Filer/src/dropbox.c --- rox-2.1.2.orig/ROX-Filer/src/dropbox.c 2004-01-22 04:03:16.000000000 +0800 +++ rox-2.1.2/ROX-Filer/src/dropbox.c 2004-10-11 18:00:50.000000000 +0800 @@ -177,6 +177,7 @@ void drop_box_set_path(DropBox *drop_box gtk_widget_set_sensitive(drop_box->buttons, FALSE); } + ensure_utf8(©); gtk_label_set_text(GTK_LABEL(drop_box->label), copy); g_free(copy); } diff -Nurp rox-2.1.2.orig/ROX-Filer/src/filer.c rox-2.1.2/ROX-Filer/src/filer.c --- rox-2.1.2.orig/ROX-Filer/src/filer.c 2004-04-13 17:04:04.000000000 +0800 +++ rox-2.1.2/ROX-Filer/src/filer.c 2004-10-11 16:58:38.000000000 +0800 @@ -2102,10 +2102,12 @@ void filer_add_tip_details(FilerWindow * g_object_unref(info); } +#ifndef __CYGWIN__ /* TODO: use G_BROKEN_FILENAME/G_FILENAME_ENCODINGS ?? */ if (!g_utf8_validate(item->leafname, -1, NULL)) g_string_append(tip, _("This filename is not valid UTF-8. " "You should rename it.n")); +#endif } /* Return the selection as a text/uri-list. diff -Nurp rox-2.1.2.orig/ROX-Filer/src/menu.c rox-2.1.2/ROX-Filer/src/menu.c --- rox-2.1.2.orig/ROX-Filer/src/menu.c 2004-05-01 00:36:42.000000000 +0800 +++ rox-2.1.2/ROX-Filer/src/menu.c 2004-10-11 16:59:02.000000000 +0800 @@ -1024,7 +1024,7 @@ static void find(FilerWindow *filer_wind * both the current and new paths. * NOTE: This function unrefs 'image'! */ -static void savebox_show(const gchar *action, const gchar *path, +static void savebox_show(const gchar *action, const gchar *path_req, MaskedPixmap *image, SaveCb callback, GdkDragAction dnd_action) { @@ -1032,6 +1032,7 @@ static void savebox_show(const gchar *ac GtkWidget *check_relative = NULL; g_return_if_fail(image != NULL); + gchar *path = filename_to_utf8(path_req); savebox = gtk_savebox_new(action); gtk_savebox_set_action(GTK_SAVEBOX(savebox), dnd_action); @@ -1293,8 +1294,10 @@ void menu_show_options(gpointer data, gu } static gboolean new_directory_cb(GObject *savebox, - const gchar *initial, const gchar *path) + const gchar *initial, const gchar *path_req) { + gchar *path = filename_from_utf8(path_req); + if (mkdir(path, S_IRWXU | S_IRWXG | S_IRWXO)) { report_error("mkdir: %s", g_strerror(errno)); @@ -1325,9 +1328,11 @@ static void new_directory(gpointer data, } static gboolean new_file_cb(GObject *savebox, - const gchar *initial, const gchar *path) + const gchar *initial, const gchar *path_req) { int fd; + + gchar *path = filename_from_utf8(path_req); fd = open(path, O_CREAT | O_EXCL, 0666); diff -Nurp rox-2.1.2.orig/ROX-Filer/src/pinboard.c rox-2.1.2/ROX-Filer/src/pinboard.c --- rox-2.1.2.orig/ROX-Filer/src/pinboard.c 2004-03-07 02:50:48.000000000 +0800 +++ rox-2.1.2/ROX-Filer/src/pinboard.c 2004-10-11 19:23:38.000000000 +0800 @@ -753,6 +753,7 @@ static void drag_backdrop_dropped(GtkWid radios = g_object_get_data(G_OBJECT(dialog), "rox-radios"); g_return_if_fail(radios != NULL); + /*gchar *path = filename_from_utf8(path_req); */ if (mc_stat(path, &info)) { delayed_error( @@ -2088,12 +2089,13 @@ static void create_pinboard_window(Pinbo } /* Load image 'path' and scale according to 'style' */ -static GdkPixmap *load_backdrop(const gchar *path, BackdropStyle style) +static GdkPixmap *load_backdrop(const gchar *path_req, BackdropStyle style) { GdkPixmap *pixmap; GdkPixbuf *pixbuf; GError *error = NULL; + gchar *path = filename_from_utf8(path_req); pixbuf = gdk_pixbuf_new_from_file(path, &error); if (error) { diff -Nurp rox-2.1.2.orig/ROX-Filer/src/support.c rox-2.1.2/ROX-Filer/src/support.c --- rox-2.1.2.orig/ROX-Filer/src/support.c 2004-04-27 18:34:30.000000000 +0800 +++ rox-2.1.2/ROX-Filer/src/support.c 2004-10-11 17:20:42.000000000 +0800 @@ -1083,6 +1083,34 @@ void ensure_utf8(gchar **sp) } } +/* +void filename_from_utf8(gchar **pathp) +{ + gchar *foo = g_filename_from_utf8(*pathp, -1, NULL, NULL, NULL); + if (foo) { + *pathp = g_strdup(foo); + g_free(foo); + } +} */ + +gchar* filename_from_utf8(const gchar* path_u) +{ + gchar *foo = g_filename_from_utf8(path_u, -1, NULL, NULL, NULL); + if (foo) { + return foo; + } else + return g_strdup(path_u); +} + +gchar* filename_to_utf8(const gchar* path) +{
Powered by ScribeFire.
没有评论:
发表评论