Version bump (2.5-2)
[ukeyboard.git] / cpanel / langset.c
blob5da57b5efae8d9438461e8ed68524a6fec6dacbc
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, "es-qwerty")) &&
99 (strcmp(lang->fname, "ru-windows")))
100 continue;
103 dict = g_malloc(sizeof(struct lang));
104 dict->fname = g_strdup(lang->fname);
105 dict->desc = g_strdup(lang->desc);
106 dict->code = g_strdup(lang->code);
107 dicts = g_list_append(dicts, dict);
109 return dicts;
112 void fill_dict(HildonTouchSelector *combo, GList *langs, gchar *deflang)
114 GList *item;
115 struct lang *lang;
116 unsigned i;
118 for (item = langs, i = 0; item; item = g_list_next(item)) {
119 lang = item->data;
121 hildon_touch_selector_append_text(combo, lang->desc);
123 if (deflang && !strcmp(lang->code, deflang))
124 hildon_touch_selector_set_active(combo, 0, i);
125 i++;
128 hildon_touch_selector_append_text(combo, _TI("tein_fi_word_completion_language_empty"));
130 if (!deflang || !*deflang)
131 hildon_touch_selector_set_active(combo, 0, i);
133 /* check if something is really selected, if not select last item */
134 if (hildon_touch_selector_get_active(combo, 0) < 0)
135 hildon_touch_selector_set_active(combo, 0, i);