summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrzej Rybczak <electricityispower@gmail.com>2016-01-15 15:27:50 +0100
committerAndrzej Rybczak <electricityispower@gmail.com>2016-01-15 15:27:50 +0100
commitf482e979621614b912ed57228ed05bdb1fc94e9e (patch)
tree337ecdbd114e6414193c3da4eb405986332579be
parent133a794cb16e6c7499feb13594c24f0513ab0a9f (diff)
search engine: fix assertion failure
-rw-r--r--NEWS1
-rw-r--r--src/search_engine.cpp31
2 files changed, 15 insertions, 17 deletions
diff --git a/NEWS b/NEWS
index a2c92e12..218e2717 100644
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,5 @@
ncmpcpp-0.7.2 (????-??-??)
+* Attempt to add non-song item to playlist from search engine doesn't trigger assertion failure anymore.
ncmpcpp-0.7.1 (2016-01-01)
* Selected songs in media library can now be added to playlists.
diff --git a/src/search_engine.cpp b/src/search_engine.cpp
index 222e93e4..e18f4b25 100644
--- a/src/search_engine.cpp
+++ b/src/search_engine.cpp
@@ -127,7 +127,19 @@ ConstSongIterator SearchEngineWindow::endS() const
std::vector<MPD::Song> SearchEngineWindow::getSelectedSongs()
{
- return {}; // TODO
+ std::vector<MPD::Song> result;
+ for (auto &item : *this)
+ {
+ if (item.isSelected())
+ {
+ assert(item.value().isSong());
+ result.push_back(item.value().song());
+ }
+ }
+ // If no item is selected, add the current one if it's a song.
+ if (result.empty() && !empty() && current()->value().isSong())
+ result.push_back(current()->value().song());
+ return result;
}
/**********************************************************************/
@@ -336,22 +348,7 @@ bool SearchEngine::addItemToPlaylist(bool play)
std::vector<MPD::Song> SearchEngine::getSelectedSongs()
{
- std::vector<MPD::Song> result;
- for (auto it = w.begin(); it != w.end(); ++it)
- {
- if (it->isSelected())
- {
- assert(it->value().isSong());
- result.push_back(it->value().song());
- }
- }
- // if no item is selected, add current one
- if (result.empty() && !w.empty())
- {
- assert(w.current()->value().isSong());
- result.push_back(w.current()->value().song());
- }
- return result;
+ return w.getSelectedSongs();
}
/***********************************************************************/