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
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>
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
);
50 res
= gconf_client_get_bool(client
, tmp
, NULL
);
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
);
63 gint
get_int(GConfClient
*client
, char *key
)
65 char *tmp
= g_strjoin("/", IM_CONF_DIR
, key
, NULL
);
68 res
= gconf_client_get_int(client
, tmp
, NULL
);
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
);
81 gchar
*get_str(GConfClient
*client
, char *key
)
83 char *tmp
= g_strjoin("/", IM_CONF_DIR
, key
, NULL
);
86 res
= gconf_client_get_string(client
, tmp
, NULL
);
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
);
99 static GConfClient
*init_conf(void)
103 client
= gconf_client_get_default();
106 gconf_client_add_dir(client
, IM_CONF_DIR
, GCONF_CLIENT_PRELOAD_RECURSIVE
, NULL
);
107 internal_kbd
= get_bool(client
, "have-internal-keyboard");
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
)
119 GtkDialog
*dialog
, *about
;
120 GtkWidget
*scroll
, *widget
, *vbox
;
122 void *plugin_data
[PLUGINS
];
126 (void)osso
; (void)user_activated
; /* shut up, GCC */
132 for (i
= 0; i
< PLUGINS
; i
++) {
136 dialog
= GTK_DIALOG(gtk_dialog_new());
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
);
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
]);
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
++)
183 prefs
[i
].action(conf
, plugin_data
[i
]);
185 gtk_widget_destroy(GTK_WIDGET(dialog
));
187 for (i
= 0; i
< PLUGINS
; i
++)
189 prefs
[i
].stop(conf
, plugin_data
[i
]);