playlist_print: added wrappers for printing the queue
Hide the details of the playlist behind wrapper functions.
This commit is contained in:
parent
cbea8a2a00
commit
2a1bef2225
|
@ -421,12 +421,7 @@ static enum command_return
|
||||||
handle_currentsong(struct client *client,
|
handle_currentsong(struct client *client,
|
||||||
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
|
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
|
||||||
{
|
{
|
||||||
int song = getPlaylistCurrentSong(&g_playlist);
|
playlist_print_current(client, &g_playlist);
|
||||||
const struct queue *queue = playlist_get_queue(&g_playlist);
|
|
||||||
|
|
||||||
if (song >= 0)
|
|
||||||
queue_print_info(client, queue, song, song + 1);
|
|
||||||
|
|
||||||
return PLAYLIST_RESULT_SUCCESS;
|
return PLAYLIST_RESULT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -642,9 +637,7 @@ static enum command_return
|
||||||
handle_playlist(struct client *client,
|
handle_playlist(struct client *client,
|
||||||
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
|
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
|
||||||
{
|
{
|
||||||
const struct queue *queue = playlist_get_queue(&g_playlist);
|
playlist_print_uris(client, &g_playlist);
|
||||||
|
|
||||||
queue_print_uris(client, queue, 0, queue_length(queue));
|
|
||||||
return COMMAND_RETURN_OK;
|
return COMMAND_RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -766,12 +759,11 @@ static enum command_return
|
||||||
handle_plchanges(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
handle_plchanges(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
||||||
{
|
{
|
||||||
uint32_t version;
|
uint32_t version;
|
||||||
const struct queue *queue = playlist_get_queue(&g_playlist);
|
|
||||||
|
|
||||||
if (!check_uint32(client, &version, argv[1], need_positive))
|
if (!check_uint32(client, &version, argv[1], need_positive))
|
||||||
return COMMAND_RETURN_ERROR;
|
return COMMAND_RETURN_ERROR;
|
||||||
|
|
||||||
queue_print_changes_info(client, queue, version);
|
playlist_print_changes_info(client, &g_playlist, version);
|
||||||
return COMMAND_RETURN_OK;
|
return COMMAND_RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -779,12 +771,11 @@ static enum command_return
|
||||||
handle_plchangesposid(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
handle_plchangesposid(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
||||||
{
|
{
|
||||||
uint32_t version;
|
uint32_t version;
|
||||||
const struct queue *queue = playlist_get_queue(&g_playlist);
|
|
||||||
|
|
||||||
if (!check_uint32(client, &version, argv[1], need_positive))
|
if (!check_uint32(client, &version, argv[1], need_positive))
|
||||||
return COMMAND_RETURN_ERROR;
|
return COMMAND_RETURN_ERROR;
|
||||||
|
|
||||||
queue_print_changes_position(client, queue, version);
|
playlist_print_changes_position(client, &g_playlist, version);
|
||||||
return COMMAND_RETURN_OK;
|
return COMMAND_RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -792,46 +783,37 @@ static enum command_return
|
||||||
handle_playlistinfo(struct client *client, int argc, char *argv[])
|
handle_playlistinfo(struct client *client, int argc, char *argv[])
|
||||||
{
|
{
|
||||||
unsigned start = 0, end = UINT_MAX;
|
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,
|
if (argc == 2 && !check_range(client, &start, &end,
|
||||||
argv[1], need_range))
|
argv[1], need_range))
|
||||||
return COMMAND_RETURN_ERROR;
|
return COMMAND_RETURN_ERROR;
|
||||||
|
|
||||||
if (end > queue_length(queue))
|
ret = playlist_print_info(client, &g_playlist, start, end);
|
||||||
end = queue_length(queue);
|
if (!ret)
|
||||||
|
|
||||||
if (start > end)
|
|
||||||
return print_playlist_result(client,
|
return print_playlist_result(client,
|
||||||
PLAYLIST_RESULT_BAD_RANGE);
|
PLAYLIST_RESULT_BAD_RANGE);
|
||||||
|
|
||||||
queue_print_info(client, queue, start, end);
|
|
||||||
return COMMAND_RETURN_OK;
|
return COMMAND_RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum command_return
|
static enum command_return
|
||||||
handle_playlistid(struct client *client, int argc, char *argv[])
|
handle_playlistid(struct client *client, int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int id = -1, start;
|
int id = -1;
|
||||||
unsigned end;
|
|
||||||
const struct queue *queue = playlist_get_queue(&g_playlist);
|
|
||||||
|
|
||||||
if (argc == 2 && !check_int(client, &id, argv[1], need_positive))
|
if (argc == 2 && !check_int(client, &id, argv[1], need_positive))
|
||||||
return COMMAND_RETURN_ERROR;
|
return COMMAND_RETURN_ERROR;
|
||||||
|
|
||||||
if (id >= 0) {
|
if (id >= 0) {
|
||||||
start = queue_id_to_position(queue, id);
|
bool ret = playlist_print_id(client, &g_playlist, id);
|
||||||
if (start < 0)
|
if (!ret)
|
||||||
return print_playlist_result(client,
|
return print_playlist_result(client,
|
||||||
PLAYLIST_RESULT_NO_SUCH_SONG);
|
PLAYLIST_RESULT_NO_SUCH_SONG);
|
||||||
|
|
||||||
end = start + 1;
|
|
||||||
} else {
|
} else {
|
||||||
start = 0;
|
playlist_print_info(client, &g_playlist, 0, UINT_MAX);
|
||||||
end = queue_length(queue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
queue_print_info(client, queue, start, end);
|
|
||||||
return COMMAND_RETURN_OK;
|
return COMMAND_RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -924,7 +906,7 @@ handle_playlistfind(struct client *client, int argc, char *argv[])
|
||||||
return COMMAND_RETURN_ERROR;
|
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);
|
locate_item_list_free(list);
|
||||||
|
|
||||||
|
@ -945,7 +927,7 @@ handle_playlistsearch(struct client *client, int argc, char *argv[])
|
||||||
return COMMAND_RETURN_ERROR;
|
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);
|
locate_item_list_free(list);
|
||||||
|
|
||||||
|
|
|
@ -17,12 +17,97 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "playlist_print.h"
|
#include "playlist_print.h"
|
||||||
|
#include "queue_print.h"
|
||||||
#include "stored_playlist.h"
|
#include "stored_playlist.h"
|
||||||
#include "song_print.h"
|
#include "song_print.h"
|
||||||
#include "song.h"
|
#include "song.h"
|
||||||
#include "database.h"
|
#include "database.h"
|
||||||
#include "client.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
|
bool
|
||||||
spl_print(struct client *client, const char *name_utf8, bool detail)
|
spl_print(struct client *client, const char *name_utf8, bool detail)
|
||||||
{
|
{
|
||||||
|
|
|
@ -20,8 +20,74 @@
|
||||||
#define PLAYLIST_PRINT_H
|
#define PLAYLIST_PRINT_H
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
struct client;
|
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.
|
* Send the stored playlist to the client.
|
||||||
|
|
Loading…
Reference in New Issue