diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/rcc.c | 185 | ||||
-rw-r--r-- | source/rcc.h | 32 | ||||
-rw-r--r-- | source/rcc_langs.h | 120 |
3 files changed, 337 insertions, 0 deletions
diff --git a/source/rcc.c b/source/rcc.c new file mode 100644 index 0000000..c02f050 --- /dev/null +++ b/source/rcc.c @@ -0,0 +1,185 @@ +#include <stdio.h> +#include <string.h> + +#include <gtk/gtklabel.h> +#include <gtk/gtknotebook.h> + +#include "config.h" +#ifdef HAVE_LIBRCC_H +# ifdef HAVE_LIBRCCUI_H +# define HAVE_LIBRCC +# include <librcc.h> +# include <librccui.h> +# endif /* HAVE_LIBRCCUI_H */ +#endif /* HAVE_LIBRCC_H */ + +#include "rcc.h" +#include "rcc_langs.h" + +#ifdef HAVE_LIBRCC +static rcc_context ctx = NULL; +static rcc_ui_context uictx = NULL; + +static rcc_class_default_charset default_id3[] = { + { "ru", "CP1251" }, + { NULL, NULL } +}; + +static rcc_class classes[] = { + { "id3", RCC_CLASS_STANDARD, NULL, default_id3, "ID3 Encoding", 0 }, + { "id3v2", RCC_CLASS_STANDARD, "id3", default_id3, "ID3 v.2 Encoding", 0 }, + { "pl", RCC_CLASS_STANDARD, "id3", default_id3, "PlayList Title Encoding", 0 }, + { "plfs", RCC_CLASS_STANDARD, "pl", NULL, "PlayList File Encoding", 0 }, + { "fs", RCC_CLASS_FS, "LC_CTYPE", NULL, "FileSystem Encoding", 0 }, + { "out", RCC_CLASS_TRANSLATE_LOCALE, "LC_CTYPE", NULL, NULL, 0 }, + { "ctype", RCC_CLASS_STANDARD, "LC_CTYPE", NULL, NULL, RCC_CLASS_FLAG_CONST|RCC_CLASS_FLAG_SKIP_SAVELOAD }, + { "utf8", RCC_CLASS_STANDARD, "UTF-8", NULL, NULL, RCC_CLASS_FLAG_CONST|RCC_CLASS_FLAG_SKIP_SAVELOAD }, + { NULL } +}; +#endif /* HAVE_LIBRCC */ + + + +void xmms_rcc_init() { +#ifdef HAVE_LIBRCC + rccInit(); + rccUiInit(); + ctx = rccCreateContext(NULL, 0, 0, classes, 0); + rccInitDb4(ctx, NULL, 0); + rccLoad(ctx, "xmms"); + uictx = rccUiCreateContext(ctx); +#endif /* HAVE_LIBRCC */ +} + +void xmms_rcc_free() { +#ifdef HAVE_LIBRCC + rccUiFreeContext(uictx); + rccSave(ctx, "xmms"); + rccFreeContext(ctx); + rccUiFree(); + rccFree(); +#endif /* HAVE_LIBRCC */ +} + +void xmms_rcc_prefswin_create(void *prefswin_notebook) { +#ifdef HAVE_LIBRCC + GtkWidget *vbox; + vbox = (GtkWidget*)rccUiGetPage(uictx, NULL); + gtk_notebook_append_page(GTK_NOTEBOOK(prefswin_notebook), vbox, gtk_label_new(rccUiGetDefaultPageName()->title)); +#endif /* HAVE_LIBRCC */ +} + +void xmms_rcc_prefswin_apply() { +#ifdef HAVE_LIBRCC + rccUiUpdate(uictx); + rccSave(ctx, "xmms"); +#endif /* HAVE_LIBRCC */ +} + +char *xmms_rcc_fs2pl(const char *fnstring, const char *filename) { +#ifdef HAVE_LIBRCC + rcc_language_config config; + + if (!rccStringCheck(fnstring)) return NULL; + + config = rccGetConfig(ctx, rccStringGetLanguage(fnstring)); + if (!config) return NULL; + + if (rccConfigGetCurrentCharset(config, (rcc_class_id)XMMS_RCC_FS) == rccConfigGetCurrentCharset(config, (rcc_class_id)XMMS_RCC_PLFS)) + return NULL; +#endif /* HAVE_LIBRCC */ + + return xmms_rcc_get(XMMS_RCC_PLFS, fnstring); +} + + +/* rcc_string to out */ +char *xmms_rcc_get(xmms_rcc_class charset, const char *buf) { +#ifdef HAVE_LIBRCC + return (char*)rccTo(ctx, (rcc_class_id)charset, (const rcc_string)buf); +#else /* HAVE_LIBRCC */ + return NULL; +#endif /* HAVE_LIBRCC */ +} + +char *xmms_rcc_put(xmms_rcc_class charset, const char *buf) { +#ifdef HAVE_LIBRCC + return (char*)rccFrom(ctx, (rcc_class_id)charset, buf); +#else /* HAVE_LIBRCC */ + return NULL; +#endif /* HAVE_LIBRCC */ +} + +char *xmms_rcc_sized_put(xmms_rcc_class charset, const char *buf, int size) { +#ifdef HAVE_LIBRCC + return (char*)rccSizedFrom(ctx, (rcc_class_id)charset, buf, size); +#else /* HAVE_LIBRCC */ + return NULL; +#endif /* HAVE_LIBRCC */ +} + +char *xmms_rcc_recode(xmms_rcc_class from, xmms_rcc_class to, const char *buf) { +#ifdef HAVE_LIBRCC + if (((from==XMMS_RCC_CTYPE)&&(to==XMMS_RCC_OUT))||((from==XMMS_RCC_OUT)&&(to==XMMS_RCC_CTYPE))) { + if (!rccGetSelectedCharset(ctx, XMMS_RCC_OUT)) return NULL; + } + + return (char*)rccRecode(ctx, (rcc_class_id)from, (rcc_class_id)to, buf); +#else /* HAVE_LIBRCC */ + return NULL; +#endif /* HAVE_LIBRCC */ +} + +char *xmms_rcc_sized_recode(xmms_rcc_class from, xmms_rcc_class to, const char *buf, int size) { +#ifdef HAVE_LIBRCC + return (char*)rccSizedRecode(ctx, (rcc_class_id)from, (rcc_class_id)to, buf, size, NULL); +#else /* HAVE_LIBRCC */ + return NULL; +#endif /* HAVE_LIBRCC */ +} + +char *xmms_rcc_fs(xmms_rcc_class from, xmms_rcc_class to, const char *fspath, const char *path, const char *filename) { +#ifdef HAVE_LIBRCC + return (char*)rccFS(ctx, (rcc_class_id)from, (rcc_class_id)to, fspath, path, filename); +#else /* HAVE_LIBRCC */ + return NULL; +#endif /* HAVE_LIBRCC */ +} + +const char *xmms_rcc_string(const char *buf) { +#ifdef HAVE_LIBRCC + return rccGetString((const rcc_string)buf); +#else /* HAVE_LIBRCC */ + return buf; +#endif /* HAVE_LIBRCC */ +} + +const char *xmms_rcc_get_language() { + const char *lang; +#ifdef HAVE_LIBRCC + lang = rccGetCurrentLanguageName(ctx); +#else /* HAVE_LIBRCC */ + lang = NULL; +#endif /* HAVE_LIBRCC */ + return xmms_rcc_get_639_2_name(lang); +} + +#define ID3_ENCODING_ISO_8859_1 0x00 +#define ID3_ENCODING_UTF16 0x01 +#define ID3_ENCODING_UTF16BE 0x02 +#define ID3_ENCODING_UTF8 0x03 + +int xmms_rcc_get_id3v2_encoding() { +#ifdef HAVE_LIBRCC + const char *name; + + name = rccGetCurrentCharsetName(ctx, (rcc_class_id)XMMS_RCC_ID3V2); + if (!name) return ID3_ENCODING_ISO_8859_1; + + if ((!strcasecmp(name,"UTF-8"))||(!strcasecmp(name,"UTF8"))) return ID3_ENCODING_UTF8; + if ((!strcasecmp(name,"UTF-16"))||(!strcasecmp(name,"UTF16"))||(!strcasecmp(name,"UTF16LE"))||(!strcasecmp(name,"UTF-16LE"))) return ID3_ENCODING_UTF16; + if ((!strcasecmp(name,"UTF-16BE"))||(!strcasecmp(name,"UTF16BE"))) return ID3_ENCODING_UTF16BE; +#endif /* HAVE_LIBRCC */ + + return ID3_ENCODING_ISO_8859_1; +} diff --git a/source/rcc.h b/source/rcc.h new file mode 100644 index 0000000..d5bc9b2 --- /dev/null +++ b/source/rcc.h @@ -0,0 +1,32 @@ +#ifndef _XMMS_CHARSET_H +#define _XMMS_CHARSET_H + +typedef enum xmms_rcc_class_t { + XMMS_RCC_ID3 = 0, + XMMS_RCC_ID3V2, + XMMS_RCC_PL, + XMMS_RCC_PLFS, + XMMS_RCC_FS, + XMMS_RCC_OUT, + XMMS_RCC_CTYPE, + XMMS_RCC_UTF8 +} xmms_rcc_class; + +void xmms_rcc_init(); +void xmms_rcc_free(); +void xmms_rcc_prefswin_create(void *prefswin_notebook); +void xmms_rcc_prefswin_apply(); + +char *xmms_rcc_fs2pl(const char *fnstring, const char *filename); +char *xmms_rcc_get(xmms_rcc_class charset, const char *buf); +char *xmms_rcc_put(xmms_rcc_class charset, const char *buf); +char *xmms_rcc_sized_put(xmms_rcc_class charset, const char *buf, int size); +char *xmms_rcc_recode(xmms_rcc_class from, xmms_rcc_class to, const char *buf); +char *xmms_rcc_sized_recode(xmms_rcc_class from, xmms_rcc_class to, const char *buf, int size); +char *xmms_rcc_fs(xmms_rcc_class from, xmms_rcc_class to, const char *fspath, const char *path, const char *filename); + +const char *xmms_rcc_string(const char *buf); +const char *xmms_rcc_get_language(); +int xmms_rcc_get_id3v2_encoding(); + +#endif /* _XMMS_CHARSET_H */ diff --git a/source/rcc_langs.h b/source/rcc_langs.h new file mode 100644 index 0000000..70abebf --- /dev/null +++ b/source/rcc_langs.h @@ -0,0 +1,120 @@ +typedef struct xmms_rcc_langs_t { + const char *sn; + const char *name; +} xmms_rcc_langs; + +static const char *default_lang = "XXX"; +static xmms_rcc_langs langs[] = { + { "aa", "aar" }, + { "ab", "abk" }, + { "af", "afr" }, + { "ak", "aka" }, + { "am", "amh" }, + { "ar", "ara" }, + { "an", "arg" }, + { "as", "asm" }, + { "av", "ava" }, + { "ae", "ave" }, + { "ay", "aym" }, + { "ba", "bak" }, + { "bm", "bam" }, + { "bn", "ben" }, + { "bh", "bih" }, + { "bi", "bis" }, + { "bs", "bos" }, + { "br", "bre" }, + { "bg", "bul" }, + { "ch", "cha" }, + { "cv", "chv" }, + { "kw", "cor" }, + { "co", "cos" }, + { "cr", "cre" }, + { "dv", "div" }, + { "dz", "dzo" }, + { "en", "eng" }, + { "et", "est" }, + { "fj", "fij" }, + { "fi", "fin" }, + { "fy", "fry" }, + { "ff", "ful" }, + { "ig", "ibo" }, + { "io", "ido" }, + { "iu", "iku" }, + { "ie", "ile" }, + { "ik", "ipk" }, + { "it", "ita" }, + { "jv", "jav" }, + { "ja", "jpn" }, + { "kn", "kan" }, + { "ks", "kas" }, + { "kr", "kau" }, + { "kk", "kaz" }, + { "km", "khm" }, + { "rw", "kin" }, + { "ky", "kir" }, + { "kv", "kom" }, + { "kg", "kon" }, + { "ku", "kur" }, + { "lo", "lao" }, + { "la", "lat" }, + { "lv", "lav" }, + { "ln", "lin" }, + { "lt", "lit" }, + { "lg", "lug" }, + { "mh", "mah" }, + { "ml", "mal" }, + { "mr", "mar" }, + { "mg", "mlg" }, + { "mt", "mlt" }, + { "mo", "mol" }, + { "mn", "mon" }, + { "na", "nau" }, + { "ng", "ndo" }, + { "oj", "oji" }, + { "or", "ori" }, + { "om", "orm" }, + { "pi", "pli" }, + { "ps", "pus" }, + { "qu", "que" }, + { "rn", "run" }, + { "ru", "rus" }, + { "sg", "sag" }, + { "sa", "san" }, + { "sn", "sna" }, + { "sd", "snd" }, + { "so", "som" }, + { "sc", "srd" }, + { "ss", "ssw" }, + { "sw", "swa" }, + { "ty", "tah" }, + { "ta", "tam" }, + { "tg", "tgk" }, + { "tl", "tgl" }, + { "ti", "tir" }, + { "tn", "tsn" }, + { "ts", "tso" }, + { "tr", "tur" }, + { "tw", "twi" }, + { "uk", "ukr" }, + { "ur", "urd" }, + { "uz", "uzb" }, + { "vi", "vie" }, + { "wa", "wln" }, + { "wo", "wol" }, + { "xh", "xho" }, + { "yi", "yid" }, + { "yo", "yor" }, + { "zu", "zul" }, + { NULL, NULL } +}; + +const char *xmms_rcc_get_639_2_name(const char *sn) { + unsigned int i; + + if ((!sn)||(!strcasecmp(sn, "off"))) return default_lang; + + for (i=0; langs[i].sn; i++) + if (!strcasecmp(sn, langs[i].sn)) return langs[i].name; + + return default_lang; +} |