Added package icon and better package description and details
[slovak-l10n] / ukeyboard / cpanel / langset.c
1 /*
2  *  Copyright (c) 2008 Jiri Benc <jbenc@upir.cz>
3  *  Copyright (c) 2009 Roman Moravcik <roman.moravcik@gmail.com>
4  *
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.
8  *
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.
13  *
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
17  */
18
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"
31
32 #define GETTEXT_PACKAGE "osso-applet-textinput"
33 #include <glib/gi18n-lib.h>
34
35 #define L_CONF_DIR      "/apps/osso/inputmethod/hildon-im-languages"
36
37 gboolean get_l_bool(GConfClient *client, char *lang, char *key)
38 {
39         char *tmp = g_strjoin("/", L_CONF_DIR, lang, key, NULL);
40         gboolean res;
41
42         res = gconf_client_get_bool(client, tmp, NULL);
43         g_free(tmp);
44         return res;
45 }
46
47 void set_l_bool(GConfClient *client, char *lang, char *key, gboolean val)
48 {
49         char *tmp = g_strjoin("/", L_CONF_DIR, lang, key, NULL);
50
51         g_debug("%s %d\n", tmp, val);
52
53         gconf_client_set_bool(client, tmp, val, NULL);
54         g_free(tmp);
55 }
56
57 gchar *get_l_str(GConfClient *client, char *lang, char *key)
58 {
59         char *tmp = g_strjoin("/", L_CONF_DIR, lang, key, NULL);
60         GConfValue *val;
61         gchar *res;
62
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;
70         }
71         res = g_strdup(gconf_value_get_string(val));
72         gconf_value_free(val);
73         return res;
74 }
75
76 void set_l_str(GConfClient *client, char *lang, char *key, gchar *val)
77 {
78         char *tmp = g_strjoin("/", L_CONF_DIR, lang, key, NULL);
79
80         gconf_client_set_string(client, tmp, val, NULL);
81         g_free(tmp);
82 }
83
84 void fill_dict(HildonTouchSelector *combo, GList *langs, gchar *deflang)
85 {
86         GList *item;
87         struct lang *lang;
88         unsigned i;
89
90         for (item = langs, i = 0; item; item = g_list_next(item)) {
91                 lang = item->data;
92                 if (lang->ext)
93                         continue;
94                 hildon_touch_selector_append_text(combo, lang->desc);
95                 if (deflang && !strcmp(lang->code, deflang))
96                         hildon_touch_selector_set_active(combo, 0, i);
97                 i++;
98         }
99         hildon_touch_selector_append_text(combo, _("tein_fi_word_completion_language_empty"));
100         if (!deflang || !*deflang)
101                 hildon_touch_selector_set_active(combo, 0, i);
102 }