From e3e6aa09ccaa4496ff6f24e66a8a84dbcb13d40d Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Wed, 27 Aug 2014 06:09:22 +0200 Subject: [PATCH] tag editor: fix filename change detection --- src/display.cpp | 4 ++-- src/mutable_song.cpp | 18 +++++++++--------- src/mutable_song.h | 6 +++--- src/tag_editor.cpp | 10 +++++----- src/tags.cpp | 4 ++-- src/tiny_tag_editor.cpp | 6 +++--- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/display.cpp b/src/display.cpp index 1e10cecc..4b2ec515 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -371,12 +371,12 @@ void Display::Tags(NC::Menu &menu) } else if (i == 12) { - if (s.getNewURI().empty()) + if (s.getNewName().empty()) menu << Charset::utf8ToLocale(s.getName()); else menu << Charset::utf8ToLocale(s.getName()) << Config.color2 << " -> " << NC::Color::End - << Charset::utf8ToLocale(s.getNewURI()); + << Charset::utf8ToLocale(s.getNewName()); } } #endif // HAVE_TAGLIB_H diff --git a/src/mutable_song.cpp b/src/mutable_song.cpp index 7750f806..6b99e886 100644 --- a/src/mutable_song.cpp +++ b/src/mutable_song.cpp @@ -18,6 +18,7 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ +#include "statusbar.h" #include #include "mutable_song.h" @@ -138,18 +139,17 @@ void MutableSong::setComment(const std::string &value, unsigned idx) replaceTag(MPD_TAG_COMMENT, Song::getComment(idx), value, idx); } -const std::string &MutableSong::getNewURI() const +const std::string &MutableSong::getNewName() const { - return m_uri; + return m_name; } -void MutableSong::setNewURI(const std::string &value) +void MutableSong::setNewName(const std::string &value) { - std::string orig_uri = getURI(); - if (orig_uri == value) - m_uri.clear(); + if (getName() == value) + m_name.clear(); else - m_uri = value; + m_name = value; } unsigned MutableSong::getDuration() const @@ -191,12 +191,12 @@ void MutableSong::setTags(SetFunction set, const std::string &value, const std:: bool MutableSong::isModified() const { - return !m_uri.empty() || !m_tags.empty(); + return !m_name.empty() || !m_tags.empty(); } void MutableSong::clearModifications() { - m_uri.clear(); + m_name.clear(); m_tags.clear(); } diff --git a/src/mutable_song.h b/src/mutable_song.h index c6344dd4..96ffdfbb 100644 --- a/src/mutable_song.h +++ b/src/mutable_song.h @@ -58,8 +58,8 @@ struct MutableSong : public Song void setDisc(const std::string &value, unsigned idx = 0); void setComment(const std::string &value, unsigned idx = 0); - const std::string &getNewURI() const; - void setNewURI(const std::string &value); + const std::string &getNewName() const; + void setNewName(const std::string &value); virtual unsigned getDuration() const OVERRIDE; virtual time_t getMTime() const OVERRIDE; @@ -105,7 +105,7 @@ private: return result; } - std::string m_uri; + std::string m_name; time_t m_mtime; unsigned m_duration; std::map m_tags; diff --git a/src/tag_editor.cpp b/src/tag_editor.cpp index 04cf6278..397da12c 100644 --- a/src/tag_editor.cpp +++ b/src/tag_editor.cpp @@ -398,7 +398,7 @@ void TagEditor::enterPressed() success = 0; } if (!FParserUsePreview) - s.setNewURI(new_file + extension); + s.setNewName(new_file + extension); *FParserPreview << file << Config.color2 << " -> " << NC::Color::End; if (new_file.empty()) *FParserPreview << Config.empty_tags_color << Config.empty_tag << NC::Color::End; @@ -523,7 +523,7 @@ void TagEditor::enterPressed() else if (w == Tags) { MPD::MutableSong &s = Tags->current().value(); - std::string old_name = s.getNewURI().empty() ? s.getName() : s.getNewURI(); + std::string old_name = s.getNewName().empty() ? s.getName() : s.getNewName(); size_t last_dot = old_name.rfind("."); std::string extension = old_name.substr(last_dot); old_name = old_name.substr(0, last_dot); @@ -531,8 +531,8 @@ void TagEditor::enterPressed() Statusbar::put() << NC::Format::Bold << "New filename: " << NC::Format::NoBold; std::string new_name = wFooter->getString(old_name); Statusbar::unlock(); - if (!new_name.empty() && new_name != old_name) - s.setNewURI(new_name + extension); + if (!new_name.empty()) + s.setNewName(new_name + extension); Tags->scroll(NC::Scroll::Down); } } @@ -1203,7 +1203,7 @@ std::string SongToString(const MPD::MutableSong &s) if (i < 11) result = (s.*SongInfo::Tags[i].Get)(0); else if (i == 12) - result = s.getNewURI().empty() ? s.getName() : s.getName() + " -> " + s.getNewURI(); + result = s.getNewName().empty() ? s.getName() : s.getName() + " -> " + s.getNewName(); return result.empty() ? Config.empty_tag : result; } diff --git a/src/tags.cpp b/src/tags.cpp index cad8b207..7405cde3 100644 --- a/src/tags.cpp +++ b/src/tags.cpp @@ -299,12 +299,12 @@ bool write(MPD::MutableSong &s) if (!f.save()) return false; - if (!s.getNewURI().empty()) + if (!s.getNewName().empty()) { std::string new_name; if (s.isFromDatabase()) new_name += Config.mpd_music_dir; - new_name += s.getDirectory() + "/" + s.getNewURI(); + new_name += s.getDirectory() + "/" + s.getNewName(); if (std::rename(old_name.c_str(), new_name.c_str()) == 0 && !s.isFromDatabase()) { // FIXME diff --git a/src/tiny_tag_editor.cpp b/src/tiny_tag_editor.cpp index 00d25b0b..eac7104b 100644 --- a/src/tiny_tag_editor.cpp +++ b/src/tiny_tag_editor.cpp @@ -115,14 +115,14 @@ void TinyTagEditor::enterPressed() else if (option == 20) { Statusbar::put() << NC::Format::Bold << "Filename: " << NC::Format::NoBold; - std::string filename = itsEdited.getNewURI().empty() ? itsEdited.getName() : itsEdited.getNewURI(); + std::string filename = itsEdited.getNewName().empty() ? itsEdited.getName() : itsEdited.getNewName(); size_t dot = filename.rfind("."); std::string extension = filename.substr(dot); filename = filename.substr(0, dot); std::string new_name = Global::wFooter->getString(filename); - itsEdited.setNewURI(new_name + extension); + itsEdited.setNewName(new_name + extension); w.at(option).value().clear(); - w.at(option).value() << NC::Format::Bold << "Filename:" << NC::Format::NoBold << ' ' << (itsEdited.getNewURI().empty() ? itsEdited.getName() : itsEdited.getNewURI()); + w.at(option).value() << NC::Format::Bold << "Filename:" << NC::Format::NoBold << ' ' << (itsEdited.getNewName().empty() ? itsEdited.getName() : itsEdited.getNewName()); } Statusbar::unlock();