diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp index d74c8561..859e5411 100644 --- a/src/ncmpcpp.cpp +++ b/src/ncmpcpp.cpp @@ -1693,6 +1693,22 @@ int main(int argc, char *argv[]) mEditorTags->Clear(0); continue; } + case 13: // capitalize first letters + { + ShowMessage("Processing..."); + for (SongList::iterator it = list.begin(); it != list.end(); it++) + CapitalizeFirstLetters(**it); + ShowMessage("Done!"); + break; + } + case 14: // lower all letters + { + ShowMessage("Processing..."); + for (SongList::iterator it = list.begin(); it != list.end(); it++) + LowerAllLetters(**it); + ShowMessage("Done!"); + break; + } default: break; } @@ -3671,8 +3687,9 @@ int main(int argc, char *argv[]) mEditorTagTypes->AddSeparator(); mEditorTagTypes->AddOption("Reset"); mEditorTagTypes->AddOption("Save"); - /*mEditorTagTypes->AddSeparator(); - mEditorTagTypes->AddOption("Capitalize first letters");*/ + mEditorTagTypes->AddSeparator(); + mEditorTagTypes->AddOption("Capitalize First Letters"); + mEditorTagTypes->AddOption("lower all letters"); } wCurrent = mEditorLeftCol; diff --git a/src/tag_editor.cpp b/src/tag_editor.cpp index 39b38e05..d5840724 100644 --- a/src/tag_editor.cpp +++ b/src/tag_editor.cpp @@ -161,6 +161,21 @@ namespace } return result.str(); } + + string tag_capitalize_first_letters(const string &s) + { + if (s.empty()) + return ""; + string result = s; + if (isalpha(result[0])) + result[0] = toupper(result[0]); + for (string::iterator it = result.begin()+1; it != result.end(); it++) + { + if (isalpha(*it) && *(it-1) == ' ') + *it = toupper(*it); + } + return result; + } } SongSetFunction IntoSetFunction(mpd_TagItems tag) @@ -684,5 +699,52 @@ void __deal_with_filenames(SongList &v) delete Preview; } +void CapitalizeFirstLetters(Song &s) +{ + s.SetTitle(tag_capitalize_first_letters(s.GetTitle())); + s.SetArtist(tag_capitalize_first_letters(s.GetArtist())); + s.SetAlbum(tag_capitalize_first_letters(s.GetAlbum())); + s.SetGenre(tag_capitalize_first_letters(s.GetGenre())); + s.SetComposer(tag_capitalize_first_letters(s.GetComposer())); + s.SetPerformer(tag_capitalize_first_letters(s.GetPerformer())); + s.SetDisc(tag_capitalize_first_letters(s.GetDisc())); + s.SetComment(tag_capitalize_first_letters(s.GetComment())); +} + +void LowerAllLetters(Song &s) +{ + string conv = s.GetTitle(); + ToLower(conv); + s.SetTitle(conv); + + conv = s.GetArtist(); + ToLower(conv); + s.SetArtist(conv); + + conv = s.GetAlbum(); + ToLower(conv); + s.SetAlbum(conv); + + conv = s.GetGenre(); + ToLower(conv); + s.SetGenre(conv); + + conv = s.GetComposer(); + ToLower(conv); + s.SetComposer(conv); + + conv = s.GetPerformer(); + ToLower(conv); + s.SetPerformer(conv); + + conv = s.GetDisc(); + ToLower(conv); + s.SetDisc(conv); + + conv = s.GetComment(); + ToLower(conv); + s.SetComment(conv); +} + #endif diff --git a/src/tag_editor.h b/src/tag_editor.h index 44048fff..c26a14d2 100644 --- a/src/tag_editor.h +++ b/src/tag_editor.h @@ -47,6 +47,9 @@ bool WriteTags(Song &); void __deal_with_filenames(MPD::SongList &); +void CapitalizeFirstLetters(Song &); +void LowerAllLetters(Song &); + #endif #endif