Changed format of string 'current directory path' at header of panel.

* path elements now are separated and shown one-by-one
   (eg. ftp://some.in.net instead of ~/some/path/ftp://some.in.net)
 * encoding info is shown separated at top of header line

Signed-off-by: Slava Zanko <slavazanko@gmail.com>
This commit is contained in:
Slava Zanko 2011-09-27 23:31:20 +03:00
parent 5dafd4d809
commit 916ac05c4b
4 changed files with 135 additions and 64 deletions

View File

@ -171,54 +171,6 @@ vfs_canon (const char *path)
}
}
/* --------------------------------------------------------------------------------------------- */
/**
* Build URL parameters (such as user:pass@host:port) from one path element object
*
* @param element path element
*
* @return newly allocated string
*/
static char *
vfs_path_build_url_params_str (vfs_path_element_t * element)
{
GString *buffer;
if (element == NULL)
return NULL;
buffer = g_string_new ("");
if (element->user != NULL)
g_string_append (buffer, element->user);
if (element->password != NULL)
{
g_string_append_c (buffer, ':');
g_string_append (buffer, element->password);
}
if (element->host != NULL)
{
if ((element->user != NULL) || (element->password != NULL))
g_string_append_c (buffer, '@');
if (element->ipv6)
g_string_append_c (buffer, '[');
g_string_append (buffer, element->host);
if (element->ipv6)
g_string_append_c (buffer, ']');
}
if ((element->port) != 0 && (element->host != NULL))
{
g_string_append_c (buffer, ':');
g_string_append_printf (buffer, "%d", element->port);
}
return g_string_free (buffer, FALSE);
}
/* --------------------------------------------------------------------------------------------- */
/** get encoding after last #enc: or NULL, if part does not contain #enc:
*
@ -570,7 +522,7 @@ vfs_path_tokens_add_class_info (vfs_path_element_t * element, GString * ret_toke
g_string_append (ret_tokens, element->vfs_prefix);
g_string_append (ret_tokens, VFS_PATH_URL_DELIMITER);
url_str = vfs_path_build_url_params_str (element);
url_str = vfs_path_build_url_params_str (element, TRUE);
if (*url_str != '\0')
{
g_string_append (ret_tokens, url_str);
@ -645,7 +597,7 @@ vfs_path_to_str_elements_count (const vfs_path_t * vpath, int elements_count)
g_string_append (buffer, element->vfs_prefix);
g_string_append (buffer, VFS_PATH_URL_DELIMITER);
url_str = vfs_path_build_url_params_str (element);
url_str = vfs_path_build_url_params_str (element, TRUE);
if (*url_str != '\0')
g_string_append (buffer, url_str);
@ -1336,3 +1288,51 @@ vfs_path_vtokens_get (const vfs_path_t * vpath, ssize_t start_position, size_t l
}
/* --------------------------------------------------------------------------------------------- */
/**
* Build URL parameters (such as user:pass@host:port) from one path element object
*
* @param element path element
*
* @return newly allocated string
*/
char *
vfs_path_build_url_params_str (const vfs_path_element_t * element, gboolean keep_password)
{
GString *buffer;
if (element == NULL)
return NULL;
buffer = g_string_new ("");
if (element->user != NULL)
g_string_append (buffer, element->user);
if (element->password != NULL && keep_password)
{
g_string_append_c (buffer, ':');
g_string_append (buffer, element->password);
}
if (element->host != NULL)
{
if ((element->user != NULL) || (element->password != NULL))
g_string_append_c (buffer, '@');
if (element->ipv6)
g_string_append_c (buffer, '[');
g_string_append (buffer, element->host);
if (element->ipv6)
g_string_append_c (buffer, ']');
}
if ((element->port) != 0 && (element->host != NULL))
{
g_string_append_c (buffer, ':');
g_string_append_printf (buffer, "%d", element->port);
}
return g_string_free (buffer, FALSE);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -75,6 +75,8 @@ gboolean vfs_path_element_need_cleanup_converter (const vfs_path_element_t * ele
char *vfs_path_serialize (const vfs_path_t * vpath, GError ** error);
vfs_path_t *vfs_path_deserialize (const char *data, GError ** error);
char *vfs_path_build_url_params_str (const vfs_path_element_t * element, gboolean keep_password);
/*** inline functions ****************************************************************************/
static inline gboolean

View File

@ -1069,7 +1069,74 @@ show_free_space (WPanel * panel)
}
/* --------------------------------------------------------------------------------------------- */
/**
* Make path string for shiwing in panel's header.
* Passwords will removed, also home dir will replaced by ~
*
* @param panel WPanel object
*
* @return newly allocated string.
*/
static char *
panel_correct_path_to_show (WPanel * panel)
{
const vfs_path_element_t *path_element;
GString *ret_str;
path_element = vfs_path_get_by_index (panel->cwd_vpath, -1);
ret_str = g_string_new ("");
if ((path_element->class->flags & VFSF_LOCAL) == 0)
{
char *url_str;
g_string_append (ret_str, path_element->vfs_prefix);
g_string_append (ret_str, VFS_PATH_URL_DELIMITER);
url_str = vfs_path_build_url_params_str (path_element, FALSE);
if (*url_str != '\0')
{
g_string_append (ret_str, url_str);
g_string_append_c (ret_str, PATH_SEP);
}
g_free (url_str);
g_string_append (ret_str, path_element->path);
}
else
{
char *tmp_path;
tmp_path = g_strdup (path_element->path);
g_string_append (ret_str, strip_home_and_password (tmp_path));
g_free (tmp_path);
}
return g_string_free (ret_str, FALSE);
}
/* --------------------------------------------------------------------------------------------- */
/**
* Get Current path element encoding
*
* @param panel WPanel object
*
* @return newly allocated string or NULL if path charset is same as system charset
*/
static char *
panel_get_encoding_info_str (WPanel * panel)
{
char *ret_str = NULL;
const vfs_path_element_t *path_element;
path_element = vfs_path_get_by_index (panel->cwd_vpath, -1);
if (path_element->encoding != NULL)
ret_str = g_strdup_printf ("[%s]", path_element->encoding);
return ret_str;
}
/* --------------------------------------------------------------------------------------------- */
static void
show_dir (WPanel * panel)
{
@ -1098,23 +1165,27 @@ show_dir (WPanel * panel)
g_free (tmp);
if (panel->active)
tty_setcolor (REVERSE_COLOR);
widget_move (&panel->widget, 0, 3);
if (panel->is_panelized)
tty_printf (" %s ", _("Panelize"));
else
{
char *tmp_path;
tmp_path = vfs_path_to_str (panel->cwd_vpath);
tty_printf (" %s ",
str_term_trim (strip_home_and_password (tmp_path),
min (max (panel->widget.cols - 12, 0), panel->widget.cols)));
g_free (tmp_path);
tmp = panel_get_encoding_info_str (panel);
if (tmp != NULL)
{
tty_printf ("%s", tmp);
widget_move (&panel->widget, 0, 3 + strlen (tmp));
g_free (tmp);
}
}
if (panel->active)
tty_setcolor (REVERSE_COLOR);
tmp = panel_correct_path_to_show (panel);
tty_printf (" %s ",
str_term_trim (tmp, min (max (panel->widget.cols - 12, 0), panel->widget.cols)));
g_free (tmp);
if (!panels_options.show_mini_info)
{

View File

@ -88,10 +88,8 @@ typedef struct WPanel
int list_type; /* listing type (was view_type) */
int active; /* If panel is currently selected */
vfs_path_t *cwd_vpath;
vfs_path_t *lwd_vpath;
// char cwd[MC_MAXPATHLEN]; /* Current Working Directory */
// char lwd[MC_MAXPATHLEN]; /* Last Working Directory */
vfs_path_t *cwd_vpath; /* Current Working Directory */
vfs_path_t *lwd_vpath; /* Last Working Directory */
GList *dir_history; /* directory history */
char *hist_name; /* directory history name for history file */
int count; /* Number of files in dir structure */