Added gettext support to ukeyboard
[ukeyboard.git] / cpanel / langset.c
blob9e2c9abfecaf021ce54f393375fbfb66500f26ab
1 /*
2 * Copyright (c) 2008 Jiri Benc <jbenc@upir.cz>
3 * Copyright (c) 2009 Roman Moravcik <roman.moravcik@gmail.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #include <stdio.h>
20 #include <string.h>
21 #include <glib.h>
22 #include <gtk/gtk.h>
23 #include <hildon/hildon-caption.h>
24 #include <hildon/hildon.h>
25 #include <libosso.h>
26 #include <gconf/gconf.h>
27 #include <gconf/gconf-client.h>
28 #include "prefs.h"
29 #include "lang.h"
30 #include "langset.h"
32 #define GETTEXT_PACKAGE "ukeyboard"
33 #include <glib/gi18n-lib.h>
35 #define L_CONF_DIR "/apps/osso/inputmethod/hildon-im-languages"
37 gboolean get_l_bool(GConfClient *client, char *lang, char *key)
39 char *tmp = g_strjoin("/", L_CONF_DIR, lang, key, NULL);
40 gboolean res;
42 res = gconf_client_get_bool(client, tmp, NULL);
43 g_free(tmp);
44 return res;
47 void set_l_bool(GConfClient *client, char *lang, char *key, gboolean val)
49 char *tmp = g_strjoin("/", L_CONF_DIR, lang, key, NULL);
51 g_debug("%s %d\n", tmp, val);
53 gconf_client_set_bool(client, tmp, val, NULL);
54 g_free(tmp);
57 gchar *get_l_str(GConfClient *client, char *lang, char *key)
59 char *tmp = g_strjoin("/", L_CONF_DIR, lang, key, NULL);
60 GConfValue *val;
61 gchar *res;
63 val = gconf_client_get_without_default(client, tmp, NULL);
64 g_free(tmp);
65 if (!val)
66 return NULL;
67 if (val->type != GCONF_VALUE_STRING) {
68 gconf_value_free(val);
69 return NULL;
71 res = g_strdup(gconf_value_get_string(val));
72 gconf_value_free(val);
73 return res;
76 void set_l_str(GConfClient *client, char *lang, char *key, gchar *val)
78 char *tmp = g_strjoin("/", L_CONF_DIR, lang, key, NULL);
80 gconf_client_set_string(client, tmp, val, NULL);
81 g_free(tmp);
84 GList *get_dicts(GList *langs)
86 GList *item, *dicts = NULL;
87 struct lang *lang, *dict;
88 unsigned i;
90 for (item = langs, i = 0; item; item = g_list_next(item)) {
91 lang = item->data;
93 /* WORKAROUND: czech, german and russian dictionary must be listed,
94 because they are officially supported */
95 if (lang->ext) {
96 if ((strcmp(lang->fname, "cz-qwertz")) &&
97 (strcmp(lang->fname, "de-qwertz")) &&
98 (strcmp(lang->fname, "ru-windows")))
99 continue;
102 dict = g_malloc(sizeof(struct lang));
103 dict->fname = g_strdup(lang->fname);
104 dict->desc = g_strdup(lang->desc);
105 dict->code = g_strdup(lang->code);
106 dicts = g_list_append(dicts, dict);
108 return dicts;
111 void fill_dict(HildonTouchSelector *combo, GList *langs, gchar *deflang)
113 GList *item;
114 struct lang *lang;
115 unsigned i;
117 for (item = langs, i = 0; item; item = g_list_next(item)) {
118 lang = item->data;
120 hildon_touch_selector_append_text(combo, lang->desc);
122 if (deflang && !strcmp(lang->code, deflang))
123 hildon_touch_selector_set_active(combo, 0, i);
124 i++;
127 hildon_touch_selector_append_text(combo, _TI("tein_fi_word_completion_language_empty"));
129 if (!deflang || !*deflang)
130 hildon_touch_selector_set_active(combo, 0, i);
132 /* check if something is really selected, if not select last item */
133 if (hildon_touch_selector_get_active(combo, 0) < 0)
134 hildon_touch_selector_set_active(combo, 0, i);