initial import
[slovak-l10n] / ukeyboard / cpanel / onscreen.c
1 /*
2  *  Copyright (c) 2008 Jiri Benc <jbenc@upir.cz>
3  *
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.
7  *
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.
12  *
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
16  */
17
18 #include <stdio.h>
19 #include <string.h>
20 #include <glib.h>
21 #include <gtk/gtk.h>
22 #include <hildon/hildon-caption.h>
23 #include <hildon/hildon-controlbar.h>
24 #include <device_symbols.h>
25 #include <libosso.h>
26 #include <gconf/gconf.h>
27 #include <gconf/gconf-client.h>
28 #include "prefs.h"
29 #include "onscreen.h"
30
31 #ifdef HAVE_MAEMO5
32 #define GETTEXT_PACKAGE "osso-applet-textinput"
33
34 #include <hildon/hildon.h>
35 #include <glib/gi18n-lib.h>
36 #endif
37
38 struct data {
39 #ifdef HAVE_MAEMO5
40         HildonCheckButton *use_finger;
41 #else
42         GtkToggleButton *stylus_im;
43         GtkToggleButton *use_finger;
44         GtkToggleButton *use_finger_sel;
45         GtkToggleButton *case_corr;
46         HildonControlbar *hand_speed;
47 #endif
48 };
49
50 #ifndef HAVE_MAEMO5
51 static gint get_hand_speed(GConfClient *client)
52 {
53         /* 150 300 400 600 900 */
54         gint res = get_int(client, "handwriting_timeout") / 200 + 1;
55         if (res > 5)
56                 res = 5;
57         if (res < 1)
58                 res = 1;
59         return res;
60 }
61
62 static void set_hand_speed(GConfClient *client, gint val)
63 {
64         switch (val) {
65         case 1: val = 150; break;
66         case 2: val = 300; break;
67         case 3: val = 400; break;
68         case 4: val = 600; break;
69         case 5: val = 900; break;
70         }
71         set_int(client, "handwriting_timeout", val);
72 }
73 #endif
74
75 #ifdef HAVE_MAEMO5
76 static GtkWidget *start(GConfClient *client, GtkWidget *win, void **data)
77 {
78         struct data *d;
79         GtkWidget *vbox;
80
81         (void)win;
82         d = g_new0(struct data, 1);
83
84         vbox = gtk_vbox_new(FALSE, 0);
85
86         d->use_finger = HILDON_CHECK_BUTTON(hildon_check_button_new(HILDON_SIZE_FINGER_HEIGHT));
87         hildon_check_button_set_active(d->use_finger, get_bool(client, "use_finger_kb"));
88         gtk_button_set_label (GTK_BUTTON (d->use_finger), _("tein_fi_use_virtual_keyboard"));
89         gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(d->use_finger), TRUE, TRUE, 0);
90
91         *data = d;
92
93         gtk_widget_show_all(vbox);
94
95         return vbox;
96 }
97 #else
98 static GtkWidget *start(GConfClient *client, GtkWidget *win, void **data)
99 {
100         struct data *d;
101         GtkBox *vbox;
102         GtkSizeGroup *group;
103         GtkWidget *align, *caption;
104
105         (void)win;
106         d = g_new0(struct data, 1);
107
108         vbox = GTK_BOX(gtk_vbox_new(FALSE, 0));
109         group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
110
111         if (internal_kbd) {
112                 d->stylus_im = GTK_TOGGLE_BUTTON(gtk_check_button_new());
113                 gtk_toggle_button_set_active(d->stylus_im, get_bool(client, "enable-stylus-im"));
114                 gtk_box_pack_start_defaults(vbox, hildon_caption_new(group, "Enable stylus input methods",
115                         GTK_WIDGET(d->stylus_im), NULL, HILDON_CAPTION_MANDATORY));
116         }
117
118         d->use_finger = GTK_TOGGLE_BUTTON(gtk_check_button_new());
119         gtk_toggle_button_set_active(d->use_finger, get_bool(client, "use_finger_kb"));
120         gtk_box_pack_start_defaults(vbox, hildon_caption_new(group, "Launch finger keyboard with finger tap",
121                 GTK_WIDGET(d->use_finger), NULL, HILDON_CAPTION_MANDATORY));
122
123         if (!internal_kbd) {
124                 d->use_finger_sel = GTK_TOGGLE_BUTTON(gtk_check_button_new());
125                 gtk_toggle_button_set_active(d->use_finger_sel, get_bool(client, "launch_finger_kb_on_select"));
126                 caption = hildon_caption_new(group, NULL,
127                         GTK_WIDGET(d->use_finger_sel), NULL, HILDON_CAPTION_MANDATORY);
128                 hildon_caption_set_label_markup(HILDON_CAPTION(caption), "Launch finger keyboard with " HWK_BUTTON_SELECT);
129                 gtk_box_pack_start_defaults(vbox, caption);
130         }
131
132         d->hand_speed = HILDON_CONTROLBAR(hildon_controlbar_new());
133         hildon_controlbar_set_range(d->hand_speed, 1, 5);
134         hildon_controlbar_set_value(d->hand_speed, get_hand_speed(client));
135         gtk_box_pack_start_defaults(vbox, hildon_caption_new(group, "Handwriting speed",
136                 GTK_WIDGET(d->hand_speed), NULL, HILDON_CAPTION_MANDATORY));
137
138         d->case_corr = GTK_TOGGLE_BUTTON(gtk_check_button_new());
139         gtk_toggle_button_set_active(d->case_corr, get_bool(client, "case_correction"));
140         gtk_box_pack_start_defaults(vbox, hildon_caption_new(group, "Handwriting case correction",
141                 GTK_WIDGET(d->case_corr), NULL, HILDON_CAPTION_MANDATORY));
142
143         g_object_unref(G_OBJECT(group));
144         *data = d;
145
146         align = gtk_alignment_new(0, 0, 1, 0);
147         gtk_container_add(GTK_CONTAINER(align), GTK_WIDGET(vbox));
148         return align;
149 }
150 #endif
151
152 static void action(GConfClient *client, void *data)
153 {
154         struct data *d = data;
155
156 #ifdef HAVE_MAEMO5
157         set_bool(client, "use_finger_kb", hildon_check_button_get_active(d->use_finger));
158 #else
159         if (d->stylus_im)
160                 set_bool(client, "enable-stylus-im", gtk_toggle_button_get_active(d->stylus_im));
161         set_bool(client, "use_finger_kb", gtk_toggle_button_get_active(d->use_finger));
162         if (d->use_finger_sel)
163                 set_bool(client, "launch_finger_kb_on_select", gtk_toggle_button_get_active(d->use_finger_sel));
164         set_hand_speed(client, hildon_controlbar_get_value(d->hand_speed));
165         set_bool(client, "case_correction", gtk_toggle_button_get_active(d->case_corr));
166 #endif
167 }
168
169 void prefs_onscreen_init(struct prefs *prefs)
170 {
171         prefs->start = start;
172         prefs->action = action;
173         prefs->stop = NULL;
174         prefs->name = internal_kbd ? "On-screen" : "General";
175 }