From 8d7137196137f06056d312e7adcd689164ab16f9 Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Fri, 24 Feb 2012 20:24:29 +0300 Subject: [PATCH] Changed function remove_encoding_from_path() for return vfs_path_t type Also, fixed bug with non-changeable encoding inside archives. Signed-off-by: Slava Zanko --- src/filemanager/midnight.c | 13 +++++++++-- src/filemanager/panel.c | 58 +++++++++++++++++++++++++++++++--------------- src/filemanager/panel.h | 2 +- 3 files changed, 51 insertions(+), 22 deletions(-) diff --git a/src/filemanager/midnight.c b/src/filemanager/midnight.c index db4d245f9..7273a8ba2 100644 --- a/src/filemanager/midnight.c +++ b/src/filemanager/midnight.c @@ -653,15 +653,20 @@ static void put_current_path (void) { char *cwd_path; + vfs_path_t *cwd_vpath; + if (!command_prompt) return; - cwd_path = remove_encoding_from_path (current_panel->cwd_vpath); + cwd_vpath = remove_encoding_from_path (current_panel->cwd_vpath); + cwd_path = vfs_path_to_str (cwd_vpath); command_insert (cmdline, cwd_path, FALSE); if (cwd_path[strlen (cwd_path) - 1] != PATH_SEP) command_insert (cmdline, PATH_SEP_STR, FALSE); + g_free (cwd_path); + vfs_path_free (cwd_vpath); } /* --------------------------------------------------------------------------------------------- */ @@ -670,6 +675,7 @@ static void put_other_path (void) { char *cwd_path; + vfs_path_t *cwd_vpath; if (get_other_type () != view_listing) return; @@ -677,12 +683,15 @@ put_other_path (void) if (!command_prompt) return; - cwd_path = remove_encoding_from_path (other_panel->cwd_vpath); + cwd_vpath = remove_encoding_from_path (other_panel->cwd_vpath); + cwd_path = vfs_path_to_str (cwd_vpath); command_insert (cmdline, cwd_path, FALSE); if (cwd_path[strlen (cwd_path) - 1] != PATH_SEP) command_insert (cmdline, PATH_SEP_STR, FALSE); + g_free (cwd_path); + vfs_path_free (cwd_vpath); } /* --------------------------------------------------------------------------------------------- */ diff --git a/src/filemanager/panel.c b/src/filemanager/panel.c index eac0e6ba8..c785da4c8 100644 --- a/src/filemanager/panel.c +++ b/src/filemanager/panel.c @@ -759,7 +759,7 @@ file_compute_color (int attr, file_entry * fe) static filename_scroll_flag_t format_file (char *dest, int limit, WPanel * panel, int file_index, int width, int attr, - int isstatus, int * field_lenght) + int isstatus, int *field_lenght) { int color, length, empty_line; const char *txt; @@ -840,7 +840,8 @@ format_file (char *dest, int limit, WPanel * panel, int file_index, int width, i tty_lowlevel_setcolor (-color); if (!isstatus && panel->content_shift > -1) - prepared_text = str_fit_to_term (txt + name_offset, len, HIDE_FIT (format->just_mode)); + prepared_text = + str_fit_to_term (txt + name_offset, len, HIDE_FIT (format->just_mode)); else prepared_text = str_fit_to_term (txt, len, format->just_mode); @@ -3764,36 +3765,55 @@ update_one_panel (int which, panel_update_flags_t flags, const char *current_fil /* --------------------------------------------------------------------------------------------- */ /*** public functions ****************************************************************************/ /* --------------------------------------------------------------------------------------------- */ +/** + * Remove encode info from last path element. + * + */ -char * +vfs_path_t * remove_encoding_from_path (const vfs_path_t * vpath) { - GString *ret; + vfs_path_t *ret_vpath; GString *tmp_conv; int indx; - ret = g_string_new (""); + ret_vpath = vfs_path_new (); + tmp_conv = g_string_new (""); for (indx = 0; indx < vfs_path_elements_count (vpath); indx++) { - const vfs_path_element_t *path_element; GIConv converter; + 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) + { + continue; + } - path_element = vfs_path_get_by_index (vpath, indx); - converter = - path_element->encoding != NULL ? - str_crt_conv_to (path_element->encoding) : str_cnv_to_term; + converter = str_crt_conv_to (path_element->encoding); if (converter == INVALID_CONV) - converter = str_cnv_to_term; + continue; + + g_free (path_element->encoding); + path_element->encoding = NULL; str_vfs_convert_from (converter, path_element->path, tmp_conv); - g_string_append (ret, tmp_conv->str); + + g_free (path_element->path); + path_element->path = g_strdup (tmp_conv->str); + g_string_set_size (tmp_conv, 0); + str_close_conv (converter); + str_close_conv (path_element->dir.converter); + path_element->dir.converter = INVALID_CONV; } g_string_free (tmp_conv, TRUE); - return g_string_free (ret, FALSE); + return ret_vpath; } /* --------------------------------------------------------------------------------------------- */ @@ -4475,7 +4495,6 @@ void panel_change_encoding (WPanel * panel) { const char *encoding = NULL; - char *cd_path; #ifdef HAVE_CHARSET char *errmsg; int r; @@ -4493,12 +4512,10 @@ panel_change_encoding (WPanel * panel) vfs_path_t *cd_path_vpath; g_free (init_translation_table (mc_global.display_codepage, mc_global.display_codepage)); - cd_path = remove_encoding_from_path (panel->cwd_vpath); - cd_path_vpath = vfs_path_from_str (cd_path); + cd_path_vpath = remove_encoding_from_path (panel->cwd_vpath); do_panel_cd (panel, cd_path_vpath, cd_parse_command); show_dir (panel); vfs_path_free (cd_path_vpath); - g_free (cd_path); return; } @@ -4514,6 +4531,7 @@ panel_change_encoding (WPanel * panel) #endif if (encoding != NULL) { + char *cd_path; vfs_change_encoding (panel->cwd_vpath, encoding); cd_path = vfs_path_to_str (panel->cwd_vpath); @@ -4702,8 +4720,10 @@ panel_init (void) panel_history_prev_item_sign = mc_skin_get ("widget-panel", "history-prev-item-sign", "<"); panel_history_next_item_sign = mc_skin_get ("widget-panel", "history-next-item-sign", ">"); panel_history_show_list_sign = mc_skin_get ("widget-panel", "history-show-list-sign", "^"); - panel_filename_scroll_left_char = mc_skin_get ("widget-panel", "filename-scroll-left-char", "{"); - panel_filename_scroll_right_char = mc_skin_get ("widget-panel", "filename-scroll-right-char", "}"); + panel_filename_scroll_left_char = + mc_skin_get ("widget-panel", "filename-scroll-left-char", "{"); + panel_filename_scroll_right_char = + mc_skin_get ("widget-panel", "filename-scroll-right-char", "}"); mc_event_add (MCEVENT_GROUP_FILEMANAGER, "update_panels", event_update_panels, NULL, NULL); mc_event_add (MCEVENT_GROUP_FILEMANAGER, "panel_save_curent_file_to_clip_file", diff --git a/src/filemanager/panel.h b/src/filemanager/panel.h index 0221eb1ab..43cb9c777 100644 --- a/src/filemanager/panel.h +++ b/src/filemanager/panel.h @@ -165,7 +165,7 @@ gboolean do_panel_cd (struct WPanel *panel, const vfs_path_t * new_dir_vpath, en void directory_history_add (struct WPanel *panel, const char *dir); -char *remove_encoding_from_path (const vfs_path_t * vpath); +vfs_path_t *remove_encoding_from_path (const vfs_path_t * vpath); gsize panel_get_num_of_sortable_fields (void); const char **panel_get_sortable_fields (gsize *); -- 2.11.4.GIT