2 * Copyright (c) 2008 Jiri Benc <jbenc@upir.cz>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include <hildon/hildon-caption.h>
24 #include <gconf/gconf.h>
25 #include <gconf/gconf-client.h>
30 #define GETTEXT_PACKAGE "osso-applet-textinput"
32 #include <hildon/hildon.h>
33 #include <glib/gi18n-lib.h>
45 HildonTouchSelector *combo;
51 static char *strip(char *s)
53 while (*s == ' ' || *s == '\t' || *s == '\n' || *s == '\r')
58 static GList *get_layouts(gchar *path, gchar *model, GList *list)
73 while (fgets(buf, 512, f)) {
75 if (!strncmp(s, "xkb_symbols", 11)) {
89 } else if (!strncmp(s, "name", 4) && layout) {
107 lay = g_malloc(sizeof(struct layout));
108 lay->model = g_strdup(model);
109 lay->layout = layout;
110 lay->name = g_strdup(s);
112 list = g_list_append(list, lay);
119 static void free_layouts(GList *list)
124 for (item = list; item; item = g_list_next(item)) {
135 static GtkWidget *start(GConfClient *client, GtkWidget *win, void **data)
139 gchar *omodel, *olayout;
152 d = g_malloc(sizeof(struct data));
154 omodel = get_str(client, "int_kb_model");
155 olayout = get_str(client, "int_kb_layout");
156 d->layouts = get_layouts("/usr/share/X11/xkb/symbols/nokia_vndr/rx-51", "nokiarx51", NULL);
157 d->layouts = get_layouts("/usr/share/X11/xkb/symbols/nokia_vndr/ukeyboard", "ukeyboard", d->layouts);
159 d->combo = HILDON_TOUCH_SELECTOR(hildon_touch_selector_new_text());
161 button = hildon_picker_button_new(HILDON_SIZE_FINGER_HEIGHT, HILDON_BUTTON_ARRANGEMENT_VERTICAL);
162 hildon_button_set_title(HILDON_BUTTON(button), _("tein_fi_keyboard_layout"));
163 hildon_picker_button_set_selector(HILDON_PICKER_BUTTON (button), d->combo);
164 hildon_button_set_alignment (HILDON_BUTTON (button), 0.0, 0.5, 1.0, 0.0);
165 hildon_button_set_title_alignment(HILDON_BUTTON(button), 0.0, 0.5);
166 hildon_button_set_value_alignment (HILDON_BUTTON (button), 0.0, 0.5);
168 for (item = d->layouts, i = 0; item; item = g_list_next(item), i++) {
170 hildon_touch_selector_append_text(d->combo, lay->name);
171 if (omodel && olayout && !strcmp(lay->model, omodel) && !strcmp(lay->layout, olayout))
172 hildon_touch_selector_set_active(d->combo, 0, i);
180 gtk_widget_show(button);
185 static GtkWidget *start(GConfClient *client, GtkWidget *win, void **data)
189 gchar *omodel, *olayout;
204 d = g_malloc(sizeof(struct data));
206 omodel = get_str(client, "int_kb_model");
207 olayout = get_str(client, "int_kb_layout");
208 d->layouts = get_layouts("/usr/share/X11/xkb/symbols/nokia_vndr/rx-44", "nokiarx44", NULL);
209 d->layouts = get_layouts("/usr/share/X11/xkb/symbols/nokia_vndr/ukeyboard", "ukeyboard", d->layouts);
211 vbox = GTK_BOX(gtk_vbox_new(FALSE, 0));
212 group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
214 d->combo = GTK_COMBO_BOX(gtk_combo_box_new_text());
215 for (item = d->layouts, i = 0; item; item = g_list_next(item), i++) {
217 gtk_combo_box_append_text(d->combo, lay->name);
218 if (omodel && olayout && !strcmp(lay->model, omodel) && !strcmp(lay->layout, olayout))
219 gtk_combo_box_set_active(d->combo, i);
221 gtk_box_pack_start_defaults(vbox, hildon_caption_new(group, "Keyboard layout",
222 GTK_WIDGET(d->combo), NULL, HILDON_CAPTION_MANDATORY));
226 g_object_unref(G_OBJECT(group));
230 align = gtk_alignment_new(0, 0, 1, 0);
231 gtk_container_add(GTK_CONTAINER(align), GTK_WIDGET(vbox));
236 static void action(GConfClient *client, void *data)
238 struct data *d = data;
245 res = hildon_touch_selector_get_active(d->combo, 0);
247 res = gtk_combo_box_get_active(d->combo);
250 lay = g_list_nth_data(d->layouts, res);
252 set_str(client, "int_kb_model", lay->model);
253 set_str(client, "int_kb_layout", lay->layout);
258 static void stop(GConfClient *client, void *data)
260 struct data *d = data;
264 free_layouts(d->layouts);
269 void prefs_hw_init(struct prefs *prefs)
271 prefs->start = start;
272 prefs->action = action;
274 prefs->name = "Hardware";