aboutsummaryrefslogtreecommitdiffstats
path: root/src/screen_file.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-11-07 15:20:35 +0100
committerMax Kellermann <max@duempel.org>2008-11-07 15:20:35 +0100
commit07ee8fd6a42aaf4b9f97972700db9da0aee895ce (patch)
treede621bfca6aead670899d67db186d3560943f638 /src/screen_file.c
parentc3fb219bd23333431679c49058a200561f93344d (diff)
downloadmpd-07ee8fd6a42aaf4b9f97972700db9da0aee895ce.tar.gz
mpd-07ee8fd6a42aaf4b9f97972700db9da0aee895ce.tar.xz
mpd-07ee8fd6a42aaf4b9f97972700db9da0aee895ce.zip
screen_file: optimized title formula
Don't allocate and copy memory.
Diffstat (limited to 'src/screen_file.c')
-rw-r--r--src/screen_file.c22
1 files changed, 10 insertions, 12 deletions
diff --git a/src/screen_file.c b/src/screen_file.c
index 5a81e8fb8..75e4d1631 100644
--- a/src/screen_file.c
+++ b/src/screen_file.c
@@ -176,21 +176,19 @@ browse_open(mpd_unused mpdclient_t *c)
static const char *
browse_title(char *str, size_t size)
{
- char *dirname, *parentdir;
+ const char *path = NULL, *prev = NULL, *slash = browser.filelist->path;
- dirname = g_path_get_dirname(browser.filelist->path);
- parentdir = g_path_get_basename(dirname);
-
- if( parentdir[0] == '.' && strlen(parentdir) == 1 ) {
- parentdir = NULL;
+ /* determine the last 2 parts of the path */
+ while ((slash = strchr(slash, '/')) != NULL) {
+ path = prev;
+ prev = ++slash;
}
- g_snprintf(str, size, _("Browse: %s%s%s"),
- parentdir ? parentdir : "",
- parentdir ? "/" : "",
- g_basename(browser.filelist->path));
- free(dirname);
- free(parentdir);
+ if (path == NULL)
+ /* fall back to full path */
+ path = browser.filelist->path;
+
+ g_snprintf(str, size, _("Browse: %s"), path);
return str;
}