Skip to content
Newer
Older
100644 160 lines (141 sloc) 4.29 KB
37e6e58 @fujiwarat Implement APIs for another non-Python panel.
authored
1 /* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
2 /* vim:set et sts=4: */
3 /* bus - The Input Bus
4 * Copyright (C) 2008-2011 Peng Huang <shawn.p.huang@gmail.com>
5 * Copyright (C) 2010-2011 Takao Fujiwara <takao.fujiwara1@gmail.com>
6 * Copyright (C) 2008-2011 Red Hat, Inc.
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library 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 GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
22 */
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include <glib.h>
28 #include <glib/gstdio.h>
29 #include <gio/gio.h>
30 #include <string.h>
31 #include "ibusxml.h"
32
33 #ifdef ENABLE_NLS
34 #include <libintl.h>
35 #endif
36
37 static GHashTable *__languages_dict;
38
39 static gboolean
40 _iso_codes_parse_xml_node (XMLNode *node)
41 {
42 GList *p;
43 g_assert (node);
44
45 if (G_UNLIKELY (g_strcmp0 (node->name, "iso_639_entries") != 0)) {
46 return FALSE;
47 }
48
49 for (p = node->sub_nodes; p != NULL; p = p->next) {
50 XMLNode *sub_node = (XMLNode *)p->data;
51 gchar **attributes = NULL;
52 int i, j;
53 struct {
54 const gchar *key;
55 gchar *value;
56 } entries[] = {
57 { "iso_639_2B_code", NULL },
58 { "iso_639_2T_code", NULL },
59 { "iso_639_1_code", NULL },
60 { NULL, NULL },
61 };
62
63
64 if (sub_node->attributes == NULL) {
65 continue;
66 }
67 attributes = sub_node->attributes;
68 for (i = 0; attributes[i]; i+=2) {
69 if (g_strcmp0 (attributes[i], "name") == 0) {
70 for (j = 0; entries[j].key; j++) {
71 if (entries[j].value == NULL) {
72 continue;
73 }
74 g_hash_table_insert (__languages_dict,
75 (gpointer) entries[j].value,
76 (gpointer) g_strdup (attributes[i + 1]));
77 entries[j].value = NULL;
78 }
79 } else {
80 for (j = 0; entries[j].key; j++) {
81 if (g_strcmp0 (attributes[i], entries[j].key) == 0 &&
82 attributes[i + 1] != NULL) {
83 entries[j].value = g_strdup (attributes[i + 1]);
84 }
85 }
86 }
87 }
88 }
89
90 return TRUE;
91 }
92
93 void
94 _load_lang()
95 {
96 gchar *filename;
97 XMLNode *node;
98 struct stat buf;
99
100 __languages_dict = g_hash_table_new (g_str_hash, (GEqualFunc) g_str_equal);
101 filename = g_build_filename (ISOCODES_PREFIX,
102 "share/xml/iso-codes/iso_639.xml",
103 NULL);
104 if (g_stat (filename, &buf) != 0) {
105 g_warning ("Can not get stat of file %s", filename);
106 g_free (filename);
107 return;
108 }
109
110 node = ibus_xml_parse_file (filename);
111 g_free (filename);
112
113 if (!node) {
114 return;
115 }
116
117 _iso_codes_parse_xml_node (node);
118 ibus_xml_free (node);
119 }
120
121 const gchar *
122 ibus_get_language_name(const gchar *_locale) {
123 const gchar *retval;
124 gchar *p = NULL;
125 gchar *lang = NULL;
126
127 if (__languages_dict == NULL ) {
128 _load_lang();
129 }
130 if ((p = strchr (_locale, '_')) != NULL) {
131 p = g_strndup (_locale, p - _locale);
132 } else {
133 p = g_strdup (_locale);
134 }
135 lang = g_ascii_strdown (p, -1);
136 g_free (p);
137 retval = (const gchar *) g_hash_table_lookup (__languages_dict, lang);
138 g_free (lang);
139 if (retval != NULL) {
140 #ifdef ENABLE_NLS
141 return dgettext("iso_639", retval);
142 #else
143 return retval;
144 #endif
145 }
146 return retval;
147 }
449cff0 @fujiwarat Add a bridge hotkey which use prev-next engines instead of on-off.
authored
148
149 gboolean
150 ibus_use_bridge_hotkey (void)
151 {
152 return (USE_BRIDGE_HOTKEY == 1) ? TRUE : FALSE;
153 }
154
155 const gchar *
156 ibus_get_default_bridge_engine_name (void)
157 {
158 return DEFAULT_BRIDGE_ENGINE_NAME;
159 }
Something went wrong with that request. Please try again.