summaryrefslogtreecommitdiffstats
path: root/patches/xmms/source/rcc.c
blob: c02f0507178ff8d6ab4df21305ce9bd54ce29da5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
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;
}