diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp index b47f95fb..fe6132ff 100644 --- a/src/ncmpcpp.cpp +++ b/src/ncmpcpp.cpp @@ -1128,10 +1128,16 @@ int main(int argc, char *argv[]) if (WriteTags(s)) { ShowMessage("Tags updated!"); - Mpd->UpdateDirectory(s.GetDirectory()); - if (prev_screen == csSearcher) - mSearcher->Current().second = s; + if (s.IsFromDB()) + { + Mpd->UpdateDirectory(s.GetDirectory()); + if (prev_screen == csSearcher) + mSearcher->Current().second = s; + } + else + mPlaylist->Current() = s; } + else ShowMessage("Error writing tags!"); } case 15: @@ -2590,7 +2596,14 @@ int main(int argc, char *argv[]) redraw_header = 1; } else - ShowMessage("Cannot read file '" + Config.mpd_music_dir + edited_song.GetFile() + "'!"); + { + string message = "Cannot read file '"; + if (edited_song.IsFromDB()) + message += Config.mpd_music_dir; + message += edited_song.GetFile(); + message += "'!"; + ShowMessage(message); + } } else if (wCurrent == mEditorDirs) { diff --git a/src/song.cpp b/src/song.cpp index 73f97a50..f316d1f5 100644 --- a/src/song.cpp +++ b/src/song.cpp @@ -110,6 +110,12 @@ bool Song::Empty() const return !itsSong || (!itsSong->file && !itsSong->title && !itsSong->artist && !itsSong->album && !itsSong->date && !itsSong->track && !itsSong->genre && !itsSong->composer && !itsSong->performer && !itsSong->disc && !itsSong->comment); } +bool Song::IsFromDB() const +{ + const string &dir = GetDirectory(); + return dir[0] != '/' || dir == "/"; +} + string Song::GetFile() const { return !itsSong->file ? (itsGetEmptyFields ? "" : EMPTY_TAG) : itsSong->file; diff --git a/src/song.h b/src/song.h index 485ef676..4f8ad78d 100644 --- a/src/song.h +++ b/src/song.h @@ -85,6 +85,7 @@ class Song void GetEmptyFields(bool get) { itsGetEmptyFields = get; } void Clear(); bool Empty() const; + bool IsFromDB() const; bool IsStream() const { return isStream; } Song & operator=(const Song &); diff --git a/src/tag_editor.cpp b/src/tag_editor.cpp index 7f087f3d..72caf6a6 100644 --- a/src/tag_editor.cpp +++ b/src/tag_editor.cpp @@ -34,6 +34,9 @@ extern ncmpcpp_config Config; extern ncmpcpp_keys Key; +extern MPDConnection *Mpd; +extern Menu *mPlaylist; + extern Menu *mTagEditor; extern Window *wFooter; @@ -128,7 +131,10 @@ string DisplayTag(const Song &s, void *data, const Menu *) bool GetSongTags(Song &s) { - string path_to_file = Config.mpd_music_dir + s.GetFile(); + string path_to_file; + if (s.IsFromDB()) + path_to_file += Config.mpd_music_dir; + path_to_file += s.GetFile(); TagLib::FileRef f(path_to_file.c_str()); if (f.isNull()) @@ -172,7 +178,11 @@ bool GetSongTags(Song &s) bool WriteTags(Song &s) { using namespace TagLib; - string path_to_file = Config.mpd_music_dir + s.GetFile(); + string path_to_file; + bool file_is_from_db = s.IsFromDB(); + if (file_is_from_db) + path_to_file += Config.mpd_music_dir; + path_to_file += s.GetFile(); FileRef f(path_to_file.c_str()); if (!f.isNull()) { @@ -213,9 +223,28 @@ bool WriteTags(Song &s) s.GetEmptyFields(0); if (!s.GetNewName().empty()) { - string old_name = Config.mpd_music_dir + s.GetFile(); - string new_name = Config.mpd_music_dir + s.GetDirectory() + "/" + s.GetNewName(); - rename(old_name.c_str(), new_name.c_str()); + string old_name; + if (file_is_from_db) + old_name += Config.mpd_music_dir; + old_name += s.GetFile(); + string new_name; + if (file_is_from_db) + new_name += Config.mpd_music_dir; + new_name += s.GetDirectory() + "/" + s.GetNewName(); + if (rename(old_name.c_str(), new_name.c_str()) == 0 && !file_is_from_db) + { + // if we rename local file, it won't get updated + // so just remove it from playlist and add again + int pos = mPlaylist->GetChoice(); + Mpd->QueueDeleteSong(pos); + Mpd->CommitQueue(); + int id = Mpd->AddSong("file://" + new_name); + if (id >= 0) + { + s = mPlaylist->Back(); + Mpd->Move(s.GetPosition(), pos); + } + } } return true; }