diff --git a/src/CommandError.cxx b/src/CommandError.cxx index d606f5df9..f22ad10de 100644 --- a/src/CommandError.cxx +++ b/src/CommandError.cxx @@ -30,55 +30,55 @@ #include enum command_return -print_playlist_result(Client &client, enum playlist_result result) +print_playlist_result(Client &client, PlaylistResult result) { switch (result) { - case PLAYLIST_RESULT_SUCCESS: + case PlaylistResult::SUCCESS: return COMMAND_RETURN_OK; - case PLAYLIST_RESULT_ERRNO: + case PlaylistResult::ERRNO: command_error(client, ACK_ERROR_SYSTEM, "%s", g_strerror(errno)); return COMMAND_RETURN_ERROR; - case PLAYLIST_RESULT_DENIED: + case PlaylistResult::DENIED: command_error(client, ACK_ERROR_PERMISSION, "Access denied"); 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"); 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"); return COMMAND_RETURN_ERROR; - case PLAYLIST_RESULT_LIST_EXISTS: + case PlaylistResult::LIST_EXISTS: command_error(client, ACK_ERROR_EXIST, "Playlist already exists"); return COMMAND_RETURN_ERROR; - case PLAYLIST_RESULT_BAD_NAME: + case PlaylistResult::BAD_NAME: command_error(client, ACK_ERROR_ARG, "playlist name is invalid: " "playlist names may not contain slashes," " newlines or carriage returns"); return COMMAND_RETURN_ERROR; - case PLAYLIST_RESULT_BAD_RANGE: + case PlaylistResult::BAD_RANGE: command_error(client, ACK_ERROR_ARG, "Bad song index"); return COMMAND_RETURN_ERROR; - case PLAYLIST_RESULT_NOT_PLAYING: + case PlaylistResult::NOT_PLAYING: command_error(client, ACK_ERROR_PLAYER_SYNC, "Not playing"); return COMMAND_RETURN_ERROR; - case PLAYLIST_RESULT_TOO_LARGE: + case PlaylistResult::TOO_LARGE: command_error(client, ACK_ERROR_PLAYLIST_MAX, "playlist is at the max size"); return COMMAND_RETURN_ERROR; - case PLAYLIST_RESULT_DISABLED: + case PlaylistResult::DISABLED: command_error(client, ACK_ERROR_UNKNOWN, "stored playlist support is disabled"); return COMMAND_RETURN_ERROR; @@ -97,7 +97,7 @@ print_error(Client &client, const Error &error) if (error.IsDomain(playlist_domain)) { return print_playlist_result(client, - playlist_result(error.GetCode())); + PlaylistResult(error.GetCode())); } else if (error.IsDomain(ack_domain)) { command_error(client, (ack)error.GetCode(), "%s", error.GetMessage()); diff --git a/src/CommandError.hxx b/src/CommandError.hxx index 99de5c6b5..507250500 100644 --- a/src/CommandError.hxx +++ b/src/CommandError.hxx @@ -27,7 +27,7 @@ class Client; class Error; 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. diff --git a/src/DatabaseQueue.cxx b/src/DatabaseQueue.cxx index 79ff004a7..e277c0fca 100644 --- a/src/DatabaseQueue.cxx +++ b/src/DatabaseQueue.cxx @@ -30,10 +30,10 @@ static bool AddToQueue(Partition &partition, Song &song, Error &error) { - enum playlist_result result = + PlaylistResult result = partition.playlist.AppendSong(partition.pc, &song, NULL); - if (result != PLAYLIST_RESULT_SUCCESS) { - error.Set(playlist_domain, result, "Playlist error"); + if (result != PlaylistResult::SUCCESS) { + error.Set(playlist_domain, int(result), "Playlist error"); return false; } diff --git a/src/Partition.hxx b/src/Partition.hxx index 0d5017985..f6315eade 100644 --- a/src/Partition.hxx +++ b/src/Partition.hxx @@ -48,21 +48,21 @@ struct Partition { playlist.Clear(pc); } - enum playlist_result AppendFile(const char *path_utf8, - unsigned *added_id=nullptr) { + PlaylistResult AppendFile(const char *path_utf8, + unsigned *added_id=nullptr) { return playlist.AppendFile(pc, path_utf8, added_id); } - enum playlist_result AppendURI(const char *uri_utf8, - unsigned *added_id=nullptr) { + PlaylistResult AppendURI(const char *uri_utf8, + unsigned *added_id=nullptr) { return playlist.AppendURI(pc, uri_utf8, added_id); } - enum playlist_result DeletePosition(unsigned position) { + PlaylistResult DeletePosition(unsigned position) { return playlist.DeletePosition(pc, position); } - enum playlist_result DeleteId(unsigned id) { + PlaylistResult DeleteId(unsigned id) { return playlist.DeleteId(pc, id); } @@ -72,7 +72,7 @@ struct Partition { * @param start the position of the first 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); } @@ -84,32 +84,32 @@ struct Partition { 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); } - enum playlist_result MoveId(unsigned id, int to) { + PlaylistResult MoveId(unsigned id, int 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); } - enum playlist_result SwapIds(unsigned id1, unsigned id2) { + PlaylistResult SwapIds(unsigned id1, unsigned id2) { return playlist.SwapIds(pc, id1, id2); } - enum playlist_result SetPriorityRange(unsigned start_position, - unsigned end_position, - uint8_t priority) { + PlaylistResult SetPriorityRange(unsigned start_position, + unsigned end_position, + uint8_t priority) { return playlist.SetPriorityRange(pc, start_position, end_position, priority); } - enum playlist_result SetPriorityId(unsigned song_id, - uint8_t priority) { + PlaylistResult SetPriorityId(unsigned song_id, + uint8_t priority) { return playlist.SetPriorityId(pc, song_id, priority); } @@ -117,11 +117,11 @@ struct Partition { playlist.Stop(pc); } - enum playlist_result PlayPosition(int position) { + PlaylistResult PlayPosition(int position) { return playlist.PlayPosition(pc, position); } - enum playlist_result PlayId(int id) { + PlaylistResult PlayId(int id) { return playlist.PlayId(pc, id); } @@ -133,16 +133,16 @@ struct Partition { return playlist.PlayPrevious(pc); } - enum playlist_result SeekSongPosition(unsigned song_position, - float seek_time) { + PlaylistResult SeekSongPosition(unsigned song_position, + float 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); } - enum playlist_result SeekCurrent(float seek_time, bool relative) { + PlaylistResult SeekCurrent(float seek_time, bool relative) { return playlist.SeekCurrent(pc, seek_time, relative); } diff --git a/src/PlayerCommands.cxx b/src/PlayerCommands.cxx index 26503ee52..9bc162ea7 100644 --- a/src/PlayerCommands.cxx +++ b/src/PlayerCommands.cxx @@ -59,7 +59,7 @@ handle_play(Client &client, int argc, char *argv[]) if (argc == 2 && !check_int(client, &song, argv[1])) return COMMAND_RETURN_ERROR; - enum playlist_result result = client.partition.PlayPosition(song); + PlaylistResult result = client.partition.PlayPosition(song); 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])) return COMMAND_RETURN_ERROR; - enum playlist_result result = client.partition.PlayId(id); + PlaylistResult result = client.partition.PlayId(id); 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])) return COMMAND_RETURN_ERROR; - enum playlist_result result = + PlaylistResult result = client.partition.SeekSongPosition(song, seek_time); 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])) return COMMAND_RETURN_ERROR; - enum playlist_result result = + PlaylistResult result = client.partition.SeekSongId(id, seek_time); 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)) return COMMAND_RETURN_ERROR; - enum playlist_result result = + PlaylistResult result = client.partition.SeekCurrent(seek_time, relative); return print_playlist_result(client, result); } diff --git a/src/Playlist.hxx b/src/Playlist.hxx index 82cac37c5..866fd9a2d 100644 --- a/src/Playlist.hxx +++ b/src/Playlist.hxx @@ -132,9 +132,9 @@ public: void FullIncrementVersions(); - enum playlist_result AppendSong(player_control &pc, - Song *song, - unsigned *added_id=nullptr); + PlaylistResult AppendSong(player_control &pc, + Song *song, + unsigned *added_id=nullptr); /** * Appends a local file (outside the music database) to the @@ -142,28 +142,28 @@ public: * * Note: the caller is responsible for checking permissions. */ - enum playlist_result AppendFile(player_control &pc, - const char *path_utf8, - unsigned *added_id=nullptr); + PlaylistResult AppendFile(player_control &pc, + const char *path_utf8, + unsigned *added_id=nullptr); - enum playlist_result AppendURI(player_control &pc, - const char *uri_utf8, - unsigned *added_id=nullptr); + PlaylistResult AppendURI(player_control &pc, + const char *uri_utf8, + unsigned *added_id=nullptr); protected: void DeleteInternal(player_control &pc, unsigned song, const Song **queued_p); public: - enum playlist_result DeletePosition(player_control &pc, - unsigned position); + PlaylistResult DeletePosition(player_control &pc, + unsigned position); - enum playlist_result DeleteOrder(player_control &pc, - unsigned order) { + PlaylistResult DeleteOrder(player_control &pc, + unsigned 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. @@ -171,50 +171,50 @@ public: * @param start the position of the first song to delete * @param end the position after the last song to delete */ - enum playlist_result DeleteRange(player_control &pc, - unsigned start, unsigned end); + PlaylistResult DeleteRange(player_control &pc, + unsigned start, unsigned end); void DeleteSong(player_control &pc, const Song &song); void Shuffle(player_control &pc, unsigned start, unsigned end); - enum playlist_result MoveRange(player_control &pc, - unsigned start, unsigned end, int to); + PlaylistResult MoveRange(player_control &pc, + 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, - unsigned song1, unsigned song2); + PlaylistResult SwapPositions(player_control &pc, + unsigned song1, unsigned song2); - enum playlist_result SwapIds(player_control &pc, - unsigned id1, unsigned id2); + PlaylistResult SwapIds(player_control &pc, + unsigned id1, unsigned id2); - enum playlist_result SetPriorityRange(player_control &pc, - unsigned start_position, - unsigned end_position, - uint8_t priority); + PlaylistResult SetPriorityRange(player_control &pc, + unsigned start_position, + unsigned end_position, + uint8_t priority); - enum playlist_result SetPriorityId(player_control &pc, - unsigned song_id, uint8_t priority); + PlaylistResult SetPriorityId(player_control &pc, + unsigned song_id, uint8_t priority); 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); - enum playlist_result PlayId(player_control &pc, int id); + PlaylistResult PlayId(player_control &pc, int id); void PlayNext(player_control &pc); void PlayPrevious(player_control &pc); - enum playlist_result SeekSongPosition(player_control &pc, - unsigned song_position, - float seek_time); + PlaylistResult SeekSongPosition(player_control &pc, + unsigned song_position, + float seek_time); - enum playlist_result SeekSongId(player_control &pc, - unsigned song_id, float seek_time); + PlaylistResult SeekSongId(player_control &pc, + unsigned song_id, float seek_time); /** * 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 * current position */ - enum playlist_result SeekCurrent(player_control &pc, - float seek_time, bool relative); + PlaylistResult SeekCurrent(player_control &pc, + float seek_time, bool relative); bool GetRepeat() const { return queue.repeat; diff --git a/src/PlaylistCommands.cxx b/src/PlaylistCommands.cxx index 4eaaf8145..02c21e01f 100644 --- a/src/PlaylistCommands.cxx +++ b/src/PlaylistCommands.cxx @@ -52,9 +52,7 @@ print_spl_list(Client &client, const PlaylistVector &list) enum command_return handle_save(Client &client, gcc_unused int argc, char *argv[]) { - enum playlist_result result; - - result = spl_save_playlist(argv[1], client.playlist); + PlaylistResult result = spl_save_playlist(argv[1], client.playlist); 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])) return COMMAND_RETURN_ERROR; - enum playlist_result result; - - result = playlist_open_into_queue(argv[1], - start_index, end_index, - client.playlist, - client.player_control, true); - if (result != PLAYLIST_RESULT_NO_SUCH_LIST) + const PlaylistResult result = + playlist_open_into_queue(argv[1], + start_index, end_index, + client.playlist, + client.player_control, true); + if (result != PlaylistResult::NO_SUCH_LIST) return print_playlist_result(client, result); Error error; @@ -85,12 +82,12 @@ handle_load(Client &client, int argc, char *argv[]) return COMMAND_RETURN_OK; 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 client wants to load a playlist file from the music directory; patch the Error object to show "no such playlist" instead */ - Error error2(playlist_domain, PLAYLIST_RESULT_NO_SUCH_LIST, + Error error2(playlist_domain, int(PlaylistResult::NO_SUCH_LIST), error.GetMessage()); error = std::move(error2); } diff --git a/src/PlaylistControl.cxx b/src/PlaylistControl.cxx index 896dbaaa8..97db2a184 100644 --- a/src/PlaylistControl.cxx +++ b/src/PlaylistControl.cxx @@ -56,7 +56,7 @@ playlist::Stop(player_control &pc) } } -enum playlist_result +PlaylistResult playlist::PlayPosition(player_control &pc, int song) { pc.ClearError(); @@ -66,13 +66,13 @@ playlist::PlayPosition(player_control &pc, int song) /* play any song ("current" song, or the first song */ if (queue.IsEmpty()) - return PLAYLIST_RESULT_SUCCESS; + return PlaylistResult::SUCCESS; if (playing) { /* already playing: unpause playback, just in case it was paused, and return */ pc.SetPause(false); - return PLAYLIST_RESULT_SUCCESS; + return PlaylistResult::SUCCESS; } /* select a song: "current" song, or the first one */ @@ -80,7 +80,7 @@ playlist::PlayPosition(player_control &pc, int song) ? current : 0; } else if (!queue.IsValidPosition(song)) - return PLAYLIST_RESULT_BAD_RANGE; + return PlaylistResult::BAD_RANGE; if (queue.random) { if (song >= 0) @@ -103,10 +103,10 @@ playlist::PlayPosition(player_control &pc, int song) error_count = 0; PlayOrder(pc, i); - return PLAYLIST_RESULT_SUCCESS; + return PlaylistResult::SUCCESS; } -enum playlist_result +PlaylistResult playlist::PlayId(player_control &pc, int id) { if (id == -1) @@ -114,7 +114,7 @@ playlist::PlayId(player_control &pc, int id) int song = queue.IdToPosition(id); if (song < 0) - return PLAYLIST_RESULT_NO_SUCH_SONG; + return PlaylistResult::NO_SUCH_SONG; return PlayPosition(pc, song); } @@ -189,11 +189,11 @@ playlist::PlayPrevious(player_control &pc) PlayOrder(pc, order); } -enum playlist_result +PlaylistResult playlist::SeekSongPosition(player_control &pc, unsigned song, float seek_time) { if (!queue.IsValidPosition(song)) - return PLAYLIST_RESULT_BAD_RANGE; + return PlaylistResult::BAD_RANGE; 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)) { UpdateQueuedSong(pc, queued_song); - return PLAYLIST_RESULT_NOT_PLAYING; + return PlaylistResult::NOT_PLAYING; } queued = -1; UpdateQueuedSong(pc, nullptr); - return PLAYLIST_RESULT_SUCCESS; + return PlaylistResult::SUCCESS; } -enum playlist_result +PlaylistResult playlist::SeekSongId(player_control &pc, unsigned id, float seek_time) { int song = queue.IdToPosition(id); if (song < 0) - return PLAYLIST_RESULT_NO_SUCH_SONG; + return PlaylistResult::NO_SUCH_SONG; return SeekSongPosition(pc, song, seek_time); } -enum playlist_result +PlaylistResult playlist::SeekCurrent(player_control &pc, float seek_time, bool relative) { if (!playing) - return PLAYLIST_RESULT_NOT_PLAYING; + return PlaylistResult::NOT_PLAYING; if (relative) { const auto status = pc.GetStatus(); if (status.state != PlayerState::PLAY && status.state != PlayerState::PAUSE) - return PLAYLIST_RESULT_NOT_PLAYING; + return PlaylistResult::NOT_PLAYING; seek_time += (int)status.elapsed_time; } diff --git a/src/PlaylistEdit.cxx b/src/PlaylistEdit.cxx index 30a7bdca3..d4515d647 100644 --- a/src/PlaylistEdit.cxx +++ b/src/PlaylistEdit.cxx @@ -56,27 +56,27 @@ playlist::Clear(player_control &pc) OnModified(); } -enum playlist_result +PlaylistResult playlist::AppendFile(struct player_control &pc, const char *path_utf8, unsigned *added_id) { Song *song = Song::LoadFile(path_utf8, nullptr); if (song == nullptr) - return PLAYLIST_RESULT_NO_SUCH_SONG; + return PlaylistResult::NO_SUCH_SONG; const auto result = AppendSong(pc, song, added_id); song->Free(); return result; } -enum playlist_result +PlaylistResult playlist::AppendSong(struct player_control &pc, Song *song, unsigned *added_id) { unsigned id; if (queue.IsFull()) - return PLAYLIST_RESULT_TOO_LARGE; + return PlaylistResult::TOO_LARGE; const Song *const queued_song = GetQueuedSong(); @@ -101,10 +101,10 @@ playlist::AppendSong(struct player_control &pc, if (added_id) *added_id = id; - return PLAYLIST_RESULT_SUCCESS; + return PlaylistResult::SUCCESS; } -enum playlist_result +PlaylistResult playlist::AppendURI(struct player_control &pc, const char *uri, unsigned *added_id) { @@ -117,14 +117,14 @@ playlist::AppendURI(struct player_control &pc, } else { db = GetDatabase(IgnoreError()); if (db == nullptr) - return PLAYLIST_RESULT_NO_SUCH_SONG; + return PlaylistResult::NO_SUCH_SONG; song = db->GetSong(uri, IgnoreError()); 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) db->ReturnSong(song); else @@ -133,11 +133,11 @@ playlist::AppendURI(struct player_control &pc, return result; } -enum playlist_result +PlaylistResult playlist::SwapPositions(player_control &pc, unsigned song1, unsigned song2) { if (!queue.IsValidPosition(song1) || !queue.IsValidPosition(song2)) - return PLAYLIST_RESULT_BAD_RANGE; + return PlaylistResult::BAD_RANGE; const Song *const queued_song = GetQueuedSong(); @@ -161,34 +161,34 @@ playlist::SwapPositions(player_control &pc, unsigned song1, unsigned song2) UpdateQueuedSong(pc, queued_song); OnModified(); - return PLAYLIST_RESULT_SUCCESS; + return PlaylistResult::SUCCESS; } -enum playlist_result +PlaylistResult playlist::SwapIds(player_control &pc, unsigned id1, unsigned id2) { int song1 = queue.IdToPosition(id1); int song2 = queue.IdToPosition(id2); if (song1 < 0 || song2 < 0) - return PLAYLIST_RESULT_NO_SUCH_SONG; + return PlaylistResult::NO_SUCH_SONG; return SwapPositions(pc, song1, song2); } -enum playlist_result +PlaylistResult playlist::SetPriorityRange(player_control &pc, unsigned start, unsigned end, uint8_t priority) { if (start >= GetLength()) - return PLAYLIST_RESULT_BAD_RANGE; + return PlaylistResult::BAD_RANGE; if (end > GetLength()) end = GetLength(); if (start >= end) - return PLAYLIST_RESULT_SUCCESS; + return PlaylistResult::SUCCESS; /* remember "current" and "queued" */ @@ -207,16 +207,16 @@ playlist::SetPriorityRange(player_control &pc, UpdateQueuedSong(pc, queued_song); OnModified(); - return PLAYLIST_RESULT_SUCCESS; + return PlaylistResult::SUCCESS; } -enum playlist_result +PlaylistResult playlist::SetPriorityId(struct player_control &pc, unsigned song_id, uint8_t priority) { int song_position = queue.IdToPosition(song_id); if (song_position < 0) - return PLAYLIST_RESULT_NO_SUCH_SONG; + return PlaylistResult::NO_SUCH_SONG; return SetPriorityRange(pc, song_position, song_position + 1, priority); @@ -269,11 +269,11 @@ playlist::DeleteInternal(player_control &pc, current--; } -enum playlist_result +PlaylistResult playlist::DeletePosition(struct player_control &pc, unsigned song) { if (song >= queue.GetLength()) - return PLAYLIST_RESULT_BAD_RANGE; + return PlaylistResult::BAD_RANGE; const Song *queued_song = GetQueuedSong(); @@ -282,20 +282,20 @@ playlist::DeletePosition(struct player_control &pc, unsigned song) UpdateQueuedSong(pc, queued_song); OnModified(); - return PLAYLIST_RESULT_SUCCESS; + return PlaylistResult::SUCCESS; } -enum playlist_result +PlaylistResult playlist::DeleteRange(struct player_control &pc, unsigned start, unsigned end) { if (start >= queue.GetLength()) - return PLAYLIST_RESULT_BAD_RANGE; + return PlaylistResult::BAD_RANGE; if (end > queue.GetLength()) end = queue.GetLength(); if (start >= end) - return PLAYLIST_RESULT_SUCCESS; + return PlaylistResult::SUCCESS; const Song *queued_song = GetQueuedSong(); @@ -306,15 +306,15 @@ playlist::DeleteRange(struct player_control &pc, unsigned start, unsigned end) UpdateQueuedSong(pc, queued_song); OnModified(); - return PLAYLIST_RESULT_SUCCESS; + return PlaylistResult::SUCCESS; } -enum playlist_result +PlaylistResult playlist::DeleteId(struct player_control &pc, unsigned id) { int song = queue.IdToPosition(id); if (song < 0) - return PLAYLIST_RESULT_NO_SUCH_SONG; + return PlaylistResult::NO_SUCH_SONG; return DeletePosition(pc, song); } @@ -328,19 +328,19 @@ playlist::DeleteSong(struct player_control &pc, const struct Song &song) DeletePosition(pc, i); } -enum playlist_result +PlaylistResult playlist::MoveRange(player_control &pc, unsigned start, unsigned end, int to) { 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()) || (to < 0 && unsigned(abs(to)) > GetLength())) - return PLAYLIST_RESULT_BAD_RANGE; + return PlaylistResult::BAD_RANGE; if ((int)start == to) /* nothing happens */ - return PLAYLIST_RESULT_SUCCESS; + return PlaylistResult::SUCCESS; const Song *const queued_song = GetQueuedSong(); @@ -353,11 +353,11 @@ playlist::MoveRange(player_control &pc, unsigned start, unsigned end, int to) if (currentSong < 0) /* can't move relative to current song, because there is no current song */ - return PLAYLIST_RESULT_BAD_RANGE; + return PlaylistResult::BAD_RANGE; if (start <= (unsigned)currentSong && (unsigned)currentSong < end) /* no-op, can't be moved to offset of itself */ - return PLAYLIST_RESULT_SUCCESS; + return PlaylistResult::SUCCESS; to = (currentSong + abs(to)) % GetLength(); if (start < (unsigned)to) to--; @@ -378,15 +378,15 @@ playlist::MoveRange(player_control &pc, unsigned start, unsigned end, int to) UpdateQueuedSong(pc, queued_song); OnModified(); - return PLAYLIST_RESULT_SUCCESS; + return PlaylistResult::SUCCESS; } -enum playlist_result +PlaylistResult playlist::MoveId(player_control &pc, unsigned id1, int to) { int song = queue.IdToPosition(id1); if (song < 0) - return PLAYLIST_RESULT_NO_SUCH_SONG; + return PlaylistResult::NO_SUCH_SONG; return MoveRange(pc, song, song + 1, to); } diff --git a/src/PlaylistError.hxx b/src/PlaylistError.hxx index 7a3dad749..8ea65ca34 100644 --- a/src/PlaylistError.hxx +++ b/src/PlaylistError.hxx @@ -22,18 +22,18 @@ class Domain; -enum playlist_result { - PLAYLIST_RESULT_SUCCESS, - PLAYLIST_RESULT_ERRNO, - PLAYLIST_RESULT_DENIED, - PLAYLIST_RESULT_NO_SUCH_SONG, - PLAYLIST_RESULT_NO_SUCH_LIST, - PLAYLIST_RESULT_LIST_EXISTS, - PLAYLIST_RESULT_BAD_NAME, - PLAYLIST_RESULT_BAD_RANGE, - PLAYLIST_RESULT_NOT_PLAYING, - PLAYLIST_RESULT_TOO_LARGE, - PLAYLIST_RESULT_DISABLED, +enum class PlaylistResult { + SUCCESS, + ERRNO, + DENIED, + NO_SUCH_SONG, + NO_SUCH_LIST, + LIST_EXISTS, + BAD_NAME, + BAD_RANGE, + NOT_PLAYING, + TOO_LARGE, + DISABLED, }; extern const Domain playlist_domain; diff --git a/src/PlaylistFile.cxx b/src/PlaylistFile.cxx index 5e14e7ec7..c5a298868 100644 --- a/src/PlaylistFile.cxx +++ b/src/PlaylistFile.cxx @@ -90,7 +90,7 @@ spl_map(Error &error) { const AllocatedPath &path_fs = map_spl_path(); if (path_fs.IsNull()) - error.Set(playlist_domain, PLAYLIST_RESULT_DISABLED, + error.Set(playlist_domain, int(PlaylistResult::DISABLED), "Stored playlists are disabled"); return path_fs; } @@ -99,7 +99,7 @@ static bool spl_check_name(const char *name_utf8, Error &error) { 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"); 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); if (path_fs.IsNull()) - error.Set(playlist_domain, PLAYLIST_RESULT_BAD_NAME, + error.Set(playlist_domain, int(PlaylistResult::BAD_NAME), "Bad playlist name"); return path_fs; @@ -129,7 +129,7 @@ playlist_errno(Error &error) { switch (errno) { case ENOENT: - error.Set(playlist_domain, PLAYLIST_RESULT_NO_SUCH_LIST, + error.Set(playlist_domain, int(PlaylistResult::NO_SUCH_LIST), "No such playlist"); break; @@ -287,7 +287,7 @@ spl_move_index(const char *utf8path, unsigned src, unsigned dest, return false; 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"); return false; } @@ -351,7 +351,7 @@ spl_remove_index(const char *utf8path, unsigned pos, Error &error) return false; if (pos >= contents.size()) { - error.Set(playlist_domain, PLAYLIST_RESULT_BAD_RANGE, + error.Set(playlist_domain, int(PlaylistResult::BAD_RANGE), "Bad range"); 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) { fclose(file); - error.Set(playlist_domain, PLAYLIST_RESULT_TOO_LARGE, + error.Set(playlist_domain, int(PlaylistResult::TOO_LARGE), "Stored playlist is too large"); return false; } @@ -430,13 +430,13 @@ spl_rename_internal(Path from_path_fs, Path to_path_fs, Error &error) { 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"); return false; } if (FileExists(to_path_fs)) { - error.Set(playlist_domain, PLAYLIST_RESULT_LIST_EXISTS, + error.Set(playlist_domain, int(PlaylistResult::LIST_EXISTS), "Playlist exists already"); return false; } diff --git a/src/PlaylistQueue.cxx b/src/PlaylistQueue.cxx index 200ce542f..1722c421c 100644 --- a/src/PlaylistQueue.cxx +++ b/src/PlaylistQueue.cxx @@ -30,13 +30,13 @@ #include -enum playlist_result +PlaylistResult playlist_load_into_queue(const char *uri, SongEnumerator &e, unsigned start_index, unsigned end_index, playlist &dest, player_control &pc, bool secure) { - enum playlist_result result; + PlaylistResult result; Song *song; 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); song->Free(); - if (result != PLAYLIST_RESULT_SUCCESS) { + if (result != PlaylistResult::SUCCESS) { g_free(base_uri); return result; } @@ -63,10 +63,10 @@ playlist_load_into_queue(const char *uri, SongEnumerator &e, g_free(base_uri); - return PLAYLIST_RESULT_SUCCESS; + return PlaylistResult::SUCCESS; } -enum playlist_result +PlaylistResult playlist_open_into_queue(const char *uri, unsigned start_index, unsigned end_index, playlist &dest, player_control &pc, @@ -78,9 +78,9 @@ playlist_open_into_queue(const char *uri, struct input_stream *is; auto playlist = playlist_open_any(uri, mutex, cond, &is); 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, start_index, end_index, dest, pc, secure); diff --git a/src/PlaylistQueue.hxx b/src/PlaylistQueue.hxx index 2860190f1..503b6bbb0 100644 --- a/src/PlaylistQueue.hxx +++ b/src/PlaylistQueue.hxx @@ -39,7 +39,7 @@ struct player_control; * @param start_index the index of the first song * @param end_index the index of the last song (excluding) */ -enum playlist_result +PlaylistResult playlist_load_into_queue(const char *uri, SongEnumerator &e, unsigned start_index, unsigned end_index, 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 * play queue. */ -enum playlist_result +PlaylistResult playlist_open_into_queue(const char *uri, unsigned start_index, unsigned end_index, playlist &dest, player_control &pc, diff --git a/src/PlaylistSave.cxx b/src/PlaylistSave.cxx index 0980869b6..bbac33a74 100644 --- a/src/PlaylistSave.cxx +++ b/src/PlaylistSave.cxx @@ -64,26 +64,26 @@ playlist_print_uri(FILE *file, const char *uri) fprintf(file, "%s\n", path.c_str()); } -enum playlist_result +PlaylistResult spl_save_queue(const char *name_utf8, const queue &queue) { if (map_spl_path().IsNull()) - return PLAYLIST_RESULT_DISABLED; + return PlaylistResult::DISABLED; 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); if (path_fs.IsNull()) - return PLAYLIST_RESULT_BAD_NAME; + return PlaylistResult::BAD_NAME; if (FileExists(path_fs)) - return PLAYLIST_RESULT_LIST_EXISTS; + return PlaylistResult::LIST_EXISTS; FILE *file = FOpen(path_fs, FOpenMode::WriteText); if (file == nullptr) - return PLAYLIST_RESULT_ERRNO; + return PlaylistResult::ERRNO; for (unsigned i = 0; i < queue.GetLength(); i++) playlist_print_song(file, queue.Get(i)); @@ -91,10 +91,10 @@ spl_save_queue(const char *name_utf8, const queue &queue) fclose(file); 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) { 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) { 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, "can't add file \"%s\"", path_utf8); 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 */ char *temp2 = g_strdup(uri_utf8.c_str()); char *p = temp2; @@ -135,7 +135,7 @@ playlist_load_spl(struct playlist &playlist, player_control &pc, p++; } - if (playlist.AppendURI(pc, temp2) != PLAYLIST_RESULT_SUCCESS) + if (playlist.AppendURI(pc, temp2) != PlaylistResult::SUCCESS) FormatError(playlist_domain, "can't add file \"%s\"", temp2); diff --git a/src/PlaylistSave.hxx b/src/PlaylistSave.hxx index 54f48f4b8..fb1bf2022 100644 --- a/src/PlaylistSave.hxx +++ b/src/PlaylistSave.hxx @@ -39,13 +39,13 @@ playlist_print_uri(FILE *fp, const char *uri); /** * Saves a queue object into a stored playlist file. */ -enum playlist_result +PlaylistResult spl_save_queue(const char *name_utf8, const queue &queue); /** * Saves a playlist object into a stored playlist file. */ -enum playlist_result +PlaylistResult spl_save_playlist(const char *name_utf8, const playlist &playlist); /** diff --git a/src/QueueCommands.cxx b/src/QueueCommands.cxx index 0e2a3604c..92355bdff 100644 --- a/src/QueueCommands.cxx +++ b/src/QueueCommands.cxx @@ -43,7 +43,7 @@ enum command_return handle_add(Client &client, gcc_unused int argc, char *argv[]) { char *uri = argv[1]; - enum playlist_result result; + PlaylistResult result; if (memcmp(uri, "file:///", 8) == 0) { const char *path_utf8 = uri + 7; @@ -86,7 +86,7 @@ handle_addid(Client &client, int argc, char *argv[]) { char *uri = argv[1]; unsigned added_id; - enum playlist_result result; + PlaylistResult result; if (memcmp(uri, "file:///", 8) == 0) { 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); } - if (result != PLAYLIST_RESULT_SUCCESS) + if (result != PlaylistResult::SUCCESS) return print_playlist_result(client, result); if (argc == 3) { @@ -121,7 +121,7 @@ handle_addid(Client &client, int argc, char *argv[]) if (!check_unsigned(client, &to, argv[2])) return COMMAND_RETURN_ERROR; result = client.partition.MoveId(added_id, to); - if (result != PLAYLIST_RESULT_SUCCESS) { + if (result != PlaylistResult::SUCCESS) { enum command_return ret = print_playlist_result(client, result); 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])) 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); } @@ -153,7 +153,7 @@ handle_deleteid(Client &client, gcc_unused int argc, char *argv[]) if (!check_unsigned(client, &id, argv[1])) return COMMAND_RETURN_ERROR; - enum playlist_result result = client.partition.DeleteId(id); + PlaylistResult result = client.partition.DeleteId(id); 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); if (!ret) return print_playlist_result(client, - PLAYLIST_RESULT_BAD_RANGE); + PlaylistResult::BAD_RANGE); 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); if (!ret) return print_playlist_result(client, - PLAYLIST_RESULT_NO_SUCH_SONG); + PlaylistResult::NO_SUCH_SONG); } else { playlist_print_info(client, client.playlist, 0, std::numeric_limits::max()); @@ -292,11 +292,11 @@ handle_prio(Client &client, int argc, char *argv[]) argv[i])) return COMMAND_RETURN_ERROR; - enum playlist_result result = + PlaylistResult result = client.partition.SetPriorityRange(start_position, end_position, priority); - if (result != PLAYLIST_RESULT_SUCCESS) + if (result != PlaylistResult::SUCCESS) 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])) return COMMAND_RETURN_ERROR; - enum playlist_result result = + PlaylistResult result = client.partition.SetPriorityId(song_id, priority); - if (result != PLAYLIST_RESULT_SUCCESS) + if (result != PlaylistResult::SUCCESS) 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])) return COMMAND_RETURN_ERROR; - enum playlist_result result = + PlaylistResult result = client.partition.MoveRange(start, end, to); return print_playlist_result(client, result); } @@ -357,7 +357,7 @@ handle_moveid(Client &client, gcc_unused int argc, char *argv[]) return COMMAND_RETURN_ERROR; if (!check_int(client, &to, argv[2])) 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); } @@ -371,7 +371,7 @@ handle_swap(Client &client, gcc_unused int argc, char *argv[]) if (!check_unsigned(client, &song2, argv[2])) return COMMAND_RETURN_ERROR; - enum playlist_result result = + PlaylistResult result = client.partition.SwapPositions(song1, song2); 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])) 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); }