do not exclude iconv support if unicode is enabled

This commit is contained in:
Andrzej Rybczak
2009-01-17 14:10:44 +01:00
parent 7d82da3fed
commit fd5a3e142c
6 changed files with 37 additions and 19 deletions

View File

@@ -20,12 +20,13 @@
#include "charset.h"
#if !defined(_UTF8) && defined(HAVE_ICONV_H)
#if defined(SUPPORTED_LOCALES) && defined(HAVE_ICONV_H)
#include <iconv.h>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <stdexcept>
#include "locale.h"
@@ -95,7 +96,10 @@ void init_current_locale()
return;
std::ifstream f(SUPPORTED_LOCALES);
if (!f.is_open())
{
std::cerr << "ncmpcpp: cannot open file "SUPPORTED_LOCALES"!\n";
return;
}
envlocale += " ";
std::string line;
while (!f.eof())
@@ -105,10 +109,19 @@ void init_current_locale()
{
try
{
locale_charset = strdup((line.substr(line.find(" ")+1) + "//TRANSLIT").c_str());
std::string charset = line.substr(line.find(" ")+1);
if (charset == "UTF-8"
|| charset == "utf-8"
|| charset == "utf8")
{
f.close();
return;
}
locale_charset = strdup((charset + "//TRANSLIT").c_str());
}
catch (std::out_of_range)
{
f.close();
return;
}
break;
@@ -165,5 +178,5 @@ void str_pool_locale_to_utf(char *&s)
charset_convert(locale_charset, "utf8", s);
}
#endif
#endif // SUPPORTED_LOCALES && HAVE_ICONV_H

View File

@@ -25,9 +25,9 @@
#include <config.h>
#endif
#include <string>
#if defined(SUPPORTED_LOCALES) && defined(HAVE_ICONV_H)
#if !defined(_UTF8) && defined(HAVE_ICONV_H)
#include <string>
void init_current_locale();
@@ -53,7 +53,7 @@ void str_pool_locale_to_utf(char *&);
#define str_pool_utf_to_locale(x);
#define str_pool_locale_to_utf(x);
#endif // !_UTF8 && HAVE_ICONV_H
#endif // SUPPORTED_LOCALES && HAVE_ICONV_H
#endif

View File

@@ -533,7 +533,8 @@ void DisplaySongInColumns(const Song &s, void *s_template, Menu<Song> *menu)
void DisplaySong(const Song &s, void *data, Menu<Song> *menu)
{
const_cast<Song *>(&s)->Localize();
if (!s.Localized())
const_cast<Song *>(&s)->Localize();
const string &song_template = data ? *static_cast<string *>(data) : "";
basic_buffer<my_char_t> buf;

View File

@@ -193,6 +193,11 @@ int main(int argc, char *argv[])
if (!ConnectToMPD())
return -1;
// redirect std::cerr output to ~/.ncmpcpp/error.log file
std::ofstream errorlog((config_dir + "error.log").c_str(), std::ios::app);
std::streambuf *cerr_buffer = std::cerr.rdbuf();
std::cerr.rdbuf(errorlog.rdbuf());
InitScreen(Config.colors_enabled);
init_current_locale();
@@ -359,11 +364,6 @@ int main(int argc, char *argv[])
signal(SIGPIPE, SIG_IGN);
// redirect std::cerr output to ~/.ncmpcpp/error.log file
std::ofstream errorlog((config_dir + "error.log").c_str(), std::ios::app);
std::streambuf * cerr_buffer = std::cerr.rdbuf();
std::cerr.rdbuf(errorlog.rdbuf());
# ifdef HAVE_CURL_CURL_H
pthread_attr_t attr_detached;
pthread_attr_init(&attr_detached);

View File

@@ -77,7 +77,7 @@ string Song::GetLength() const
void Song::Localize()
{
# if !defined(_UTF8) && defined(HAVE_ICONV_H)
# if defined(SUPPORTED_LOCALES) && defined(HAVE_ICONV_H)
if (isLocalised)
return;
str_pool_utf_to_locale(itsSong->file);
@@ -94,7 +94,7 @@ void Song::Localize()
str_pool_utf_to_locale(itsSong->disc);
str_pool_utf_to_locale(itsSong->comment);
isLocalised = 1;
# endif // !_UTF8 && HAVE_ICONV_H
# endif // SUPPORTED_LOCALES && HAVE_ICONV_H
}
/*void Song::Delocalize()