Media library: remove argument to SortSongs contructor to simplify sorting

This commit is contained in:
Andrzej Rybczak
2017-10-11 19:20:55 +02:00
parent 2cd5de9141
commit 464fd318c3

View File

@@ -99,20 +99,18 @@ struct SortSongs {
static const std::array<MPD::Song::GetFunction, 3> GetFuns; static const std::array<MPD::Song::GetFunction, 3> GetFuns;
LocaleStringComparison m_cmp; LocaleStringComparison m_cmp;
std::ptrdiff_t m_offset;
public: public:
SortSongs(bool disc_only = false) SortSongs()
: m_cmp(std::locale(), Config.ignore_leading_the), m_offset(disc_only ? 2 : 0) { } : m_cmp(std::locale(), Config.ignore_leading_the) { }
bool operator()(const SongItem &a, const SongItem &b) { bool operator()(const SongItem &a, const SongItem &b) {
return (*this)(a.value(), b.value()); return (*this)(a.value(), b.value());
} }
bool operator()(const MPD::Song &a, const MPD::Song &b) { bool operator()(const MPD::Song &a, const MPD::Song &b) {
int ret; int ret;
for (auto get = GetFuns.begin()+m_offset; get != GetFuns.end(); ++get) { for (auto get : GetFuns) {
ret = m_cmp(a.getTags(*get), ret = m_cmp(a.getTags(get), b.getTags(get));
b.getTags(*get));
if (ret != 0) if (ret != 0)
return ret < 0; return ret < 0;
} }
@@ -453,7 +451,7 @@ void MediaLibrary::update()
}; };
if (idx < Songs.size()) if (idx < Songs.size())
Songs.resizeList(idx); Songs.resizeList(idx);
std::sort(Songs.begin(), Songs.end(), SortSongs(!album.isAllTracksEntry())); std::sort(Songs.begin(), Songs.end(), SortSongs());
} }
} }