From 857fe38e87a6a7097c0ac0cb37fb7b8213a3cc4e Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Mon, 22 Jul 2013 15:25:12 +0300 Subject: [PATCH] Fix panel recoding Signed-off-by: Slava Zanko --- lib/vfs/path.c | 33 +++++++++++++++++++++++++++++++++ lib/vfs/path.h | 1 + lib/vfs/vfs.c | 34 ---------------------------------- lib/vfs/vfs.h | 4 ---- src/filemanager/panel.c | 10 ++++++++-- 5 files changed, 42 insertions(+), 40 deletions(-) diff --git a/lib/vfs/path.c b/lib/vfs/path.c index 65fe3254f..76575ec88 100644 --- a/lib/vfs/path.c +++ b/lib/vfs/path.c @@ -1033,6 +1033,39 @@ vfs_path_element_need_cleanup_converter (const vfs_path_element_t * element) { return (element->dir.converter != str_cnv_from_term && element->dir.converter != INVALID_CONV); } + +/* --------------------------------------------------------------------------------------------- */ +/** + * Change encoding for last part (vfs_path_element_t) of vpath + * + * @param vpath pointer to path structure + * encoding name of charset + * + * @return pointer to path structure (for use function in anoter functions) + */ +vfs_path_t * +vfs_path_change_encoding (vfs_path_t * vpath, const char *encoding) +{ + vfs_path_element_t *path_element; + + path_element = (vfs_path_element_t *) vfs_path_get_by_index (vpath, -1); + /* don't add current encoding */ + if ((path_element->encoding != NULL) && (strcmp (encoding, path_element->encoding) == 0)) + return vpath; + + g_free (path_element->encoding); + path_element->encoding = g_strdup (encoding); + + if (vfs_path_element_need_cleanup_converter (path_element)) + str_close_conv (path_element->dir.converter); + + path_element->dir.converter = str_crt_conv_from (path_element->encoding); + + g_free (vpath->str); + vpath->str = vfs_path_to_str_flags (vpath, 0, VPF_NONE); + return vpath; +} + #endif /* --------------------------------------------------------------------------------------------- */ diff --git a/lib/vfs/path.h b/lib/vfs/path.h index 88501b8c8..d4afbfd49 100644 --- a/lib/vfs/path.h +++ b/lib/vfs/path.h @@ -83,6 +83,7 @@ struct vfs_class *vfs_prefix_to_class (const char *prefix); #ifdef HAVE_CHARSET gboolean vfs_path_element_need_cleanup_converter (const vfs_path_element_t * element); +vfs_path_t *vfs_path_change_encoding (vfs_path_t * vpath, const char *encoding); #endif char *vfs_path_serialize (const vfs_path_t * vpath, GError ** error); diff --git a/lib/vfs/vfs.c b/lib/vfs/vfs.c index 767d3ae7a..aad4272b4 100644 --- a/lib/vfs/vfs.c +++ b/lib/vfs/vfs.c @@ -588,40 +588,6 @@ _vfs_get_cwd (void) } /* --------------------------------------------------------------------------------------------- */ - -#ifdef HAVE_CHARSET -/** - * Change encoding for last part (vfs_path_element_t) of vpath - * - * @param vpath pointer to path structure - * encoding name of charset - * - * @return pointer to path structure (for use function in anoter functions) - */ -vfs_path_t * -vfs_change_encoding (vfs_path_t * vpath, const char *encoding) -{ - vfs_path_element_t *path_element; - - path_element = (vfs_path_element_t *) vfs_path_get_by_index (vpath, -1); - /* don't add current encoding */ - if ((path_element->encoding != NULL) && (strcmp (encoding, path_element->encoding) == 0)) - return vpath; - - g_free (path_element->encoding); - path_element->encoding = g_strdup (encoding); - - if (vfs_path_element_need_cleanup_converter (path_element)) - str_close_conv (path_element->dir.converter); - - path_element->dir.converter = str_crt_conv_from (path_element->encoding); - - return vpath; -} -#endif /* HAVE_CHARSET */ - -/* --------------------------------------------------------------------------------------------- */ - /** * Preallocate space for file in new place for ensure that file * will be fully copied with less fragmentation. diff --git a/lib/vfs/vfs.h b/lib/vfs/vfs.h index 4260a2813..450286f68 100644 --- a/lib/vfs/vfs.h +++ b/lib/vfs/vfs.h @@ -272,10 +272,6 @@ void vfs_free_handle (int handle); void vfs_setup_cwd (void); char *_vfs_get_cwd (void); -#ifdef HAVE_CHARSET -vfs_path_t *vfs_change_encoding (vfs_path_t * vpath, const char *encoding); -#endif - int vfs_preallocate (int dest_desc, off_t src_fsize, off_t dest_fsize); /** diff --git a/src/filemanager/panel.c b/src/filemanager/panel.c index a0bd66bbb..f371f9e41 100644 --- a/src/filemanager/panel.c +++ b/src/filemanager/panel.c @@ -4535,7 +4535,7 @@ panel_change_encoding (WPanel * panel) encoding = get_codepage_id (panel->codepage); if (encoding != NULL) { - vfs_change_encoding (panel->cwd_vpath, encoding); + vfs_path_change_encoding (panel->cwd_vpath, encoding); if (!do_panel_cd (panel, panel->cwd_vpath, cd_parse_command)) message (D_ERROR, MSG_ERROR, _("Cannot chdir to \"%s\""), @@ -4566,14 +4566,19 @@ remove_encoding_from_path (const vfs_path_t * vpath) vfs_path_element_t *path_element; path_element = vfs_path_element_clone (vfs_path_get_by_index (vpath, indx)); - vfs_path_add_element (ret_vpath, path_element); if (path_element->encoding == NULL) + { + vfs_path_add_element (ret_vpath, path_element); continue; + } converter = str_crt_conv_to (path_element->encoding); if (converter == INVALID_CONV) + { + vfs_path_add_element (ret_vpath, path_element); continue; + } g_free (path_element->encoding); path_element->encoding = NULL; @@ -4588,6 +4593,7 @@ remove_encoding_from_path (const vfs_path_t * vpath) str_close_conv (converter); str_close_conv (path_element->dir.converter); path_element->dir.converter = INVALID_CONV; + vfs_path_add_element (ret_vpath, path_element); } g_string_free (tmp_conv, TRUE); return ret_vpath;