mpd: Item: do not wrap Song in shared_ptr
This commit is contained in:
@@ -675,7 +675,7 @@ void DeleteBrowserItems::run()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
MPD::Item &item = myBrowser->main().current().value();
|
MPD::Item &item = myBrowser->main().current().value();
|
||||||
std::string iname = item.type == MPD::itSong ? item.song->getName() : item.name;
|
std::string iname = item.type == MPD::itSong ? item.song.getName() : item.name;
|
||||||
question = boost::format("Delete %1% \"%2%\"?")
|
question = boost::format("Delete %1% \"%2%\"?")
|
||||||
% itemTypeToString(item.type) % wideShorten(iname, COLS-question.size()-10);
|
% itemTypeToString(item.type) % wideShorten(iname, COLS-question.size()-10);
|
||||||
}
|
}
|
||||||
@@ -689,7 +689,7 @@ void DeleteBrowserItems::run()
|
|||||||
for (const auto &item : list)
|
for (const auto &item : list)
|
||||||
{
|
{
|
||||||
const MPD::Item &i = item->value();
|
const MPD::Item &i = item->value();
|
||||||
std::string iname = i.type == MPD::itSong ? i.song->getName() : i.name;
|
std::string iname = i.type == MPD::itSong ? i.song.getName() : i.name;
|
||||||
std::string errmsg;
|
std::string errmsg;
|
||||||
if (myBrowser->deleteItem(i, errmsg))
|
if (myBrowser->deleteItem(i, errmsg))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ void Browser::enterPressed()
|
|||||||
}
|
}
|
||||||
case itSong:
|
case itSong:
|
||||||
{
|
{
|
||||||
addSongToPlaylist(*item.song, true, -1);
|
addSongToPlaylist(item.song, true, -1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case itPlaylist:
|
case itPlaylist:
|
||||||
@@ -184,7 +184,7 @@ void Browser::spacePressed()
|
|||||||
myBrowser->GetLocalDirectory(items, item.name, 1);
|
myBrowser->GetLocalDirectory(items, item.name, 1);
|
||||||
list.reserve(items.size());
|
list.reserve(items.size());
|
||||||
for (MPD::ItemList::const_iterator it = items.begin(); it != items.end(); ++it)
|
for (MPD::ItemList::const_iterator it = items.begin(); it != items.end(); ++it)
|
||||||
list.push_back(*it->song);
|
list.push_back(it->song);
|
||||||
success = addSongsToPlaylist(list.begin(), list.end(), false, -1);
|
success = addSongsToPlaylist(list.begin(), list.end(), false, -1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -200,7 +200,7 @@ void Browser::spacePressed()
|
|||||||
}
|
}
|
||||||
case itSong:
|
case itSong:
|
||||||
{
|
{
|
||||||
addSongToPlaylist(*item.song, false);
|
addSongToPlaylist(item.song, false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case itPlaylist:
|
case itPlaylist:
|
||||||
@@ -329,7 +329,7 @@ ProxySongList Browser::proxySongList()
|
|||||||
return ProxySongList(w, [](NC::Menu<MPD::Item>::Item &item) -> MPD::Song * {
|
return ProxySongList(w, [](NC::Menu<MPD::Item>::Item &item) -> MPD::Song * {
|
||||||
MPD::Song *ptr = 0;
|
MPD::Song *ptr = 0;
|
||||||
if (item.value().type == itSong)
|
if (item.value().type == itSong)
|
||||||
ptr = item.value().song.get();
|
ptr = &item.value().song;
|
||||||
return ptr;
|
return ptr;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -356,7 +356,7 @@ MPD::SongList Browser::getSelectedSongs()
|
|||||||
MPD::ItemList list;
|
MPD::ItemList list;
|
||||||
GetLocalDirectory(list, item.name, true);
|
GetLocalDirectory(list, item.name, true);
|
||||||
for (auto it = list.begin(); it != list.end(); ++it)
|
for (auto it = list.begin(); it != list.end(); ++it)
|
||||||
result.push_back(*it->song);
|
result.push_back(it->song);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
# endif // !WIN32
|
# endif // !WIN32
|
||||||
@@ -365,7 +365,7 @@ MPD::SongList Browser::getSelectedSongs()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (item.type == itSong)
|
else if (item.type == itSong)
|
||||||
result.push_back(*item.song);
|
result.push_back(item.song);
|
||||||
else if (item.type == itPlaylist)
|
else if (item.type == itPlaylist)
|
||||||
{
|
{
|
||||||
std::copy(
|
std::copy(
|
||||||
@@ -404,7 +404,7 @@ void Browser::LocateSong(const MPD::Song &s)
|
|||||||
GetDirectory(s.getDirectory());
|
GetDirectory(s.getDirectory());
|
||||||
for (size_t i = 0; i < w.size(); ++i)
|
for (size_t i = 0; i < w.size(); ++i)
|
||||||
{
|
{
|
||||||
if (w[i].value().type == itSong && s == *w[i].value().song)
|
if (w[i].value().type == itSong && s == w[i].value().song)
|
||||||
{
|
{
|
||||||
w.highlight(i);
|
w.highlight(i);
|
||||||
break;
|
break;
|
||||||
@@ -466,7 +466,7 @@ void Browser::GetDirectory(std::string dir, std::string subdir)
|
|||||||
}
|
}
|
||||||
case itSong:
|
case itSong:
|
||||||
{
|
{
|
||||||
w.addItem(*it, myPlaylist->checkForSong(*it->song));
|
w.addItem(*it, myPlaylist->checkForSong(it->song));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -502,8 +502,9 @@ void Browser::GetLocalDirectory(MPD::ItemList &v, const std::string &directory,
|
|||||||
{
|
{
|
||||||
item.type = itSong;
|
item.type = itSong;
|
||||||
mpd_pair file_pair = { "file", e.path().native().c_str() };
|
mpd_pair file_pair = { "file", e.path().native().c_str() };
|
||||||
MPD::MutableSong *s = new MPD::MutableSong(mpd_song_begin(&file_pair));
|
item.song = mpd_song_begin(&file_pair);
|
||||||
item.song = std::shared_ptr<MPD::Song>(s);
|
// FIXME no tag reading for now
|
||||||
|
/*
|
||||||
# ifdef HAVE_TAGLIB_H
|
# ifdef HAVE_TAGLIB_H
|
||||||
if (!recursively)
|
if (!recursively)
|
||||||
{
|
{
|
||||||
@@ -511,6 +512,7 @@ void Browser::GetLocalDirectory(MPD::ItemList &v, const std::string &directory,
|
|||||||
Tags::read(*s);
|
Tags::read(*s);
|
||||||
}
|
}
|
||||||
# endif // HAVE_TAGLIB_H
|
# endif // HAVE_TAGLIB_H
|
||||||
|
*/
|
||||||
v.push_back(item);
|
v.push_back(item);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -585,8 +587,8 @@ bool Browser::deleteItem(const MPD::Item &item, std::string &errmsg)
|
|||||||
std::string path;
|
std::string path;
|
||||||
if (!isLocal())
|
if (!isLocal())
|
||||||
path = Config.mpd_music_dir;
|
path = Config.mpd_music_dir;
|
||||||
path += item.type == itSong ? item.song->getURI() : item.name;
|
path += item.type == itSong ? item.song.getURI() : item.name;
|
||||||
|
|
||||||
bool rv;
|
bool rv;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -636,10 +638,10 @@ std::string ItemToString(const MPD::Item &item)
|
|||||||
switch (Config.browser_display_mode)
|
switch (Config.browser_display_mode)
|
||||||
{
|
{
|
||||||
case DisplayMode::Classic:
|
case DisplayMode::Classic:
|
||||||
result = item.song->toString(Config.song_list_format_dollar_free, Config.tags_separator);
|
result = item.song.toString(Config.song_list_format_dollar_free, Config.tags_separator);
|
||||||
break;
|
break;
|
||||||
case DisplayMode::Columns:
|
case DisplayMode::Columns:
|
||||||
result = item.song->toString(Config.song_in_columns_to_string_format, Config.tags_separator);
|
result = item.song.toString(Config.song_in_columns_to_string_format, Config.tags_separator);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -395,10 +395,10 @@ void Display::Items(NC::Menu<MPD::Item> &menu, const ProxySongList &pl)
|
|||||||
switch (Config.browser_display_mode)
|
switch (Config.browser_display_mode)
|
||||||
{
|
{
|
||||||
case DisplayMode::Classic:
|
case DisplayMode::Classic:
|
||||||
showSongs(menu, *item.song, pl, Config.song_list_format);
|
showSongs(menu, item.song, pl, Config.song_list_format);
|
||||||
break;
|
break;
|
||||||
case DisplayMode::Columns:
|
case DisplayMode::Columns:
|
||||||
showSongsInColumns(menu, *item.song, pl);
|
showSongsInColumns(menu, item.song, pl);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -691,7 +691,7 @@ void Connection::GetDirectory(const std::string &directory, ItemConsumer f)
|
|||||||
it.type = itDirectory;
|
it.type = itDirectory;
|
||||||
break;
|
break;
|
||||||
case MPD_ENTITY_TYPE_SONG:
|
case MPD_ENTITY_TYPE_SONG:
|
||||||
it.song = std::make_shared<Song>(Song(mpd_song_dup(mpd_entity_get_song(item))));
|
it.song = Song(mpd_song_dup(mpd_entity_get_song(item)));
|
||||||
it.type = itSong;
|
it.type = itSong;
|
||||||
break;
|
break;
|
||||||
case MPD_ENTITY_TYPE_PLAYLIST:
|
case MPD_ENTITY_TYPE_PLAYLIST:
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ private:
|
|||||||
|
|
||||||
struct Item
|
struct Item
|
||||||
{
|
{
|
||||||
std::shared_ptr<Song> song;
|
Song song;
|
||||||
ItemType type;
|
ItemType type;
|
||||||
std::string name;
|
std::string name;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -69,14 +69,14 @@ bool LocaleBasedItemSorting::operator()(const MPD::Item &a, const MPD::Item &b)
|
|||||||
switch (m_sort_mode)
|
switch (m_sort_mode)
|
||||||
{
|
{
|
||||||
case SortMode::Name:
|
case SortMode::Name:
|
||||||
result = m_cmp(*a.song, *b.song);
|
result = m_cmp(a.song, b.song);
|
||||||
break;
|
break;
|
||||||
case SortMode::ModificationTime:
|
case SortMode::ModificationTime:
|
||||||
result = a.song->getMTime() > b.song->getMTime();
|
result = a.song.getMTime() > b.song.getMTime();
|
||||||
break;
|
break;
|
||||||
case SortMode::CustomFormat:
|
case SortMode::CustomFormat:
|
||||||
result = m_cmp(a.song->toString(Config.browser_sort_format, Config.tags_separator),
|
result = m_cmp(a.song.toString(Config.browser_sort_format, Config.tags_separator),
|
||||||
b.song->toString(Config.browser_sort_format, Config.tags_separator));
|
b.song.toString(Config.browser_sort_format, Config.tags_separator));
|
||||||
break;
|
break;
|
||||||
case SortMode::NoOp:
|
case SortMode::NoOp:
|
||||||
throw std::logic_error("can't sort with NoOp sorting mode");
|
throw std::logic_error("can't sort with NoOp sorting mode");
|
||||||
|
|||||||
Reference in New Issue
Block a user