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