summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2017-06-03 23:42:18 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2017-06-04 03:04:35 +0200
commit86b87bee7404cdcc1cdf9aada528ef331b67c7e4 (patch)
tree26a230c0e6e159e7bef9fcf0670816151d71d65b
parent5721074b4819dcbe604978509d3b6e9d270390ce (diff)
downloadnncmpp-86b87bee7404cdcc1cdf9aada528ef331b67c7e4.tar.gz
nncmpp-86b87bee7404cdcc1cdf9aada528ef331b67c7e4.tar.xz
nncmpp-86b87bee7404cdcc1cdf9aada528ef331b67c7e4.zip
Cleanup
-rw-r--r--nncmpp.c47
1 files changed, 22 insertions, 25 deletions
diff --git a/nncmpp.c b/nncmpp.c
index a2279b9..2a7a519 100644
--- a/nncmpp.c
+++ b/nncmpp.c
@@ -1953,6 +1953,19 @@ library_tab_compare (char **a, char **b)
return app_casecmp ((uint8_t *) xa.path, (uint8_t *) xb.path);
}
+static char *
+library_tab_above (void)
+{
+ struct str *path = &g_library_tab.path;
+ if (!path->len)
+ return NULL;
+
+ char *last_slash;
+ if ((last_slash = strrchr (path->str, '/')))
+ return xstrndup (path->str, last_slash - path->str);
+ return xstrdup ("");
+}
+
static void
library_tab_on_data (const struct mpd_response *response,
const struct strv *data, void *user_data)
@@ -1963,20 +1976,12 @@ library_tab_on_data (const struct mpd_response *response,
strv_reset (&g_library_tab.items);
- struct str *path = &g_library_tab.path;
- if (path->len)
+ char *above = library_tab_above ();
+ if (above)
{
library_tab_add (LIBRARY_ROOT, "", "");
-
- char *last_slash;
- if ((last_slash = strrchr (path->str, '/')))
- {
- char *up = xstrndup (path->str, last_slash - path->str);
- library_tab_add (LIBRARY_UP, "", up);
- free (up);
- }
- else
- library_tab_add (LIBRARY_UP, "", "");
+ library_tab_add (LIBRARY_UP, "", above);
+ free (above);
}
struct str_map map;
@@ -2052,21 +2057,13 @@ library_tab_on_action (enum action action)
return true;
case ACTION_UP:
{
- // TODO: probably put this in a special function
- char *path = g_library_tab.path.str;
- if (!*path)
- return false;
-
- char *last_slash;
- if ((last_slash = strrchr (path, '/')))
+ char *above = library_tab_above ();
+ if (above)
{
- char *up = xstrndup (path, last_slash - path);
- library_tab_reload (up);
- free (up);
+ library_tab_reload (above);
+ free (above);
}
- else
- library_tab_reload ("");
- return true;
+ return above != NULL;
}
case ACTION_MPD_REPLACE:
// FIXME: we also need to play it if we've been playing things already