From 916ac05c4b18bf7ab3f07fdd4a8e973cc97ba561 Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Tue, 27 Sep 2011 23:31:20 +0300 Subject: [PATCH] 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 --- lib/vfs/path.c | 100 ++++++++++++++++++++-------------------- lib/vfs/path.h | 2 + src/filemanager/panel.c | 91 ++++++++++++++++++++++++++++++++---- src/filemanager/panel.h | 6 +-- 4 files changed, 135 insertions(+), 64 deletions(-) diff --git a/lib/vfs/path.c b/lib/vfs/path.c index b9eab52c1..081eed615 100644 --- a/lib/vfs/path.c +++ b/lib/vfs/path.c @@ -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); +} + +/* --------------------------------------------------------------------------------------------- */ diff --git a/lib/vfs/path.h b/lib/vfs/path.h index 600ae5f84..4911cdfc9 100644 --- a/lib/vfs/path.h +++ b/lib/vfs/path.h @@ -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 diff --git a/src/filemanager/panel.c b/src/filemanager/panel.c index da6815d14..db8315d76 100644 --- a/src/filemanager/panel.c +++ b/src/filemanager/panel.c @@ -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) { diff --git a/src/filemanager/panel.h b/src/filemanager/panel.h index 5ce7fdb34..f45b9f343 100644 --- a/src/filemanager/panel.h +++ b/src/filemanager/panel.h @@ -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 */