summaryrefslogtreecommitdiff
path: root/src/queue
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2016-02-28 10:51:07 +0100
committerMax Kellermann <max@duempel.org>2016-02-28 11:02:36 +0100
commitb6cb9b853a3385650d40cc121a6b4230e5cf81bc (patch)
treef3b9eb4c27f3c907350652184aa309915ffbe6dd /src/queue
parent50b930f283c33f01ce43c54216896e7d3736a1c9 (diff)
queue/PlaylistEdit: throw PlaylistError on error
Diffstat (limited to 'src/queue')
-rw-r--r--src/queue/Playlist.hxx13
-rw-r--r--src/queue/PlaylistEdit.cxx42
2 files changed, 21 insertions, 34 deletions
diff --git a/src/queue/Playlist.hxx b/src/queue/Playlist.hxx
index 1abfb56a2..868dccceb 100644
--- a/src/queue/Playlist.hxx
+++ b/src/queue/Playlist.hxx
@@ -195,11 +195,11 @@ public:
#endif
/**
- * @return the new song id or 0 on error
+ * Throws PlaylistError if the queue would be too large.
+ *
+ * @return the new song id
*/
- unsigned AppendSong(PlayerControl &pc,
- DetachedSong &&song,
- Error &error);
+ unsigned AppendSong(PlayerControl &pc, DetachedSong &&song);
/**
* @return the new song id or 0 on error
@@ -254,9 +254,8 @@ public:
* Sets the start_time and end_time attributes on the song
* with the specified id.
*/
- bool SetSongIdRange(PlayerControl &pc, unsigned id,
- SongTime start, SongTime end,
- Error &error);
+ void SetSongIdRange(PlayerControl &pc, unsigned id,
+ SongTime start, SongTime end);
void AddSongIdTag(unsigned id, TagType tag_type, const char *value);
void ClearSongIdTag(unsigned id, TagType tag_type);
diff --git a/src/queue/PlaylistEdit.cxx b/src/queue/PlaylistEdit.cxx
index becaf1622..63699394f 100644
--- a/src/queue/PlaylistEdit.cxx
+++ b/src/queue/PlaylistEdit.cxx
@@ -92,15 +92,13 @@ playlist::CommitBulk(PlayerControl &pc)
}
unsigned
-playlist::AppendSong(PlayerControl &pc, DetachedSong &&song, Error &error)
+playlist::AppendSong(PlayerControl &pc, DetachedSong &&song)
{
unsigned id;
- if (queue.IsFull()) {
- error.Set(playlist_domain, int(PlaylistResult::TOO_LARGE),
- "Playlist is too large");
- return 0;
- }
+ if (queue.IsFull())
+ throw PlaylistError(PlaylistResult::TOO_LARGE,
+ "Playlist is too large");
const DetachedSong *const queued_song = GetQueuedSong();
@@ -134,7 +132,7 @@ playlist::AppendURI(PlayerControl &pc, const SongLoader &loader,
if (song == nullptr)
return 0;
- return AppendSong(pc, std::move(*song), error);
+ return AppendSong(pc, std::move(*song));
}
void
@@ -419,26 +417,20 @@ playlist::Shuffle(PlayerControl &pc, unsigned start, unsigned end)
OnModified();
}
-bool
+void
playlist::SetSongIdRange(PlayerControl &pc, unsigned id,
- SongTime start, SongTime end,
- Error &error)
+ SongTime start, SongTime end)
{
assert(end.IsZero() || start < end);
int position = queue.IdToPosition(id);
- if (position < 0) {
- error.Set(playlist_domain, int(PlaylistResult::NO_SUCH_SONG),
- "No such song");
- return false;
- }
+ if (position < 0)
+ throw PlaylistError::NoSuchSong();
if (playing) {
- if (position == current) {
- error.Set(playlist_domain, int(PlaylistResult::DENIED),
- "Cannot edit the current song");
- return false;
- }
+ if (position == current)
+ throw PlaylistError(PlaylistResult::DENIED,
+ "Cannot edit the current song");
if (position == queued) {
/* if we're manipulating the "queued" song,
@@ -455,12 +447,9 @@ playlist::SetSongIdRange(PlayerControl &pc, unsigned id,
if (!duration.IsNegative()) {
/* validate the offsets */
- if (start > duration) {
- error.Set(playlist_domain,
- int(PlaylistResult::BAD_RANGE),
- "Invalid start offset");
- return false;
- }
+ if (start > duration)
+ throw PlaylistError(PlaylistResult::BAD_RANGE,
+ "Invalid start offset");
if (end >= duration)
end = SongTime::zero();
@@ -474,5 +463,4 @@ playlist::SetSongIdRange(PlayerControl &pc, unsigned id,
UpdateQueuedSong(pc, nullptr);
queue.ModifyAtPosition(position);
OnModified();
- return true;
}