diff options
author | Andrzej Rybczak <electricityispower@gmail.com> | 2012-09-10 23:44:35 +0200 |
---|---|---|
committer | Andrzej Rybczak <electricityispower@gmail.com> | 2012-09-10 23:44:35 +0200 |
commit | fe0d088faa240dc28b37105bbd3a189fe58da010 (patch) | |
tree | 45f2273ba705a4a60b103b749c7f03b3f640d64d | |
parent | 43778b3718e3f7e7c4c5ede7aa31ab73da57c03c (diff) |
mutable song: rename a few functions
-rw-r--r-- | src/actions.cpp | 2 | ||||
-rw-r--r-- | src/mutable_song.cpp | 13 | ||||
-rw-r--r-- | src/mutable_song.h | 17 | ||||
-rw-r--r-- | src/song.cpp | 5 | ||||
-rw-r--r-- | src/tag_editor.cpp | 6 | ||||
-rw-r--r-- | src/tiny_tag_editor.cpp | 2 |
6 files changed, 22 insertions, 23 deletions
diff --git a/src/actions.cpp b/src/actions.cpp index daee4796..4c017ad3 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -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)) diff --git a/src/mutable_song.cpp b/src/mutable_song.cpp index b11bc465..cd8024a9 100644 --- a/src/mutable_song.cpp +++ b/src/mutable_song.cpp @@ -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); diff --git a/src/mutable_song.h b/src/mutable_song.h index 95ee77e3..4e244303 100644 --- a/src/mutable_song.h +++ b/src/mutable_song.h @@ -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; diff --git a/src/song.cpp b/src/song.cpp index 534be967..6ae89d56 100644 --- a/src/song.cpp +++ b/src/song.cpp @@ -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 diff --git a/src/tag_editor.cpp b/src/tag_editor.cpp index a3685393..989210f3 100644 --- a/src/tag_editor.cpp +++ b/src/tag_editor.cpp @@ -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"; diff --git a/src/tiny_tag_editor.cpp b/src/tiny_tag_editor.cpp index 9202ddec..9c4174e7 100644 --- a/src/tiny_tag_editor.cpp +++ b/src/tiny_tag_editor.cpp @@ -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)); |