From 133554bfea16a737eac10ee1af00e37aa2fccc17 Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Sat, 8 Dec 2012 16:34:46 +0100 Subject: [PATCH] settings: new configuration variable: generate_win32_compatible_filenames --- doc/config | 2 ++ doc/ncmpcpp.1 | 3 +++ src/lastfm.cpp | 2 +- src/lyrics.cpp | 2 +- src/settings.cpp | 5 +++++ src/settings.h | 1 + src/tag_editor.cpp | 2 +- src/utility/string.cpp | 4 ++-- src/utility/string.h | 2 +- 9 files changed, 17 insertions(+), 6 deletions(-) diff --git a/doc/config b/doc/config index 19e11abe..0b3ed85b 100644 --- a/doc/config +++ b/doc/config @@ -345,6 +345,8 @@ # #store_lyrics_in_song_dir = "no" # +#generate_win32_compatible_filenames = "yes" +# ## ## Note: If you set this variable, ncmpcpp will try to ## get info from last.fm in language you set and if it diff --git a/doc/ncmpcpp.1 b/doc/ncmpcpp.1 index c1dd91cd..07363063 100644 --- a/doc/ncmpcpp.1 +++ b/doc/ncmpcpp.1 @@ -258,6 +258,9 @@ If enabled, each time song changes lyrics fetcher will be automatically run in b .B store_lyrics_in_song_dir = yes/no If enabled, lyrics will be saved in song's directory, otherwise in ~/.lyrics. Note that it needs properly set mpd_music_dir. .TP +.B generate_win32_compatible_filenames = yes/no +If set to yes, filenames generated by ncmpcpp (with tag editor, for lyrics, artists etc.) will not contain the following characters: /\?*:|"<> - otherwise only slash (/) will not be used. +.TP .B lastfm_preferred_language = ISO 639 alpha-2 language code If set, ncmpcpp will try to get info from last.fm in language you set and if it fails, it will fall back to english. Otherwise it will use english the first time. .TP diff --git a/src/lastfm.cpp b/src/lastfm.cpp index a10fbe9e..d632c6a9 100644 --- a/src/lastfm.cpp +++ b/src/lastfm.cpp @@ -115,7 +115,7 @@ void Lastfm::Load() std::string artist = itsArgs.find("artist")->second; std::string file = boost::locale::to_lower(artist + ".txt"); - removeInvalidCharsFromFilename(file); + removeInvalidCharsFromFilename(file, Config.generate_win32_compatible_filenames); itsFilename = itsFolder + "/" + file; diff --git a/src/lyrics.cpp b/src/lyrics.cpp index c37c698f..62ceb3a1 100644 --- a/src/lyrics.cpp +++ b/src/lyrics.cpp @@ -290,7 +290,7 @@ std::string Lyrics::GenerateFilename(const MPD::Song &s) file += " - "; file += s.getTitle(); file += ".txt"; - removeInvalidCharsFromFilename(file); + removeInvalidCharsFromFilename(file, Config.generate_win32_compatible_filenames); filename = Config.lyrics_directory; filename += "/"; filename += file; diff --git a/src/settings.cpp b/src/settings.cpp index 692d0198..18f12e65 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -215,6 +215,7 @@ void Configuration::SetDefaults() tag_editor_extended_numeration = false; discard_colors_if_item_is_selected = true; store_lyrics_in_song_dir = false; + generate_win32_compatible_filenames = true; ask_for_locked_screen_width_part = true; progressbar_boldness = true; set_window_title = true; @@ -764,6 +765,10 @@ void Configuration::Read() else store_lyrics_in_song_dir = v == "yes"; } + else if (name == "generate_win32_compatible_filenames") + { + generate_win32_compatible_filenames = v == "yes"; + } else if (name == "enable_window_title") { set_window_title = v == "yes"; diff --git a/src/settings.h b/src/settings.h index 6be969ff..5b67dd75 100644 --- a/src/settings.h +++ b/src/settings.h @@ -181,6 +181,7 @@ struct Configuration bool tag_editor_extended_numeration; bool discard_colors_if_item_is_selected; bool store_lyrics_in_song_dir; + bool generate_win32_compatible_filenames; bool ask_for_locked_screen_width_part; bool progressbar_boldness; diff --git a/src/tag_editor.cpp b/src/tag_editor.cpp index 6ac1f049..bc3780d1 100644 --- a/src/tag_editor.cpp +++ b/src/tag_editor.cpp @@ -1099,7 +1099,7 @@ MPD::MutableSong::SetFunction IntoSetFunction(char c) std::string GenerateFilename(const MPD::MutableSong &s, const std::string &pattern) { std::string result = s.toString(pattern, Config.tags_separator); - removeInvalidCharsFromFilename(result); + removeInvalidCharsFromFilename(result, Config.generate_win32_compatible_filenames); return result; } diff --git a/src/utility/string.cpp b/src/utility/string.cpp index 22e103cb..327a2992 100644 --- a/src/utility/string.cpp +++ b/src/utility/string.cpp @@ -91,9 +91,9 @@ std::string getEnclosedString(const std::string &s, char a, char b, size_t *pos) return result; } -void removeInvalidCharsFromFilename(std::string &filename) +void removeInvalidCharsFromFilename(std::string &filename, bool win32_compatible) { - const char *unallowed_chars = "\"*/:<>?\\|"; + const char *unallowed_chars = win32_compatible ? "\"*/:<>?\\|" : "/"; for (const char *c = unallowed_chars; *c; ++c) { for (size_t i = 0; i < filename.length(); ++i) diff --git a/src/utility/string.h b/src/utility/string.h index e885229a..80268aa2 100644 --- a/src/utility/string.h +++ b/src/utility/string.h @@ -39,6 +39,6 @@ std::string getSharedDirectory(const std::string &dir1, const std::string &dir2) std::string getEnclosedString(const std::string &s, char a, char b, size_t *pos); -void removeInvalidCharsFromFilename(std::string &filename); +void removeInvalidCharsFromFilename(std::string &filename, bool win32_compatible); #endif // NCMPCPP_UTILITY_STRING_H