pass ProxySongList around since it already has shared_ptr inside
This commit is contained in:
@@ -539,93 +539,93 @@ void ScrollDown::Run()
|
||||
|
||||
bool ScrollUpArtist::canBeRun() const
|
||||
{
|
||||
return proxySongList(myScreen).get();
|
||||
return proxySongList(myScreen);
|
||||
}
|
||||
|
||||
void ScrollUpArtist::Run()
|
||||
{
|
||||
auto pl = proxySongList(myScreen);
|
||||
assert(pl);
|
||||
size_t pos = pl->choice();
|
||||
if (MPD::Song *s = pl->getSong(pos))
|
||||
size_t pos = pl.choice();
|
||||
if (MPD::Song *s = pl.getSong(pos))
|
||||
{
|
||||
std::string artist = s->getArtist();
|
||||
while (pos > 0)
|
||||
{
|
||||
s = pl->getSong(--pos);
|
||||
s = pl.getSong(--pos);
|
||||
if (!s || s->getArtist() != artist)
|
||||
break;
|
||||
}
|
||||
pl->highlight(pos);
|
||||
pl.highlight(pos);
|
||||
}
|
||||
}
|
||||
|
||||
bool ScrollUpAlbum::canBeRun() const
|
||||
{
|
||||
return proxySongList(myScreen).get();
|
||||
return proxySongList(myScreen);
|
||||
}
|
||||
|
||||
void ScrollUpAlbum::Run()
|
||||
{
|
||||
auto pl = proxySongList(myScreen);
|
||||
assert(pl);
|
||||
size_t pos = pl->choice();
|
||||
if (MPD::Song *s = pl->getSong(pos))
|
||||
size_t pos = pl.choice();
|
||||
if (MPD::Song *s = pl.getSong(pos))
|
||||
{
|
||||
std::string album = s->getAlbum();
|
||||
while (pos > 0)
|
||||
{
|
||||
s = pl->getSong(--pos);
|
||||
s = pl.getSong(--pos);
|
||||
if (!s || s->getAlbum() != album)
|
||||
break;
|
||||
}
|
||||
pl->highlight(pos);
|
||||
pl.highlight(pos);
|
||||
}
|
||||
}
|
||||
|
||||
bool ScrollDownArtist::canBeRun() const
|
||||
{
|
||||
return proxySongList(myScreen).get();
|
||||
return proxySongList(myScreen);
|
||||
}
|
||||
|
||||
void ScrollDownArtist::Run()
|
||||
{
|
||||
auto pl = proxySongList(myScreen);
|
||||
assert(pl);
|
||||
size_t pos = pl->choice();
|
||||
if (MPD::Song *s = pl->getSong(pos))
|
||||
size_t pos = pl.choice();
|
||||
if (MPD::Song *s = pl.getSong(pos))
|
||||
{
|
||||
std::string artist = s->getArtist();
|
||||
while (pos < pl->size() - 1)
|
||||
while (pos < pl.size() - 1)
|
||||
{
|
||||
s = pl->getSong(++pos);
|
||||
s = pl.getSong(++pos);
|
||||
if (!s || s->getArtist() != artist)
|
||||
break;
|
||||
}
|
||||
pl->highlight(pos);
|
||||
pl.highlight(pos);
|
||||
}
|
||||
}
|
||||
|
||||
bool ScrollDownAlbum::canBeRun() const
|
||||
{
|
||||
return proxySongList(myScreen).get();
|
||||
return proxySongList(myScreen);
|
||||
}
|
||||
|
||||
void ScrollDownAlbum::Run()
|
||||
{
|
||||
auto pl = proxySongList(myScreen);
|
||||
assert(pl);
|
||||
size_t pos = pl->choice();
|
||||
if (MPD::Song *s = pl->getSong(pos))
|
||||
size_t pos = pl.choice();
|
||||
if (MPD::Song *s = pl.getSong(pos))
|
||||
{
|
||||
std::string album = s->getAlbum();
|
||||
while (pos < pl->size() - 1)
|
||||
while (pos < pl.size() - 1)
|
||||
{
|
||||
s = pl->getSong(++pos);
|
||||
s = pl.getSong(++pos);
|
||||
if (!s || s->getAlbum() != album)
|
||||
break;
|
||||
}
|
||||
pl->highlight(pos);
|
||||
pl.highlight(pos);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1720,50 +1720,50 @@ void ReverseSelection::Run()
|
||||
|
||||
bool RemoveSelection::canBeRun() const
|
||||
{
|
||||
return proxySongList(myScreen).get();
|
||||
return proxySongList(myScreen);
|
||||
}
|
||||
|
||||
void RemoveSelection::Run()
|
||||
{
|
||||
auto pl = proxySongList(myScreen);
|
||||
for (size_t i = 0; i < pl->size(); ++i)
|
||||
pl->setSelected(i, false);
|
||||
for (size_t i = 0; i < pl.size(); ++i)
|
||||
pl.setSelected(i, false);
|
||||
Statusbar::msg("Selection removed");
|
||||
}
|
||||
|
||||
bool SelectAlbum::canBeRun() const
|
||||
{
|
||||
auto w = hasSongs(myScreen);
|
||||
return w && w->allowsSelection() && w->getProxySongList().get();
|
||||
return w && w->allowsSelection() && w->proxySongList();
|
||||
}
|
||||
|
||||
void SelectAlbum::Run()
|
||||
{
|
||||
auto pl = proxySongList(myScreen);
|
||||
size_t pos = pl->choice();
|
||||
if (MPD::Song *s = pl->getSong(pos))
|
||||
size_t pos = pl.choice();
|
||||
if (MPD::Song *s = pl.getSong(pos))
|
||||
{
|
||||
std::string album = s->getAlbum();
|
||||
// select song under cursor
|
||||
pl->setSelected(pos, true);
|
||||
pl.setSelected(pos, true);
|
||||
// go up
|
||||
while (pos > 0)
|
||||
{
|
||||
s = pl->getSong(--pos);
|
||||
s = pl.getSong(--pos);
|
||||
if (!s || s->getAlbum() != album)
|
||||
break;
|
||||
else
|
||||
pl->setSelected(pos, true);
|
||||
pl.setSelected(pos, true);
|
||||
}
|
||||
// go down
|
||||
pos = pl->choice();
|
||||
while (pos < pl->size() - 1)
|
||||
pos = pl.choice();
|
||||
while (pos < pl.size() - 1)
|
||||
{
|
||||
s = pl->getSong(++pos);
|
||||
s = pl.getSong(++pos);
|
||||
if (!s || s->getAlbum() != album)
|
||||
break;
|
||||
else
|
||||
pl->setSelected(pos, true);
|
||||
pl.setSelected(pos, true);
|
||||
}
|
||||
Statusbar::msg("Album around cursor position selected");
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ void Browser::switchTo()
|
||||
if (w.empty())
|
||||
GetDirectory(itsBrowsedDir);
|
||||
else
|
||||
markSongsInPlaylist(getProxySongList());
|
||||
markSongsInPlaylist(proxySongList());
|
||||
|
||||
drawHeader();
|
||||
}
|
||||
@@ -287,9 +287,9 @@ void Browser::prevFound(bool wrap)
|
||||
|
||||
/***********************************************************************/
|
||||
|
||||
std::shared_ptr<ProxySongList> Browser::getProxySongList()
|
||||
ProxySongList Browser::proxySongList()
|
||||
{
|
||||
return mkProxySongList(w, [](NC::Menu<MPD::Item>::Item &item) -> MPD::Song * {
|
||||
return ProxySongList(w, [](NC::Menu<MPD::Item>::Item &item) -> MPD::Song * {
|
||||
MPD::Song *ptr = 0;
|
||||
if (item.value().type == itSong)
|
||||
ptr = item.value().song.get();
|
||||
|
||||
@@ -56,7 +56,7 @@ struct Browser: Screen<NC::Menu<MPD::Item>>, Filterable, HasSongs, Searchable, T
|
||||
virtual void prevFound(bool wrap) OVERRIDE;
|
||||
|
||||
// HasSongs implementation
|
||||
virtual std::shared_ptr<ProxySongList> getProxySongList() OVERRIDE;
|
||||
virtual ProxySongList proxySongList() OVERRIDE;
|
||||
|
||||
virtual bool allowsSelection() OVERRIDE;
|
||||
virtual void reverseSelection() OVERRIDE;
|
||||
|
||||
@@ -80,9 +80,9 @@ void setProperties(NC::Menu<T> &menu, const MPD::Song &s, HasSongs &screen, bool
|
||||
separate_albums = false;
|
||||
if (Config.playlist_separate_albums)
|
||||
{
|
||||
auto pl = screen.getProxySongList();
|
||||
auto pl = screen.proxySongList();
|
||||
assert(pl);
|
||||
auto next = pl->getSong(drawn_pos+1);
|
||||
auto next = pl.getSong(drawn_pos+1);
|
||||
if (next && next->getAlbum() != s.getAlbum())
|
||||
separate_albums = true;
|
||||
}
|
||||
|
||||
@@ -90,12 +90,12 @@ std::string Timestamp(time_t t)
|
||||
return result;
|
||||
}
|
||||
|
||||
void markSongsInPlaylist(std::shared_ptr<ProxySongList> pl)
|
||||
void markSongsInPlaylist(ProxySongList pl)
|
||||
{
|
||||
size_t list_size = pl->size();
|
||||
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));
|
||||
if (auto s = pl.getSong(i))
|
||||
pl.setBold(i, myPlaylist->checkForSong(*s));
|
||||
}
|
||||
|
||||
std::wstring Scroller(const std::wstring &str, size_t &pos, size_t width)
|
||||
|
||||
@@ -38,13 +38,13 @@ inline HasSongs *hasSongs(BaseScreen *screen)
|
||||
return dynamic_cast<HasSongs *>(screen);
|
||||
}
|
||||
|
||||
inline std::shared_ptr<ProxySongList> proxySongList(BaseScreen *screen)
|
||||
inline ProxySongList proxySongList(BaseScreen *screen)
|
||||
{
|
||||
auto ptr = nullProxySongList();
|
||||
auto pl = ProxySongList();
|
||||
auto hs = hasSongs(screen);
|
||||
if (hs)
|
||||
ptr = hs->getProxySongList();
|
||||
return ptr;
|
||||
pl = hs->proxySongList();
|
||||
return pl;
|
||||
}
|
||||
|
||||
inline MPD::Song *currentSong(BaseScreen *screen)
|
||||
@@ -52,7 +52,7 @@ inline MPD::Song *currentSong(BaseScreen *screen)
|
||||
MPD::Song *ptr = 0;
|
||||
auto pl = proxySongList(screen);
|
||||
if (pl)
|
||||
ptr = pl->currentSong();
|
||||
ptr = pl.currentSong();
|
||||
return ptr;
|
||||
}
|
||||
|
||||
@@ -471,7 +471,7 @@ bool addSongsToPlaylist(const MPD::SongList &list, bool play, size_t position =
|
||||
|
||||
std::string Timestamp(time_t t);
|
||||
|
||||
void markSongsInPlaylist(std::shared_ptr<ProxySongList> pl);
|
||||
void markSongsInPlaylist(ProxySongList pl);
|
||||
|
||||
std::wstring Scroller(const std::wstring &str, size_t &pos, size_t width);
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ struct Searchable
|
||||
|
||||
struct HasSongs
|
||||
{
|
||||
virtual std::shared_ptr<ProxySongList> getProxySongList() = 0;
|
||||
virtual ProxySongList proxySongList() = 0;
|
||||
|
||||
virtual bool allowsSelection() = 0;
|
||||
virtual void reverseSelection() = 0;
|
||||
|
||||
@@ -553,9 +553,9 @@ void MediaLibrary::prevFound(bool wrap)
|
||||
|
||||
/***********************************************************************/
|
||||
|
||||
std::shared_ptr<ProxySongList> MediaLibrary::getProxySongList()
|
||||
ProxySongList MediaLibrary::proxySongList()
|
||||
{
|
||||
auto ptr = nullProxySongList();
|
||||
auto ptr = ProxySongList();
|
||||
if (isActiveWindow(Songs))
|
||||
ptr = songsProxyList();
|
||||
return ptr;
|
||||
@@ -744,9 +744,9 @@ int MediaLibrary::Columns()
|
||||
return 3;
|
||||
}
|
||||
|
||||
std::shared_ptr<ProxySongList> MediaLibrary::songsProxyList()
|
||||
ProxySongList MediaLibrary::songsProxyList()
|
||||
{
|
||||
return mkProxySongList(Songs, [](NC::Menu<MPD::Song>::Item &item) {
|
||||
return ProxySongList(Songs, [](NC::Menu<MPD::Song>::Item &item) {
|
||||
return &item.value();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ struct MediaLibrary: Screen<NC::Window *>, Filterable, HasColumns, HasSongs, Sea
|
||||
virtual void prevFound(bool wrap) OVERRIDE;
|
||||
|
||||
// HasSongs implementation
|
||||
virtual std::shared_ptr<ProxySongList> getProxySongList() OVERRIDE;
|
||||
virtual ProxySongList proxySongList() OVERRIDE;
|
||||
|
||||
virtual bool allowsSelection() OVERRIDE;
|
||||
virtual void reverseSelection() OVERRIDE;
|
||||
@@ -72,7 +72,7 @@ struct MediaLibrary: Screen<NC::Window *>, Filterable, HasColumns, HasSongs, Sea
|
||||
void toggleColumnsMode();
|
||||
int Columns();
|
||||
void LocateSong(const MPD::Song &);
|
||||
std::shared_ptr<ProxySongList> songsProxyList();
|
||||
ProxySongList songsProxyList();
|
||||
|
||||
struct SearchConstraints
|
||||
{
|
||||
|
||||
@@ -171,9 +171,9 @@ void Playlist::prevFound(bool wrap)
|
||||
|
||||
/***********************************************************************/
|
||||
|
||||
std::shared_ptr<ProxySongList> Playlist::getProxySongList()
|
||||
ProxySongList Playlist::proxySongList()
|
||||
{
|
||||
return mkProxySongList(w, [](NC::Menu<MPD::Song>::Item &item) {
|
||||
return ProxySongList(w, [](NC::Menu<MPD::Song>::Item &item) {
|
||||
return &item.value();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ struct Playlist: Screen<NC::Menu<MPD::Song>>, Filterable, HasSongs, Searchable,
|
||||
virtual void prevFound(bool wrap) OVERRIDE;
|
||||
|
||||
// HasSongs implementation
|
||||
virtual std::shared_ptr<ProxySongList> getProxySongList() OVERRIDE;
|
||||
virtual ProxySongList proxySongList() OVERRIDE;
|
||||
|
||||
virtual bool allowsSelection() OVERRIDE;
|
||||
virtual void reverseSelection() OVERRIDE;
|
||||
|
||||
@@ -202,9 +202,9 @@ bool PlaylistEditor::isContentFiltered()
|
||||
return false;
|
||||
}
|
||||
|
||||
std::shared_ptr<ProxySongList> PlaylistEditor::contentProxyList()
|
||||
ProxySongList PlaylistEditor::contentProxyList()
|
||||
{
|
||||
return mkProxySongList(Content, [](NC::Menu<MPD::Song>::Item &item) {
|
||||
return ProxySongList(Content, [](NC::Menu<MPD::Song>::Item &item) {
|
||||
return &item.value();
|
||||
});
|
||||
}
|
||||
@@ -386,9 +386,9 @@ void PlaylistEditor::prevFound(bool wrap)
|
||||
|
||||
/***********************************************************************/
|
||||
|
||||
std::shared_ptr<ProxySongList> PlaylistEditor::getProxySongList()
|
||||
ProxySongList PlaylistEditor::proxySongList()
|
||||
{
|
||||
auto ptr = nullProxySongList();
|
||||
auto ptr = ProxySongList();
|
||||
if (isActiveWindow(Content))
|
||||
ptr = contentProxyList();
|
||||
return ptr;
|
||||
|
||||
@@ -55,7 +55,7 @@ struct PlaylistEditor: Screen<NC::Window *>, Filterable, HasColumns, HasSongs, S
|
||||
virtual void prevFound(bool wrap) OVERRIDE;
|
||||
|
||||
// HasSongs implementation
|
||||
virtual std::shared_ptr<ProxySongList> getProxySongList() OVERRIDE;
|
||||
virtual ProxySongList proxySongList() OVERRIDE;
|
||||
|
||||
virtual bool allowsSelection() OVERRIDE;
|
||||
virtual void reverseSelection() OVERRIDE;
|
||||
@@ -74,7 +74,7 @@ struct PlaylistEditor: Screen<NC::Window *>, Filterable, HasColumns, HasSongs, S
|
||||
|
||||
virtual void Locate(const std::string &);
|
||||
bool isContentFiltered();
|
||||
std::shared_ptr<ProxySongList> contentProxyList();
|
||||
ProxySongList contentProxyList();
|
||||
|
||||
NC::Menu<std::string> Playlists;
|
||||
NC::Menu<MPD::Song> Content;
|
||||
|
||||
@@ -99,6 +99,8 @@ class ProxySongList
|
||||
std::shared_ptr<Interface> m_impl;
|
||||
|
||||
public:
|
||||
ProxySongList() { }
|
||||
|
||||
template <typename T, typename F>
|
||||
ProxySongList(typename NC::Menu<T> &menu, F f) : m_impl(new Impl<T, F>(menu, f)) { }
|
||||
|
||||
@@ -115,17 +117,9 @@ public:
|
||||
|
||||
MPD::Song *getSong(size_t pos) { return m_impl->getSong(pos); }
|
||||
MPD::Song *currentSong() { return m_impl->currentSong(); }
|
||||
|
||||
/// @return true if there is no underlying menu object, false otherwise
|
||||
operator bool() const { return m_impl.get() != 0; }
|
||||
};
|
||||
|
||||
template <typename T, typename F>
|
||||
std::shared_ptr<ProxySongList> mkProxySongList(typename NC::Menu<T> &menu, F f)
|
||||
{
|
||||
return std::make_shared<ProxySongList>(ProxySongList(menu, f));
|
||||
}
|
||||
|
||||
inline std::shared_ptr<ProxySongList> nullProxySongList()
|
||||
{
|
||||
return std::shared_ptr<ProxySongList>();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -129,7 +129,7 @@ void SearchEngine::switchTo()
|
||||
SwitchTo::execute(this);
|
||||
if (w.empty())
|
||||
Prepare();
|
||||
markSongsInPlaylist(getProxySongList());
|
||||
markSongsInPlaylist(proxySongList());
|
||||
drawHeader();
|
||||
}
|
||||
|
||||
@@ -184,7 +184,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);
|
||||
markSongsInPlaylist(getProxySongList());
|
||||
markSongsInPlaylist(proxySongList());
|
||||
Statusbar::msg("Searching finished");
|
||||
if (Config.block_search_constraints_change)
|
||||
for (size_t i = 0; i < StaticOptions-4; ++i)
|
||||
@@ -296,9 +296,9 @@ void SearchEngine::prevFound(bool wrap)
|
||||
|
||||
/***********************************************************************/
|
||||
|
||||
std::shared_ptr< ProxySongList > SearchEngine::getProxySongList()
|
||||
ProxySongList SearchEngine::proxySongList()
|
||||
{
|
||||
return mkProxySongList(w, [](NC::Menu<SEItem>::Item &item) -> MPD::Song * {
|
||||
return ProxySongList(w, [](NC::Menu<SEItem>::Item &item) -> MPD::Song * {
|
||||
MPD::Song *ptr = 0;
|
||||
if (!item.isSeparator() && item.value().isSong())
|
||||
ptr = &item.value().song();
|
||||
|
||||
@@ -104,7 +104,7 @@ struct SearchEngine: Screen<NC::Menu<SEItem>>, Filterable, HasSongs, Searchable,
|
||||
virtual void prevFound(bool wrap) OVERRIDE;
|
||||
|
||||
// HasSongs implementation
|
||||
virtual std::shared_ptr<ProxySongList> getProxySongList() OVERRIDE;
|
||||
virtual ProxySongList proxySongList() OVERRIDE;
|
||||
|
||||
virtual bool allowsSelection() OVERRIDE;
|
||||
virtual void reverseSelection() OVERRIDE;
|
||||
|
||||
@@ -165,9 +165,9 @@ void Status::Changes::playlist()
|
||||
Playlist::ReloadRemaining = true;
|
||||
|
||||
if (isVisible(myBrowser))
|
||||
markSongsInPlaylist(myBrowser->getProxySongList());
|
||||
markSongsInPlaylist(myBrowser->proxySongList());
|
||||
if (isVisible(mySearcher))
|
||||
markSongsInPlaylist(mySearcher->getProxySongList());
|
||||
markSongsInPlaylist(mySearcher->proxySongList());
|
||||
if (isVisible(myLibrary))
|
||||
markSongsInPlaylist(myLibrary->songsProxyList());
|
||||
if (isVisible(myPlaylistEditor))
|
||||
|
||||
@@ -796,11 +796,11 @@ void TagEditor::prevFound(bool wrap)
|
||||
|
||||
/***********************************************************************/
|
||||
|
||||
std::shared_ptr<ProxySongList> TagEditor::getProxySongList()
|
||||
ProxySongList TagEditor::proxySongList()
|
||||
{
|
||||
auto ptr = nullProxySongList();
|
||||
auto ptr = ProxySongList();
|
||||
if (w == Tags)
|
||||
ptr = mkProxySongList(*Tags, [](NC::Menu<MPD::MutableSong>::Item &item) {
|
||||
ptr = ProxySongList(*Tags, [](NC::Menu<MPD::MutableSong>::Item &item) {
|
||||
return &item.value();
|
||||
});
|
||||
return ptr;
|
||||
|
||||
@@ -63,7 +63,7 @@ struct TagEditor: Screen<NC::Window *>, Filterable, HasColumns, HasSongs, Search
|
||||
virtual void prevFound(bool wrap) OVERRIDE;
|
||||
|
||||
// HasSongs implementation
|
||||
virtual std::shared_ptr<ProxySongList> getProxySongList() OVERRIDE;
|
||||
virtual ProxySongList proxySongList() OVERRIDE;
|
||||
|
||||
virtual bool allowsSelection() OVERRIDE;
|
||||
virtual void reverseSelection() OVERRIDE;
|
||||
|
||||
Reference in New Issue
Block a user