PlaylistError: convert playlist_result to a strictly-typed enum

This commit is contained in:
Max Kellermann 2013-10-19 19:50:54 +02:00
parent c1e7be3b8e
commit c772bc45c6
16 changed files with 204 additions and 207 deletions

View File

@ -30,55 +30,55 @@
#include <errno.h> #include <errno.h>
enum command_return enum command_return
print_playlist_result(Client &client, enum playlist_result result) print_playlist_result(Client &client, PlaylistResult result)
{ {
switch (result) { switch (result) {
case PLAYLIST_RESULT_SUCCESS: case PlaylistResult::SUCCESS:
return COMMAND_RETURN_OK; return COMMAND_RETURN_OK;
case PLAYLIST_RESULT_ERRNO: case PlaylistResult::ERRNO:
command_error(client, ACK_ERROR_SYSTEM, "%s", command_error(client, ACK_ERROR_SYSTEM, "%s",
g_strerror(errno)); g_strerror(errno));
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
case PLAYLIST_RESULT_DENIED: case PlaylistResult::DENIED:
command_error(client, ACK_ERROR_PERMISSION, "Access denied"); command_error(client, ACK_ERROR_PERMISSION, "Access denied");
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
case PLAYLIST_RESULT_NO_SUCH_SONG: case PlaylistResult::NO_SUCH_SONG:
command_error(client, ACK_ERROR_NO_EXIST, "No such song"); command_error(client, ACK_ERROR_NO_EXIST, "No such song");
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
case PLAYLIST_RESULT_NO_SUCH_LIST: case PlaylistResult::NO_SUCH_LIST:
command_error(client, ACK_ERROR_NO_EXIST, "No such playlist"); command_error(client, ACK_ERROR_NO_EXIST, "No such playlist");
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
case PLAYLIST_RESULT_LIST_EXISTS: case PlaylistResult::LIST_EXISTS:
command_error(client, ACK_ERROR_EXIST, command_error(client, ACK_ERROR_EXIST,
"Playlist already exists"); "Playlist already exists");
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
case PLAYLIST_RESULT_BAD_NAME: case PlaylistResult::BAD_NAME:
command_error(client, ACK_ERROR_ARG, command_error(client, ACK_ERROR_ARG,
"playlist name is invalid: " "playlist name is invalid: "
"playlist names may not contain slashes," "playlist names may not contain slashes,"
" newlines or carriage returns"); " newlines or carriage returns");
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
case PLAYLIST_RESULT_BAD_RANGE: case PlaylistResult::BAD_RANGE:
command_error(client, ACK_ERROR_ARG, "Bad song index"); command_error(client, ACK_ERROR_ARG, "Bad song index");
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
case PLAYLIST_RESULT_NOT_PLAYING: case PlaylistResult::NOT_PLAYING:
command_error(client, ACK_ERROR_PLAYER_SYNC, "Not playing"); command_error(client, ACK_ERROR_PLAYER_SYNC, "Not playing");
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
case PLAYLIST_RESULT_TOO_LARGE: case PlaylistResult::TOO_LARGE:
command_error(client, ACK_ERROR_PLAYLIST_MAX, command_error(client, ACK_ERROR_PLAYLIST_MAX,
"playlist is at the max size"); "playlist is at the max size");
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
case PLAYLIST_RESULT_DISABLED: case PlaylistResult::DISABLED:
command_error(client, ACK_ERROR_UNKNOWN, command_error(client, ACK_ERROR_UNKNOWN,
"stored playlist support is disabled"); "stored playlist support is disabled");
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
@ -97,7 +97,7 @@ print_error(Client &client, const Error &error)
if (error.IsDomain(playlist_domain)) { if (error.IsDomain(playlist_domain)) {
return print_playlist_result(client, return print_playlist_result(client,
playlist_result(error.GetCode())); PlaylistResult(error.GetCode()));
} else if (error.IsDomain(ack_domain)) { } else if (error.IsDomain(ack_domain)) {
command_error(client, (ack)error.GetCode(), command_error(client, (ack)error.GetCode(),
"%s", error.GetMessage()); "%s", error.GetMessage());

View File

@ -27,7 +27,7 @@ class Client;
class Error; class Error;
enum command_return enum command_return
print_playlist_result(Client &client, enum playlist_result result); print_playlist_result(Client &client, PlaylistResult result);
/** /**
* Send the #Error to the client. * Send the #Error to the client.

View File

@ -30,10 +30,10 @@
static bool static bool
AddToQueue(Partition &partition, Song &song, Error &error) AddToQueue(Partition &partition, Song &song, Error &error)
{ {
enum playlist_result result = PlaylistResult result =
partition.playlist.AppendSong(partition.pc, &song, NULL); partition.playlist.AppendSong(partition.pc, &song, NULL);
if (result != PLAYLIST_RESULT_SUCCESS) { if (result != PlaylistResult::SUCCESS) {
error.Set(playlist_domain, result, "Playlist error"); error.Set(playlist_domain, int(result), "Playlist error");
return false; return false;
} }

View File

@ -48,21 +48,21 @@ struct Partition {
playlist.Clear(pc); playlist.Clear(pc);
} }
enum playlist_result AppendFile(const char *path_utf8, PlaylistResult AppendFile(const char *path_utf8,
unsigned *added_id=nullptr) { unsigned *added_id=nullptr) {
return playlist.AppendFile(pc, path_utf8, added_id); return playlist.AppendFile(pc, path_utf8, added_id);
} }
enum playlist_result AppendURI(const char *uri_utf8, PlaylistResult AppendURI(const char *uri_utf8,
unsigned *added_id=nullptr) { unsigned *added_id=nullptr) {
return playlist.AppendURI(pc, uri_utf8, added_id); return playlist.AppendURI(pc, uri_utf8, added_id);
} }
enum playlist_result DeletePosition(unsigned position) { PlaylistResult DeletePosition(unsigned position) {
return playlist.DeletePosition(pc, position); return playlist.DeletePosition(pc, position);
} }
enum playlist_result DeleteId(unsigned id) { PlaylistResult DeleteId(unsigned id) {
return playlist.DeleteId(pc, id); return playlist.DeleteId(pc, id);
} }
@ -72,7 +72,7 @@ struct Partition {
* @param start the position of the first song to delete * @param start the position of the first song to delete
* @param end the position after the last song to delete * @param end the position after the last song to delete
*/ */
enum playlist_result DeleteRange(unsigned start, unsigned end) { PlaylistResult DeleteRange(unsigned start, unsigned end) {
return playlist.DeleteRange(pc, start, end); return playlist.DeleteRange(pc, start, end);
} }
@ -84,32 +84,32 @@ struct Partition {
playlist.Shuffle(pc, start, end); playlist.Shuffle(pc, start, end);
} }
enum playlist_result MoveRange(unsigned start, unsigned end, int to) { PlaylistResult MoveRange(unsigned start, unsigned end, int to) {
return playlist.MoveRange(pc, start, end, to); return playlist.MoveRange(pc, start, end, to);
} }
enum playlist_result MoveId(unsigned id, int to) { PlaylistResult MoveId(unsigned id, int to) {
return playlist.MoveId(pc, id, to); return playlist.MoveId(pc, id, to);
} }
enum playlist_result SwapPositions(unsigned song1, unsigned song2) { PlaylistResult SwapPositions(unsigned song1, unsigned song2) {
return playlist.SwapPositions(pc, song1, song2); return playlist.SwapPositions(pc, song1, song2);
} }
enum playlist_result SwapIds(unsigned id1, unsigned id2) { PlaylistResult SwapIds(unsigned id1, unsigned id2) {
return playlist.SwapIds(pc, id1, id2); return playlist.SwapIds(pc, id1, id2);
} }
enum playlist_result SetPriorityRange(unsigned start_position, PlaylistResult SetPriorityRange(unsigned start_position,
unsigned end_position, unsigned end_position,
uint8_t priority) { uint8_t priority) {
return playlist.SetPriorityRange(pc, return playlist.SetPriorityRange(pc,
start_position, end_position, start_position, end_position,
priority); priority);
} }
enum playlist_result SetPriorityId(unsigned song_id, PlaylistResult SetPriorityId(unsigned song_id,
uint8_t priority) { uint8_t priority) {
return playlist.SetPriorityId(pc, song_id, priority); return playlist.SetPriorityId(pc, song_id, priority);
} }
@ -117,11 +117,11 @@ struct Partition {
playlist.Stop(pc); playlist.Stop(pc);
} }
enum playlist_result PlayPosition(int position) { PlaylistResult PlayPosition(int position) {
return playlist.PlayPosition(pc, position); return playlist.PlayPosition(pc, position);
} }
enum playlist_result PlayId(int id) { PlaylistResult PlayId(int id) {
return playlist.PlayId(pc, id); return playlist.PlayId(pc, id);
} }
@ -133,16 +133,16 @@ struct Partition {
return playlist.PlayPrevious(pc); return playlist.PlayPrevious(pc);
} }
enum playlist_result SeekSongPosition(unsigned song_position, PlaylistResult SeekSongPosition(unsigned song_position,
float seek_time) { float seek_time) {
return playlist.SeekSongPosition(pc, song_position, seek_time); return playlist.SeekSongPosition(pc, song_position, seek_time);
} }
enum playlist_result SeekSongId(unsigned song_id, float seek_time) { PlaylistResult SeekSongId(unsigned song_id, float seek_time) {
return playlist.SeekSongId(pc, song_id, seek_time); return playlist.SeekSongId(pc, song_id, seek_time);
} }
enum playlist_result SeekCurrent(float seek_time, bool relative) { PlaylistResult SeekCurrent(float seek_time, bool relative) {
return playlist.SeekCurrent(pc, seek_time, relative); return playlist.SeekCurrent(pc, seek_time, relative);
} }

View File

@ -59,7 +59,7 @@ handle_play(Client &client, int argc, char *argv[])
if (argc == 2 && !check_int(client, &song, argv[1])) if (argc == 2 && !check_int(client, &song, argv[1]))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
enum playlist_result result = client.partition.PlayPosition(song); PlaylistResult result = client.partition.PlayPosition(song);
return print_playlist_result(client, result); return print_playlist_result(client, result);
} }
@ -71,7 +71,7 @@ handle_playid(Client &client, int argc, char *argv[])
if (argc == 2 && !check_int(client, &id, argv[1])) if (argc == 2 && !check_int(client, &id, argv[1]))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
enum playlist_result result = client.partition.PlayId(id); PlaylistResult result = client.partition.PlayId(id);
return print_playlist_result(client, result); return print_playlist_result(client, result);
} }
@ -293,7 +293,7 @@ handle_seek(Client &client, gcc_unused int argc, char *argv[])
if (!check_unsigned(client, &seek_time, argv[2])) if (!check_unsigned(client, &seek_time, argv[2]))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
enum playlist_result result = PlaylistResult result =
client.partition.SeekSongPosition(song, seek_time); client.partition.SeekSongPosition(song, seek_time);
return print_playlist_result(client, result); return print_playlist_result(client, result);
} }
@ -308,7 +308,7 @@ handle_seekid(Client &client, gcc_unused int argc, char *argv[])
if (!check_unsigned(client, &seek_time, argv[2])) if (!check_unsigned(client, &seek_time, argv[2]))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
enum playlist_result result = PlaylistResult result =
client.partition.SeekSongId(id, seek_time); client.partition.SeekSongId(id, seek_time);
return print_playlist_result(client, result); return print_playlist_result(client, result);
} }
@ -322,7 +322,7 @@ handle_seekcur(Client &client, gcc_unused int argc, char *argv[])
if (!check_int(client, &seek_time, p)) if (!check_int(client, &seek_time, p))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
enum playlist_result result = PlaylistResult result =
client.partition.SeekCurrent(seek_time, relative); client.partition.SeekCurrent(seek_time, relative);
return print_playlist_result(client, result); return print_playlist_result(client, result);
} }

