From 86b87bee7404cdcc1cdf9aada528ef331b67c7e4 Mon Sep 17 00:00:00 2001 From: Přemysl Janouch Date: Sat, 3 Jun 2017 23:42:18 +0200 Subject: Cleanup --- nncmpp.c | 47 ++++++++++++++++++++++------------------------- 1 file 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 -- cgit v1.2.3-70-g09d2