generalize UpdateSongsList (-> markSongsInPlaylist)
This commit is contained in:
@@ -108,7 +108,10 @@ void Browser::SwitchTo()
|
||||
if (isLocal() && Config.browser_sort_mode == smMTime) // local browser doesn't support sorting by mtime
|
||||
Config.browser_sort_mode = smName;
|
||||
|
||||
w->empty() ? myBrowser->GetDirectory(itsBrowsedDir) : myBrowser->UpdateItemList();
|
||||
if (w->empty())
|
||||
myBrowser->GetDirectory(itsBrowsedDir);
|
||||
else
|
||||
markSongsInPlaylist(getProxySongList());
|
||||
|
||||
if (myScreen != this && myScreen->isTabbable())
|
||||
Global::myPrevScreen = myScreen;
|
||||
@@ -612,13 +615,6 @@ bool Browser::deleteItem(const MPD::Item &item)
|
||||
}
|
||||
#endif // !WIN32
|
||||
|
||||
void Browser::UpdateItemList()
|
||||
{
|
||||
for (auto it = w->begin(); it != w->end(); ++it)
|
||||
if (it->value().type == itSong)
|
||||
it->setBold(myPlaylist->checkForSong(*it->value().song));
|
||||
}
|
||||
|
||||
namespace {//
|
||||
|
||||
bool hasSupportedExtension(const std::string &file)
|
||||
|
||||
@@ -73,7 +73,6 @@ class Browser : public Screen< NC::Menu<MPD::Item> >, public Filterable, public
|
||||
void ChangeBrowseMode();
|
||||
bool deleteItem(const MPD::Item &);
|
||||
# endif // !WIN32
|
||||
void UpdateItemList();
|
||||
|
||||
static bool isParentDirectory(const MPD::Item &item) {
|
||||
return item.type == MPD::itDirectory && item.name == "..";
|
||||
|
||||
@@ -282,11 +282,12 @@ std::string Timestamp(time_t t)
|
||||
return result;
|
||||
}
|
||||
|
||||
void UpdateSongList(NC::Menu<MPD::Song> *menu)
|
||||
void markSongsInPlaylist(std::shared_ptr<ProxySongList> pl)
|
||||
{
|
||||
for (auto it = menu->begin(); it != menu->end(); ++it)
|
||||
it->setBold(myPlaylist->checkForSong(it->value()));
|
||||
menu->refresh();
|
||||
size_t list_size = pl->size();
|
||||
for (size_t i = 0; i < list_size; ++i)
|
||||
if (auto s = pl->getSong(i))
|
||||
pl->setBold(i, myPlaylist->checkForSong(*s));
|
||||
}
|
||||
|
||||
std::basic_string<my_char_t> Scroller(const std::basic_string<my_char_t> &str, size_t &pos, size_t width)
|
||||
|
||||
@@ -394,7 +394,7 @@ template <typename T> void ShowTag(T &buf, const std::string &tag)
|
||||
|
||||
std::string Timestamp(time_t t);
|
||||
|
||||
void UpdateSongList(NC::Menu<MPD::Song> *);
|
||||
void markSongsInPlaylist(std::shared_ptr<ProxySongList> pl);
|
||||
|
||||
std::basic_string<my_char_t> Scroller(const std::basic_string<my_char_t> &str, size_t &pos, size_t width);
|
||||
|
||||
|
||||
@@ -206,8 +206,8 @@ void MediaLibrary::SwitchTo()
|
||||
Global::myPrevScreen = myScreen;
|
||||
myScreen = this;
|
||||
Global::RedrawHeader = true;
|
||||
markSongsInPlaylist(songsProxyList());
|
||||
Refresh();
|
||||
UpdateSongList(Songs);
|
||||
}
|
||||
|
||||
std::basic_string<my_char_t> MediaLibrary::Title()
|
||||
@@ -533,9 +533,7 @@ std::shared_ptr<ProxySongList> MediaLibrary::getProxySongList()
|
||||
{
|
||||
auto ptr = nullProxySongList();
|
||||
if (w == Songs)
|
||||
ptr = mkProxySongList(*Songs, [](NC::Menu<MPD::Song>::Item &item) {
|
||||
return &item.value();
|
||||
});
|
||||
ptr = songsProxyList();
|
||||
return ptr;
|
||||
}
|
||||
|
||||
@@ -696,6 +694,13 @@ void MediaLibrary::PrevColumn()
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<ProxySongList> MediaLibrary::songsProxyList()
|
||||
{
|
||||
return mkProxySongList(*Songs, [](NC::Menu<MPD::Song>::Item &item) {
|
||||
return &item.value();
|
||||
});
|
||||
}
|
||||
|
||||
void MediaLibrary::LocateSong(const MPD::Song &s)
|
||||
{
|
||||
std::string primary_tag;
|
||||
|
||||
@@ -68,6 +68,8 @@ class MediaLibrary : public Screen<NC::Window>, public Filterable, public HasSon
|
||||
|
||||
void LocateSong(const MPD::Song &);
|
||||
|
||||
std::shared_ptr<ProxySongList> songsProxyList();
|
||||
|
||||
struct SearchConstraints
|
||||
{
|
||||
SearchConstraints() { }
|
||||
|
||||
@@ -133,7 +133,7 @@ void PlaylistEditor::SwitchTo()
|
||||
Global::myPrevScreen = myScreen;
|
||||
myScreen = this;
|
||||
Global::RedrawHeader = true;
|
||||
UpdateSongList(Content);
|
||||
markSongsInPlaylist(contentProxyList());
|
||||
Refresh();
|
||||
}
|
||||
|
||||
@@ -285,6 +285,13 @@ bool PlaylistEditor::PrevColumn()
|
||||
return false;
|
||||
}
|
||||
|
||||
std::shared_ptr<ProxySongList> PlaylistEditor::contentProxyList()
|
||||
{
|
||||
return mkProxySongList(*Content, [](NC::Menu<MPD::Song>::Item &item) {
|
||||
return &item.value();
|
||||
});
|
||||
}
|
||||
|
||||
void PlaylistEditor::AddToPlaylist(bool add_n_play)
|
||||
{
|
||||
MPD::SongList list;
|
||||
@@ -451,9 +458,7 @@ std::shared_ptr<ProxySongList> PlaylistEditor::getProxySongList()
|
||||
{
|
||||
auto ptr = nullProxySongList();
|
||||
if (w == Content)
|
||||
ptr = mkProxySongList(*Content, [](NC::Menu<MPD::Song>::Item &item) {
|
||||
return &item.value();
|
||||
});
|
||||
ptr = contentProxyList();
|
||||
return ptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -72,6 +72,8 @@ class PlaylistEditor : public Screen<NC::Window>, public Filterable, public HasS
|
||||
bool isPrevColumnAvailable();
|
||||
bool PrevColumn();
|
||||
|
||||
std::shared_ptr<ProxySongList> contentProxyList();
|
||||
|
||||
NC::Menu<std::string> *Playlists;
|
||||
NC::Menu<MPD::Song> *Content;
|
||||
|
||||
|
||||
@@ -48,6 +48,9 @@ class ProxySongList
|
||||
virtual bool isSelected(size_t pos) = 0;
|
||||
virtual void setSelected(size_t pos, bool selected) = 0;
|
||||
|
||||
virtual bool isBold(size_t pos) = 0;
|
||||
virtual void setBold(size_t pos, bool bold) = 0;
|
||||
|
||||
virtual MPD::Song *getSong(size_t pos) = 0;
|
||||
virtual MPD::Song *currentSong() = 0;
|
||||
};
|
||||
@@ -67,15 +70,20 @@ class ProxySongList
|
||||
virtual bool isSelected(size_t pos) {
|
||||
return m_menu[pos].isSelected();
|
||||
}
|
||||
|
||||
virtual void setSelected(size_t pos, bool selected) {
|
||||
m_menu[pos].setSelected(selected);
|
||||
}
|
||||
|
||||
virtual bool isBold(size_t pos) {
|
||||
return m_menu[pos].isBold();
|
||||
}
|
||||
virtual void setBold(size_t pos, bool bold) {
|
||||
m_menu[pos].setBold(bold);
|
||||
}
|
||||
|
||||
virtual MPD::Song *getSong(size_t pos) {
|
||||
return m_song_getter(m_menu[pos]);
|
||||
}
|
||||
|
||||
virtual MPD::Song *currentSong() {
|
||||
if (!m_menu.empty())
|
||||
return getSong(m_menu.choice());
|
||||
@@ -102,6 +110,9 @@ public:
|
||||
bool isSelected(size_t pos) { return m_impl->isSelected(pos); }
|
||||
void setSelected(size_t pos, bool selected) { m_impl->setSelected(pos, selected); }
|
||||
|
||||
bool isBold(size_t pos) { return m_impl->isBold(pos); }
|
||||
void setBold(size_t pos, bool bold) { m_impl->setBold(pos, bold); }
|
||||
|
||||
MPD::Song *getSong(size_t pos) { return m_impl->getSong(pos); }
|
||||
MPD::Song *currentSong() { return m_impl->currentSong(); }
|
||||
};
|
||||
|
||||
@@ -150,11 +150,7 @@ void SearchEngine::SwitchTo()
|
||||
myScreen = this;
|
||||
Global::RedrawHeader = true;
|
||||
|
||||
if (!w->back().value().isSong())
|
||||
{
|
||||
*w << NC::XY(0, 0) << "Updating list...";
|
||||
UpdateFoundList();
|
||||
}
|
||||
markSongsInPlaylist(getProxySongList());
|
||||
}
|
||||
|
||||
std::basic_string<my_char_t> SearchEngine::Title()
|
||||
@@ -208,7 +204,7 @@ void SearchEngine::EnterPressed()
|
||||
w->insertItem(ResetButton+2, SEItem(), 1, 1);
|
||||
w->at(ResetButton+2).value().mkBuffer() << Config.color1 << "Search results: " << Config.color2 << "Found " << found << (found > 1 ? " songs" : " song") << NC::clDefault;
|
||||
w->insertSeparator(ResetButton+3);
|
||||
UpdateFoundList();
|
||||
markSongsInPlaylist(getProxySongList());
|
||||
ShowMessage("Searching finished");
|
||||
if (Config.block_search_constraints_change)
|
||||
for (size_t i = 0; i < StaticOptions-4; ++i)
|
||||
@@ -362,13 +358,6 @@ MPD::SongList SearchEngine::getSelectedSongs()
|
||||
|
||||
/***********************************************************************/
|
||||
|
||||
void SearchEngine::UpdateFoundList()
|
||||
{
|
||||
for (auto it = w->begin(); it != w->end(); ++it)
|
||||
if (it->value().isSong())
|
||||
it->setBold(myPlaylist->checkForSong(it->value().song()));
|
||||
}
|
||||
|
||||
void SearchEngine::Prepare()
|
||||
{
|
||||
w->setTitle("");
|
||||
|
||||
@@ -106,8 +106,6 @@ class SearchEngine : public Screen< NC::Menu<SEItem> >, public Filterable, publi
|
||||
|
||||
virtual bool isMergable() { return true; }
|
||||
|
||||
void UpdateFoundList();
|
||||
|
||||
static size_t StaticOptions;
|
||||
static size_t SearchButton;
|
||||
static size_t ResetButton;
|
||||
|
||||
@@ -260,13 +260,13 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *)
|
||||
Playlist::ReloadRemaining = true;
|
||||
|
||||
if (isVisible(myBrowser))
|
||||
myBrowser->UpdateItemList();
|
||||
markSongsInPlaylist(myBrowser->getProxySongList());
|
||||
if (isVisible(mySearcher))
|
||||
mySearcher->UpdateFoundList();
|
||||
markSongsInPlaylist(myLibrary->getProxySongList());
|
||||
if (isVisible(myLibrary))
|
||||
UpdateSongList(myLibrary->Songs);
|
||||
markSongsInPlaylist(myLibrary->songsProxyList());
|
||||
if (isVisible(myPlaylistEditor))
|
||||
UpdateSongList(myPlaylistEditor->Content);
|
||||
markSongsInPlaylist(myPlaylistEditor->contentProxyList());
|
||||
}
|
||||
if (changed.StoredPlaylists)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user