addSongsToPlaylist: add all valid entries instead of stopping at first failure

This commit is contained in:
James Pike
2013-12-31 02:14:34 +00:00
committed by Andrzej Rybczak
parent 4415fe8684
commit 7094852c20

View File

@@ -488,33 +488,43 @@ template <typename BufferT> void ShowTag(BufferT &buf, const std::string &tag)
template <typename SongIterator> template <typename SongIterator>
void addSongsToPlaylist(SongIterator first, SongIterator last, bool play, int position) void addSongsToPlaylist(SongIterator first, SongIterator last, bool play, int position)
{ {
auto addSongNoError = [&](SongIterator song) -> int {
try
{
return Mpd.AddSong(*song, position);
}
catch (...)
{
return -1;
}
};
if (last-first >= 1) if (last-first >= 1)
{ {
int id = Mpd.AddSong(*first, position); int id = addSongNoError(first);
if (id > 0) while (id < 0) {
{ if (++first == last)
Mpd.StartCommandsList(); return;
id = addSongNoError(first);
}
if (position == -1) if (position == -1)
{ {
++first; ++first;
for(; first != last; ++first) for(; first != last; ++first)
if (Mpd.AddSong(*first) < 0) addSongNoError(first);
break;
} }
else else
{ {
++position; ++position;
--last; --last;
for (; first != last; --last) for (; first != last; --last)
if (Mpd.AddSong(*last, position) < 0) addSongNoError(last);
break;
} }
Mpd.CommitCommandsList();
if (play) if (play)
Mpd.PlayID(id); Mpd.PlayID(id);
} }
} }
}
bool addSongToPlaylist(const MPD::Song &s, bool play, int position = -1); bool addSongToPlaylist(const MPD::Song &s, bool play, int position = -1);