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>
25 #include <gconf/gconf.h>
26 #include <gconf/gconf-client.h>
31 #define GETTEXT_PACKAGE "osso-applet-textinput"
33 #include <hildon/hildon.h>
34 #include <glib/gi18n-lib.h>
46 HildonTouchSelector *combo;
52 static char *strip(char *s)
54 while (*s == ' ' || *s == '\t' || *s == '\n' || *s == '\r')
59 static GList *get_layouts(gchar *path, gchar *model, GList *list)
74 while (fgets(buf, 512, f)) {
76 if (!strncmp(s, "xkb_symbols", 11)) {
90 } else if (!strncmp(s, "name", 4) && layout) {
108 lay = g_malloc(sizeof(struct layout));
109 lay->model = g_strdup(model);
110 lay->layout = layout;
111 lay->name = g_strdup(s);
113 list = g_list_append(list, lay);
120 static void free_layouts(GList *list)
125 for (item = list; item; item = g_list_next(item)) {
136 static GtkWidget *start(GConfClient *client, GtkWidget *win, void **data)
140 gchar *omodel, *olayout;
153 d = g_malloc(sizeof(struct data));
155 omodel = get_str(client, "int_kb_model");
156 olayout = get_str(client, "int_kb_layout");
157 d->layouts = get_layouts("/usr/share/X11/xkb/symbols/nokia_vndr/rx-51", "nokiarx51", NULL);
158 d->layouts = get_layouts("/usr/share/X11/xkb/symbols/nokia_vndr/ukbdrx51", "ukbdrx51", d->layouts);
160 d->combo = HILDON_TOUCH_SELECTOR(hildon_touch_selector_new_text());
162 button = hildon_picker_button_new(HILDON_SIZE_FINGER_HEIGHT, HILDON_BUTTON_ARRANGEMENT_VERTICAL);
163 hildon_button_set_title(HILDON_BUTTON(button), _("tein_fi_keyboard_layout"));
164 hildon_picker_button_set_selector(HILDON_PICKER_BUTTON (button), d->combo);
165 hildon_button_set_alignment (HILDON_BUTTON (button), 0.0, 0.5, 1.0, 0.0);
166 hildon_button_set_title_alignment(HILDON_BUTTON(button), 0.0, 0.5);
167 hildon_button_set_value_alignment (HILDON_BUTTON (button), 0.0, 0.5);
169 for (item = d->layouts, i = 0; item; item = g_list_next(item), i++) {
171 hildon_touch_selector_append_text(d->combo, lay->name);
172 if (omodel && olayout && !strcmp(lay->model, omodel) && !strcmp(lay->layout, olayout))
173 hildon_touch_selector_set_active(d->combo, 0, i);
181 gtk_widget_show(button);
186 static GtkWidget *start(GConfClient *client, GtkWidget *win, void **data)
190 gchar *omodel, *olayout;
205 d = g_malloc(sizeof(struct data));
207 omodel = get_str(client, "int_kb_model");
208 olayout = get_str(client, "int_kb_layout");
209 d->layouts = get_layouts("/usr/share/X11/xkb/symbols/nokia_vndr/rx-44", "nokiarx44", NULL);
210 d->layouts = get_layouts("/usr/share/X11/xkb/symbols/nokia_vndr/ukbdrx44", "ukbdrx44", d->layouts);
212 vbox = GTK_BOX(gtk_vbox_new(FALSE, 0));
213 group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
215 d->combo = GTK_COMBO_BOX(gtk_combo_box_new_text());
216 for (item = d->layouts, i = 0; item; item = g_list_next(item), i++) {
218 gtk_combo_box_append_text(d->combo, lay->name);
219 if (omodel && olayout && !strcmp(lay->model, omodel) && !strcmp(lay->layout, olayout))
220 gtk_combo_box_set_active(d->combo, i);
222 gtk_box_pack_start_defaults(vbox, hildon_caption_new(group, "Keyboard layout",
223 GTK_WIDGET(d->combo), NULL, HILDON_CAPTION_MANDATORY));
227 g_object_unref(G_OBJECT(group));
231 align = gtk_alignment_new(0, 0, 1, 0);
232 gtk_container_add(GTK_CONTAINER(align), GTK_WIDGET(vbox));
237 static void action(GConfClient *client, void *data)
239 struct data *d = data;
246 res = hildon_touch_selector_get_active(d->combo, 0);
248 res = gtk_combo_box_get_active(d->combo);
251 lay = g_list_nth_data(d->layouts, res);
253 set_str(client, "int_kb_model", lay->model);
254 set_str(client, "int_kb_layout", lay->layout);
259 static void stop(GConfClient *client, void *data)
261 struct data *d = data;
265 free_layouts(d->layouts);
270 void prefs_hw_init(struct prefs *prefs)
272 prefs->start = start;
273 prefs->action = action;
275 prefs->name = "Hardware";