void PlaylistEditor::Update() { if (Playlists->ReallyEmpty()) { Content->Clear(); MPD::TagList list; Mpd.GetPlaylists(list); sort(list.begin(), list.end(), CaseInsensitiveSorting()); for (MPD::TagList::iterator it = list.begin(); it != list.end(); ++it) { utf_to_locale(*it); Playlists->AddOption(*it); } Playlists->Window::Clear(); Playlists->Refresh(); } if (!Playlists->Empty() && Content->ReallyEmpty()) { Content->Reset(); MPD::SongList list; Mpd.GetPlaylistContent(locale_to_utf_cpy(Playlists->Current()), list); if (!list.empty()) Content->SetTitle(Config.titles_visibility ? "Playlist's content (" + IntoStr(list.size()) + " item" + (list.size() == 1 ? ")" : "s)") : ""); else Content->SetTitle(Config.titles_visibility ? "Playlist's content" : ""); bool bold = 0; for (MPD::SongList::const_iterator it = list.begin(); it != list.end(); ++it) { for (size_t j = 0; j < myPlaylist->Items->Size(); ++j) { if ((*it)->GetHash() == myPlaylist->Items->at(j).GetHash()) { bold = 1; break; } } Content->AddOption(**it, bold); bold = 0; } MPD::FreeSongList(list); Content->Window::Clear(); Content->Display(); } if (w == Content && Content->ReallyEmpty()) { Content->HighlightColor(Config.main_highlight_color); Playlists->HighlightColor(Config.active_column_color); w = Playlists; } if (Content->ReallyEmpty()) { *Content << XY(0, 0) << "Playlist is empty."; Content->Window::Refresh(); } }
bool addSongsToPlaylist(const MPD::SongList &list, bool play, size_t position) { if (list.empty()) return false; position = std::min(position, Mpd.GetPlaylistLength()); Mpd.StartCommandsList(); for (auto s = list.rbegin(); s != list.rend(); ++s) if (Mpd.AddSong(*s, position) < 0) break; if (play) Mpd.Play(position); return Mpd.CommitCommandsList(); }
std::string FindSharedDir(const MPD::SongList &v) { if (v.empty()) // this should never happen, but in case... FatalError("empty SongList passed to FindSharedDir(const SongList &)!"); size_t i = -1; std::string first = v.front()->GetDirectory(); for (MPD::SongList::const_iterator it = ++v.begin(); it != v.end(); ++it) { size_t j = 0; std::string dir = (*it)->GetDirectory(); size_t length = std::min(first.length(), dir.length()); while (!first.compare(j, 1, dir, j, 1) && j < length && j < i) ++j; i = j; } return i ? first.substr(0, i) : "/"; }
MPD::SongList SearchEngine::getSelectedSongs() { MPD::SongList 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; }
MPD::SongList Browser::getSelectedSongs() { MPD::SongList result; auto item_handler = [this, &result](const MPD::Item &item) { if (item.type == itDirectory) { # ifndef WIN32 if (isLocal()) { MPD::ItemList list; GetLocalDirectory(list, item.name, true); for (auto it = list.begin(); it != list.end(); ++it) result.push_back(*it->song); } else # endif // !WIN32 { auto list = Mpd.GetDirectoryRecursive(item.name); result.insert(result.end(), list.begin(), list.end()); } } else if (item.type == itSong) result.push_back(*item.song); else if (item.type == itPlaylist) { auto list = Mpd.GetPlaylistContent(item.name); result.insert(result.end(), list.begin(), list.end()); } }; for (auto it = w.begin(); it != w.end(); ++it) if (it->isSelected()) item_handler(it->value()); // if no item is selected, add current one if (result.empty() && !w.empty()) item_handler(w.current().value()); return result; }
MPD::SongList MediaLibrary::getSelectedSongs() { MPD::SongList result; if (isActiveWindow(Tags)) { auto tag_handler = [&result](const std::string &tag) { Mpd.StartSearch(true); Mpd.AddSearch(Config.media_lib_primary_tag, tag); Mpd.CommitSearchSongs(vectorMoveInserter(result)); }; bool any_selected = false; for (auto &e : Tags) { if (e.isSelected()) { any_selected = true; tag_handler(e.value().tag()); } } // if no item is selected, add current one if (!any_selected && !Tags.empty()) tag_handler(Tags.current().value().tag()); } else if (isActiveWindow(Albums)) { bool any_selected = false; for (auto it = Albums.begin(); it != Albums.end() && !it->isSeparator(); ++it) { if (it->isSelected()) { any_selected = true; auto &sc = it->value(); Mpd.StartSearch(true); if (hasTwoColumns) Mpd.AddSearch(Config.media_lib_primary_tag, sc.entry().tag()); else Mpd.AddSearch(Config.media_lib_primary_tag, Tags.current().value().tag()); Mpd.AddSearch(MPD_TAG_ALBUM, sc.entry().album()); Mpd.AddSearch(MPD_TAG_DATE, sc.entry().date()); size_t begin = result.size(); Mpd.CommitSearchSongs(vectorMoveInserter(result)); std::sort(result.begin()+begin, result.end(), SortSongs(false)); } } // if no item is selected, add songs from right column if (!any_selected && !Albums.empty()) { withUnfilteredMenu(Songs, [this, &result]() { result.insert(result.end(), Songs.beginV(), Songs.endV()); }); } } else if (isActiveWindow(Songs)) { for (auto it = Songs.begin(); it != Songs.end(); ++it) if (it->isSelected()) result.push_back(it->value()); // if no item is selected, add current one if (result.empty() && !Songs.empty()) result.push_back(Songs.current().value()); } return result; }