command: use queue_print_*()
Replaced several wrapper functions from playlist.c, and make command.c use the queue print functions directly.
This commit is contained in:
@@ -20,6 +20,7 @@
|
|||||||
#include "player_control.h"
|
#include "player_control.h"
|
||||||
#include "playlist.h"
|
#include "playlist.h"
|
||||||
#include "playlist_print.h"
|
#include "playlist_print.h"
|
||||||
|
#include "queue_print.h"
|
||||||
#include "ls.h"
|
#include "ls.h"
|
||||||
#include "directory.h"
|
#include "directory.h"
|
||||||
#include "directory_print.h"
|
#include "directory_print.h"
|
||||||
@@ -419,13 +420,12 @@ 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();
|
int song = getPlaylistCurrentSong();
|
||||||
enum playlist_result result;
|
const struct queue *queue = playlist_get_queue();
|
||||||
|
|
||||||
if (song < 0)
|
if (song >= 0)
|
||||||
return COMMAND_RETURN_OK;
|
queue_print_info(client, queue, song, song + 1);
|
||||||
|
|
||||||
result = playlistInfo(client, song, song + 1);
|
return PLAYLIST_RESULT_SUCCESS;
|
||||||
return print_playlist_result(client, result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum command_return
|
static enum command_return
|
||||||
@@ -639,7 +639,9 @@ 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[])
|
||||||
{
|
{
|
||||||
showPlaylist(client);
|
const struct queue *queue = playlist_get_queue();
|
||||||
|
|
||||||
|
queue_print_uris(client, queue, 0, queue_length(queue));
|
||||||
return COMMAND_RETURN_OK;
|
return COMMAND_RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -757,47 +759,73 @@ 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();
|
||||||
|
|
||||||
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;
|
||||||
return playlistChanges(client, version);
|
|
||||||
|
queue_print_changes_info(client, queue, version);
|
||||||
|
return COMMAND_RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum command_return
|
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();
|
||||||
|
|
||||||
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;
|
||||||
return playlistChangesPosId(client, version);
|
|
||||||
|
queue_print_changes_position(client, queue, version);
|
||||||
|
return COMMAND_RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum command_return
|
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;
|
||||||
enum playlist_result result;
|
const struct queue *queue = playlist_get_queue();
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
result = playlistInfo(client, start, end);
|
if (end > queue_length(queue))
|
||||||
return print_playlist_result(client, result);
|
end = queue_length(queue);
|
||||||
|
|
||||||
|
if (start > end)
|
||||||
|
return print_playlist_result(client,
|
||||||
|
PLAYLIST_RESULT_BAD_RANGE);
|
||||||
|
|
||||||
|
queue_print_info(client, queue, start, end);
|
||||||
|
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;
|
int id = -1, start;
|
||||||
enum playlist_result result;
|
unsigned end;
|
||||||
|
const struct queue *queue = playlist_get_queue();
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
result = playlistId(client, id);
|
if (id >= 0) {
|
||||||
return print_playlist_result(client, result);
|
start = queue_id_to_position(queue, id);
|
||||||
|
if (start < 0)
|
||||||
|
return print_playlist_result(client,
|
||||||
|
PLAYLIST_RESULT_NO_SUCH_SONG);
|
||||||
|
|
||||||
|
end = start + 1;
|
||||||
|
} else {
|
||||||
|
start = 0;
|
||||||
|
end = queue_length(queue);
|
||||||
|
}
|
||||||
|
|
||||||
|
queue_print_info(client, queue, start, end);
|
||||||
|
return COMMAND_RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum command_return
|
static enum command_return
|
||||||
|
@@ -157,12 +157,6 @@ void clearPlaylist(void)
|
|||||||
incrPlaylistVersion();
|
incrPlaylistVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
void showPlaylist(struct client *client)
|
|
||||||
{
|
|
||||||
queue_print_uris(client, &playlist.queue,
|
|
||||||
0, queue_length(&playlist.queue));
|
|
||||||
}
|
|
||||||
|
|
||||||
void savePlaylistState(FILE *fp)
|
void savePlaylistState(FILE *fp)
|
||||||
{
|
{
|
||||||
fprintf(fp, "%s", PLAYLIST_STATE_FILE_STATE);
|
fprintf(fp, "%s", PLAYLIST_STATE_FILE_STATE);
|
||||||
@@ -288,48 +282,6 @@ void readPlaylistState(FILE *fp)
|
|||||||
setPlaylistRandomStatus(random_mode);
|
setPlaylistRandomStatus(random_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
int playlistChanges(struct client *client, uint32_t version)
|
|
||||||
{
|
|
||||||
queue_print_changes_info(client, &playlist.queue, version);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int playlistChangesPosId(struct client *client, uint32_t version)
|
|
||||||
{
|
|
||||||
queue_print_changes_position(client, &playlist.queue, version);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
enum playlist_result
|
|
||||||
playlistInfo(struct client *client, unsigned start, unsigned end)
|
|
||||||
{
|
|
||||||
if (end > queue_length(&playlist.queue))
|
|
||||||
end = queue_length(&playlist.queue);
|
|
||||||
|
|
||||||
if (start > end)
|
|
||||||
return PLAYLIST_RESULT_BAD_RANGE;
|
|
||||||
|
|
||||||
queue_print_info(client, &playlist.queue, start, end);
|
|
||||||
return PLAYLIST_RESULT_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
enum playlist_result playlistId(struct client *client, int id)
|
|
||||||
{
|
|
||||||
int begin = 0;
|
|
||||||
unsigned end = queue_length(&playlist.queue);
|
|
||||||
|
|
||||||
if (id >= 0) {
|
|
||||||
begin = queue_id_to_position(&playlist.queue, id);
|
|
||||||
if (begin < 0)
|
|
||||||
return PLAYLIST_RESULT_NO_SUCH_SONG;
|
|
||||||
|
|
||||||
end = begin + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
queue_print_info(client, &playlist.queue, begin, end);
|
|
||||||
return PLAYLIST_RESULT_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Queue a song, addressed by its order number.
|
* Queue a song, addressed by its order number.
|
||||||
*/
|
*/
|
||||||
|
@@ -120,25 +120,10 @@ enum playlist_result addToPlaylist(const char *file, unsigned *added_id);
|
|||||||
enum playlist_result
|
enum playlist_result
|
||||||
addSongToPlaylist(struct song *song, unsigned *added_id);
|
addSongToPlaylist(struct song *song, unsigned *added_id);
|
||||||
|
|
||||||
void showPlaylist(struct client *client);
|
|
||||||
|
|
||||||
enum playlist_result deleteFromPlaylist(unsigned song);
|
enum playlist_result deleteFromPlaylist(unsigned song);
|
||||||
|
|
||||||
enum playlist_result deleteFromPlaylistById(unsigned song);
|
enum playlist_result deleteFromPlaylistById(unsigned song);
|
||||||
|
|
||||||
/**
|
|
||||||
* Send detailed information about a range of songs in the playlist to
|
|
||||||
* a client.
|
|
||||||
*
|
|
||||||
* @param client the client which has requested information
|
|
||||||
* @param start the index of the first song (including)
|
|
||||||
* @param end the index of the last song (excluding)
|
|
||||||
*/
|
|
||||||
enum playlist_result
|
|
||||||
playlistInfo(struct client *client, unsigned start, unsigned end);
|
|
||||||
|
|
||||||
enum playlist_result playlistId(struct client *client, int song);
|
|
||||||
|
|
||||||
void stopPlaylist(void);
|
void stopPlaylist(void);
|
||||||
|
|
||||||
enum playlist_result playPlaylist(int song);
|
enum playlist_result playPlaylist(int song);
|
||||||
@@ -190,10 +175,6 @@ enum playlist_result seekSongInPlaylistById(unsigned id, float seek_time);
|
|||||||
|
|
||||||
void playlistVersionChange(void);
|
void playlistVersionChange(void);
|
||||||
|
|
||||||
int playlistChanges(struct client *client, uint32_t version);
|
|
||||||
|
|
||||||
int playlistChangesPosId(struct client *client, uint32_t version);
|
|
||||||
|
|
||||||
void
|
void
|
||||||
searchForSongsInPlaylist(struct client *client,
|
searchForSongsInPlaylist(struct client *client,
|
||||||
unsigned numItems, const LocateTagItem *items);
|
unsigned numItems, const LocateTagItem *items);
|
||||||
|
@@ -33,6 +33,14 @@ void
|
|||||||
queue_print_song_info(struct client *client, const struct queue *queue,
|
queue_print_song_info(struct client *client, const struct queue *queue,
|
||||||
unsigned position);
|
unsigned position);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send detailed information about a range of songs in the queue to a
|
||||||
|
* client.
|
||||||
|
*
|
||||||
|
* @param client the client which has requested information
|
||||||
|
* @param start the index of the first song (including)
|
||||||
|
* @param end the index of the last song (excluding)
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
queue_print_info(struct client *client, const struct queue *queue,
|
queue_print_info(struct client *client, const struct queue *queue,
|
||||||
unsigned start, unsigned end);
|
unsigned start, unsigned end);
|
||||||
|
Reference in New Issue
Block a user