mutable song: rename a few functions

This commit is contained in:
Andrzej Rybczak
2012-09-10 23:44:35 +02:00
parent 43778b3718
commit fe0d088faa
6 changed files with 22 additions and 23 deletions

View File

@@ -1379,7 +1379,7 @@ void EditLibraryTag::Run()
for (auto s = songs.begin(); s != songs.end(); ++s)
{
MPD::MutableSong es = *s;
es.setTag(set, new_tag);
es.setTags(set, new_tag);
ShowMessage("Updating tags in \"%s\"...", es.getName().c_str());
std::string path = Config.mpd_music_dir + es.getURI();
if (!TagEditor::WriteTags(es))

View File

@@ -166,7 +166,7 @@ void MutableSong::setDuration(unsigned int duration)
m_duration = duration;
}
void MutableSong::setTag(SetFunction set, const std::string &value, const std::string &delimiter)
void MutableSong::setTags(SetFunction set, const std::string &value, const std::string &delimiter)
{
auto tags = split(value, delimiter);
for (size_t i = 0; i < tags.size(); ++i)
@@ -184,17 +184,6 @@ void MutableSong::clearModifications()
m_tags.clear();
}
std::string MutableSong::getTag(mpd_tag_type tag_type, std::function<std::string()> orig_value, unsigned idx) const
{
auto it = m_tags.find(Tag(tag_type, idx));
std::string result;
if (it == m_tags.end())
result = orig_value();
else
result = it->second;
return result;
}
void MutableSong::replaceTag(mpd_tag_type tag_type, std::string &&orig_value, const std::string &value, unsigned idx)
{
Tag tag(tag_type, idx);

View File

@@ -63,7 +63,7 @@ struct MutableSong : public Song
virtual unsigned getDuration() const;
void setDuration(unsigned duration);
void setTag(SetFunction set, const std::string &value, const std::string &delimiter = "");
void setTags(SetFunction set, const std::string &value, const std::string &delimiter = "");
bool isModified() const;
void clearModifications();
@@ -88,8 +88,19 @@ private:
unsigned m_idx;
};
std::string getTag(mpd_tag_type tag_type, std::function<std::string()> orig_value, unsigned idx) const;
void replaceTag(mpd_tag_type tag_type, std::string &&orig_value, const std::string &value, unsigned idx);
void replaceTag(mpd_tag_type tag_type, std::string &&orig_value,
const std::string &value, unsigned idx);
template <typename F>
std::string getTag(mpd_tag_type tag_type, F orig_value, unsigned idx) const {
auto it = m_tags.find(Tag(tag_type, idx));
std::string result;
if (it == m_tags.end())
result = orig_value();
else
result = it->second;
return result;
}
std::string m_uri;
unsigned m_duration;

View File

@@ -123,9 +123,8 @@ std::string Song::getTrack(unsigned idx) const
std::string track = getTag(MPD_TAG_TRACK, idx);
if ((track.length() == 1 && track[0] != '0')
|| (track.length() > 3 && track[1] == '/'))
return "0"+track;
else
return track;
track = "0"+track;
return track;
}
std::string Song::getTrackNumber(unsigned idx) const

View File

@@ -525,7 +525,7 @@ void TagEditor::EnterPressed()
std::string new_tag = wFooter->getString(Tags->current().value().getTags(get));
UnlockStatusbar();
for (auto it = EditedSongs.begin(); it != EditedSongs.end(); ++it)
(*it)->setTag(set, new_tag);
(*it)->setTags(set, new_tag);
}
else if (w == Tags)
{
@@ -534,7 +534,7 @@ void TagEditor::EnterPressed()
std::string new_tag = wFooter->getString(Tags->current().value().getTags(get));
UnlockStatusbar();
if (new_tag != Tags->current().value().getTags(get))
Tags->current().value().setTag(set, new_tag);
Tags->current().value().setTags(set, new_tag);
Tags->scroll(NC::wDown);
}
}
@@ -1291,7 +1291,7 @@ std::string ParseFilename(MPD::MutableSong &s, std::string mask, bool preview)
{
MPD::MutableSong::SetFunction set = IntoSetFunction(it->first);
if (set)
s.setTag(set, it->second);
s.setTags(set, it->second);
}
else
result << "%" << it->first << ": " << it->second << "\n";

View File

@@ -109,7 +109,7 @@ void TinyTagEditor::EnterPressed()
{
size_t pos = option-8;
Statusbar() << NC::fmtBold << SongInfo::Tags[pos].Name << ": " << NC::fmtBoldEnd;
itsEdited.setTag(SongInfo::Tags[pos].Set, Global::wFooter->getString(itsEdited.getTags(SongInfo::Tags[pos].Get)));
itsEdited.setTags(SongInfo::Tags[pos].Set, Global::wFooter->getString(itsEdited.getTags(SongInfo::Tags[pos].Get)));
w->at(option).value().clear();
w->at(option).value() << NC::fmtBold << SongInfo::Tags[pos].Name << ':' << NC::fmtBoldEnd << ' ';
ShowTag(w->at(option).value(), itsEdited.getTags(SongInfo::Tags[pos].Get));