tag editor: fix filename change detection
This commit is contained in:
@@ -371,12 +371,12 @@ void Display::Tags(NC::Menu<MPD::MutableSong> &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
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#include "statusbar.h"
|
||||
#include <boost/algorithm/string/split.hpp>
|
||||
#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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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<Tag, std::string> m_tags;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user