xmms - Fix inline linking problems with old glib
[flac.git] / src / plugin_xmms / charset.c
1 /* libxmms-flac - XMMS FLAC input plugin
2  * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009  Daisuke Shimamura
3  *
4  * Almost from charset.c
5  *  EasyTAG - Tag editor for MP3 and OGG files
6  *  Copyright (C) 1999-2001  Håvard Kvålen <havardk@xmms.org>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 #include "plugin.h"
24
25 #include <stdlib.h>
26 #include <glib.h>
27 #include <string.h>
28 #include <errno.h>
29
30 #include "plugin_common/charset.h"
31 #include "charset.h"
32 #include "configure.h"
33 #include "locale_hack.h"
34
35
36 /****************
37  * Declarations *
38  ****************/
39
40 #define CHARSET_TRANS_ARRAY_LEN ( sizeof(charset_trans_array) / sizeof((charset_trans_array)[0]) )
41 const CharsetInfo charset_trans_array[] = {
42         {N_("Arabic (IBM-864)"),                  "IBM864"        },
43         {N_("Arabic (ISO-8859-6)"),               "ISO-8859-6"    },
44         {N_("Arabic (Windows-1256)"),             "windows-1256"  },
45         {N_("Baltic (ISO-8859-13)"),              "ISO-8859-13"   },
46         {N_("Baltic (ISO-8859-4)"),               "ISO-8859-4"    },
47         {N_("Baltic (Windows-1257)"),             "windows-1257"  },
48         {N_("Celtic (ISO-8859-14)"),              "ISO-8859-14"   },
49         {N_("Central European (IBM-852)"),        "IBM852"        },
50         {N_("Central European (ISO-8859-2)"),     "ISO-8859-2"    },
51         {N_("Central European (Windows-1250)"),   "windows-1250"  },
52         {N_("Chinese Simplified (GB18030)"),      "gb18030"       },
53         {N_("Chinese Simplified (GB2312)"),       "GB2312"        },
54         {N_("Chinese Traditional (Big5)"),        "Big5"          },
55         {N_("Chinese Traditional (Big5-HKSCS)"),  "Big5-HKSCS"    },
56         {N_("Cyrillic (IBM-855)"),                "IBM855"        },
57         {N_("Cyrillic (ISO-8859-5)"),             "ISO-8859-5"    },
58         {N_("Cyrillic (ISO-IR-111)"),             "ISO-IR-111"    },
59         {N_("Cyrillic (KOI8-R)"),                 "KOI8-R"        },
60         {N_("Cyrillic (Windows-1251)"),           "windows-1251"  },
61         {N_("Cyrillic/Russian (CP-866)"),         "IBM866"        },
62         {N_("Cyrillic/Ukrainian (KOI8-U)"),       "KOI8-U"        },
63         {N_("English (US-ASCII)"),                "us-ascii"      },
64         {N_("Greek (ISO-8859-7)"),                "ISO-8859-7"    },
65         {N_("Greek (Windows-1253)"),              "windows-1253"  },
66         {N_("Hebrew (IBM-862)"),                  "IBM862"        },
67         {N_("Hebrew (Windows-1255)"),             "windows-1255"  },
68         {N_("Japanese (EUC-JP)"),                 "EUC-JP"        },
69         {N_("Japanese (ISO-2022-JP)"),            "ISO-2022-JP"   },
70         {N_("Japanese (Shift_JIS)"),              "Shift_JIS"     },
71         {N_("Korean (EUC-KR)"),                   "EUC-KR"        },
72         {N_("Nordic (ISO-8859-10)"),              "ISO-8859-10"   },
73         {N_("South European (ISO-8859-3)"),       "ISO-8859-3"    },
74         {N_("Thai (TIS-620)"),                    "TIS-620"       },
75         {N_("Turkish (IBM-857)"),                 "IBM857"        },
76         {N_("Turkish (ISO-8859-9)"),              "ISO-8859-9"    },
77         {N_("Turkish (Windows-1254)"),            "windows-1254"  },
78         {N_("Unicode (UTF-7)"),                   "UTF-7"         },
79         {N_("Unicode (UTF-8)"),                   "UTF-8"         },
80         {N_("Unicode (UTF-16BE)"),                "UTF-16BE"      },
81         {N_("Unicode (UTF-16LE)"),                "UTF-16LE"      },
82         {N_("Unicode (UTF-32BE)"),                "UTF-32BE"      },
83         {N_("Unicode (UTF-32LE)"),                "UTF-32LE"      },
84         {N_("Vietnamese (VISCII)"),               "VISCII"        },
85         {N_("Vietnamese (Windows-1258)"),         "windows-1258"  },
86         {N_("Visual Hebrew (ISO-8859-8)"),        "ISO-8859-8"    },
87         {N_("Western (IBM-850)"),                 "IBM850"        },
88         {N_("Western (ISO-8859-1)"),              "ISO-8859-1"    },
89         {N_("Western (ISO-8859-15)"),             "ISO-8859-15"   },
90         {N_("Western (Windows-1252)"),            "windows-1252"  }
91
92         /*
93          * From this point, character sets aren't supported by iconv
94          */
95 #if 0
96         {N_("Arabic (IBM-864-I)"),                "IBM864i"              },
97         {N_("Arabic (ISO-8859-6-E)"),             "ISO-8859-6-E"         },
98         {N_("Arabic (ISO-8859-6-I)"),             "ISO-8859-6-I"         },
99         {N_("Arabic (MacArabic)"),                "x-mac-arabic"         },
100         {N_("Armenian (ARMSCII-8)"),              "armscii-8"            },
101         {N_("Central European (MacCE)"),          "x-mac-ce"             },
102         {N_("Chinese Simplified (GBK)"),          "x-gbk"                },
103         {N_("Chinese Simplified (HZ)"),           "HZ-GB-2312"           },
104         {N_("Chinese Traditional (EUC-TW)"),      "x-euc-tw"             },
105         {N_("Croatian (MacCroatian)"),            "x-mac-croatian"       },
106         {N_("Cyrillic (MacCyrillic)"),            "x-mac-cyrillic"       },
107         {N_("Cyrillic/Ukrainian (MacUkrainian)"), "x-mac-ukrainian"      },
108         {N_("Farsi (MacFarsi)"),                  "x-mac-farsi"},
109         {N_("Greek (MacGreek)"),                  "x-mac-greek"          },
110         {N_("Gujarati (MacGujarati)"),            "x-mac-gujarati"       },
111         {N_("Gurmukhi (MacGurmukhi)"),            "x-mac-gurmukhi"       },
112         {N_("Hebrew (ISO-8859-8-E)"),             "ISO-8859-8-E"         },
113         {N_("Hebrew (ISO-8859-8-I)"),             "ISO-8859-8-I"         },
114         {N_("Hebrew (MacHebrew)"),                "x-mac-hebrew"         },
115         {N_("Hindi (MacDevanagari)"),             "x-mac-devanagari"     },
116         {N_("Icelandic (MacIcelandic)"),          "x-mac-icelandic"      },
117         {N_("Korean (JOHAB)"),                    "x-johab"              },
118         {N_("Korean (UHC)"),                      "x-windows-949"        },
119         {N_("Romanian (MacRomanian)"),            "x-mac-romanian"       },
120         {N_("Turkish (MacTurkish)"),              "x-mac-turkish"        },
121         {N_("User Defined"),                      "x-user-defined"       },
122         {N_("Vietnamese (TCVN)"),                 "x-viet-tcvn5712"      },
123         {N_("Vietnamese (VPS)"),                  "x-viet-vps"           },
124         {N_("Western (MacRoman)"),                "x-mac-roman"          },
125         /* charsets whithout posibly translatable names */
126         {"T61.8bit",                              "T61.8bit"             },
127         {"x-imap4-modified-utf7",                 "x-imap4-modified-utf7"},
128         {"x-u-escaped",                           "x-u-escaped"          },
129         {"windows-936",                           "windows-936"          }
130 #endif
131 };
132
133 /*************
134  * Functions *
135  *************/
136
137 /*
138  * Commons conversion functions
139  */
140 char *convert_from_utf8_to_user(const char *string)
141 {
142         return FLAC_plugin__charset_convert_string(string, "UTF-8", flac_cfg.title.user_char_set);
143 }
144
145 char *convert_from_user_to_utf8(const char *string)
146 {
147         return FLAC_plugin__charset_convert_string(string, flac_cfg.title.user_char_set, "UTF-8");
148 }
149
150 GList *Charset_Create_List (void)
151 {
152         GList *list = NULL;
153         guint i;
154
155         for (i=0; i<CHARSET_TRANS_ARRAY_LEN; i++)
156                 list = g_list_append(list,_(charset_trans_array[i].charset_title));
157         return list;
158 }
159
160 GList *Charset_Create_List_UTF8_Only (void)
161 {
162         GList *list = NULL;
163
164         list = g_list_append(list,_(Charset_Get_Title_From_Name("UTF-8")));
165         return list;
166 }
167
168
169 /*
170  * Return charset_name from charset_title
171  */
172 gchar *Charset_Get_Name_From_Title (gchar *charset_title)
173 {
174         guint i;
175
176         if (charset_title)
177                 for (i=0; i<CHARSET_TRANS_ARRAY_LEN; i++)
178                         if ( strcasecmp(_(charset_title),_(charset_trans_array[i].charset_title)) == 0 )
179                                 return charset_trans_array[i].charset_name;
180         return "";
181 }
182
183
184 /*
185  * Return charset_title from charset_name
186  */
187 gchar *Charset_Get_Title_From_Name (gchar *charset_name)
188 {
189         guint i;
190
191         if (charset_name)
192                 for (i=0; i<CHARSET_TRANS_ARRAY_LEN; i++)
193                         if ( strcasecmp(charset_name,charset_trans_array[i].charset_name) == 0 )
194                                 return _(charset_trans_array[i].charset_title);
195         return "";
196 }