From 9c983c442c03a71bbf80ccbf1dad84894403a983 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@duempel.org>
Date: Wed, 22 Oct 2008 19:16:56 +0200
Subject: command: added command "listplaylists"

"listplaylists" returns a list of all stored playlists.  This command
seems more elaborate than listing them below "lsinfo".
---
 doc/COMMANDS  |  7 +++++++
 src/command.c | 17 +++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/doc/COMMANDS b/doc/COMMANDS
index e84f85afd..66b014a03 100644
--- a/doc/COMMANDS
+++ b/doc/COMMANDS
@@ -119,6 +119,10 @@ load <string name>
 lsinfo <string directory>
 	list contents of _directory_, from the db.  _directory_ is optional
 
+	When listing the root directory, this currently returns the
+	list of stored playlists.  This behavior is deprecated; use
+	"listplaylists" instead.
+
 move <int from> <int to>
 	move song at _from_ to _to_ in the playlist
 	increments playlist version by 1
@@ -184,6 +188,9 @@ random <int state>
 repeat <int state>
 	set repeat state to _state_, _state_ should be 0 or 1
 
+listplaylists
+	prints a list of the playlist directory
+
 rm <string name>
 	removes the playlist <name>.m3u from the playlist directory
 
diff --git a/src/command.c b/src/command.c
index dbdbe4003..db793350d 100644
--- a/src/command.c
+++ b/src/command.c
@@ -1156,6 +1156,22 @@ static int handlePlaylistAdd(struct client *client,
 	return print_playlist_result(client, result);
 }
 
+static int
+handle_list_playlists(struct client *client,
+		      mpd_unused int argc, mpd_unused char *argv[])
+{
+	GPtrArray *list = spl_list();
+	if (list == NULL) {
+		command_error(client, ACK_ERROR_SYSTEM,
+			      "failed to get list of stored playlists");
+		return -1;
+	}
+
+	print_spl_list(client, list);
+	spl_list_free(list);
+	return 0;
+}
+
 static int
 handle_idle(struct client *client,
 	    mpd_unused int argc, mpd_unused char *argv[])
@@ -1194,6 +1210,7 @@ static const struct command commands[] = {
 	{ "listallinfo", PERMISSION_READ, 0, 1, handleListAllInfo },
 	{ "listplaylist", PERMISSION_READ, 1, 1, handleListPlaylist },
 	{ "listplaylistinfo", PERMISSION_READ, 1, 1, handleListPlaylistInfo },
+	{ "listplaylists", PERMISSION_READ, 0, 0, handle_list_playlists },
 	{ "load", PERMISSION_ADD, 1, 1, handleLoad },
 	{ "lsinfo", PERMISSION_READ, 0, 1, handleLsInfo },
 	{ "move", PERMISSION_CONTROL, 2, 2, handleMove },
-- 
cgit v1.2.3