diff options
author | Max Kellermann <max@duempel.org> | 2011-07-19 00:34:33 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2011-07-19 00:34:33 +0200 |
commit | b159bc0c5f64dd4030f18cfa38539c5851d5157d (patch) | |
tree | 452a1e9fc6d5949244dc5eca4ebc8b89e5225166 /src/command.c | |
parent | a222c4879cd7104bcd51011bc13d4a76ac3d7a96 (diff) | |
download | mpd-b159bc0c5f64dd4030f18cfa38539c5851d5157d.tar.gz mpd-b159bc0c5f64dd4030f18cfa38539c5851d5157d.tar.xz mpd-b159bc0c5f64dd4030f18cfa38539c5851d5157d.zip |
queue: implement song "priorities"
Sorts remaining songs by priority. This can be used for the
much-demanded "queue feature".
Diffstat (limited to 'src/command.c')
-rw-r--r-- | src/command.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/command.c b/src/command.c index e369da69b..3e60e0ac3 100644 --- a/src/command.c +++ b/src/command.c @@ -1171,6 +1171,68 @@ handle_previous(G_GNUC_UNUSED struct client *client, } static enum command_return +handle_prio(struct client *client, int argc, char *argv[]) +{ + unsigned priority; + + if (!check_unsigned(client, &priority, argv[1])) + return COMMAND_RETURN_ERROR; + + if (priority > 0xff) { + command_error(client, ACK_ERROR_ARG, + "Priority out of range: %s", argv[1]); + return COMMAND_RETURN_ERROR; + } + + for (int i = 2; i < argc; ++i) { + unsigned start_position, end_position; + if (!check_range(client, &start_position, &end_position, + argv[i], need_range)) + return COMMAND_RETURN_ERROR; + + enum playlist_result result = + playlist_set_priority(&g_playlist, + client->player_control, + start_position, end_position, + priority); + if (result != PLAYLIST_RESULT_SUCCESS) + return print_playlist_result(client, result); + } + + return COMMAND_RETURN_OK; +} + +static enum command_return +handle_prioid(struct client *client, int argc, char *argv[]) +{ + unsigned priority; + + if (!check_unsigned(client, &priority, argv[1])) + return COMMAND_RETURN_ERROR; + + if (priority > 0xff) { + command_error(client, ACK_ERROR_ARG, + "Priority out of range: %s", argv[1]); + return COMMAND_RETURN_ERROR; + } + + for (int i = 2; i < argc; ++i) { + unsigned song_id; + if (!check_unsigned(client, &song_id, argv[i])) + return COMMAND_RETURN_ERROR; + + enum playlist_result result = + playlist_set_priority_id(&g_playlist, + client->player_control, + song_id, priority); + if (result != PLAYLIST_RESULT_SUCCESS) + return print_playlist_result(client, result); + } + + return COMMAND_RETURN_OK; +} + +static enum command_return handle_listall(struct client *client, G_GNUC_UNUSED int argc, char *argv[]) { char *directory = NULL; @@ -2062,6 +2124,8 @@ static const struct command commands[] = { { "plchanges", PERMISSION_READ, 1, 1, handle_plchanges }, { "plchangesposid", PERMISSION_READ, 1, 1, handle_plchangesposid }, { "previous", PERMISSION_CONTROL, 0, 0, handle_previous }, + { "prio", PERMISSION_CONTROL, 2, -1, handle_prio }, + { "prioid", PERMISSION_CONTROL, 2, -1, handle_prioid }, { "random", PERMISSION_CONTROL, 1, 1, handle_random }, { "readmessages", PERMISSION_READ, 0, 0, handle_read_messages }, { "rename", PERMISSION_CONTROL, 2, 2, handle_rename }, |