diff options
author | Max Kellermann <max@duempel.org> | 2009-02-04 22:09:04 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2009-02-04 22:09:04 +0100 |
commit | 2a1bef222555cbc0a84b0c90ccf4309b35e6387b (patch) | |
tree | eec3bc0065e9ccd3e4550516a95f1a00c62ea952 /src | |
parent | cbea8a2a00e82ead82fbc3bf968f22c004e80931 (diff) | |
download | mpd-2a1bef222555cbc0a84b0c90ccf4309b35e6387b.tar.gz mpd-2a1bef222555cbc0a84b0c90ccf4309b35e6387b.tar.xz mpd-2a1bef222555cbc0a84b0c90ccf4309b35e6387b.zip |
playlist_print: added wrappers for printing the queue
Hide the details of the playlist behind wrapper functions.
Diffstat (limited to '')
-rw-r--r-- | src/command.c | 44 | ||||
-rw-r--r-- | src/playlist_print.c | 85 | ||||
-rw-r--r-- | src/playlist_print.h | 66 |
3 files changed, 164 insertions, 31 deletions
diff --git a/src/command.c b/src/command.c index 36c070f0e..5ff93307a 100644 --- a/src/command.c +++ b/src/command.c @@ -421,12 +421,7 @@ static enum command_return handle_currentsong(struct client *client, G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[]) { - int song = getPlaylistCurrentSong(&g_playlist); - const struct queue *queue = playlist_get_queue(&g_playlist); - - if (song >= 0) - queue_print_info(client, queue, song, song + 1); - + playlist_print_current(client, &g_playlist); return PLAYLIST_RESULT_SUCCESS; } @@ -642,9 +637,7 @@ static enum command_return handle_playlist(struct client *client, G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[]) { - const struct queue *queue = playlist_get_queue(&g_playlist); - - queue_print_uris(client, queue, 0, queue_length(queue)); + playlist_print_uris(client, &g_playlist); return COMMAND_RETURN_OK; } @@ -766,12 +759,11 @@ static enum command_return handle_plchanges(struct client *client, G_GNUC_UNUSED int argc, char *argv[]) { uint32_t version; - const struct queue *queue = playlist_get_queue(&g_playlist); if (!check_uint32(client, &version, argv[1], need_positive)) return COMMAND_RETURN_ERROR; - queue_print_changes_info(client, queue, version); + playlist_print_changes_info(client, &g_playlist, version); return COMMAND_RETURN_OK; } @@ -779,12 +771,11 @@ static enum command_return handle_plchangesposid(struct client *client, G_GNUC_UNUSED int argc, char *argv[]) { uint32_t version; - const struct queue *queue = playlist_get_queue(&g_playlist); if (!check_uint32(client, &version, argv[1], need_positive)) return COMMAND_RETURN_ERROR; - queue_print_changes_position(client, queue, version); + playlist_print_changes_position(client, &g_playlist, version); return COMMAND_RETURN_OK; } @@ -792,46 +783,37 @@ static enum command_return handle_playlistinfo(struct client *client, int argc, char *argv[]) { unsigned start = 0, end = UINT_MAX; - const struct queue *queue = playlist_get_queue(&g_playlist); + bool ret; if (argc == 2 && !check_range(client, &start, &end, argv[1], need_range)) return COMMAND_RETURN_ERROR; - if (end > queue_length(queue)) - end = queue_length(queue); - - if (start > end) + ret = playlist_print_info(client, &g_playlist, start, end); + if (!ret) return print_playlist_result(client, PLAYLIST_RESULT_BAD_RANGE); - queue_print_info(client, queue, start, end); return COMMAND_RETURN_OK; } static enum command_return handle_playlistid(struct client *client, int argc, char *argv[]) { - int id = -1, start; - unsigned end; - const struct queue *queue = playlist_get_queue(&g_playlist); + int id = -1; if (argc == 2 && !check_int(client, &id, argv[1], need_positive)) return COMMAND_RETURN_ERROR; if (id >= 0) { - start = queue_id_to_position(queue, id); - if (start < 0) + bool ret = playlist_print_id(client, &g_playlist, id); + if (!ret) return print_playlist_result(client, PLAYLIST_RESULT_NO_SUCH_SONG); - - end = start + 1; } else { - start = 0; - end = queue_length(queue); + playlist_print_info(client, &g_playlist, 0, UINT_MAX); } - queue_print_info(client, queue, start, end); return COMMAND_RETURN_OK; } @@ -924,7 +906,7 @@ handle_playlistfind(struct client *client, int argc, char *argv[]) return COMMAND_RETURN_ERROR; } - queue_find(client, playlist_get_queue(&g_playlist), list); + playlist_print_find(client, &g_playlist, list); locate_item_list_free(list); @@ -945,7 +927,7 @@ handle_playlistsearch(struct client *client, int argc, char *argv[]) return COMMAND_RETURN_ERROR; } - queue_search(client, playlist_get_queue(&g_playlist), list); + playlist_print_search(client, &g_playlist, list); locate_item_list_free(list); diff --git a/src/playlist_print.c b/src/playlist_print.c index c4a9c4f34..05adf5748 100644 --- a/src/playlist_print.c +++ b/src/playlist_print.c @@ -17,12 +17,97 @@ */ #include "playlist_print.h" +#include "queue_print.h" #include "stored_playlist.h" #include "song_print.h" #include "song.h" #include "database.h" #include "client.h" +void +playlist_print_uris(struct client *client, const struct playlist *playlist) +{ + const struct queue *queue = &playlist->queue; + + queue_print_uris(client, queue, 0, queue_length(queue)); +} + +bool +playlist_print_info(struct client *client, const struct playlist *playlist, + unsigned start, unsigned end) +{ + const struct queue *queue = &playlist->queue; + + if (end > queue_length(queue)) + /* correct the "end" offset */ + end = queue_length(queue); + + if (start > end) + /* an invalid "start" offset is fatal */ + return false; + + queue_print_info(client, queue, start, end); + return true; +} + +bool +playlist_print_id(struct client *client, const struct playlist *playlist, + unsigned id) +{ + const struct queue *queue = &playlist->queue; + int position; + + position = queue_id_to_position(queue, id); + if (position < 0) + /* no such song */ + return false; + + return playlist_print_info(client, playlist, position, position + 1); +} + +bool +playlist_print_current(struct client *client, const struct playlist *playlist) +{ + int current_position = getPlaylistCurrentSong(playlist); + + if (current_position < 0) + return false; + + queue_print_info(client, &playlist->queue, + current_position, current_position + 1); + return true; +} + +void +playlist_print_find(struct client *client, const struct playlist *playlist, + const struct locate_item_list *list) +{ + queue_find(client, &playlist->queue, list); +} + +void +playlist_print_search(struct client *client, const struct playlist *playlist, + const struct locate_item_list *list) +{ + queue_search(client, &playlist->queue, list); +} + +void +playlist_print_changes_info(struct client *client, + const struct playlist *playlist, + uint32_t version) +{ + queue_print_changes_info(client, &playlist->queue, version); +} + +void +playlist_print_changes_position(struct client *client, + const struct playlist *playlist, + uint32_t version) +{ + queue_print_changes_position(client, &playlist->queue, version); +} + bool spl_print(struct client *client, const char *name_utf8, bool detail) { diff --git a/src/playlist_print.h b/src/playlist_print.h index 3cedeaa7d..6513007ea 100644 --- a/src/playlist_print.h +++ b/src/playlist_print.h @@ -20,8 +20,74 @@ #define PLAYLIST_PRINT_H #include <stdbool.h> +#include <stdint.h> struct client; +struct playlist; +struct locate_item_list; + +/** + * Sends the whole playlist to the client, song URIs only. + */ +void +playlist_print_uris(struct client *client, const struct playlist *playlist); + +/** + * Sends a range of the playlist to the client, including all known + * information about the songs. The "end" offset is decreased + * automatically if it is too large; passing UINT_MAX is allowed. + * This function however fails when the start offset is invalid. + */ +bool +playlist_print_info(struct client *client, const struct playlist *playlist, + unsigned start, unsigned end); + +/** + * Sends the song with the specified id to the client. + * + * @return true on suite, false if there is no such song + */ +bool +playlist_print_id(struct client *client, const struct playlist *playlist, + unsigned id); + +/** + * Sends the current song to the client. + * + * @return true on success, false if there is no current song + */ +bool +playlist_print_current(struct client *client, const struct playlist *playlist); + +/** + * Find songs in the playlist. + */ +void +playlist_print_find(struct client *client, const struct playlist *playlist, + const struct locate_item_list *list); + +/** + * Search for songs in the playlist. + */ +void +playlist_print_search(struct client *client, const struct playlist *playlist, + const struct locate_item_list *list); + +/** + * Print detailed changes since the specified playlist version. + */ +void +playlist_print_changes_info(struct client *client, + const struct playlist *playlist, + uint32_t version); + +/** + * Print changes since the specified playlist version, position only. + */ +void +playlist_print_changes_position(struct client *client, + const struct playlist *playlist, + uint32_t version); /** * Send the stored playlist to the client. |