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