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 <slavazanko@gmail.com>
This commit is contained in:
Slava Zanko 2012-02-24 20:24:29 +03:00
parent 80d4a13daf
commit be271db9f3
3 changed files with 44 additions and 18 deletions

View File

@ -652,15 +652,20 @@ static void
put_current_path (void) put_current_path (void)
{ {
char *cwd_path; char *cwd_path;
vfs_path_t *cwd_vpath;
if (!command_prompt) if (!command_prompt)
return; 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); command_insert (cmdline, cwd_path, FALSE);
if (cwd_path[strlen (cwd_path) - 1] != PATH_SEP) if (cwd_path[strlen (cwd_path) - 1] != PATH_SEP)
command_insert (cmdline, PATH_SEP_STR, FALSE); command_insert (cmdline, PATH_SEP_STR, FALSE);
g_free (cwd_path); g_free (cwd_path);
vfs_path_free (cwd_vpath);
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
@ -669,6 +674,7 @@ static void
put_other_path (void) put_other_path (void)
{ {
char *cwd_path; char *cwd_path;
vfs_path_t *cwd_vpath;
if (get_other_type () != view_listing) if (get_other_type () != view_listing)
return; return;
@ -676,12 +682,15 @@ put_other_path (void)
if (!command_prompt) if (!command_prompt)
return; 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); command_insert (cmdline, cwd_path, FALSE);
if (cwd_path[strlen (cwd_path) - 1] != PATH_SEP) if (cwd_path[strlen (cwd_path) - 1] != PATH_SEP)
command_insert (cmdline, PATH_SEP_STR, FALSE); command_insert (cmdline, PATH_SEP_STR, FALSE);
g_free (cwd_path); g_free (cwd_path);
vfs_path_free (cwd_vpath);
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */

View File

@ -3642,36 +3642,55 @@ update_one_panel (int which, panel_update_flags_t flags, const char *current_fil
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
/*** public functions ****************************************************************************/ /*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
/**
* Remove encode info from last path element.
*
*/
char * vfs_path_t *
remove_encoding_from_path (const vfs_path_t * vpath) remove_encoding_from_path (const vfs_path_t * vpath)
{ {
GString *ret; vfs_path_t *ret_vpath;
GString *tmp_conv; GString *tmp_conv;
int indx; int indx;
ret = g_string_new (""); ret_vpath = vfs_path_new ();
tmp_conv = g_string_new (""); tmp_conv = g_string_new ("");
for (indx = 0; indx < vfs_path_elements_count (vpath); indx++) for (indx = 0; indx < vfs_path_elements_count (vpath); indx++)
{ {
const vfs_path_element_t *path_element;
GIConv converter; GIConv converter;
vfs_path_element_t *path_element;
path_element = vfs_path_get_by_index (vpath, indx); path_element = vfs_path_element_clone (vfs_path_get_by_index (vpath, indx));
converter = vfs_path_add_element (ret_vpath, path_element);
path_element->encoding != NULL ?
str_crt_conv_to (path_element->encoding) : str_cnv_to_term; if (path_element->encoding == NULL)
{
continue;
}
converter = str_crt_conv_to (path_element->encoding);
if (converter == INVALID_CONV) 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); 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); g_string_set_size (tmp_conv, 0);
str_close_conv (converter); str_close_conv (converter);
str_close_conv (path_element->dir.converter);
path_element->dir.converter = INVALID_CONV;
} }
g_string_free (tmp_conv, TRUE); g_string_free (tmp_conv, TRUE);
return g_string_free (ret, FALSE); return ret_vpath;
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
@ -4349,7 +4368,6 @@ void
panel_change_encoding (WPanel * panel) panel_change_encoding (WPanel * panel)
{ {
const char *encoding = NULL; const char *encoding = NULL;
char *cd_path;
#ifdef HAVE_CHARSET #ifdef HAVE_CHARSET
char *errmsg; char *errmsg;
int r; int r;
@ -4367,12 +4385,10 @@ panel_change_encoding (WPanel * panel)
vfs_path_t *cd_path_vpath; vfs_path_t *cd_path_vpath;
g_free (init_translation_table (mc_global.display_codepage, mc_global.display_codepage)); 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 = remove_encoding_from_path (panel->cwd_vpath);
cd_path_vpath = vfs_path_from_str (cd_path);
do_panel_cd (panel, cd_path_vpath, cd_parse_command); do_panel_cd (panel, cd_path_vpath, cd_parse_command);
show_dir (panel); show_dir (panel);
vfs_path_free (cd_path_vpath); vfs_path_free (cd_path_vpath);
g_free (cd_path);
return; return;
} }
@ -4388,6 +4404,7 @@ panel_change_encoding (WPanel * panel)
#endif #endif
if (encoding != NULL) if (encoding != NULL)
{ {
char *cd_path;
vfs_change_encoding (panel->cwd_vpath, encoding); vfs_change_encoding (panel->cwd_vpath, encoding);
cd_path = vfs_path_to_str (panel->cwd_vpath); cd_path = vfs_path_to_str (panel->cwd_vpath);

View File

@ -163,7 +163,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); 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); gsize panel_get_num_of_sortable_fields (void);
const char **panel_get_sortable_fields (gsize *); const char **panel_get_sortable_fields (gsize *);