aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2017-06-05 20:53:00 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2017-06-05 20:54:50 +0200
commit19605f9b7b3e08ce046533ee01bb78b12ef0539a (patch)
treedb528ce124615677781fed8d193aa9b0d0d8eede
parentcadc846fd46ad6875ed7c38b8d7ec2f4dcdf4568 (diff)
downloadnncmpp-19605f9b7b3e08ce046533ee01bb78b12ef0539a.tar.gz
nncmpp-19605f9b7b3e08ce046533ee01bb78b12ef0539a.tar.xz
nncmpp-19605f9b7b3e08ce046533ee01bb78b12ef0539a.zip
Use song IDs when available
-rw-r--r--nncmpp.c22
1 files changed, 9 insertions, 13 deletions
diff --git a/nncmpp.c b/nncmpp.c
index 52b34f8..7f3bc3b 100644
--- a/nncmpp.c
+++ b/nncmpp.c
@@ -492,7 +492,7 @@ static compact_map_t
item_list_get (struct item_list *self, int i)
{
if (i < 0 || (size_t) i >= self->len || !self->items[i])
- return false;
+ return NULL;
return self->items[i];
}
@@ -1935,22 +1935,18 @@ static bool
current_tab_on_action (enum action action)
{
struct tab *self = g.active_tab;
- if (self->item_selected < 0 || !self->item_count)
+ compact_map_t map = item_list_get (&g.playlist, self->item_selected);
+
+ const char *id;
+ if (!map || !(id = compact_map_find (map, "id")))
return false;
+ // TODO: add actions to move the current selection up or down with Shift,
+ // with multiple items we need to use all number indexes, but "moveid"
switch (action)
{
- char *song;
- case ACTION_CHOOSE:
- song = xstrdup_printf ("%d", self->item_selected);
- MPD_SIMPLE ("play", song);
- free (song);
- return true;
- case ACTION_DELETE:
- song = xstrdup_printf ("%d", self->item_selected);
- MPD_SIMPLE ("delete", song);
- free (song);
- return true;
+ case ACTION_CHOOSE: MPD_SIMPLE ("playid", id); return true;
+ case ACTION_DELETE: MPD_SIMPLE ("deleteid", id); return true;
default:
break;
}