mpd: use lambda closures instead of passing vectors to functions
This commit is contained in:
@@ -290,7 +290,11 @@ void Browser::GetSelectedSongs(MPD::SongList &v)
|
||||
}
|
||||
else
|
||||
# endif // !WIN32
|
||||
Mpd.GetDirectoryRecursive(locale_to_utf_cpy(item.name), v);
|
||||
{
|
||||
Mpd.GetDirectoryRecursive(locale_to_utf_cpy(item.name), [&v](MPD::Song &&s) {
|
||||
v.push_back(s);
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
case itSong:
|
||||
@@ -300,7 +304,9 @@ void Browser::GetSelectedSongs(MPD::SongList &v)
|
||||
}
|
||||
case itPlaylist:
|
||||
{
|
||||
Mpd.GetPlaylistContent(locale_to_utf_cpy(item.name), v);
|
||||
Mpd.GetPlaylistContent(locale_to_utf_cpy(item.name), [&v](MPD::Song &&s) {
|
||||
v.push_back(s);
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -370,9 +376,18 @@ void Browser::GetDirectory(std::string dir, std::string subdir)
|
||||
|
||||
MPD::ItemList list;
|
||||
# ifndef WIN32
|
||||
isLocal() ? GetLocalDirectory(list) : Mpd.GetDirectory(dir, list);
|
||||
if (isLocal())
|
||||
GetLocalDirectory(list);
|
||||
else
|
||||
{
|
||||
Mpd.GetDirectory(dir, [&list](MPD::Item &&i) {
|
||||
list.push_back(i);
|
||||
});
|
||||
}
|
||||
# else
|
||||
Mpd.GetDirectory(dir, list);
|
||||
Mpd.GetDirectory(dir, [&list](MPD::Item &&i) {
|
||||
list.push_back(i);
|
||||
});
|
||||
# endif // !WIN32
|
||||
if (!isLocal()) // local directory is already sorted
|
||||
std::sort(list.begin(), list.end(), CaseInsensitiveSorting());
|
||||
|
||||
@@ -354,6 +354,12 @@ void Display::Tags(const MPD::Song &s, void *data, Menu<MPD::Song> *menu)
|
||||
}
|
||||
}
|
||||
|
||||
void Display::Outputs (const MPD::Output &o, void * , Menu< MPD::Output > *menu)
|
||||
{
|
||||
*menu << o.name();
|
||||
}
|
||||
|
||||
|
||||
void Display::Items(const MPD::Item &item, void *data, Menu<MPD::Item> *menu)
|
||||
{
|
||||
switch (item.type)
|
||||
|
||||
@@ -53,6 +53,8 @@ namespace Display
|
||||
|
||||
void Tags(const MPD::Song &, void *, Menu<MPD::Song> *);
|
||||
|
||||
void Outputs(const MPD::Output &, void *, Menu<MPD::Output> *);
|
||||
|
||||
void SearchEngine(const SEItem &, void *, Menu<SEItem> *);
|
||||
|
||||
void Items(const MPD::Item &, void *, Menu<MPD::Item> *);
|
||||
|
||||
@@ -226,28 +226,26 @@ void MediaLibrary::Update()
|
||||
locale_to_utf(Artists->Current());
|
||||
Mpd.StartFieldSearch(MPD_TAG_ALBUM);
|
||||
Mpd.AddSearch(Config.media_lib_primary_tag, Artists->Current());
|
||||
Mpd.CommitSearch(list);
|
||||
|
||||
for (MPD::TagList::iterator it = list.begin(); it != list.end(); ++it)
|
||||
Mpd.CommitSearchTags([&list](std::string &&album) {
|
||||
list.push_back(album);
|
||||
});
|
||||
for (auto album = list.begin(); album != list.end(); ++album)
|
||||
{
|
||||
if (Config.media_library_display_date)
|
||||
{
|
||||
MPD::TagList l;
|
||||
Mpd.StartFieldSearch(MPD_TAG_DATE);
|
||||
Mpd.AddSearch(Config.media_lib_primary_tag, Artists->Current());
|
||||
Mpd.AddSearch(MPD_TAG_ALBUM, *it);
|
||||
Mpd.CommitSearch(l);
|
||||
utf_to_locale(*it);
|
||||
for (MPD::TagList::iterator j = l.begin(); j != l.end(); ++j)
|
||||
{
|
||||
utf_to_locale(*j);
|
||||
Albums->AddOption(SearchConstraints(*it, *j));
|
||||
}
|
||||
Mpd.AddSearch(MPD_TAG_ALBUM, *album);
|
||||
utf_to_locale(*album);
|
||||
Mpd.CommitSearchTags([this, &album](std::string &&date) {
|
||||
utf_to_locale(date);
|
||||
Albums->AddOption(SearchConstraints(*album, date));
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
utf_to_locale(*it);
|
||||
Albums->AddOption(SearchConstraints(*it, ""));
|
||||
utf_to_locale(*album);
|
||||
Albums->AddOption(SearchConstraints(*album, ""));
|
||||
}
|
||||
}
|
||||
utf_to_locale(Artists->Current());
|
||||
@@ -269,43 +267,42 @@ void MediaLibrary::Update()
|
||||
Albums->Window::Refresh();
|
||||
Mpd.BlockIdle(1);
|
||||
Mpd.GetList(artists, Config.media_lib_primary_tag);
|
||||
for (MPD::TagList::iterator i = artists.begin(); i != artists.end(); ++i)
|
||||
for (auto artist = artists.begin(); artist != artists.end(); ++artist)
|
||||
{
|
||||
MPD::TagList albums;
|
||||
Mpd.StartFieldSearch(MPD_TAG_ALBUM);
|
||||
Mpd.AddSearch(Config.media_lib_primary_tag, *i);
|
||||
Mpd.CommitSearch(albums);
|
||||
for (MPD::TagList::iterator j = albums.begin(); j != albums.end(); ++j)
|
||||
Mpd.AddSearch(Config.media_lib_primary_tag, *artist);
|
||||
Mpd.CommitSearchTags([&albums](std::string &&album) {
|
||||
albums.push_back(album);
|
||||
});
|
||||
for (auto album = albums.begin(); album != albums.end(); ++album)
|
||||
{
|
||||
if (Config.media_library_display_date)
|
||||
{
|
||||
if (Config.media_lib_primary_tag != MPD_TAG_DATE)
|
||||
{
|
||||
MPD::TagList dates;
|
||||
Mpd.StartFieldSearch(MPD_TAG_DATE);
|
||||
Mpd.AddSearch(Config.media_lib_primary_tag, *i);
|
||||
Mpd.AddSearch(MPD_TAG_ALBUM, *j);
|
||||
Mpd.CommitSearch(dates);
|
||||
utf_to_locale(*i);
|
||||
utf_to_locale(*j);
|
||||
for (MPD::TagList::iterator k = dates.begin(); k != dates.end(); ++k)
|
||||
{
|
||||
utf_to_locale(*k);
|
||||
Albums->AddOption(SearchConstraints(*i, *j, *k));
|
||||
}
|
||||
Mpd.AddSearch(Config.media_lib_primary_tag, *artist);
|
||||
Mpd.AddSearch(MPD_TAG_ALBUM, *album);
|
||||
utf_to_locale(*artist);
|
||||
utf_to_locale(*album);
|
||||
Mpd.CommitSearchTags([this, &artist, &album](std::string &&tag) {
|
||||
utf_to_locale(tag);
|
||||
Albums->AddOption(SearchConstraints(*artist, *album, tag));
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
utf_to_locale(*i);
|
||||
utf_to_locale(*j);
|
||||
Albums->AddOption(SearchConstraints(*i, *j, *i));
|
||||
utf_to_locale(*artist);
|
||||
utf_to_locale(*album);
|
||||
Albums->AddOption(SearchConstraints(*artist, *album, *artist));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
utf_to_locale(*i);
|
||||
utf_to_locale(*j);
|
||||
Albums->AddOption(SearchConstraints(*i, *j, ""));
|
||||
utf_to_locale(*artist);
|
||||
utf_to_locale(*album);
|
||||
Albums->AddOption(SearchConstraints(*artist, *album, ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -335,24 +332,17 @@ void MediaLibrary::Update()
|
||||
if (Config.media_library_display_date)
|
||||
Mpd.AddSearch(MPD_TAG_DATE, locale_to_utf_cpy(Albums->Current().Date));
|
||||
}
|
||||
Mpd.CommitSearch(list);
|
||||
Mpd.CommitSearchSongs([&list](MPD::Song &&s) {
|
||||
list.push_back(s);
|
||||
});
|
||||
|
||||
std::sort(list.begin(), list.end(), Albums->Current().Date == AllTracksMarker ? SortAllTracks : SortSongsByTrack);
|
||||
bool bold = 0;
|
||||
if (Albums->Current().Date == AllTracksMarker)
|
||||
std::sort(list.begin(), list.end(), SortAllTracks);
|
||||
else
|
||||
std::sort(list.begin(), list.end(), SortSongsByTrack);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
Songs->AddOption(*it, bold);
|
||||
bold = 0;
|
||||
}
|
||||
for (auto it = list.begin(); it != list.end(); ++it)
|
||||
Songs->AddOption(*it, myPlaylist->checkForSong(*it));
|
||||
Songs->Window::Clear();
|
||||
Songs->Refresh();
|
||||
}
|
||||
@@ -493,7 +483,9 @@ void MediaLibrary::GetSelectedSongs(MPD::SongList &v)
|
||||
MPD::SongList list;
|
||||
Mpd.StartSearch(1);
|
||||
Mpd.AddSearch(Config.media_lib_primary_tag, locale_to_utf_cpy(Artists->at(*it)));
|
||||
Mpd.CommitSearch(list);
|
||||
Mpd.CommitSearchSongs([&list](MPD::Song &&s) {
|
||||
list.push_back(s);
|
||||
});
|
||||
std::sort(list.begin(), list.end(), SortAllTracks);
|
||||
std::copy(list.begin(), list.end(), std::back_inserter(v));
|
||||
}
|
||||
@@ -513,15 +505,15 @@ void MediaLibrary::GetSelectedSongs(MPD::SongList &v)
|
||||
{
|
||||
for (auto it = selected.begin(); it != selected.end(); ++it)
|
||||
{
|
||||
MPD::SongList list;
|
||||
Mpd.StartSearch(1);
|
||||
Mpd.AddSearch(Config.media_lib_primary_tag, hasTwoColumns
|
||||
? Albums->at(*it).PrimaryTag
|
||||
: locale_to_utf_cpy(Artists->Current()));
|
||||
Mpd.AddSearch(MPD_TAG_ALBUM, Albums->at(*it).Album);
|
||||
Mpd.AddSearch(MPD_TAG_DATE, Albums->at(*it).Date);
|
||||
Mpd.CommitSearch(list);
|
||||
std::copy(list.begin(), list.end(), std::back_inserter(v));
|
||||
Mpd.CommitSearchSongs([&v](MPD::Song &&s) {
|
||||
v.push_back(s);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -621,17 +621,15 @@ bool MPD::Connection::Rename(const std::string &from, const std::string &to)
|
||||
}
|
||||
}
|
||||
|
||||
void MPD::Connection::GetPlaylistChanges(unsigned version, SongList &v)
|
||||
void MPD::Connection::GetPlaylistChanges(unsigned version, std::function<void(MPD::Song &&)> f)
|
||||
{
|
||||
if (!itsConnection)
|
||||
return;
|
||||
assert(!isCommandsListEnabled);
|
||||
if (!version)
|
||||
v.reserve(GetPlaylistLength());
|
||||
GoBusy();
|
||||
mpd_send_queue_changes_meta(itsConnection, version);
|
||||
while (mpd_song *s = mpd_recv_song(itsConnection))
|
||||
v.push_back(Song(s));
|
||||
f(Song(s));
|
||||
mpd_response_finish(itsConnection);
|
||||
GoIdle();
|
||||
}
|
||||
@@ -669,7 +667,7 @@ MPD::Song MPD::Connection::GetCurrentlyPlayingSong()
|
||||
return result;
|
||||
}
|
||||
|
||||
void MPD::Connection::GetPlaylistContent(const std::string &path, SongList &v)
|
||||
void MPD::Connection::GetPlaylistContent(const std::string &path, std::function<void(MPD::Song &&)> f)
|
||||
{
|
||||
if (!itsConnection)
|
||||
return;
|
||||
@@ -677,7 +675,7 @@ void MPD::Connection::GetPlaylistContent(const std::string &path, SongList &v)
|
||||
GoBusy();
|
||||
mpd_send_list_playlist_meta(itsConnection, path.c_str());
|
||||
while (mpd_song *s = mpd_recv_song(itsConnection))
|
||||
v.push_back(Song(s));
|
||||
f(Song(s));
|
||||
mpd_response_finish(itsConnection);
|
||||
GoIdle();
|
||||
}
|
||||
@@ -923,7 +921,9 @@ bool MPD::Connection::AddRandomTag(mpd_tag_type tag, size_t number)
|
||||
StartSearch(1);
|
||||
AddSearch(tag, *it++);
|
||||
SongList list;
|
||||
CommitSearch(list);
|
||||
CommitSearchSongs([&list](MPD::Song &&s) {
|
||||
list.push_back(s);
|
||||
});
|
||||
StartCommandsList();
|
||||
for (auto j = list.begin(); j != list.end(); ++j)
|
||||
AddSong(*j);
|
||||
@@ -1079,11 +1079,10 @@ void MPD::Connection::GetPlaylists(TagList &v)
|
||||
{
|
||||
if (!itsConnection)
|
||||
return;
|
||||
ItemList list;
|
||||
GetDirectory("/", list);
|
||||
for (ItemList::const_iterator it = list.begin(); it != list.end(); ++it)
|
||||
if (it->type == itPlaylist)
|
||||
v.push_back(it->name);
|
||||
GetDirectory("/", [&v](Item &&it) {
|
||||
if (it.type == itPlaylist)
|
||||
v.push_back(it.name);
|
||||
});
|
||||
}
|
||||
|
||||
void MPD::Connection::GetList(TagList &v, mpd_tag_type type)
|
||||
@@ -1141,7 +1140,7 @@ void MPD::Connection::AddSearchURI(const std::string &str) const
|
||||
mpd_search_add_uri_constraint(itsConnection, MPD_OPERATOR_DEFAULT, str.c_str());
|
||||
}
|
||||
|
||||
void MPD::Connection::CommitSearch(SongList &v)
|
||||
void MPD::Connection::CommitSearchSongs(std::function<void(MPD::Song &&)> f)
|
||||
{
|
||||
if (!itsConnection)
|
||||
return;
|
||||
@@ -1149,12 +1148,12 @@ void MPD::Connection::CommitSearch(SongList &v)
|
||||
GoBusy();
|
||||
mpd_search_commit(itsConnection);
|
||||
while (mpd_song *s = mpd_recv_song(itsConnection))
|
||||
v.push_back(Song(s));
|
||||
f(Song(s));
|
||||
mpd_response_finish(itsConnection);
|
||||
GoIdle();
|
||||
}
|
||||
|
||||
void MPD::Connection::CommitSearch(TagList &v)
|
||||
void MPD::Connection::CommitSearchTags(std::function<void(std::string &&)> f)
|
||||
{
|
||||
if (!itsConnection)
|
||||
return;
|
||||
@@ -1163,14 +1162,14 @@ void MPD::Connection::CommitSearch(TagList &v)
|
||||
mpd_search_commit(itsConnection);
|
||||
while (mpd_pair *tag = mpd_recv_pair_tag(itsConnection, itsSearchedField))
|
||||
{
|
||||
v.push_back(tag->value);
|
||||
f(tag->value);
|
||||
mpd_return_pair(itsConnection, tag);
|
||||
}
|
||||
mpd_response_finish(itsConnection);
|
||||
GoIdle();
|
||||
}
|
||||
|
||||
void MPD::Connection::GetDirectory(const std::string &path, ItemList &v)
|
||||
void MPD::Connection::GetDirectory(const std::string &path, std::function<void(Item &&)> f)
|
||||
{
|
||||
if (!itsConnection)
|
||||
return;
|
||||
@@ -1185,28 +1184,26 @@ void MPD::Connection::GetDirectory(const std::string &path, ItemList &v)
|
||||
case MPD_ENTITY_TYPE_DIRECTORY:
|
||||
it.name = mpd_directory_get_path(mpd_entity_get_directory(item));
|
||||
it.type = itDirectory;
|
||||
goto WRITE;
|
||||
break;
|
||||
case MPD_ENTITY_TYPE_SONG:
|
||||
it.song = Song(mpd_song_dup(mpd_entity_get_song(item)));
|
||||
it.type = itSong;
|
||||
goto WRITE;
|
||||
break;
|
||||
case MPD_ENTITY_TYPE_PLAYLIST:
|
||||
it.name = mpd_playlist_get_path(mpd_entity_get_playlist(item));
|
||||
it.type = itPlaylist;
|
||||
goto WRITE;
|
||||
WRITE:
|
||||
v.push_back(it);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
assert(false);
|
||||
}
|
||||
mpd_entity_free(item);
|
||||
f(std::move(it));
|
||||
}
|
||||
mpd_response_finish(itsConnection);
|
||||
GoIdle();
|
||||
}
|
||||
|
||||
void MPD::Connection::GetDirectoryRecursive(const std::string &path, SongList &v)
|
||||
void MPD::Connection::GetDirectoryRecursive(const std::string &path, std::function<void(MPD::Song &&)> f)
|
||||
{
|
||||
if (!itsConnection)
|
||||
return;
|
||||
@@ -1214,20 +1211,7 @@ void MPD::Connection::GetDirectoryRecursive(const std::string &path, SongList &v
|
||||
GoBusy();
|
||||
mpd_send_list_all_meta(itsConnection, path.c_str());
|
||||
while (mpd_song *s = mpd_recv_song(itsConnection))
|
||||
v.push_back(Song(s));
|
||||
mpd_response_finish(itsConnection);
|
||||
GoIdle();
|
||||
}
|
||||
|
||||
void MPD::Connection::GetSongs(const std::string &path, SongList &v)
|
||||
{
|
||||
if (!itsConnection)
|
||||
return;
|
||||
assert(!isCommandsListEnabled);
|
||||
GoBusy();
|
||||
mpd_send_list_meta(itsConnection, path.c_str());
|
||||
while (mpd_song *s = mpd_recv_song(itsConnection))
|
||||
v.push_back(Song(s));
|
||||
f(Song(s));
|
||||
mpd_response_finish(itsConnection);
|
||||
GoIdle();
|
||||
}
|
||||
@@ -1248,7 +1232,7 @@ void MPD::Connection::GetDirectories(const std::string &path, TagList &v)
|
||||
GoIdle();
|
||||
}
|
||||
|
||||
void MPD::Connection::GetOutputs(OutputList &v)
|
||||
void MPD::Connection::GetOutputs(std::function<void(Output &&)> f)
|
||||
{
|
||||
if (!itsConnection)
|
||||
return;
|
||||
@@ -1257,7 +1241,7 @@ void MPD::Connection::GetOutputs(OutputList &v)
|
||||
mpd_send_outputs(itsConnection);
|
||||
while (mpd_output *output = mpd_recv_output(itsConnection))
|
||||
{
|
||||
v.push_back(std::make_pair(mpd_output_get_name(output), mpd_output_get_enabled(output)));
|
||||
f(Output(mpd_output_get_name(output), mpd_output_get_enabled(output)));
|
||||
mpd_output_free(output);
|
||||
}
|
||||
mpd_response_finish(itsConnection);
|
||||
@@ -1296,7 +1280,7 @@ bool MPD::Connection::DisableOutput(int id)
|
||||
}
|
||||
}
|
||||
|
||||
void MPD::Connection::GetURLHandlers(TagList &v)
|
||||
void MPD::Connection::GetURLHandlers(std::function<void(std::string &&)> f)
|
||||
{
|
||||
if (!itsConnection)
|
||||
return;
|
||||
@@ -1305,14 +1289,14 @@ void MPD::Connection::GetURLHandlers(TagList &v)
|
||||
mpd_send_list_url_schemes(itsConnection);
|
||||
while (mpd_pair *handler = mpd_recv_pair_named(itsConnection, "handler"))
|
||||
{
|
||||
v.push_back(handler->value);
|
||||
f(handler->value);
|
||||
mpd_return_pair(itsConnection, handler);
|
||||
}
|
||||
mpd_response_finish(itsConnection);
|
||||
GoIdle();
|
||||
}
|
||||
|
||||
void MPD::Connection::GetTagTypes(TagList &v)
|
||||
void MPD::Connection::GetTagTypes(std::function<void(std::string &&)> f)
|
||||
{
|
||||
if (!itsConnection)
|
||||
return;
|
||||
@@ -1321,7 +1305,7 @@ void MPD::Connection::GetTagTypes(TagList &v)
|
||||
mpd_send_list_tag_types(itsConnection);
|
||||
while (mpd_pair *tag_type = mpd_recv_pair_named(itsConnection, "tagtype"))
|
||||
{
|
||||
v.push_back(tag_type->value);
|
||||
f(tag_type->value);
|
||||
mpd_return_pair(itsConnection, tag_type);
|
||||
}
|
||||
mpd_response_finish(itsConnection);
|
||||
|
||||
31
src/mpdpp.h
31
src/mpdpp.h
@@ -59,7 +59,18 @@ namespace MPD
|
||||
bool Outputs:1;
|
||||
};
|
||||
|
||||
typedef std::pair<std::string, bool> Output;
|
||||
struct Output
|
||||
{
|
||||
Output(const std::string &name_, bool enabled) : m_name(name_), m_enabled(enabled) { }
|
||||
|
||||
const std::string &name() const { return m_name; }
|
||||
bool isEnabled() const { return m_enabled; }
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
bool m_enabled;
|
||||
|
||||
};
|
||||
|
||||
typedef std::vector<Item> ItemList;
|
||||
typedef std::vector<Song> SongList;
|
||||
@@ -142,7 +153,7 @@ namespace MPD
|
||||
unsigned long DBPlayTime() const { return itsStats ? mpd_stats_get_db_play_time(itsStats) : 0; }
|
||||
|
||||
size_t GetPlaylistLength() const { return itsCurrentStatus ? mpd_status_get_queue_length(itsCurrentStatus) : 0; }
|
||||
void GetPlaylistChanges(unsigned, SongList &);
|
||||
void GetPlaylistChanges(unsigned, std::function<void(Song &&)> f);
|
||||
|
||||
const std::string & GetErrorMessage() const { return itsErrorMessage; }
|
||||
|
||||
@@ -150,7 +161,7 @@ namespace MPD
|
||||
int GetCurrentlyPlayingSongPos() const;
|
||||
int GetCurrentSongPos() const;
|
||||
Song GetSong(const std::string &);
|
||||
void GetPlaylistContent(const std::string &, SongList &);
|
||||
void GetPlaylistContent(const std::string &, std::function<void(Song &&)> f);
|
||||
|
||||
void GetSupportedExtensions(std::set<std::string> &);
|
||||
|
||||
@@ -191,22 +202,22 @@ namespace MPD
|
||||
void AddSearch(mpd_tag_type, const std::string &) const;
|
||||
void AddSearchAny(const std::string &str) const;
|
||||
void AddSearchURI(const std::string &str) const;
|
||||
void CommitSearch(SongList &);
|
||||
void CommitSearch(TagList &);
|
||||
void CommitSearchSongs(std::function<void(Song &&)> f);
|
||||
void CommitSearchTags(std::function<void(std::string &&)> f);
|
||||
|
||||
void GetPlaylists(TagList &);
|
||||
void GetList(TagList &, mpd_tag_type);
|
||||
void GetDirectory(const std::string &, ItemList &);
|
||||
void GetDirectoryRecursive(const std::string &, SongList &);
|
||||
void GetDirectory(const std::string &, std::function<void(Item &&)> f);
|
||||
void GetDirectoryRecursive(const std::string &, std::function<void(Song &&)> f);
|
||||
void GetSongs(const std::string &, SongList &);
|
||||
void GetDirectories(const std::string &, TagList &);
|
||||
|
||||
void GetOutputs(OutputList &);
|
||||
void GetOutputs(std::function<void(Output &&)> f);
|
||||
bool EnableOutput(int);
|
||||
bool DisableOutput(int);
|
||||
|
||||
void GetURLHandlers(TagList &v);
|
||||
void GetTagTypes(TagList &v);
|
||||
void GetURLHandlers(std::function<void(std::string &&)> f);
|
||||
void GetTagTypes(std::function<void(std::string &&)> f);
|
||||
|
||||
private:
|
||||
void GoIdle();
|
||||
|
||||
@@ -37,7 +37,7 @@ void Outputs::Init()
|
||||
w->CyclicScrolling(Config.use_cyclic_scrolling);
|
||||
w->CenteredCursor(Config.centered_cursor);
|
||||
w->HighlightColor(Config.main_highlight_color);
|
||||
w->SetItemDisplayer(Display::Pairs);
|
||||
w->SetItemDisplayer(Display::Outputs);
|
||||
|
||||
isInitialized = 1;
|
||||
FetchList();
|
||||
@@ -83,15 +83,15 @@ std::basic_string<my_char_t> Outputs::Title()
|
||||
|
||||
void Outputs::EnterPressed()
|
||||
{
|
||||
if (w->Current().second)
|
||||
if (w->Current().isEnabled())
|
||||
{
|
||||
if (Mpd.DisableOutput(w->Choice()))
|
||||
ShowMessage("Output \"%s\" disabled", w->Current().first.c_str());
|
||||
ShowMessage("Output \"%s\" disabled", w->Current().name().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Mpd.EnableOutput(w->Choice()))
|
||||
ShowMessage("Output \"%s\" enabled", w->Current().first.c_str());
|
||||
ShowMessage("Output \"%s\" enabled", w->Current().name().c_str());
|
||||
}
|
||||
if (!Mpd.SupportsIdle())
|
||||
FetchList();
|
||||
@@ -115,11 +115,10 @@ void Outputs::FetchList()
|
||||
{
|
||||
if (!isInitialized)
|
||||
return;
|
||||
MPD::OutputList ol;
|
||||
Mpd.GetOutputs(ol);
|
||||
w->Clear();
|
||||
for (MPD::OutputList::const_iterator it = ol.begin(); it != ol.end(); ++it)
|
||||
w->AddOption(*it, it->second);
|
||||
Mpd.GetOutputs([this](MPD::Output &&o) {
|
||||
w->AddOption(o, o.isEnabled());
|
||||
});
|
||||
if (myScreen == this)
|
||||
w->Refresh();
|
||||
}
|
||||
|
||||
@@ -605,3 +605,11 @@ void Playlist::SetSelectedItemsPriority(int prio)
|
||||
if (Mpd.CommitCommandsList())
|
||||
ShowMessage("Priority set");
|
||||
}
|
||||
|
||||
bool Playlist::checkForSong (const MPD::Song &s)
|
||||
{
|
||||
for (size_t i = 0; i < Items->Size(); ++i)
|
||||
if (s.getHash() == (*Items)[i].getHash())
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -79,6 +79,8 @@ class Playlist : public Screen<Window>
|
||||
|
||||
void SetSelectedItemsPriority(int prio);
|
||||
|
||||
bool checkForSong(const MPD::Song &s);
|
||||
|
||||
static std::string SongToString(const MPD::Song &, void *);
|
||||
static std::string SongInColumnsToString(const MPD::Song &, void *);
|
||||
|
||||
|
||||
@@ -146,30 +146,20 @@ void PlaylistEditor::Update()
|
||||
if (!Playlists->Empty() && Content->ReallyEmpty())
|
||||
{
|
||||
Content->Reset();
|
||||
MPD::SongList list;
|
||||
Mpd.GetPlaylistContent(locale_to_utf_cpy(Playlists->Current()), list);
|
||||
if (!list.empty())
|
||||
size_t plsize = 0;
|
||||
Mpd.GetPlaylistContent(locale_to_utf_cpy(Playlists->Current()), [this, &plsize](MPD::Song &&s) {
|
||||
Content->AddOption(s, myPlaylist->checkForSong(s));
|
||||
++plsize;
|
||||
});
|
||||
if (plsize > 0)
|
||||
{
|
||||
std::string title = Config.titles_visibility ? "Playlist's content (" + IntoStr(list.size()) + " item" + (list.size() == 1 ? ")" : "s)") : "";
|
||||
std::string title = Config.titles_visibility ? "Playlist content (" + IntoStr(plsize) + " item" + (plsize == 1 ? ")" : "s)") : "";
|
||||
title.resize(Content->GetWidth());
|
||||
Content->SetTitle(title);
|
||||
}
|
||||
else
|
||||
Content->SetTitle(Config.titles_visibility ? "Playlist's content" : "");
|
||||
bool bold = 0;
|
||||
for (auto 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;
|
||||
}
|
||||
Content->SetTitle(Config.titles_visibility ? "Playlist content" : "");
|
||||
|
||||
Content->Window::Clear();
|
||||
Content->Display();
|
||||
}
|
||||
|
||||
@@ -187,7 +187,7 @@ void SearchEngine::EnterPressed()
|
||||
}
|
||||
else
|
||||
{
|
||||
bool res = myPlaylist->Add(w->Current().song(), 1, 1);
|
||||
bool res = myPlaylist->Add(w->Current().song(), w->isBold(), 1);
|
||||
w->Bold(w->Choice(), res);
|
||||
}
|
||||
|
||||
@@ -207,7 +207,7 @@ void SearchEngine::SpacePressed()
|
||||
return;
|
||||
}
|
||||
|
||||
bool res = myPlaylist->Add(w->Current().song(), 0, 0);
|
||||
bool res = myPlaylist->Add(w->Current().song(), w->isBold(), 0);
|
||||
w->Bold(w->Choice(), res);
|
||||
w->Scroll(wDown);
|
||||
}
|
||||
@@ -383,16 +383,19 @@ void SearchEngine::Search()
|
||||
Mpd.AddSearch(MPD_TAG_DATE, itsConstraints[9]);
|
||||
if (!itsConstraints[10].empty())
|
||||
Mpd.AddSearch(MPD_TAG_COMMENT, itsConstraints[10]);
|
||||
MPD::SongList results;
|
||||
Mpd.CommitSearch(results);
|
||||
for (auto it = results.begin(); it != results.end(); ++it)
|
||||
w->AddOption(*it);
|
||||
Mpd.CommitSearchSongs([this](MPD::Song &&s) {
|
||||
w->AddOption(s);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
MPD::SongList list;
|
||||
if (Config.search_in_db)
|
||||
Mpd.GetDirectoryRecursive("/", list);
|
||||
{
|
||||
Mpd.GetDirectoryRecursive("/", [&list](MPD::Song &&s) {
|
||||
list.push_back(s);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
list.reserve(myPlaylist->Items->Size());
|
||||
|
||||
@@ -35,8 +35,12 @@ void ServerInfo::Init()
|
||||
SetDimensions();
|
||||
w = new Scrollpad((COLS-itsWidth)/2, (MainHeight-itsHeight)/2+MainStartY, itsWidth, itsHeight, "MPD server info", Config.main_color, Config.window_border);
|
||||
|
||||
Mpd.GetURLHandlers(itsURLHandlers);
|
||||
Mpd.GetTagTypes(itsTagTypes);
|
||||
Mpd.GetURLHandlers([this](std::string &&handler) {
|
||||
itsURLHandlers.push_back(handler);
|
||||
});
|
||||
Mpd.GetTagTypes([this](std::string &&tag_type) {
|
||||
itsTagTypes.push_back(tag_type);
|
||||
});
|
||||
|
||||
isInitialized = 1;
|
||||
}
|
||||
|
||||
@@ -222,31 +222,28 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *)
|
||||
|
||||
if (changed.Playlist)
|
||||
{
|
||||
bool was_filtered = myPlaylist->Items->isFiltered();
|
||||
bool is_filtered = myPlaylist->Items->isFiltered();
|
||||
myPlaylist->Items->ShowAll();
|
||||
MPD::SongList list;
|
||||
|
||||
size_t playlist_length = Mpd.GetPlaylistLength();
|
||||
if (playlist_length < myPlaylist->Items->Size())
|
||||
myPlaylist->Items->ResizeList(playlist_length);
|
||||
|
||||
Mpd.GetPlaylistChanges(Mpd.GetOldPlaylistID(), list);
|
||||
myPlaylist->Items->Reserve(playlist_length);
|
||||
for (MPD::SongList::const_iterator it = list.begin(); it != list.end(); ++it)
|
||||
{
|
||||
int pos = it->getPosition();
|
||||
Mpd.GetPlaylistChanges(Mpd.GetOldPlaylistID(), [](MPD::Song &&s) {
|
||||
int pos = s.getPosition();
|
||||
if (pos < int(myPlaylist->Items->Size()))
|
||||
{
|
||||
// if song's already in playlist, replace it with a new one
|
||||
myPlaylist->Items->at(pos) = *it;
|
||||
myPlaylist->Items->at(pos) = s;
|
||||
}
|
||||
else
|
||||
{
|
||||
// otherwise just add it to playlist
|
||||
myPlaylist->Items->AddOption(*it);
|
||||
myPlaylist->Items->AddOption(s);
|
||||
}
|
||||
}
|
||||
if (was_filtered)
|
||||
});
|
||||
|
||||
if (is_filtered)
|
||||
{
|
||||
myPlaylist->ApplyFilter(myPlaylist->Items->GetFilter());
|
||||
if (myPlaylist->Items->Empty())
|
||||
|
||||
@@ -236,11 +236,12 @@ void Visualizer::FindOutputID()
|
||||
itsOutputID = -1;
|
||||
if (!Config.visualizer_output_name.empty())
|
||||
{
|
||||
MPD::OutputList outputs;
|
||||
Mpd.GetOutputs(outputs);
|
||||
for (unsigned i = 0; i < outputs.size(); ++i)
|
||||
if (outputs[i].first == Config.visualizer_output_name)
|
||||
size_t i = 0;
|
||||
Mpd.GetOutputs([this, &i](MPD::Output &&o) {
|
||||
if (o.name() == Config.visualizer_output_name)
|
||||
itsOutputID = i;
|
||||
++i;
|
||||
});
|
||||
if (itsOutputID == -1)
|
||||
ShowMessage("There is no output named \"%s\"", Config.visualizer_output_name.c_str());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user