View File

@ -132,9 +132,9 @@ public:
void FullIncrementVersions(); void FullIncrementVersions();
enum playlist_result AppendSong(player_control &pc, PlaylistResult AppendSong(player_control &pc,
Song *song, Song *song,
unsigned *added_id=nullptr); unsigned *added_id=nullptr);
/** /**
* Appends a local file (outside the music database) to the * Appends a local file (outside the music database) to the
@ -142,28 +142,28 @@ public:
* *
* Note: the caller is responsible for checking permissions. * Note: the caller is responsible for checking permissions.
*/ */
enum playlist_result AppendFile(player_control &pc, PlaylistResult AppendFile(player_control &pc,
const char *path_utf8, const char *path_utf8,
unsigned *added_id=nullptr); unsigned *added_id=nullptr);
enum playlist_result AppendURI(player_control &pc, PlaylistResult AppendURI(player_control &pc,
const char *uri_utf8, const char *uri_utf8,
unsigned *added_id=nullptr); unsigned *added_id=nullptr);
protected: protected:
void DeleteInternal(player_control &pc, void DeleteInternal(player_control &pc,
unsigned song, const Song **queued_p); unsigned song, const Song **queued_p);
public: public:
enum playlist_result DeletePosition(player_control &pc, PlaylistResult DeletePosition(player_control &pc,
unsigned position); unsigned position);
enum playlist_result DeleteOrder(player_control &pc, PlaylistResult DeleteOrder(player_control &pc,
unsigned order) { unsigned order) {
return DeletePosition(pc, queue.OrderToPosition(order)); return DeletePosition(pc, queue.OrderToPosition(order));
} }
enum playlist_result DeleteId(player_control &pc, unsigned id); PlaylistResult DeleteId(player_control &pc, unsigned id);
/** /**
* Deletes a range of songs from the playlist. * Deletes a range of songs from the playlist.
@ -171,50 +171,50 @@ public:
* @param start the position of the first song to delete * @param start the position of the first song to delete
* @param end the position after the last song to delete * @param end the position after the last song to delete
*/ */
enum playlist_result DeleteRange(player_control &pc, PlaylistResult DeleteRange(player_control &pc,
unsigned start, unsigned end); unsigned start, unsigned end);
void DeleteSong(player_control &pc, const Song &song); void DeleteSong(player_control &pc, const Song &song);
void Shuffle(player_control &pc, unsigned start, unsigned end); void Shuffle(player_control &pc, unsigned start, unsigned end);
enum playlist_result MoveRange(player_control &pc, PlaylistResult MoveRange(player_control &pc,
unsigned start, unsigned end, int to); unsigned start, unsigned end, int to);
enum playlist_result MoveId(player_control &pc, unsigned id, int to); PlaylistResult MoveId(player_control &pc, unsigned id, int to);
enum playlist_result SwapPositions(player_control &pc, PlaylistResult SwapPositions(player_control &pc,
unsigned song1, unsigned song2); unsigned song1, unsigned song2);
enum playlist_result SwapIds(player_control &pc, PlaylistResult SwapIds(player_control &pc,
unsigned id1, unsigned id2); unsigned id1, unsigned id2);
enum playlist_result SetPriorityRange(player_control &pc, PlaylistResult SetPriorityRange(player_control &pc,
unsigned start_position, unsigned start_position,
unsigned end_position, unsigned end_position,
uint8_t priority); uint8_t priority);
enum playlist_result SetPriorityId(player_control &pc, PlaylistResult SetPriorityId(player_control &pc,
unsigned song_id, uint8_t priority); unsigned song_id, uint8_t priority);
void Stop(player_control &pc); void Stop(player_control &pc);
enum playlist_result PlayPosition(player_control &pc, int position); PlaylistResult PlayPosition(player_control &pc, int position);
void PlayOrder(player_control &pc, int order); void PlayOrder(player_control &pc, int order);
enum playlist_result PlayId(player_control &pc, int id); PlaylistResult PlayId(player_control &pc, int id);
void PlayNext(player_control &pc); void PlayNext(player_control &pc);
void PlayPrevious(player_control &pc); void PlayPrevious(player_control &pc);
enum playlist_result SeekSongPosition(player_control &pc, PlaylistResult SeekSongPosition(player_control &pc,
unsigned song_position, unsigned song_position,
float seek_time); float seek_time);
enum playlist_result SeekSongId(player_control &pc, PlaylistResult SeekSongId(player_control &pc,
unsigned song_id, float seek_time); unsigned song_id, float seek_time);
/** /**
* Seek within the current song. Fails if MPD is not currently * Seek within the current song. Fails if MPD is not currently
@ -224,8 +224,8 @@ public:
* @param relative if true, then the specified time is relative to the * @param relative if true, then the specified time is relative to the
* current position * current position
*/ */
enum playlist_result SeekCurrent(player_control &pc, PlaylistResult SeekCurrent(player_control &pc,
float seek_time, bool relative); float seek_time, bool relative);
bool GetRepeat() const { bool GetRepeat() const {
return queue.repeat; return queue.repeat;

View File

@ -52,9 +52,7 @@ print_spl_list(Client &client, const PlaylistVector &list)
enum command_return enum command_return
handle_save(Client &client, gcc_unused int argc, char *argv[]) handle_save(Client &client, gcc_unused int argc, char *argv[])
{ {
enum playlist_result result; PlaylistResult result = spl_save_playlist(argv[1], client.playlist);
result = spl_save_playlist(argv[1], client.playlist);
return print_playlist_result(client, result); return print_playlist_result(client, result);
} }
@ -69,13 +67,12 @@ handle_load(Client &client, int argc, char *argv[])
} else if (!check_range(client, &start_index, &end_index, argv[2])) } else if (!check_range(client, &start_index, &end_index, argv[2]))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
enum playlist_result result; const PlaylistResult result =
playlist_open_into_queue(argv[1],
result = playlist_open_into_queue(argv[1], start_index, end_index,
start_index, end_index, client.playlist,
client.playlist, client.player_control, true);
client.player_control, true); if (result != PlaylistResult::NO_SUCH_LIST)
if (result != PLAYLIST_RESULT_NO_SUCH_LIST)
return print_playlist_result(client, result); return print_playlist_result(client, result);
Error error; Error error;
@ -85,12 +82,12 @@ handle_load(Client &client, int argc, char *argv[])
return COMMAND_RETURN_OK; return COMMAND_RETURN_OK;
if (error.IsDomain(playlist_domain) && if (error.IsDomain(playlist_domain) &&
error.GetCode() == PLAYLIST_RESULT_BAD_NAME) { PlaylistResult(error.GetCode()) == PlaylistResult::BAD_NAME) {
/* the message for BAD_NAME is confusing when the /* the message for BAD_NAME is confusing when the
client wants to load a playlist file from the music client wants to load a playlist file from the music
directory; patch the Error object to show "no such directory; patch the Error object to show "no such
playlist" instead */ playlist" instead */
Error error2(playlist_domain, PLAYLIST_RESULT_NO_SUCH_LIST, Error error2(playlist_domain, int(PlaylistResult::NO_SUCH_LIST),
error.GetMessage()); error.GetMessage());
error = std::move(error2); error = std::move(error2);
} }

