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
23 #include <hildon/hildon-caption.h>
24 #include <hildon/hildon.h>
26 #include <gconf/gconf.h>
27 #include <gconf/gconf-client.h>
31 #define GETTEXT_PACKAGE "osso-applet-textinput"
32 #include <glib/gi18n-lib.h>
42 HildonTouchSelector *combo;
45 static char *strip(char *s)
47 while (*s == ' ' || *s == '\t' || *s == '\n' || *s == '\r')
52 static GList *get_layouts(gchar *path, gchar *model, GList *list)
67 while (fgets(buf, 512, f)) {
69 if (!strncmp(s, "xkb_symbols", 11)) {
83 } else if (!strncmp(s, "name", 4) && layout) {
101 lay = g_malloc(sizeof(struct layout));
102 lay->model = g_strdup(model);
103 lay->layout = layout;
104 lay->name = g_strdup(s);
106 list = g_list_append(list, lay);
113 static void free_layouts(GList *list)
118 for (item = list; item; item = g_list_next(item)) {
128 static GtkWidget *start(GConfClient *client, GtkWidget *win, void **data)
132 gchar *omodel, *olayout;
145 d = g_malloc(sizeof(struct data));
147 omodel = get_str(client, "int_kb_model");
148 olayout = get_str(client, "int_kb_layout");
149 d->layouts = get_layouts("/usr/share/X11/xkb/symbols/nokia_vndr/rx-51", "nokiarx51", NULL);
150 d->layouts = get_layouts("/usr/share/X11/xkb/symbols/nokia_vndr/ukeyboard", "ukeyboard", d->layouts);
152 d->combo = HILDON_TOUCH_SELECTOR(hildon_touch_selector_new_text());
154 button = hildon_picker_button_new(HILDON_SIZE_FINGER_HEIGHT, HILDON_BUTTON_ARRANGEMENT_VERTICAL);
155 hildon_button_set_title(HILDON_BUTTON(button), _("tein_fi_keyboard_layout"));
156 hildon_picker_button_set_selector(HILDON_PICKER_BUTTON (button), d->combo);
157 hildon_button_set_alignment (HILDON_BUTTON (button), 0.0, 0.5, 1.0, 0.0);
158 hildon_button_set_title_alignment(HILDON_BUTTON(button), 0.0, 0.5);
159 hildon_button_set_value_alignment (HILDON_BUTTON (button), 0.0, 0.5);
161 for (item = d->layouts, i = 0; item; item = g_list_next(item), i++) {
163 hildon_touch_selector_append_text(d->combo, lay->name);
164 if (omodel && olayout && !strcmp(lay->model, omodel) && !strcmp(lay->layout, olayout))
165 hildon_touch_selector_set_active(d->combo, 0, i);
173 gtk_widget_show(button);
178 static void action(GConfClient *client, void *data)
180 struct data *d = data;
186 res = hildon_touch_selector_get_active(d->combo, 0);
188 lay = g_list_nth_data(d->layouts, res);
190 set_str(client, "int_kb_model", lay->model);
191 set_str(client, "int_kb_layout", lay->layout);
196 static void stop(GConfClient *client, void *data)
198 struct data *d = data;
202 free_layouts(d->layouts);
207 void prefs_hw_init(struct prefs *prefs)
209 prefs->start = start;
210 prefs->action = action;
212 prefs->name = "Hardware";