Song: add support for hiding duplicate tags
This commit is contained in:
@@ -405,6 +405,9 @@ bool Configuration::read(const std::vector<std::string> &config_paths, bool igno
|
||||
p.add("discard_colors_if_item_is_selected", yes_no(
|
||||
discard_colors_if_item_is_selected, true
|
||||
));
|
||||
p.add("show_duplicate_tags", yes_no(
|
||||
MPD::Song::ShowDuplicateTags, true
|
||||
));
|
||||
p.add("incremental_seeking", yes_no(
|
||||
incremental_seeking, true
|
||||
));
|
||||
|
||||
37
src/song.cpp
37
src/song.cpp
@@ -46,6 +46,8 @@ namespace MPD {
|
||||
|
||||
std::string Song::TagsSeparator = " | ";
|
||||
|
||||
bool Song::ShowDuplicateTags = true;
|
||||
|
||||
std::string Song::get(mpd_tag_type type, unsigned idx) const
|
||||
{
|
||||
std::string result;
|
||||
@@ -206,11 +208,38 @@ std::string MPD::Song::getTags(GetFunction f) const
|
||||
assert(m_song);
|
||||
unsigned idx = 0;
|
||||
std::string result;
|
||||
for (std::string tag; !(tag = (this->*f)(idx)).empty(); ++idx)
|
||||
if (ShowDuplicateTags)
|
||||
{
|
||||
if (!result.empty())
|
||||
result += TagsSeparator;
|
||||
result += tag;
|
||||
for (std::string tag; !(tag = (this->*f)(idx)).empty(); ++idx)
|
||||
{
|
||||
if (!result.empty())
|
||||
result += TagsSeparator;
|
||||
result += tag;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
bool already_present;
|
||||
// This is O(n^2), but it doesn't really matter as a list of tags will have
|
||||
// at most 2 or 3 items the vast majority of time.
|
||||
for (std::string tag; !(tag = (this->*f)(idx)).empty(); ++idx)
|
||||
{
|
||||
already_present = false;
|
||||
for (unsigned i = 0; i < idx; ++i)
|
||||
{
|
||||
if ((this->*f)(i) == tag)
|
||||
{
|
||||
already_present = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!already_present)
|
||||
{
|
||||
if (idx > 0)
|
||||
result += TagsSeparator;
|
||||
result += tag;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -103,6 +103,8 @@ struct Song
|
||||
|
||||
static std::string TagsSeparator;
|
||||
|
||||
static bool ShowDuplicateTags;
|
||||
|
||||
private:
|
||||
std::shared_ptr<mpd_song> m_song;
|
||||
size_t m_hash;
|
||||
|
||||
Reference in New Issue
Block a user