aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-01-24 14:52:04 +0100
committerMax Kellermann <max@duempel.org>2009-01-24 14:52:04 +0100
commit627d590ce524faf7ec197c54e65076107af27fe9 (patch)
treee3b594abc6c2c12c6ea054a77aabc09bc5ffd59b /src
parentd449d6abab3c263ae6bcfe2ae5e4465d7a1d149f (diff)
downloadmpd-627d590ce524faf7ec197c54e65076107af27fe9.tar.gz
mpd-627d590ce524faf7ec197c54e65076107af27fe9.tar.xz
mpd-627d590ce524faf7ec197c54e65076107af27fe9.zip
command: use queue_print_*()
Replaced several wrapper functions from playlist.c, and make command.c use the queue print functions directly.
Diffstat (limited to 'src')
-rw-r--r--src/command.c58
-rw-r--r--src/playlist.c48
-rw-r--r--src/playlist.h19
-rw-r--r--src/queue_print.h8
4 files changed, 51 insertions, 82 deletions
diff --git a/src/command.c b/src/command.c
index 07d202155..2000ecd26 100644
--- a/src/command.c
+++ b/src/command.c
@@ -20,6 +20,7 @@
#include "player_control.h"
#include "playlist.h"
#include "playlist_print.h"
+#include "queue_print.h"
#include "ls.h"
#include "directory.h"
#include "directory_print.h"
@@ -419,13 +420,12 @@ handle_currentsong(struct client *client,
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
{
int song = getPlaylistCurrentSong();
- enum playlist_result result;
+ const struct queue *queue = playlist_get_queue();
- if (song < 0)
- return COMMAND_RETURN_OK;
+ if (song >= 0)
+ queue_print_info(client, queue, song, song + 1);
- result = playlistInfo(client, song, song + 1);
- return print_playlist_result(client, result);
+ return PLAYLIST_RESULT_SUCCESS;
}
static enum command_return
@@ -639,7 +639,9 @@ static enum command_return
handle_playlist(struct client *client,
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;
}
@@ -757,47 +759,73 @@ 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();
if (!check_uint32(client, &version, argv[1], need_positive))
return COMMAND_RETURN_ERROR;
- return playlistChanges(client, version);
+
+ queue_print_changes_info(client, queue, version);
+ return COMMAND_RETURN_OK;
}
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();
if (!check_uint32(client, &version, argv[1], need_positive))
return COMMAND_RETURN_ERROR;
- return playlistChangesPosId(client, version);
+
+ queue_print_changes_position(client, queue, version);
+ return COMMAND_RETURN_OK;
}
static enum command_return
handle_playlistinfo(struct client *client, int argc, char *argv[])
{
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,
argv[1], need_range))
return COMMAND_RETURN_ERROR;
- result = playlistInfo(client, start, end);
- return print_playlist_result(client, result);
+ if (end > queue_length(queue))
+ 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
handle_playlistid(struct client *client, int argc, char *argv[])
{
- int id = -1;
- enum playlist_result result;
+ int id = -1, start;
+ unsigned end;
+ const struct queue *queue = playlist_get_queue();
if (argc == 2 && !check_int(client, &id, argv[1], need_positive))
return COMMAND_RETURN_ERROR;
- result = playlistId(client, id);
- return print_playlist_result(client, result);
+ if (id >= 0) {
+ 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
diff --git a/src/playlist.c b/src/playlist.c
index 9d1f4f5b4..32e5bba78 100644
--- a/src/playlist.c
+++ b/src/playlist.c
@@ -157,12 +157,6 @@ void clearPlaylist(void)
incrPlaylistVersion();
}
-void showPlaylist(struct client *client)
-{
- queue_print_uris(client, &playlist.queue,
- 0, queue_length(&playlist.queue));
-}
-
void savePlaylistState(FILE *fp)
{
fprintf(fp, "%s", PLAYLIST_STATE_FILE_STATE);
@@ -288,48 +282,6 @@ void readPlaylistState(FILE *fp)
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.
*/
diff --git a/src/playlist.h b/src/playlist.h
index 3875aaed0..7fe10cb40 100644
--- a/src/playlist.h
+++ b/src/playlist.h
@@ -120,25 +120,10 @@ enum playlist_result addToPlaylist(const char *file, unsigned *added_id);
enum playlist_result
addSongToPlaylist(struct song *song, unsigned *added_id);
-void showPlaylist(struct client *client);
-
enum playlist_result deleteFromPlaylist(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);
enum playlist_result playPlaylist(int song);
@@ -190,10 +175,6 @@ enum playlist_result seekSongInPlaylistById(unsigned id, float seek_time);
void playlistVersionChange(void);
-int playlistChanges(struct client *client, uint32_t version);
-
-int playlistChangesPosId(struct client *client, uint32_t version);
-
void
searchForSongsInPlaylist(struct client *client,
unsigned numItems, const LocateTagItem *items);
diff --git a/src/queue_print.h b/src/queue_print.h
index c67caff62..8ec7ff0fa 100644
--- a/src/queue_print.h
+++ b/src/queue_print.h
@@ -33,6 +33,14 @@ void
queue_print_song_info(struct client *client, const struct queue *queue,
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
queue_print_info(struct client *client, const struct queue *queue,
unsigned start, unsigned end);