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
25 #include <hildon-cp-plugin/hildon-cp-plugin-interface.h>
26 #include <hildon/hildon.h>
27 #include <gconf/gconf.h>
28 #include <gconf/gconf-client.h>
35 #define GETTEXT_PACKAGE "ukeyboard"
36 #include <glib/gi18n-lib.h>
38 static init_func inits
[] = { prefs_hw_init
, prefs_onscreen_init
, prefs_lang_init
, prefs_about_init
};
39 #define PLUGINS (sizeof(inits) / sizeof(init_func))
40 static struct prefs prefs
[PLUGINS
];
42 gboolean internal_kbd
;
43 gboolean inside_scratchbox
;
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 if (access("/targets/links/scratchbox.config", F_OK
) == 0)
133 inside_scratchbox
= TRUE
;
135 inside_scratchbox
= FALSE
;
137 for (i
= 0; i
< PLUGINS
; i
++) {
141 dialog
= GTK_DIALOG(gtk_dialog_new());
146 gtk_window_set_transient_for(GTK_WINDOW(dialog
), GTK_WINDOW(data
));
148 title
= g_strdup_printf("%s (ukeyboard)", _TI("tein_ti_text_input_title"));
149 gtk_window_set_title(GTK_WINDOW(dialog
), title
);
153 gtk_dialog_add_button(GTK_DIALOG(dialog
), GTK_STOCK_ABOUT
, GTK_RESPONSE_HELP
);
154 gtk_dialog_add_button(GTK_DIALOG(dialog
), _HL("wdgt_bd_save"), GTK_RESPONSE_ACCEPT
);
156 scroll
= hildon_pannable_area_new();
157 g_object_set (G_OBJECT (scroll
), "hscrollbar-policy", GTK_POLICY_NEVER
, NULL
);
158 gtk_widget_set_size_request(GTK_WIDGET (scroll
), -1, 345);
159 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog
)->vbox
), scroll
);
161 vbox
= gtk_vbox_new(FALSE
, 0);
162 hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA(scroll
), vbox
);
164 gtk_widget_show_all(GTK_WIDGET(dialog
));
166 for (i
= 0; i
< PLUGINS
- 1; i
++) {
167 widget
= prefs
[i
].start(conf
, GTK_WIDGET(dialog
), &plugin_data
[i
]);
169 gtk_box_pack_start(GTK_BOX(vbox
), widget
, FALSE
, TRUE
, 0);
172 while ((res
= gtk_dialog_run(GTK_DIALOG(dialog
))) == GTK_RESPONSE_HELP
) {
173 about
= GTK_DIALOG(gtk_dialog_new());
174 gtk_window_set_title(GTK_WINDOW(about
), _HL("ecdg_ti_aboutdialog_title"));
175 gtk_widget_set_size_request (GTK_WIDGET (about
), -1, 300);
177 widget
= prefs
[3].start(conf
, GTK_WIDGET(about
), &plugin_data
[3]);
178 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(about
)->vbox
), widget
);
180 gtk_widget_show_all(GTK_WIDGET(about
));
181 gtk_dialog_run(GTK_DIALOG(about
));
182 gtk_widget_destroy(GTK_WIDGET(about
));
185 if (res
== GTK_RESPONSE_ACCEPT
) {
186 for (i
= 0; i
< PLUGINS
; i
++)
188 prefs
[i
].action(conf
, plugin_data
[i
]);
190 gtk_widget_destroy(GTK_WIDGET(dialog
));
192 for (i
= 0; i
< PLUGINS
; i
++)
194 prefs
[i
].stop(conf
, plugin_data
[i
]);