Added dependency to version of hildon-im-fkb provided by PR1.2 due the the changes...
[ukeyboard.git] / cpanel / prefs.c
blob355024d7e7e0b3ba940bf9f98b5a977f7a2c7415
1 /*
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
19 #include <stdio.h>
20 #include <string.h>
21 #include <glib.h>
22 #include <gtk/gtk.h>
23 #include <libosso.h>
24 #include <hildon-cp-plugin/hildon-cp-plugin-interface.h>
25 #include <hildon/hildon.h>
26 #include <gconf/gconf.h>
27 #include <gconf/gconf-client.h>
28 #include "prefs.h"
29 #include "hw.h"
30 #include "onscreen.h"
31 #include "lang.h"
32 #include "about.h"
34 #define GETTEXT_PACKAGE "osso-applet-textinput"
35 #include <glib/gi18n-lib.h>
37 static init_func inits[] = { prefs_hw_init, prefs_onscreen_init, prefs_lang_init, prefs_about_init };
38 #define PLUGINS (sizeof(inits) / sizeof(init_func))
39 static struct prefs prefs[PLUGINS];
41 gboolean internal_kbd;
43 #define IM_CONF_DIR "/apps/osso/inputmethod"
45 gboolean get_bool(GConfClient *client, char *key)
47 char *tmp = g_strjoin("/", IM_CONF_DIR, key, NULL);
48 gboolean res;
50 res = gconf_client_get_bool(client, tmp, NULL);
51 g_free(tmp);
52 return res;
55 void set_bool(GConfClient *client, char *key, gboolean val)
57 char *tmp = g_strjoin("/", IM_CONF_DIR, key, NULL);
59 gconf_client_set_bool(client, tmp, val, NULL);
60 g_free(tmp);
63 gint get_int(GConfClient *client, char *key)
65 char *tmp = g_strjoin("/", IM_CONF_DIR, key, NULL);
66 gint res;
68 res = gconf_client_get_int(client, tmp, NULL);
69 g_free(tmp);
70 return res;
73 void set_int(GConfClient *client, char *key, gint val)
75 char *tmp = g_strjoin("/", IM_CONF_DIR, key, NULL);
77 gconf_client_set_int(client, tmp, val, NULL);
78 g_free(tmp);
81 gchar *get_str(GConfClient *client, char *key)
83 char *tmp = g_strjoin("/", IM_CONF_DIR, key, NULL);
84 gchar *res;
86 res = gconf_client_get_string(client, tmp, NULL);
87 g_free(tmp);
88 return res;
91 void set_str(GConfClient *client, char *key, gchar *val)
93 char *tmp = g_strjoin("/", IM_CONF_DIR, key, NULL);
95 gconf_client_set_string(client, tmp, val, NULL);
96 g_free(tmp);
99 static GConfClient *init_conf(void)
101 GConfClient *client;
103 client = gconf_client_get_default();
104 if (!client)
105 return NULL;
106 gconf_client_add_dir(client, IM_CONF_DIR, GCONF_CLIENT_PRELOAD_RECURSIVE, NULL);
107 internal_kbd = get_bool(client, "have-internal-keyboard");
108 return client;
111 static void deinit_conf(GConfClient *client)
113 g_object_unref(G_OBJECT(client));
116 osso_return_t execute(osso_context_t *osso, gpointer data, gboolean user_activated)
118 GConfClient *conf;
119 GtkDialog *dialog, *about;
120 GtkWidget *scroll, *widget, *vbox;
121 gchar *title;
122 void *plugin_data[PLUGINS];
123 unsigned i;
124 int res;
126 (void)osso; (void)user_activated; /* shut up, GCC */
128 conf = init_conf();
129 if (!conf)
130 return OSSO_ERROR;
132 for (i = 0; i < PLUGINS; i++) {
133 inits[i](prefs + i);
136 dialog = GTK_DIALOG(gtk_dialog_new());
137 if (!dialog) {
138 deinit_conf(conf);
139 return OSSO_ERROR;
141 gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(data));
143 title = g_strdup_printf("%s (ukeyboard)", _("tein_ti_text_input_title"));
144 gtk_window_set_title(GTK_WINDOW(dialog), title);
145 g_free(title);
148 gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_ABOUT, GTK_RESPONSE_HELP);
149 gtk_dialog_add_button(GTK_DIALOG(dialog), _HL("wdgt_bd_save"), GTK_RESPONSE_ACCEPT);
151 scroll = hildon_pannable_area_new();
152 g_object_set (G_OBJECT (scroll), "hscrollbar-policy", GTK_POLICY_NEVER, NULL);
153 gtk_widget_set_size_request(GTK_WIDGET (scroll), -1, 345);
154 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), scroll);
156 vbox = gtk_vbox_new(FALSE, 0);
157 hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA(scroll), vbox);
159 gtk_widget_show_all(GTK_WIDGET(dialog));
161 for (i = 0; i < PLUGINS - 1; i++) {
162 widget = prefs[i].start(conf, GTK_WIDGET(dialog), &plugin_data[i]);
163 if (widget)
164 gtk_box_pack_start(GTK_BOX(vbox), widget, FALSE, TRUE, 0);
167 while ((res = gtk_dialog_run(GTK_DIALOG(dialog))) == GTK_RESPONSE_HELP) {
168 about = GTK_DIALOG(gtk_dialog_new());
169 gtk_window_set_title(GTK_WINDOW(about), _HL("ecdg_ti_aboutdialog_title"));
170 gtk_widget_set_size_request (GTK_WIDGET (about), -1, 300);
172 widget = prefs[3].start(conf, GTK_WIDGET(about), &plugin_data[3]);
173 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(about)->vbox), widget);
175 gtk_widget_show_all(GTK_WIDGET(about));
176 gtk_dialog_run(GTK_DIALOG(about));
177 gtk_widget_destroy(GTK_WIDGET(about));
180 if (res == GTK_RESPONSE_ACCEPT) {
181 for (i = 0; i < PLUGINS; i++)
182 if (prefs[i].action)
183 prefs[i].action(conf, plugin_data[i]);
185 gtk_widget_destroy(GTK_WIDGET(dialog));
187 for (i = 0; i < PLUGINS; i++)
188 if (prefs[i].stop)
189 prefs[i].stop(conf, plugin_data[i]);
191 deinit_conf(conf);
192 return OSSO_OK;