From 9ae8249b73f927bc640de0bd2590f507af2b60c0 Mon Sep 17 00:00:00 2001 From: unK Date: Sun, 14 Sep 2008 14:55:08 +0200 Subject: [PATCH] filter chars unallowed in filename / more actions for songs in tag editor --- src/ncmpcpp.cpp | 50 ++++++++++++++++++++++++++++++++++++++-------- src/tag_editor.cpp | 17 +++++++++++++++- src/tag_editor.h | 1 + 3 files changed, 59 insertions(+), 9 deletions(-) diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp index b4821bff..2da0909c 100644 --- a/src/ncmpcpp.cpp +++ b/src/ncmpcpp.cpp @@ -42,12 +42,14 @@ mvvline(main_start_y, middle_col_startx-1, 0, main_height); \ mPlaylistEditor->Display(redraw_screen) -#define REFRESH_ALBUM_EDITOR_SCREEN \ +#ifdef HAVE_TAGLIB_H +# define REFRESH_TAG_EDITOR_SCREEN \ mEditorLeftCol->Display(redraw_screen); \ mvvline(main_start_y, middle_col_startx-1, 0, main_height); \ mEditorTagTypes->Display(redraw_screen); \ mvvline(main_start_y, right_col_startx-1, 0, main_height); \ mEditorTags->Display(redraw_screen) +#endif // HAVE_TAGLIB_H ncmpcpp_config Config; ncmpcpp_keys Key; @@ -836,7 +838,7 @@ int main(int argc, char *argv[]) } else if (current_screen == csTagEditor) { - REFRESH_ALBUM_EDITOR_SCREEN; + REFRESH_TAG_EDITOR_SCREEN; } else # endif // HAVE_TAGLIB_H @@ -1027,6 +1029,10 @@ int main(int argc, char *argv[]) { REFRESH_PLAYLIST_EDITOR_SCREEN; } + else if (current_screen == csTagEditor) + { + REFRESH_TAG_EDITOR_SCREEN; + } break; } } @@ -1393,7 +1399,7 @@ int main(int argc, char *argv[]) __deal_with_filenames(list); current_screen = csTagEditor; redraw_screen = 1; - REFRESH_ALBUM_EDITOR_SCREEN; + REFRESH_TAG_EDITOR_SCREEN; } else if (wCurrent == mEditorTags) { @@ -2236,7 +2242,8 @@ int main(int argc, char *argv[]) || (wCurrent == mBrowser && mBrowser->Current().type == itSong) || (wCurrent == mSearcher && mSearcher->Current().first == ".") || (wCurrent == mLibSongs && !mLibSongs->Empty()) - || (wCurrent == mPlaylistEditor && !mPlaylistEditor->Empty())) + || (wCurrent == mPlaylistEditor && !mPlaylistEditor->Empty()) + || (wCurrent == mEditorTags && !mEditorTags->Empty())) { int id = wCurrent->GetChoice(); switch (current_screen) @@ -2256,6 +2263,9 @@ int main(int argc, char *argv[]) case csPlaylistEditor: edited_song = mPlaylistEditor->at(id); break; + case csTagEditor: + edited_song = mEditorTags->at(id); + break; default: break; } @@ -2310,7 +2320,8 @@ int main(int argc, char *argv[]) if ((wCurrent == mPlaylist && !mPlaylist->Empty()) || (wCurrent == mSearcher && mSearcher->Current().first == ".") || (wCurrent == mLibSongs && !mLibSongs->Empty()) - || (wCurrent == mPlaylistEditor && !mPlaylistEditor->Empty())) + || (wCurrent == mPlaylistEditor && !mPlaylistEditor->Empty()) + || (wCurrent == mEditorTags && !mEditorTags->Empty())) { int id = wCurrent->GetChoice(); Song *s; @@ -2328,6 +2339,9 @@ int main(int argc, char *argv[]) case csPlaylistEditor: s = &mPlaylistEditor->at(id); break; + case csTagEditor: + s = &mEditorTags->at(id); + break; default: break; } @@ -2720,13 +2734,20 @@ int main(int argc, char *argv[]) { REFRESH_PLAYLIST_EDITOR_SCREEN; } +# ifdef HAVE_TAGLIB_H + else if (current_screen == csTagEditor) + { + REFRESH_TAG_EDITOR_SCREEN; + } +# endif // HAVE_TAGLIB_H } else if ( (wCurrent == mPlaylist && !mPlaylist->Empty()) || (wCurrent == mBrowser && mBrowser->Current().type == itSong) || (wCurrent == mSearcher && mSearcher->Current().first == ".") || (wCurrent == mLibSongs && !mLibSongs->Empty()) - || (wCurrent == mPlaylistEditor && !mPlaylistEditor->Empty())) + || (wCurrent == mPlaylistEditor && !mPlaylistEditor->Empty()) + || (wCurrent == mEditorTags && !mEditorTags->Empty())) { Song *s; int id = wCurrent->GetChoice(); @@ -2747,6 +2768,9 @@ int main(int argc, char *argv[]) case csPlaylistEditor: s = &mPlaylistEditor->at(id); break; + case csTagEditor: + s = &mEditorTags->at(id); + break; default: break; } @@ -2777,13 +2801,20 @@ int main(int argc, char *argv[]) { REFRESH_PLAYLIST_EDITOR_SCREEN; } +# ifdef HAVE_TAGLIB_H + else if (current_screen == csTagEditor) + { + REFRESH_TAG_EDITOR_SCREEN; + } +# endif // HAVE_TAGLIB_H } else if ( (wCurrent == mPlaylist && !mPlaylist->Empty()) || (wCurrent == mBrowser && mBrowser->Current().type == itSong) || (wCurrent == mSearcher && mSearcher->Current().first == ".") || (wCurrent == mLibSongs && !mLibSongs->Empty()) - || (wCurrent == mPlaylistEditor && !mPlaylistEditor->Empty())) + || (wCurrent == mPlaylistEditor && !mPlaylistEditor->Empty()) + || (wCurrent == mEditorTags && !mEditorTags->Empty())) { Song *s; int id = wCurrent->GetChoice(); @@ -2804,6 +2835,9 @@ int main(int argc, char *argv[]) case csPlaylistEditor: s = &mPlaylistEditor->at(id); break; + case csTagEditor: + s = &mEditorTags->at(id); + break; default: break; } @@ -2954,7 +2988,7 @@ int main(int argc, char *argv[]) redraw_screen = 1; redraw_header = 1; - REFRESH_ALBUM_EDITOR_SCREEN; + REFRESH_TAG_EDITOR_SCREEN; if (mEditorTagTypes->Empty()) { diff --git a/src/tag_editor.cpp b/src/tag_editor.cpp index f68fcbe2..e3c5f047 100644 --- a/src/tag_editor.cpp +++ b/src/tag_editor.cpp @@ -177,6 +177,21 @@ SongSetFunction IntoSetFunction(char c) } } +string GenerateFilename(const Song &s, string &pattern) +{ + const string unallowed_chars = "\"*/:<>?\\|"; + string result = Window::OmitBBCodes(DisplaySong(s, &pattern)); + for (string::const_iterator it = unallowed_chars.begin(); it != unallowed_chars.end(); it++) + { + for (int i = 0; i < result.length(); i++) + { + if (result[i] == *it) + result.erase(result.begin()+i); + } + } + return result; +} + string ParseFilename(Song &s, string mask, bool preview) { std::stringstream result; @@ -376,7 +391,7 @@ void __deal_with_filenames(SongList &v) int last_dot = file.find_last_of("."); string extension = file.substr(last_dot); s.GetEmptyFields(1); - string new_file = Window::OmitBBCodes(DisplaySong(s, &pattern)); + string new_file = GenerateFilename(s, pattern); if (new_file.empty()) { if (preview) diff --git a/src/tag_editor.h b/src/tag_editor.h index 1f5f62ec..15e1e861 100644 --- a/src/tag_editor.h +++ b/src/tag_editor.h @@ -41,6 +41,7 @@ string DisplayTag(const Song &, void *, const Menu *); bool GetSongTags(Song &); bool WriteTags(Song &); +string GenerateFilename(const Song &, string &); string ParseFilename(Song &, string, bool); void __deal_with_filenames(SongList &);