From daca5964e8ac58ec50939efa1ae6053ccf0d4a7d Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Mon, 12 Jan 2009 08:22:45 +0100 Subject: [PATCH] convert lyrics and artist's info to current locale if needed --- src/lyrics.cpp | 29 +++++++++++++++++++++++++++-- src/tag_editor.cpp | 2 +- src/window.cpp | 3 ++- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/lyrics.cpp b/src/lyrics.cpp index 43eae3c4..ed918a8a 100644 --- a/src/lyrics.cpp +++ b/src/lyrics.cpp @@ -21,6 +21,7 @@ #include #include +#include "charset.h" #include "helpers.h" #include "lyrics.h" #include "settings.h" @@ -71,6 +72,8 @@ void * GetArtistInfo(void *ptr) string artist = *strptr; delete strptr; + locale_to_utf(artist); + string filename = artist + ".txt"; ToLower(filename); EscapeUnallowedChars(filename); @@ -89,6 +92,7 @@ void * GetArtistInfo(void *ptr) { if (!first) *sInfo << "\n"; + utf_to_locale(line); *sInfo << line; first = 0; } @@ -204,12 +208,27 @@ void * GetArtistInfo(void *ptr) result = result.substr(0, i+1); } + Buffer filebuffer; + if (save) + filebuffer << result; + utf_to_locale(result); *sInfo << result; + if (save) + filebuffer << "\n\nSimilar artists:\n"; *sInfo << fmtBold << "\n\nSimilar artists:\n" << fmtBoldEnd; for (size_t i = 1; i < similar.size(); i++) + { + if (save) + filebuffer << "\n * " << similar[i] << " (" << urls[i] << ")"; + utf_to_locale(similar[i]); + utf_to_locale(urls[i]); *sInfo << "\n" << Config.color2 << " * " << clEnd << similar[i] << " (" << urls[i] << ")"; + } + if (save) + filebuffer << "\n\n" << urls.front(); + utf_to_locale(urls.front()); *sInfo << "\n\n" << urls.front(); if (save) @@ -217,7 +236,7 @@ void * GetArtistInfo(void *ptr) std::ofstream output(fullpath.c_str()); if (output.is_open()) { - output << TO_STRING(sInfo->Content()); + output << filebuffer.Str(); output.close(); } } @@ -234,6 +253,9 @@ void *GetLyrics(void *song) string artist = static_cast(song)->GetArtist(); string title = static_cast(song)->GetTitle(); + locale_to_utf(artist); + locale_to_utf(title); + string filename = artist + " - " + title + ".txt"; const string fullpath = lyrics_folder + "/" + filename; mkdir(lyrics_folder.c_str(), 0755); @@ -248,6 +270,7 @@ void *GetLyrics(void *song) { if (!first) *sLyrics << "\n"; + utf_to_locale(line); *sLyrics << line; first = 0; } @@ -321,7 +344,9 @@ void *GetLyrics(void *song) EscapeHtml(result); - *sLyrics << result; + string localized_result = result; + utf_to_locale(localized_result); + *sLyrics << localized_result; std::ofstream output(fullpath.c_str()); if (output.is_open()) diff --git a/src/tag_editor.cpp b/src/tag_editor.cpp index cc6420c9..39b38e05 100644 --- a/src/tag_editor.cpp +++ b/src/tag_editor.cpp @@ -599,7 +599,7 @@ void __deal_with_filenames(SongList &v) int last_dot = file.find_last_of("."); string extension = file.substr(last_dot); basic_buffer new_file; - new_file << ToWString(GenerateFilename(s, Config.pattern)); + new_file << TO_WSTRING(GenerateFilename(s, Config.pattern)); if (new_file.Str().empty()) { if (preview) diff --git a/src/window.cpp b/src/window.cpp index b342a6e1..232b39da 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -716,7 +716,8 @@ Window &Window::operator<<(const double &d) Window &Window::operator<<(const string &s) { - wprintw(itsWindow, "%s", s.c_str()); + for (string::const_iterator it = s.begin(); it != s.end(); it++) + wprintw(itsWindow, "%c", *it); return *this; }