aboutsummaryrefslogtreecommitdiffstats
path: root/src/queue
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-02-27 17:27:23 +0100
committerMax Kellermann <max@duempel.org>2014-02-27 17:27:23 +0100
commit1c772ef69947127e01e7171b007a2295d51e7ae7 (patch)
tree1461d15b1f94e29ef23a750b97dcf16d77de9fd5 /src/queue
parent809b89b5af5eaf7abc3240d786cda15f354b6624 (diff)
downloadmpd-1c772ef69947127e01e7171b007a2295d51e7ae7.tar.gz
mpd-1c772ef69947127e01e7171b007a2295d51e7ae7.tar.xz
mpd-1c772ef69947127e01e7171b007a2295d51e7ae7.zip
Playlist: use the Error library to return errors
Diffstat (limited to 'src/queue')
-rw-r--r--src/queue/Playlist.hxx22
-rw-r--r--src/queue/PlaylistEdit.cxx40
2 files changed, 29 insertions, 33 deletions
diff --git a/src/queue/Playlist.hxx b/src/queue/Playlist.hxx
index 09980155e..4a4c7f30c 100644
--- a/src/queue/Playlist.hxx
+++ b/src/queue/Playlist.hxx
@@ -146,14 +146,20 @@ public:
void DatabaseModified(const Database &db);
#endif
- PlaylistResult AppendSong(PlayerControl &pc,
- DetachedSong &&song,
- unsigned *added_id=nullptr);
-
- PlaylistResult AppendURI(PlayerControl &pc,
- const SongLoader &loader,
- const char *uri_utf8,
- unsigned *added_id=nullptr);
+ /**
+ * @return the new song id or 0 on error
+ */
+ unsigned AppendSong(PlayerControl &pc,
+ DetachedSong &&song,
+ Error &error);
+
+ /**
+ * @return the new song id or 0 on error
+ */
+ unsigned AppendURI(PlayerControl &pc,
+ const SongLoader &loader,
+ const char *uri_utf8,
+ Error &error);
protected:
void DeleteInternal(PlayerControl &pc,
diff --git a/src/queue/PlaylistEdit.cxx b/src/queue/PlaylistEdit.cxx
index 8d2c76e6e..ef409a260 100644
--- a/src/queue/PlaylistEdit.cxx
+++ b/src/queue/PlaylistEdit.cxx
@@ -32,7 +32,6 @@
#include "DetachedSong.hxx"
#include "SongLoader.hxx"
#include "Idle.hxx"
-#include "Log.hxx"
#include <stdlib.h>
@@ -55,14 +54,16 @@ playlist::Clear(PlayerControl &pc)
OnModified();
}
-PlaylistResult
-playlist::AppendSong(PlayerControl &pc,
- DetachedSong &&song, unsigned *added_id)
+unsigned
+playlist::AppendSong(PlayerControl &pc, DetachedSong &&song, Error &error)
{
unsigned id;
- if (queue.IsFull())
- return PlaylistResult::TOO_LARGE;
+ if (queue.IsFull()) {
+ error.Set(playlist_domain, int(PlaylistResult::TOO_LARGE),
+ "Playlist is too large");
+ return 0;
+ }
const DetachedSong *const queued_song = GetQueuedSong();
@@ -84,30 +85,19 @@ playlist::AppendSong(PlayerControl &pc,
UpdateQueuedSong(pc, queued_song);
OnModified();
- if (added_id)
- *added_id = id;
-
- return PlaylistResult::SUCCESS;
+ return id;
}
-PlaylistResult
-playlist::AppendURI(PlayerControl &pc,
- const SongLoader &loader,
- const char *uri, unsigned *added_id)
+unsigned
+playlist::AppendURI(PlayerControl &pc, const SongLoader &loader,
+ const char *uri,
+ Error &error)
{
- FormatDebug(playlist_domain, "add to playlist: %s", uri);
-
- Error error;
DetachedSong *song = loader.LoadSong(uri, error);
- if (song == nullptr) {
- // TODO: return the Error
- LogError(error);
- return error.IsDomain(playlist_domain)
- ? PlaylistResult(error.GetCode())
- : PlaylistResult::NO_SUCH_SONG;
- }
+ if (song == nullptr)
+ return 0;
- PlaylistResult result = AppendSong(pc, std::move(*song), added_id);
+ unsigned result = AppendSong(pc, std::move(*song), error);
delete song;
return result;