convert lyrics and artist's info to current locale if needed

This commit is contained in:
Andrzej Rybczak
2009-01-12 08:22:45 +01:00
parent 67b8ca70fa
commit daca5964e8
3 changed files with 30 additions and 4 deletions

View File

@@ -21,6 +21,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <fstream> #include <fstream>
#include "charset.h"
#include "helpers.h" #include "helpers.h"
#include "lyrics.h" #include "lyrics.h"
#include "settings.h" #include "settings.h"
@@ -71,6 +72,8 @@ void * GetArtistInfo(void *ptr)
string artist = *strptr; string artist = *strptr;
delete strptr; delete strptr;
locale_to_utf(artist);
string filename = artist + ".txt"; string filename = artist + ".txt";
ToLower(filename); ToLower(filename);
EscapeUnallowedChars(filename); EscapeUnallowedChars(filename);
@@ -89,6 +92,7 @@ void * GetArtistInfo(void *ptr)
{ {
if (!first) if (!first)
*sInfo << "\n"; *sInfo << "\n";
utf_to_locale(line);
*sInfo << line; *sInfo << line;
first = 0; first = 0;
} }
@@ -204,12 +208,27 @@ void * GetArtistInfo(void *ptr)
result = result.substr(0, i+1); result = result.substr(0, i+1);
} }
Buffer filebuffer;
if (save)
filebuffer << result;
utf_to_locale(result);
*sInfo << result; *sInfo << result;
if (save)
filebuffer << "\n\nSimilar artists:\n";
*sInfo << fmtBold << "\n\nSimilar artists:\n" << fmtBoldEnd; *sInfo << fmtBold << "\n\nSimilar artists:\n" << fmtBoldEnd;
for (size_t i = 1; i < similar.size(); i++) 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] << ")"; *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(); *sInfo << "\n\n" << urls.front();
if (save) if (save)
@@ -217,7 +236,7 @@ void * GetArtistInfo(void *ptr)
std::ofstream output(fullpath.c_str()); std::ofstream output(fullpath.c_str());
if (output.is_open()) if (output.is_open())
{ {
output << TO_STRING(sInfo->Content()); output << filebuffer.Str();
output.close(); output.close();
} }
} }
@@ -234,6 +253,9 @@ void *GetLyrics(void *song)
string artist = static_cast<Song *>(song)->GetArtist(); string artist = static_cast<Song *>(song)->GetArtist();
string title = static_cast<Song *>(song)->GetTitle(); string title = static_cast<Song *>(song)->GetTitle();
locale_to_utf(artist);
locale_to_utf(title);
string filename = artist + " - " + title + ".txt"; string filename = artist + " - " + title + ".txt";
const string fullpath = lyrics_folder + "/" + filename; const string fullpath = lyrics_folder + "/" + filename;
mkdir(lyrics_folder.c_str(), 0755); mkdir(lyrics_folder.c_str(), 0755);
@@ -248,6 +270,7 @@ void *GetLyrics(void *song)
{ {
if (!first) if (!first)
*sLyrics << "\n"; *sLyrics << "\n";
utf_to_locale(line);
*sLyrics << line; *sLyrics << line;
first = 0; first = 0;
} }
@@ -321,7 +344,9 @@ void *GetLyrics(void *song)
EscapeHtml(result); EscapeHtml(result);
*sLyrics << result; string localized_result = result;
utf_to_locale(localized_result);
*sLyrics << localized_result;
std::ofstream output(fullpath.c_str()); std::ofstream output(fullpath.c_str());
if (output.is_open()) if (output.is_open())

View File

@@ -599,7 +599,7 @@ void __deal_with_filenames(SongList &v)
int last_dot = file.find_last_of("."); int last_dot = file.find_last_of(".");
string extension = file.substr(last_dot); string extension = file.substr(last_dot);
basic_buffer<my_char_t> new_file; basic_buffer<my_char_t> new_file;
new_file << ToWString(GenerateFilename(s, Config.pattern)); new_file << TO_WSTRING(GenerateFilename(s, Config.pattern));
if (new_file.Str().empty()) if (new_file.Str().empty())
{ {
if (preview) if (preview)

View File

@@ -716,7 +716,8 @@ Window &Window::operator<<(const double &d)
Window &Window::operator<<(const string &s) 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; return *this;
} }