summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--libxklavier/xkl_config_registry.h11
-rw-r--r--libxklavier/xklavier_config.c17
-rw-r--r--libxklavier/xklavier_config_i18n.c112
-rw-r--r--libxklavier/xklavier_private.h7
-rw-r--r--tests/test_config.c22
6 files changed, 59 insertions, 117 deletions
diff --git a/ChangeLog b/ChangeLog
index 2e2ad76..5580206 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2006-07-30 svu
+ * libxklavier/xkl_config_registry.h, libxklavier/xklavier_config.c,
+ libxklavier/xklavier_config_i18n.c, libxklavier/xklavier_private.h,
+ tests/test_config.c: simplifying description charset conversion,
+ adding custom charset (as Andriy requested)
+
+2006-07-30 svu
+
* configure.in, libxklavier/Makefile.am: fixing autoconf stuff for
modular X
diff --git a/libxklavier/xkl_config_registry.h b/libxklavier/xkl_config_registry.h
index 7180dde..9290ea9 100644
--- a/libxklavier/xkl_config_registry.h
+++ b/libxklavier/xkl_config_registry.h
@@ -75,6 +75,17 @@ extern "C" {
config);
/**
+ * xkl_config_registry_set_custom_charset
+ * @config: the config registry
+ *
+ * Sets custom charset. This charset (if specified) overrides the local
+ * user charset used for description strings in XklConfigItems
+ */
+ extern void
+ xkl_config_registry_set_custom_charset(XklConfigRegistry *
+ config,
+ const gchar * charset);
+/**
* ConfigItemProcessFunc:
* @config: the config registry
* @item: the item from registry
diff --git a/libxklavier/xklavier_config.c b/libxklavier/xklavier_config.c
index 4ea5d9f..5c03d29 100644
--- a/libxklavier/xklavier_config.c
+++ b/libxklavier/xklavier_config.c
@@ -37,7 +37,8 @@ xkl_node_get_xml_lang_attr(xmlNodePtr nptr)
}
static gboolean
-xkl_read_config_item(xmlNodePtr iptr, XklConfigItem * item)
+xkl_read_config_item(XklConfigRegistry * config, xmlNodePtr iptr,
+ XklConfigItem * item)
{
xmlNodePtr name_element, nptr, ptr;
xmlNodePtr desc_element = NULL, short_desc_element = NULL;
@@ -135,7 +136,7 @@ xkl_read_config_item(xmlNodePtr iptr, XklConfigItem * item)
if (short_desc_element != NULL
&& short_desc_element->children != NULL) {
- gchar *lmsg = xkl_locale_from_utf8((const gchar *)
+ gchar *lmsg = xkl_locale_from_utf8(config, (const gchar *)
short_desc_element->
children->content);
strncat(item->short_description, lmsg,
@@ -145,7 +146,8 @@ xkl_read_config_item(xmlNodePtr iptr, XklConfigItem * item)
if (desc_element != NULL && desc_element->children != NULL) {
gchar *lmsg =
- xkl_locale_from_utf8((const gchar *) desc_element->
+ xkl_locale_from_utf8(config,
+ (const gchar *) desc_element->
children->content);
strncat(item->description, lmsg,
XKL_MAX_CI_DESC_LENGTH - 1);
@@ -165,7 +167,7 @@ xkl_config_registry_foreach_in_nodeset(XklConfigRegistry * config,
xmlNodePtr *pnode = nodes->nodeTab;
XklConfigItem *ci = xkl_config_item_new();
for (i = nodes->nodeNr; --i >= 0;) {
- if (xkl_read_config_item(*pnode, ci))
+ if (xkl_read_config_item(config, *pnode, ci))
func(config, ci, data);
pnode++;
@@ -244,7 +246,7 @@ xkl_config_registry_find_object(XklConfigRegistry * config,
nodes = xpath_obj->nodesetval;
if (nodes != NULL && nodes->nodeTab != NULL) {
- rv = xkl_read_config_item(*nodes->nodeTab, pitem);
+ rv = xkl_read_config_item(config, *nodes->nodeTab, pitem);
if (pnode != NULL) {
*pnode = *nodes->nodeTab;
}
@@ -427,7 +429,7 @@ xkl_config_registry_foreach_option_group(XklConfigRegistry * config,
XklConfigItem *ci = xkl_config_item_new();
for (i = nodes->nodeNr; --i >= 0;) {
- if (xkl_read_config_item(*pnode, ci)) {
+ if (xkl_read_config_item(config, *pnode, ci)) {
gboolean allow_multisel = TRUE;
xmlChar *sallow_multisel =
xmlGetProp(*pnode,
@@ -722,8 +724,7 @@ xkl_config_registry_class_init(XklConfigRegistryClass * klass)
"XklEngine",
XKL_TYPE_ENGINE,
G_PARAM_CONSTRUCT_ONLY
- |
- G_PARAM_READWRITE);
+ | G_PARAM_READWRITE);
g_object_class_install_property(object_class,
PROP_ENGINE, engine_param_spec);
diff --git a/libxklavier/xklavier_config_i18n.c b/libxklavier/xklavier_config_i18n.c
index 450362b..e612010 100644
--- a/libxklavier/xklavier_config_i18n.c
+++ b/libxklavier/xklavier_config_i18n.c
@@ -43,111 +43,21 @@ xkl_parse_LC_ALL_to_LC_MESSAGES(const gchar * lc_all)
return buf;
}
-/* Taken from gnome-vfs */
-static gboolean
-xkl_get_charset(const gchar ** a)
+gchar *
+xkl_locale_from_utf8(XklConfigRegistry * config, const gchar * utf8string)
{
- static const gchar *charset = NULL;
-
- if (charset == NULL) {
- charset = g_getenv("CHARSET");
-
- if (charset == NULL || charset[0] == '\0') {
-#ifdef HAVE_LANGINFO_CODESET
- charset = nl_langinfo(CODESET);
- if (charset == NULL || charset[0] == '\0') {
-#endif
-#ifdef HAVE_SETLOCALE
- charset = setlocale(LC_CTYPE, NULL);
- if (charset == NULL || charset[0] == '\0') {
-#endif
- charset = getenv("LC_ALL");
- if (charset == NULL
- || charset[0] == '\0') {
- charset =
- getenv("LC_CTYPE");
- if (charset == NULL
- || charset[0] == '\0')
- charset =
- getenv("LANG");
- }
-#ifdef HAVE_SETLOCALE
- } else {
- xkl_debug(150,
- "Using charset from setlocale: [%s]\n",
- charset);
- }
-#endif
-#ifdef HAVE_LANGINFO_CODESET
- } else {
- xkl_debug(150,
- "Using charset from nl_langinfo: [%s]\n",
- charset);
- }
-#endif
- }
- }
-
- if (charset != NULL && *charset != '\0') {
- *a = charset;
- return (charset != NULL
- && g_strstr_len(charset, -1, "UTF-8") != NULL);
- }
- /* Assume this for compatibility at present. */
- *a = "US-ASCII";
- xkl_debug(150, "Using charset fallback: [%s]\n", *a);
-
- return FALSE;
+ const gchar *custom_charset =
+ xkl_config_registry_priv(config, custom_charset);
+ return custom_charset ? g_convert(utf8string, -1, custom_charset,
+ "UTF-8", NULL, NULL, NULL)
+ : g_locale_from_utf8(utf8string, -1, NULL, NULL, NULL);
}
-gchar *
-xkl_locale_from_utf8(const gchar * utf8string)
+void
+xkl_config_registry_set_custom_charset(XklConfigRegistry * config,
+ const gchar * charset)
{
- size_t len;
-
- iconv_t converter;
- gchar converted[XKL_MAX_CI_DESC_LENGTH];
- gchar *converted_start = converted;
- gchar *utf_start = (char *) utf8string;
- size_t clen = XKL_MAX_CI_DESC_LENGTH - 1;
- const gchar *charset;
-
- static gboolean already_warned = FALSE;
-
- if (utf8string == NULL)
- return NULL;
-
- len = strlen(utf8string);
-
- if (xkl_get_charset(&charset))
- return g_strdup(utf8string);
-
- converter = iconv_open(charset, "UTF-8");
- if (converter == (iconv_t) - 1) {
- if (!already_warned) {
- already_warned = TRUE;
- xkl_debug(0,
- "Unable to convert MIME info from UTF-8 "
- "to the current locale %s. "
- "MIME info will probably display wrong.",
- charset);
- }
- return g_strdup(utf8string);
- }
-
- if (iconv(converter, &utf_start, &len, &converted_start, &clen) ==
- -1) {
- xkl_debug(0,
- "Unable to convert %s from UTF-8 to %s, "
- "this string will probably display wrong.",
- utf8string, charset);
- return g_strdup(utf8string);
- }
- *converted_start = '\0';
-
- iconv_close(converter);
-
- return g_strdup(converted);
+ xkl_config_registry_priv(config, custom_charset) = charset;
}
/*
diff --git a/libxklavier/xklavier_private.h b/libxklavier/xklavier_private.h
index 4f88dca..cb6522c 100644
--- a/libxklavier/xklavier_private.h
+++ b/libxklavier/xklavier_private.h
@@ -222,6 +222,8 @@ struct _XklConfigRegistryPrivate {
xmlDocPtr doc;
xmlXPathContextPtr xpath_context;
+
+ const gchar *custom_charset;
};
extern void xkl_engine_ensure_vtable_inited(XklEngine * engine);
@@ -312,8 +314,6 @@ extern void xkl_engine_try_call_state_func(XklEngine * engine,
extern void xkl_i18n_init(void);
-extern gchar *xkl_locale_from_utf8(const gchar * utf8string);
-
extern gint xkl_get_language_priority(const gchar * language);
extern gchar *xkl_engine_get_ruleset_name(XklEngine * engine,
@@ -373,6 +373,9 @@ extern gboolean xkl_config_registry_load_from_file(XklConfigRegistry *
extern void xkl_config_registry_free(XklConfigRegistry * config);
+extern gchar *xkl_locale_from_utf8(XklConfigRegistry * config,
+ const gchar * utf8string);
+
#define XKLAVIER_STATE_PROP_LENGTH 2
/* taken from XFree86 maprules.c */
diff --git a/tests/test_config.c b/tests/test_config.c
index 457da67..13232d6 100644
--- a/tests/test_config.c
+++ b/tests/test_config.c
@@ -21,7 +21,7 @@ static void
print_usage(void)
{
printf
- ("Usage: test_config (-g)|(-s -m <model> -l <layouts> -o <options>)|(-h)|(-ws)|(-wb)(-d <debugLevel>)\n");
+ ("Usage: test_config (-g)|(-s -m <model> -l <layouts> -o <options>)|(-h)|(-ws)|(-wb)(-d <debugLevel>)(-c charset)\n");
printf("Options:\n");
printf(" -al - list all available layouts and variants\n");
printf(" -am - list all available models\n");
@@ -36,6 +36,7 @@ print_usage(void)
printf(" -wb - Write the source XKB config file (" PACKAGE
".xkb)\n");
printf(" -d - Set the debug level (by default, 0)\n");
+ printf(" -c - Set the custom charset\n");
printf(" -h - Show this help\n");
}
@@ -90,11 +91,12 @@ int
main(int argc, char *const argv[])
{
int c;
- char which_list = 0;
+ gchar which_list = 0;
int action = ACTION_NONE;
- const char *model = NULL;
- const char *layouts = NULL;
- const char *options = NULL;
+ const gchar *model = NULL;
+ const gchar *layouts = NULL;
+ const gchar *options = NULL;
+ const gchar *charset = NULL;
int debug_level = -1;
int binary = 0;
Display *dpy;
@@ -104,7 +106,7 @@ main(int argc, char *const argv[])
G_TYPE_DEBUG_SIGNALS);
while (1) {
- c = getopt(argc, argv, "ha:sgm:l:o:d:w:");
+ c = getopt(argc, argv, "ha:sgm:l:o:d:w:c:");
if (c == -1)
break;
switch (c) {
@@ -136,6 +138,9 @@ main(int argc, char *const argv[])
case 'd':
debug_level = atoi(optarg);
break;
+ case 'c':
+ charset = optarg;
+ break;
case 'w':
action = ACTION_WRITE;
binary = ('b' == optarg[0]);
@@ -170,6 +175,11 @@ main(int argc, char *const argv[])
xkl_debug(0, "Xklavier initialized\n");
config = xkl_config_registry_get_instance(engine);
xkl_config_registry_load(config);
+
+ if (charset != NULL)
+ xkl_config_registry_set_custom_charset(config,
+ charset);
+
xkl_debug(0, "Xklavier registry loaded\n");
xkl_debug(0, "Backend: [%s]\n",
xkl_engine_get_backend_name(engine));