View File

@ -56,7 +56,7 @@ playlist::Stop(player_control &pc)
} }
} }
enum playlist_result PlaylistResult
playlist::PlayPosition(player_control &pc, int song) playlist::PlayPosition(player_control &pc, int song)
{ {
pc.ClearError(); pc.ClearError();
@ -66,13 +66,13 @@ playlist::PlayPosition(player_control &pc, int song)
/* play any song ("current" song, or the first song */ /* play any song ("current" song, or the first song */
if (queue.IsEmpty()) if (queue.IsEmpty())
return PLAYLIST_RESULT_SUCCESS; return PlaylistResult::SUCCESS;
if (playing) { if (playing) {
/* already playing: unpause playback, just in /* already playing: unpause playback, just in
case it was paused, and return */ case it was paused, and return */
pc.SetPause(false); pc.SetPause(false);
return PLAYLIST_RESULT_SUCCESS; return PlaylistResult::SUCCESS;
} }
/* select a song: "current" song, or the first one */ /* select a song: "current" song, or the first one */
@ -80,7 +80,7 @@ playlist::PlayPosition(player_control &pc, int song)
? current ? current
: 0; : 0;
} else if (!queue.IsValidPosition(song)) } else if (!queue.IsValidPosition(song))
return PLAYLIST_RESULT_BAD_RANGE; return PlaylistResult::BAD_RANGE;
if (queue.random) { if (queue.random) {
if (song >= 0) if (song >= 0)
@ -103,10 +103,10 @@ playlist::PlayPosition(player_control &pc, int song)
error_count = 0; error_count = 0;
PlayOrder(pc, i); PlayOrder(pc, i);
return PLAYLIST_RESULT_SUCCESS; return PlaylistResult::SUCCESS;
} }
enum playlist_result PlaylistResult
playlist::PlayId(player_control &pc, int id) playlist::PlayId(player_control &pc, int id)
{ {
if (id == -1) if (id == -1)
@ -114,7 +114,7 @@ playlist::PlayId(player_control &pc, int id)
int song = queue.IdToPosition(id); int song = queue.IdToPosition(id);
if (song < 0) if (song < 0)
return PLAYLIST_RESULT_NO_SUCH_SONG; return PlaylistResult::NO_SUCH_SONG;
return PlayPosition(pc, song); return PlayPosition(pc, song);
} }
@ -189,11 +189,11 @@ playlist::PlayPrevious(player_control &pc)
PlayOrder(pc, order); PlayOrder(pc, order);
} }
enum playlist_result PlaylistResult
playlist::SeekSongPosition(player_control &pc, unsigned song, float seek_time) playlist::SeekSongPosition(player_control &pc, unsigned song, float seek_time)
{ {
if (!queue.IsValidPosition(song)) if (!queue.IsValidPosition(song))
return PLAYLIST_RESULT_BAD_RANGE; return PlaylistResult::BAD_RANGE;
const Song *queued_song = GetQueuedSong(); const Song *queued_song = GetQueuedSong();
@ -219,37 +219,37 @@ playlist::SeekSongPosition(player_control &pc, unsigned song, float seek_time)
if (!pc.Seek(the_song, seek_time)) { if (!pc.Seek(the_song, seek_time)) {
UpdateQueuedSong(pc, queued_song); UpdateQueuedSong(pc, queued_song);
return PLAYLIST_RESULT_NOT_PLAYING; return PlaylistResult::NOT_PLAYING;
} }
queued = -1; queued = -1;
UpdateQueuedSong(pc, nullptr); UpdateQueuedSong(pc, nullptr);
return PLAYLIST_RESULT_SUCCESS; return PlaylistResult::SUCCESS;
} }
enum playlist_result PlaylistResult
playlist::SeekSongId(player_control &pc, unsigned id, float seek_time) playlist::SeekSongId(player_control &pc, unsigned id, float seek_time)
{ {
int song = queue.IdToPosition(id); int song = queue.IdToPosition(id);
if (song < 0) if (song < 0)
return PLAYLIST_RESULT_NO_SUCH_SONG; return PlaylistResult::NO_SUCH_SONG;
return SeekSongPosition(pc, song, seek_time); return SeekSongPosition(pc, song, seek_time);
} }
enum playlist_result PlaylistResult
playlist::SeekCurrent(player_control &pc, float seek_time, bool relative) playlist::SeekCurrent(player_control &pc, float seek_time, bool relative)
{ {
if (!playing) if (!playing)
return PLAYLIST_RESULT_NOT_PLAYING; return PlaylistResult::NOT_PLAYING;
if (relative) { if (relative) {
const auto status = pc.GetStatus(); const auto status = pc.GetStatus();
if (status.state != PlayerState::PLAY && if (status.state != PlayerState::PLAY &&
status.state != PlayerState::PAUSE) status.state != PlayerState::PAUSE)
return PLAYLIST_RESULT_NOT_PLAYING; return PlaylistResult::NOT_PLAYING;
seek_time += (int)status.elapsed_time; seek_time += (int)status.elapsed_time;
} }

View File

@ -56,27 +56,27 @@ playlist::Clear(player_control &pc)
OnModified(); OnModified();
} }
enum playlist_result PlaylistResult
playlist::AppendFile(struct player_control &pc, playlist::AppendFile(struct player_control &pc,
const char *path_utf8, unsigned *added_id) const char *path_utf8, unsigned *added_id)
{ {
Song *song = Song::LoadFile(path_utf8, nullptr); Song *song = Song::LoadFile(path_utf8, nullptr);
if (song == nullptr) if (song == nullptr)
return PLAYLIST_RESULT_NO_SUCH_SONG; return PlaylistResult::NO_SUCH_SONG;
const auto result = AppendSong(pc, song, added_id); const auto result = AppendSong(pc, song, added_id);
song->Free(); song->Free();
return result; return result;
} }
enum playlist_result PlaylistResult
playlist::AppendSong(struct player_control &pc, playlist::AppendSong(struct player_control &pc,
Song *song, unsigned *added_id) Song *song, unsigned *added_id)
{ {
unsigned id; unsigned id;
if (queue.IsFull()) if (queue.IsFull())
return PLAYLIST_RESULT_TOO_LARGE; return PlaylistResult::TOO_LARGE;
const Song *const queued_song = GetQueuedSong(); const Song *const queued_song = GetQueuedSong();
@ -101,10 +101,10 @@ playlist::AppendSong(struct player_control &pc,
if (added_id) if (added_id)
*added_id = id; *added_id = id;
return PLAYLIST_RESULT_SUCCESS; return PlaylistResult::SUCCESS;
} }
enum playlist_result PlaylistResult
playlist::AppendURI(struct player_control &pc, playlist::AppendURI(struct player_control &pc,
const char *uri, unsigned *added_id) const char *uri, unsigned *added_id)
{ {
@ -117,14 +117,14 @@ playlist::AppendURI(struct player_control &pc,
} else { } else {
db = GetDatabase(IgnoreError()); db = GetDatabase(IgnoreError());
if (db == nullptr) if (db == nullptr)
return PLAYLIST_RESULT_NO_SUCH_SONG; return PlaylistResult::NO_SUCH_SONG;
song = db->GetSong(uri, IgnoreError()); song = db->GetSong(uri, IgnoreError());
if (song == nullptr) if (song == nullptr)
return PLAYLIST_RESULT_NO_SUCH_SONG; return PlaylistResult::NO_SUCH_SONG;
} }
enum playlist_result result = AppendSong(pc, song, added_id); PlaylistResult result = AppendSong(pc, song, added_id);
if (db != nullptr) if (db != nullptr)
db->ReturnSong(song); db->ReturnSong(song);
else else
@ -133,11 +133,11 @@ playlist::AppendURI(struct player_control &pc,
return result; return result;
} }
enum playlist_result PlaylistResult
playlist::SwapPositions(player_control &pc, unsigned song1, unsigned song2) playlist::SwapPositions(player_control &pc, unsigned song1, unsigned song2)
{ {
if (!queue.IsValidPosition(song1) || !queue.IsValidPosition(song2)) if (!queue.IsValidPosition(song1) || !queue.IsValidPosition(song2))
return PLAYLIST_RESULT_BAD_RANGE; return PlaylistResult::BAD_RANGE;
const Song *const queued_song = GetQueuedSong(); const Song *const queued_song = GetQueuedSong();
@ -161,34 +161,34 @@ playlist::SwapPositions(player_control &pc, unsigned song1, unsigned song2)
UpdateQueuedSong(pc, queued_song); UpdateQueuedSong(pc, queued_song);
OnModified(); OnModified();
return PLAYLIST_RESULT_SUCCESS; return PlaylistResult::SUCCESS;
} }
enum playlist_result PlaylistResult
playlist::SwapIds(player_control &pc, unsigned id1, unsigned id2) playlist::SwapIds(player_control &pc, unsigned id1, unsigned id2)
{ {
int song1 = queue.IdToPosition(id1); int song1 = queue.IdToPosition(id1);
int song2 = queue.IdToPosition(id2); int song2 = queue.IdToPosition(id2);
if (song1 < 0 || song2 < 0) if (song1 < 0 || song2 < 0)
return PLAYLIST_RESULT_NO_SUCH_SONG; return PlaylistResult::NO_SUCH_SONG;
return SwapPositions(pc, song1, song2); return SwapPositions(pc, song1, song2);
} }
enum playlist_result PlaylistResult
playlist::SetPriorityRange(player_control &pc, playlist::SetPriorityRange(player_control &pc,
unsigned start, unsigned end, unsigned start, unsigned end,
uint8_t priority) uint8_t priority)
{ {
if (start >= GetLength()) if (start >= GetLength())
return PLAYLIST_RESULT_BAD_RANGE; return PlaylistResult::BAD_RANGE;
if (end > GetLength()) if (end > GetLength())
end = GetLength(); end = GetLength();
if (start >= end) if (start >= end)
return PLAYLIST_RESULT_SUCCESS; return PlaylistResult::SUCCESS;
/* remember "current" and "queued" */ /* remember "current" and "queued" */
@ -207,16 +207,16 @@ playlist::SetPriorityRange(player_control &pc,
UpdateQueuedSong(pc, queued_song); UpdateQueuedSong(pc, queued_song);
OnModified(); OnModified();
return PLAYLIST_RESULT_SUCCESS; return PlaylistResult::SUCCESS;
} }
enum playlist_result PlaylistResult
playlist::SetPriorityId(struct player_control &pc, playlist::SetPriorityId(struct player_control &pc,
unsigned song_id, uint8_t priority) unsigned song_id, uint8_t priority)
{ {
int song_position = queue.IdToPosition(song_id); int song_position = queue.IdToPosition(song_id);
if (song_position < 0) if (song_position < 0)
return PLAYLIST_RESULT_NO_SUCH_SONG; return PlaylistResult::NO_SUCH_SONG;
return SetPriorityRange(pc, song_position, song_position + 1, return SetPriorityRange(pc, song_position, song_position + 1,
priority); priority);
@ -269,11 +269,11 @@ playlist::DeleteInternal(player_control &pc,
current--; current--;
} }
enum playlist_result PlaylistResult
playlist::DeletePosition(struct player_control &pc, unsigned song) playlist::DeletePosition(struct player_control &pc, unsigned song)
{ {
if (song >= queue.GetLength()) if (song >= queue.GetLength())
return PLAYLIST_RESULT_BAD_RANGE; return PlaylistResult::BAD_RANGE;
const Song *queued_song = GetQueuedSong(); const Song *queued_song = GetQueuedSong();
@ -282,20 +282,20 @@ playlist::DeletePosition(struct player_control &pc, unsigned song)
UpdateQueuedSong(pc, queued_song); UpdateQueuedSong(pc, queued_song);
OnModified(); OnModified();
return PLAYLIST_RESULT_SUCCESS; return PlaylistResult::SUCCESS;
} }
enum playlist_result PlaylistResult
playlist::DeleteRange(struct player_control &pc, unsigned start, unsigned end) playlist::DeleteRange(struct player_control &pc, unsigned start, unsigned end)
{ {
if (start >= queue.GetLength()) if (start >= queue.GetLength())
return PLAYLIST_RESULT_BAD_RANGE; return PlaylistResult::BAD_RANGE;
if (end > queue.GetLength()) if (end > queue.GetLength())
end = queue.GetLength(); end = queue.GetLength();
if (start >= end) if (start >= end)
return PLAYLIST_RESULT_SUCCESS; return PlaylistResult::SUCCESS;
const Song *queued_song = GetQueuedSong(); const Song *queued_song = GetQueuedSong();
@ -306,15 +306,15 @@ playlist::DeleteRange(struct player_control &pc, unsigned start, unsigned end)
UpdateQueuedSong(pc, queued_song); UpdateQueuedSong(pc, queued_song);
OnModified(); OnModified();
return PLAYLIST_RESULT_SUCCESS; return PlaylistResult::SUCCESS;
} }
enum playlist_result PlaylistResult
playlist::DeleteId(struct player_control &pc, unsigned id) playlist::DeleteId(struct player_control &pc, unsigned id)
{ {
int song = queue.IdToPosition(id); int song = queue.IdToPosition(id);
if (song < 0) if (song < 0)
return PLAYLIST_RESULT_NO_SUCH_SONG; return PlaylistResult::NO_SUCH_SONG;
return DeletePosition(pc, song); return DeletePosition(pc, song);
} }
@ -328,19 +328,19 @@ playlist::DeleteSong(struct player_control &pc, const struct Song &song)
DeletePosition(pc, i); DeletePosition(pc, i);
} }
enum playlist_result PlaylistResult
playlist::MoveRange(player_control &pc, unsigned start, unsigned end, int to) playlist::MoveRange(player_control &pc, unsigned start, unsigned end, int to)
{ {
if (!queue.IsValidPosition(start) || !queue.IsValidPosition(end - 1)) if (!queue.IsValidPosition(start) || !queue.IsValidPosition(end - 1))
return PLAYLIST_RESULT_BAD_RANGE; return PlaylistResult::BAD_RANGE;
if ((to >= 0 && to + end - start - 1 >= GetLength()) || if ((to >= 0 && to + end - start - 1 >= GetLength()) ||
(to < 0 && unsigned(abs(to)) > GetLength())) (to < 0 && unsigned(abs(to)) > GetLength()))
return PLAYLIST_RESULT_BAD_RANGE; return PlaylistResult::BAD_RANGE;
if ((int)start == to) if ((int)start == to)
/* nothing happens */ /* nothing happens */
return PLAYLIST_RESULT_SUCCESS; return PlaylistResult::SUCCESS;
const Song *const queued_song = GetQueuedSong(); const Song *const queued_song = GetQueuedSong();
@ -353,11 +353,11 @@ playlist::MoveRange(player_control &pc, unsigned start, unsigned end, int to)
if (currentSong < 0) if (currentSong < 0)
/* can't move relative to current song, /* can't move relative to current song,
because there is no current song */ because there is no current song */
return PLAYLIST_RESULT_BAD_RANGE; return PlaylistResult::BAD_RANGE;
if (start <= (unsigned)currentSong && (unsigned)currentSong < end) if (start <= (unsigned)currentSong && (unsigned)currentSong < end)
/* no-op, can't be moved to offset of itself */ /* no-op, can't be moved to offset of itself */
return PLAYLIST_RESULT_SUCCESS; return PlaylistResult::SUCCESS;
to = (currentSong + abs(to)) % GetLength(); to = (currentSong + abs(to)) % GetLength();
if (start < (unsigned)to) if (start < (unsigned)to)
to--; to--;
@ -378,15 +378,15 @@ playlist::MoveRange(player_control &pc, unsigned start, unsigned end, int to)
UpdateQueuedSong(pc, queued_song); UpdateQueuedSong(pc, queued_song);
OnModified(); OnModified();
return PLAYLIST_RESULT_SUCCESS; return PlaylistResult::SUCCESS;
} }
enum playlist_result PlaylistResult
playlist::MoveId(player_control &pc, unsigned id1, int to) playlist::MoveId(player_control &pc, unsigned id1, int to)
{ {
int song = queue.IdToPosition(id1); int song = queue.IdToPosition(id1);
if (song < 0) if (song < 0)
return PLAYLIST_RESULT_NO_SUCH_SONG; return PlaylistResult::NO_SUCH_SONG;
return MoveRange(pc, song, song + 1, to); return MoveRange(pc, song, song + 1, to);
} }

View File

@ -22,18 +22,18 @@
class Domain; class Domain;
enum playlist_result { enum class PlaylistResult {
PLAYLIST_RESULT_SUCCESS, SUCCESS,
PLAYLIST_RESULT_ERRNO, ERRNO,
PLAYLIST_RESULT_DENIED, DENIED,
PLAYLIST_RESULT_NO_SUCH_SONG, NO_SUCH_SONG,
PLAYLIST_RESULT_NO_SUCH_LIST, NO_SUCH_LIST,
PLAYLIST_RESULT_LIST_EXISTS, LIST_EXISTS,
PLAYLIST_RESULT_BAD_NAME, BAD_NAME,
PLAYLIST_RESULT_BAD_RANGE, BAD_RANGE,
PLAYLIST_RESULT_NOT_PLAYING, NOT_PLAYING,
PLAYLIST_RESULT_TOO_LARGE, TOO_LARGE,
PLAYLIST_RESULT_DISABLED, DISABLED,
}; };
extern const Domain playlist_domain; extern const Domain playlist_domain;

View File

@ -90,7 +90,7 @@ spl_map(Error &error)
{ {
const AllocatedPath &path_fs = map_spl_path(); const AllocatedPath &path_fs = map_spl_path();
if (path_fs.IsNull()) if (path_fs.IsNull())
error.Set(playlist_domain, PLAYLIST_RESULT_DISABLED, error.Set(playlist_domain, int(PlaylistResult::DISABLED),
"Stored playlists are disabled"); "Stored playlists are disabled");
return path_fs; return path_fs;
} }
@ -99,7 +99,7 @@ static bool
spl_check_name(const char *name_utf8, Error &error) spl_check_name(const char *name_utf8, Error &error)
{ {
if (!spl_valid_name(name_utf8)) { if (!spl_valid_name(name_utf8)) {
error.Set(playlist_domain, PLAYLIST_RESULT_BAD_NAME, error.Set(playlist_domain, int(PlaylistResult::BAD_NAME),
"Bad playlist name"); "Bad playlist name");
return false; return false;
} }
@ -115,7 +115,7 @@ spl_map_to_fs(const char *name_utf8, Error &error)
auto path_fs = map_spl_utf8_to_fs(name_utf8); auto path_fs = map_spl_utf8_to_fs(name_utf8);
if (path_fs.IsNull()) if (path_fs.IsNull())
error.Set(playlist_domain, PLAYLIST_RESULT_BAD_NAME, error.Set(playlist_domain, int(PlaylistResult::BAD_NAME),
"Bad playlist name"); "Bad playlist name");
return path_fs; return path_fs;
@ -129,7 +129,7 @@ playlist_errno(Error &error)
{ {
switch (errno) { switch (errno) {
case ENOENT: case ENOENT:
error.Set(playlist_domain, PLAYLIST_RESULT_NO_SUCH_LIST, error.Set(playlist_domain, int(PlaylistResult::NO_SUCH_LIST),
"No such playlist"); "No such playlist");
break; break;
@ -287,7 +287,7 @@ spl_move_index(const char *utf8path, unsigned src, unsigned dest,
return false; return false;
if (src >= contents.size() || dest >= contents.size()) { if (src >= contents.size() || dest >= contents.size()) {
error.Set(playlist_domain, PLAYLIST_RESULT_BAD_RANGE, error.Set(playlist_domain, int(PlaylistResult::BAD_RANGE),
"Bad range"); "Bad range");
return false; return false;
} }
@ -351,7 +351,7 @@ spl_remove_index(const char *utf8path, unsigned pos, Error &error)
return false; return false;
if (pos >= contents.size()) { if (pos >= contents.size()) {
error.Set(playlist_domain, PLAYLIST_RESULT_BAD_RANGE, error.Set(playlist_domain, int(PlaylistResult::BAD_RANGE),
"Bad range"); "Bad range");
return false; return false;
} }
@ -389,7 +389,7 @@ spl_append_song(const char *utf8path, const Song &song, Error &error)
if (st.st_size / off_t(MPD_PATH_MAX + 1) >= (off_t)playlist_max_length) { if (st.st_size / off_t(MPD_PATH_MAX + 1) >= (off_t)playlist_max_length) {
fclose(file); fclose(file);
error.Set(playlist_domain, PLAYLIST_RESULT_TOO_LARGE, error.Set(playlist_domain, int(PlaylistResult::TOO_LARGE),
"Stored playlist is too large"); "Stored playlist is too large");
return false; return false;
} }
@ -430,13 +430,13 @@ spl_rename_internal(Path from_path_fs, Path to_path_fs,
Error &error) Error &error)
{ {
if (!FileExists(from_path_fs)) { if (!FileExists(from_path_fs)) {
error.Set(playlist_domain, PLAYLIST_RESULT_NO_SUCH_LIST, error.Set(playlist_domain, int(PlaylistResult::NO_SUCH_LIST),
"No such playlist"); "No such playlist");
return false; return false;
} }
if (FileExists(to_path_fs)) { if (FileExists(to_path_fs)) {
error.Set(playlist_domain, PLAYLIST_RESULT_LIST_EXISTS, error.Set(playlist_domain, int(PlaylistResult::LIST_EXISTS),
"Playlist exists already"); "Playlist exists already");
return false; return false;
} }

View File

@ -30,13 +30,13 @@
#include <glib.h> #include <glib.h>
enum playlist_result PlaylistResult
playlist_load_into_queue(const char *uri, SongEnumerator &e, playlist_load_into_queue(const char *uri, SongEnumerator &e,
unsigned start_index, unsigned end_index, unsigned start_index, unsigned end_index,
playlist &dest, player_control &pc, playlist &dest, player_control &pc,
bool secure) bool secure)
{ {
enum playlist_result result; PlaylistResult result;
Song *song; Song *song;
char *base_uri = uri != nullptr ? g_path_get_dirname(uri) : nullptr; char *base_uri = uri != nullptr ? g_path_get_dirname(uri) : nullptr;
@ -55,7 +55,7 @@ playlist_load_into_queue(const char *uri, SongEnumerator &e,
result = dest.AppendSong(pc, song); result = dest.AppendSong(pc, song);
song->Free(); song->Free();
if (result != PLAYLIST_RESULT_SUCCESS) { if (result != PlaylistResult::SUCCESS) {
g_free(base_uri); g_free(base_uri);
return result; return result;
} }
@ -63,10 +63,10 @@ playlist_load_into_queue(const char *uri, SongEnumerator &e,
g_free(base_uri); g_free(base_uri);
return PLAYLIST_RESULT_SUCCESS; return PlaylistResult::SUCCESS;
} }
enum playlist_result PlaylistResult
playlist_open_into_queue(const char *uri, playlist_open_into_queue(const char *uri,
unsigned start_index, unsigned end_index, unsigned start_index, unsigned end_index,
playlist &dest, player_control &pc, playlist &dest, player_control &pc,
@ -78,9 +78,9 @@ playlist_open_into_queue(const char *uri,
struct input_stream *is; struct input_stream *is;
auto playlist = playlist_open_any(uri, mutex, cond, &is); auto playlist = playlist_open_any(uri, mutex, cond, &is);
if (playlist == nullptr) if (playlist == nullptr)
return PLAYLIST_RESULT_NO_SUCH_LIST; return PlaylistResult::NO_SUCH_LIST;
enum playlist_result result = PlaylistResult result =
playlist_load_into_queue(uri, *playlist, playlist_load_into_queue(uri, *playlist,
start_index, end_index, start_index, end_index,
dest, pc, secure); dest, pc, secure);

View File

@ -39,7 +39,7 @@ struct player_control;
* @param start_index the index of the first song * @param start_index the index of the first song
* @param end_index the index of the last song (excluding) * @param end_index the index of the last song (excluding)
*/ */
enum playlist_result PlaylistResult
playlist_load_into_queue(const char *uri, SongEnumerator &e, playlist_load_into_queue(const char *uri, SongEnumerator &e,
unsigned start_index, unsigned end_index, unsigned start_index, unsigned end_index,
playlist &dest, player_control &pc, playlist &dest, player_control &pc,
@ -49,7 +49,7 @@ playlist_load_into_queue(const char *uri, SongEnumerator &e,
* Opens a playlist with a playlist plugin and append to the specified * Opens a playlist with a playlist plugin and append to the specified
* play queue. * play queue.
*/ */
enum playlist_result PlaylistResult
playlist_open_into_queue(const char *uri, playlist_open_into_queue(const char *uri,
unsigned start_index, unsigned end_index, unsigned start_index, unsigned end_index,
playlist &dest, player_control &pc, playlist &dest, player_control &pc,

View File

@ -64,26 +64,26 @@ playlist_print_uri(FILE *file, const char *uri)
fprintf(file, "%s\n", path.c_str()); fprintf(file, "%s\n", path.c_str());
} }
enum playlist_result PlaylistResult
spl_save_queue(const char *name_utf8, const queue &queue) spl_save_queue(const char *name_utf8, const queue &queue)
{ {
if (map_spl_path().IsNull()) if (map_spl_path().IsNull())
return PLAYLIST_RESULT_DISABLED; return PlaylistResult::DISABLED;
if (!spl_valid_name(name_utf8)) if (!spl_valid_name(name_utf8))
return PLAYLIST_RESULT_BAD_NAME; return PlaylistResult::BAD_NAME;
const auto path_fs = map_spl_utf8_to_fs(name_utf8); const auto path_fs = map_spl_utf8_to_fs(name_utf8);
if (path_fs.IsNull()) if (path_fs.IsNull())
return PLAYLIST_RESULT_BAD_NAME; return PlaylistResult::BAD_NAME;
if (FileExists(path_fs)) if (FileExists(path_fs))
return PLAYLIST_RESULT_LIST_EXISTS; return PlaylistResult::LIST_EXISTS;
FILE *file = FOpen(path_fs, FOpenMode::WriteText); FILE *file = FOpen(path_fs, FOpenMode::WriteText);
if (file == nullptr) if (file == nullptr)
return PLAYLIST_RESULT_ERRNO; return PlaylistResult::ERRNO;
for (unsigned i = 0; i < queue.GetLength(); i++) for (unsigned i = 0; i < queue.GetLength(); i++)
playlist_print_song(file, queue.Get(i)); playlist_print_song(file, queue.Get(i));
@ -91,10 +91,10 @@ spl_save_queue(const char *name_utf8, const queue &queue)
fclose(file); fclose(file);
idle_add(IDLE_STORED_PLAYLIST); idle_add(IDLE_STORED_PLAYLIST);
return PLAYLIST_RESULT_SUCCESS; return PlaylistResult::SUCCESS;
} }
enum playlist_result PlaylistResult
spl_save_playlist(const char *name_utf8, const playlist &playlist) spl_save_playlist(const char *name_utf8, const playlist &playlist)
{ {
return spl_save_queue(name_utf8, playlist.queue); return spl_save_queue(name_utf8, playlist.queue);
@ -119,13 +119,13 @@ playlist_load_spl(struct playlist &playlist, player_control &pc,
if (memcmp(uri_utf8.c_str(), "file:///", 8) == 0) { if (memcmp(uri_utf8.c_str(), "file:///", 8) == 0) {
const char *path_utf8 = uri_utf8.c_str() + 7; const char *path_utf8 = uri_utf8.c_str() + 7;
if (playlist.AppendFile(pc, path_utf8) != PLAYLIST_RESULT_SUCCESS) if (playlist.AppendFile(pc, path_utf8) != PlaylistResult::SUCCESS)
FormatError(playlist_domain, FormatError(playlist_domain,
"can't add file \"%s\"", path_utf8); "can't add file \"%s\"", path_utf8);
continue; continue;
} }
if ((playlist.AppendURI(pc, uri_utf8.c_str())) != PLAYLIST_RESULT_SUCCESS) { if ((playlist.AppendURI(pc, uri_utf8.c_str())) != PlaylistResult::SUCCESS) {
/* for windows compatibility, convert slashes */ /* for windows compatibility, convert slashes */
char *temp2 = g_strdup(uri_utf8.c_str()); char *temp2 = g_strdup(uri_utf8.c_str());
char *p = temp2; char *p = temp2;
@ -135,7 +135,7 @@ playlist_load_spl(struct playlist &playlist, player_control &pc,
p++; p++;
} }
if (playlist.AppendURI(pc, temp2) != PLAYLIST_RESULT_SUCCESS) if (playlist.AppendURI(pc, temp2) != PlaylistResult::SUCCESS)
FormatError(playlist_domain, FormatError(playlist_domain,
"can't add file \"%s\"", temp2); "can't add file \"%s\"", temp2);

View File

@ -39,13 +39,13 @@ playlist_print_uri(FILE *fp, const char *uri);
/** /**
* Saves a queue object into a stored playlist file. * Saves a queue object into a stored playlist file.
*/ */
enum playlist_result PlaylistResult
spl_save_queue(const char *name_utf8, const queue &queue); spl_save_queue(const char *name_utf8, const queue &queue);
/** /**
* Saves a playlist object into a stored playlist file. * Saves a playlist object into a stored playlist file.
*/ */
enum playlist_result PlaylistResult
spl_save_playlist(const char *name_utf8, const playlist &playlist); spl_save_playlist(const char *name_utf8, const playlist &playlist);
/** /**

View File

@ -43,7 +43,7 @@ enum command_return
handle_add(Client &client, gcc_unused int argc, char *argv[]) handle_add(Client &client, gcc_unused int argc, char *argv[])
{ {
char *uri = argv[1]; char *uri = argv[1];
enum playlist_result result; PlaylistResult result;
if (memcmp(uri, "file:///", 8) == 0) { if (memcmp(uri, "file:///", 8) == 0) {
const char *path_utf8 = uri + 7; const char *path_utf8 = uri + 7;
@ -86,7 +86,7 @@ handle_addid(Client &client, int argc, char *argv[])
{ {
char *uri = argv[1]; char *uri = argv[1];
unsigned added_id; unsigned added_id;
enum playlist_result result; PlaylistResult result;
if (memcmp(uri, "file:///", 8) == 0) { if (memcmp(uri, "file:///", 8) == 0) {
const char *path_utf8 = uri + 7; const char *path_utf8 = uri + 7;
@ -113,7 +113,7 @@ handle_addid(Client &client, int argc, char *argv[])
result = client.partition.AppendURI(uri, &added_id); result = client.partition.AppendURI(uri, &added_id);
} }
if (result != PLAYLIST_RESULT_SUCCESS) if (result != PlaylistResult::SUCCESS)
return print_playlist_result(client, result); return print_playlist_result(client, result);
if (argc == 3) { if (argc == 3) {
@ -121,7 +121,7 @@ handle_addid(Client &client, int argc, char *argv[])
if (!check_unsigned(client, &to, argv[2])) if (!check_unsigned(client, &to, argv[2]))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
result = client.partition.MoveId(added_id, to); result = client.partition.MoveId(added_id, to);
if (result != PLAYLIST_RESULT_SUCCESS) { if (result != PlaylistResult::SUCCESS) {
enum command_return ret = enum command_return ret =
print_playlist_result(client, result); print_playlist_result(client, result);
client.partition.DeleteId(added_id); client.partition.DeleteId(added_id);
@ -141,7 +141,7 @@ handle_delete(Client &client, gcc_unused int argc, char *argv[])
if (!check_range(client, &start, &end, argv[1])) if (!check_range(client, &start, &end, argv[1]))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
enum playlist_result result = client.partition.DeleteRange(start, end); PlaylistResult result = client.partition.DeleteRange(start, end);
return print_playlist_result(client, result); return print_playlist_result(client, result);
} }
@ -153,7 +153,7 @@ handle_deleteid(Client &client, gcc_unused int argc, char *argv[])
if (!check_unsigned(client, &id, argv[1])) if (!check_unsigned(client, &id, argv[1]))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
enum playlist_result result = client.partition.DeleteId(id); PlaylistResult result = client.partition.DeleteId(id);
return print_playlist_result(client, result); return print_playlist_result(client, result);
} }
@ -221,7 +221,7 @@ handle_playlistinfo(Client &client, int argc, char *argv[])
ret = playlist_print_info(client, client.playlist, start, end); ret = playlist_print_info(client, client.playlist, start, end);
if (!ret) if (!ret)
return print_playlist_result(client, return print_playlist_result(client,
PLAYLIST_RESULT_BAD_RANGE); PlaylistResult::BAD_RANGE);
return COMMAND_RETURN_OK; return COMMAND_RETURN_OK;
} }
@ -237,7 +237,7 @@ handle_playlistid(Client &client, int argc, char *argv[])
bool ret = playlist_print_id(client, client.playlist, id); bool ret = playlist_print_id(client, client.playlist, id);
if (!ret) if (!ret)
return print_playlist_result(client, return print_playlist_result(client,
PLAYLIST_RESULT_NO_SUCH_SONG); PlaylistResult::NO_SUCH_SONG);
} else { } else {
playlist_print_info(client, client.playlist, playlist_print_info(client, client.playlist,
0, std::numeric_limits<unsigned>::max()); 0, std::numeric_limits<unsigned>::max());
@ -292,11 +292,11 @@ handle_prio(Client &client, int argc, char *argv[])
argv[i])) argv[i]))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
enum playlist_result result = PlaylistResult result =
client.partition.SetPriorityRange(start_position, client.partition.SetPriorityRange(start_position,
end_position, end_position,
priority); priority);
if (result != PLAYLIST_RESULT_SUCCESS) if (result != PlaylistResult::SUCCESS)
return print_playlist_result(client, result); return print_playlist_result(client, result);
} }
@ -322,9 +322,9 @@ handle_prioid(Client &client, int argc, char *argv[])
if (!check_unsigned(client, &song_id, argv[i])) if (!check_unsigned(client, &song_id, argv[i]))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
enum playlist_result result = PlaylistResult result =
client.partition.SetPriorityId(song_id, priority); client.partition.SetPriorityId(song_id, priority);
if (result != PLAYLIST_RESULT_SUCCESS) if (result != PlaylistResult::SUCCESS)
return print_playlist_result(client, result); return print_playlist_result(client, result);
} }
@ -342,7 +342,7 @@ handle_move(Client &client, gcc_unused int argc, char *argv[])
if (!check_int(client, &to, argv[2])) if (!check_int(client, &to, argv[2]))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
enum playlist_result result = PlaylistResult result =
client.partition.MoveRange(start, end, to); client.partition.MoveRange(start, end, to);
return print_playlist_result(client, result); return print_playlist_result(client, result);
} }
@ -357,7 +357,7 @@ handle_moveid(Client &client, gcc_unused int argc, char *argv[])
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
if (!check_int(client, &to, argv[2])) if (!check_int(client, &to, argv[2]))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
enum playlist_result result = client.partition.MoveId(id, to); PlaylistResult result = client.partition.MoveId(id, to);
return print_playlist_result(client, result); return print_playlist_result(client, result);
} }
@ -371,7 +371,7 @@ handle_swap(Client &client, gcc_unused int argc, char *argv[])
if (!check_unsigned(client, &song2, argv[2])) if (!check_unsigned(client, &song2, argv[2]))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
enum playlist_result result = PlaylistResult result =
client.partition.SwapPositions(song1, song2); client.partition.SwapPositions(song1, song2);
return print_playlist_result(client, result); return print_playlist_result(client, result);
} }
@ -386,6 +386,6 @@ handle_swapid(Client &client, gcc_unused int argc, char *argv[])
if (!check_unsigned(client, &id2, argv[2])) if (!check_unsigned(client, &id2, argv[2]))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
enum playlist_result result = client.partition.SwapIds(id1, id2); PlaylistResult result = client.partition.SwapIds(id1, id2);
return print_playlist_result(client, result); return print_playlist_result(client, result);
} }