2 * ISF(Input Service Framework)
4 * ISF is based on SCIM 1.4.7 and extended for supporting more mobile fitable.
5 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
7 * Contact: Shuo Liu <shuo0805.liu@samsung.com>, Hengliang Luo <hl.luo@samsung.com>
9 * This library is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU Lesser General Public License as published by the
11 * Free Software Foundation; either version 2.1 of the License, or (at your option)
14 * This library is distributed in the hope that it will be useful, but WITHOUT ANY
15 * WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17 * License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this library; if not, write to the Free Software Foundation, Inc., 51
21 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 #ifndef UG_WIZARD_MODULE_API
26 #define UG_WIZARD_MODULE_API __attribute__ ((visibility("default")))
29 #define Uses_SCIM_CONFIG_PATH
30 #define Uses_SCIM_HELPER_MODULE
33 #include <Elementary.h>
34 #include <Ecore_IMF.h>
35 #include "isf_control.h"
38 #include <glib-object.h>
39 #include <vconf-keys.h>
41 #include <ui-gadget-module.h>
42 #include <ui-gadget.h>
45 #include "scim_stl_map.h"
46 #include "isf_setting_wizard.h"
47 #include "../efl_panel/isf_panel_utility.h"
53 #define WIZARD_PACKAGE "keyboard-setting-wizard-efl"
54 #define WIZARD_LOCALEDIR "/opt/ug/res/locale"
55 #define T_(s) dgettext(WIZARD_PACKAGE, s)
56 #define LOG_TAG "isfsettingwizard"
58 static Elm_Genlist_Item_Class itc1,itcSeparator;
62 static Ecore_IMF_Context *imf_context = NULL;
64 static Evas_Object *sw_radio_grp = NULL; //sw view raido group
65 static std::vector<String> sw_iselist;
67 static ConfigPointer _config;
69 static char ise_bak[256] = {'\0'};
70 static char _active_ise_name[256] = {'\0'};
73 extern std::vector <String> _names;
74 extern std::vector <String> _uuids;
75 extern std::vector <String> _module_names;
76 extern std::vector <String> _langs;
78 static String uuid_to_name(String uuid)
81 for(unsigned int i = 0;i<_uuids.size();i++)
83 if (strcmp(uuid.c_str(),_uuids[i].c_str())== 0) {
91 static Evas_Object *_create_bg(Evas_Object *win)
93 Evas_Object *bg = elm_bg_add(win);
94 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
99 static Evas_Object *create_fullview (Evas_Object *parent, struct ug_data *ugd)
101 Evas_Object *bg = _create_bg(parent);
102 Evas_Object *layout_main = NULL;
104 layout_main = elm_layout_add (parent);
106 if (layout_main == NULL)
109 elm_layout_theme_set (layout_main, "layout","application","default");
110 elm_object_style_set(bg, "group_list");
111 elm_object_part_content_set (layout_main, "elm.swallow.bg", bg);
116 static Evas_Object *create_frameview (Evas_Object *parent, struct ug_data *ugd)
118 Evas_Object *bg = _create_bg(parent);
119 Evas_Object *layout_main = elm_layout_add (parent);
120 if (layout_main == NULL)
122 elm_layout_theme_set (layout_main, "layout", "application", "default");
123 elm_object_style_set(bg, "group_list");
124 elm_object_part_content_set (layout_main, "elm.swallow.bg", bg);
129 static void back_cb (void *data, Evas_Object *obj, void *event_info)
134 struct ug_data *ugd = (struct ug_data *)data;
135 ug_destroy_me (ugd->ug);
138 static Evas_Object* _create_naviframe_layout (Evas_Object* parent)
140 Evas_Object *naviframe = elm_naviframe_add (parent);
141 elm_object_part_content_set (parent, "elm.swallow.content", naviframe);
142 evas_object_show (naviframe);
147 static bool in_exit = false;
148 static void sw_keyboard_selection_view_back_cb (void *data, Evas_Object *obj, void *event_info)
151 LOGD("do nothing ,exit!\n");
159 struct ug_data *ugd = NULL;
160 ugd = (ug_data *)data;
162 if (strcmp (ise_bak, _active_ise_name) != 0) {
163 //if _active_ise_name is changed , active _active_ise_name.
164 //find the uuid of the active
166 for (unsigned int i = 0; i < _names.size (); i++) {
167 if (strcmp (_names[i].c_str (), _active_ise_name) == 0)
170 isf_control_set_active_ise_by_uuid ( uuid.c_str ());
172 snprintf (ise_bak, sizeof (ise_bak), "%s", _active_ise_name);
177 bundle_add(b, "name", "keyboard-setting-wizard-efl");
178 bundle_add(b, "description", "previous clicked");
179 ug_send_result(ugd->ug, b);
182 back_cb(data,obj,event_info);
184 LOGD("End of %s", __func__);
187 static void sw_keyboard_selection_view_set_cb (void *data, Evas_Object *obj, void *event_info)
196 struct ug_data *ugd = (struct ug_data *)data;
198 if (strcmp (ise_bak, _active_ise_name) != 0) {
199 //if _active_ise_name is changed , active _active_ise_name.
200 //find the uuid of the active
202 for (unsigned int i = 0; i < _names.size (); i++) {
203 if (strcmp (_names[i].c_str (), _active_ise_name) == 0)
206 isf_control_set_active_ise_by_uuid ( uuid.c_str ());
208 snprintf (ise_bak, sizeof (ise_bak), "%s", _active_ise_name);
209 LOGD("Set active ISE : %s", ise_bak);
214 bundle_add(b, "name", "keyboard-setting-wizard-efl");
215 bundle_add(b, "description", "next clicked");
216 ug_send_result(ugd->ug, b);
219 back_cb(data,obj,event_info);
221 LOGD("End of %s", __func__);
225 static void _gl_sel(void *data, Evas_Object *obj, void *event_info)
227 Elm_Object_Item *item = (Elm_Object_Item *)event_info;
228 elm_genlist_item_selected_set(item, 0);
230 snprintf (_active_ise_name, sizeof (_active_ise_name), "%s", sw_iselist[mark].c_str ());
231 elm_genlist_item_update(item);
235 static void _sw_radio_cb (void *data, Evas_Object *obj, void *event_info)
237 int index = GPOINTER_TO_INT(data);
238 elm_radio_value_set (sw_radio_grp, index);
239 snprintf (_active_ise_name, sizeof (_active_ise_name), "%s", sw_iselist[index].c_str ());
242 static char *_gl_label_get(void *data, Evas_Object *obj, const char *part)
244 int index = (int)(data);
245 if (!strcmp(part, "elm.text")) {
246 return strdup(sw_iselist[index].c_str());
251 static Evas_Object *_gl_icon_get(void *data, Evas_Object *obj, const char *part)
253 if (!strcmp(part, "elm.icon")) {
255 int index = (int)(data);
256 Evas_Object *radio = elm_radio_add (obj);
257 elm_radio_state_value_set (radio, index);
258 if (sw_radio_grp == NULL)
259 sw_radio_grp = elm_radio_add(obj);
260 elm_radio_group_add (radio, sw_radio_grp);
261 evas_object_show (radio);
262 evas_object_smart_callback_add (radio, "changed", _sw_radio_cb, (void *) (index));
264 elm_radio_value_set (sw_radio_grp, mark);
271 static Eina_Bool _gl_state_get(void *data, Evas_Object *obj, const char *part)
276 static void _gl_del(void *data, Evas_Object *obj)
281 static Evas_Object *isf_setting_main_view_tizen(ug_data * ugd)
283 String tmpStr = _config->read(SCIM_CONFIG_DEFAULT_HELPER_ISE,String("b70bf6cc-ff77-47dc-a137-60acc32d1e0c"));
284 snprintf (_active_ise_name, sizeof (_active_ise_name), "%s", (uuid_to_name(tmpStr)).c_str());
285 snprintf (ise_bak, sizeof (ise_bak), "%s", _active_ise_name);
286 LOGD("Default ISE Name : %s", ise_bak);
288 ugd->naviframe = _create_naviframe_layout (ugd->layout_main);
289 const char *navi_btn_l_lable = bundle_get_val(ugd->data, "navi_btn_left");
290 const char *navi_btn_r_lable = bundle_get_val(ugd->data, "navi_btn_right");
292 if (sw_radio_grp != NULL)
294 evas_object_del(sw_radio_grp);
298 Evas_Object *genlist = elm_genlist_add(ugd->naviframe);
299 evas_object_show(genlist);
301 Elm_Object_Item *nf_it;
302 Evas_Object *cbar = elm_toolbar_add (ugd->naviframe);
303 elm_toolbar_shrink_mode_set(cbar, ELM_TOOLBAR_SHRINK_EXPAND);
304 if (cbar == NULL) return NULL;
306 if (navi_btn_l_lable!= NULL) {
307 elm_toolbar_item_append(cbar, NULL, navi_btn_l_lable, sw_keyboard_selection_view_back_cb, ugd);
308 elm_toolbar_item_append(cbar, NULL, navi_btn_r_lable, sw_keyboard_selection_view_set_cb, ugd);
310 nf_it = elm_naviframe_item_push(ugd->naviframe, T_("Keyboard"), NULL, NULL, genlist, NULL);
311 elm_object_item_part_content_set(nf_it, "controlbar", cbar);
314 elm_toolbar_item_append(cbar, NULL, navi_btn_r_lable, sw_keyboard_selection_view_set_cb, ugd);
315 nf_it = elm_naviframe_item_push(ugd->naviframe, T_("Keyboard"), NULL, NULL, genlist, NULL);
316 elm_object_item_part_content_set(nf_it, "controlbar", cbar);
322 std::vector<String> selected_langs, all_langs;
324 isf_get_all_languages (all_langs);
325 isf_get_helper_names_in_languages (all_langs, sw_iselist);
326 std::sort (sw_iselist.begin (), sw_iselist.end ());
328 if (sw_iselist.size () > 0) {
329 // Set item class for dialogue group seperator
330 itcSeparator.item_style = "dialogue/separator/21/with_line";
331 itcSeparator.func.text_get = NULL;
332 itcSeparator.func.content_get = NULL;
333 itcSeparator.func.state_get = NULL;
334 itcSeparator.func.del = NULL;
337 Elm_Object_Item *item;
338 item = elm_genlist_item_append(
339 genlist, // genlist object
340 &itcSeparator, // item class
343 ELM_GENLIST_ITEM_NONE,
346 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
349 for (i = 0; i < sw_iselist.size (); i++) {
350 if (strcmp (_active_ise_name, sw_iselist[i].c_str ()) == 0) {
356 //set item class for 1text.1icon(text+radiobutton)
357 itc1.item_style = "dialogue/1text.1icon.2";
358 itc1.func.text_get = _gl_label_get;
359 itc1.func.content_get = _gl_icon_get;
360 itc1.func.state_get = _gl_state_get;
361 itc1.func.del = _gl_del;
362 for (i = 0;i < sw_iselist.size();i++) {
363 elm_genlist_item_append(genlist, &itc1,
364 (void *)(i), NULL, ELM_GENLIST_ITEM_NONE, _gl_sel,
368 return ugd->naviframe;
371 ConfigPointer isf_imf_context_get_config(void);
372 static void *on_create (struct ui_gadget *ug, enum ug_mode mode, bundle *data, void *priv)
374 Evas_Object *parent = NULL;
375 Evas_Object *content = NULL;
377 if ( ug == NULL || priv == NULL)
380 bindtextdomain (WIZARD_PACKAGE, WIZARD_LOCALEDIR);
382 struct ug_data *ugd = (struct ug_data *)priv;
385 parent = (Evas_Object *) ug_get_parent_layout (ug);
388 //-------------------------- ise infomation ----------------------------
390 const char *ctx_id = ecore_imf_context_default_id_get ();
391 if (ctx_id != NULL) {
392 imf_context = ecore_imf_context_add (ctx_id);
395 _config = isf_imf_context_get_config ();
396 if (_config.null ()) {
397 std::cerr << "Create dummy config!!!\n";
398 _config = new DummyConfig ();
401 if (_config.null ()) {
402 std::cerr << "Can not create Config Object!\n";
405 //only helper ISEs will be needed in isfsetting according to phone requirement.
406 isf_load_ise_information (HELPER_ONLY, _config);
407 // Request ISF to update ISE list, below codes are very important, dont remove
408 char **iselist = NULL;
409 int count = isf_control_get_ise_list (&iselist);
410 for (unsigned int i = 0; i < (unsigned int)count; i++) {
411 SCIM_DEBUG_MAIN (3) << " [" << i << " : " << iselist[i] << "] \n";
412 if (iselist[i] != NULL)
413 delete [] (iselist[i]);
418 //-------------------------- ise infomation ----------------------------
420 //construct the UI part of the isfsetting module
421 if (mode == UG_MODE_FULLVIEW)
422 ugd->layout_main = create_fullview (parent, ugd);
424 ugd->layout_main = create_frameview (parent, ugd);
426 if (ugd->layout_main != NULL) {
427 content = isf_setting_main_view_tizen(ugd);
428 elm_object_part_content_set (ugd->layout_main, "elm.swallow.content", content);
430 return (void *)ugd->layout_main;
433 static void on_start (struct ui_gadget *ug, bundle *data, void *priv)
437 static void on_pause (struct ui_gadget *ug, bundle *data, void *priv)
442 static void on_resume (struct ui_gadget *ug, bundle *data, void *priv)
447 static void on_destroy (struct ui_gadget *ug, bundle *data, void *priv)
449 if ( ug == NULL|| priv == NULL)
452 if (imf_context != NULL) {
453 ecore_imf_context_del(imf_context);
457 struct ug_data *ugd = (struct ug_data *) priv;
459 if (ugd->naviframe != NULL) {
460 evas_object_del (ugd->naviframe);
461 ugd->naviframe = NULL;
464 if (ugd->layout_main != NULL) {
465 evas_object_del (ugd->layout_main);
466 ugd->layout_main = NULL;
469 if (!_config.null ()) {
475 static void on_message (struct ui_gadget *ug, bundle *msg, bundle *data, void *priv)
479 static void on_event (struct ui_gadget *ug, enum ug_event event, bundle *data, void *priv)
482 case UG_EVENT_LOW_MEMORY:
484 case UG_EVENT_LOW_BATTERY:
486 case UG_EVENT_LANG_CHANGE:
488 case UG_EVENT_ROTATE_PORTRAIT:
490 case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
492 case UG_EVENT_ROTATE_LANDSCAPE:
494 case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
501 static void on_key_event(struct ui_gadget *ug, enum ug_key_event event, bundle *data, void *priv)
507 case UG_KEY_EVENT_END:
519 UG_WIZARD_MODULE_API int UG_MODULE_INIT (struct ug_module_ops *ops) {
523 struct ug_data *ugd = (ug_data*)calloc (1, sizeof (struct ug_data));
527 ops->create = on_create;
528 ops->start = on_start;
529 ops->pause = on_pause;
530 ops->resume = on_resume;
531 ops->destroy = on_destroy;
532 ops->message = on_message;
533 ops->event = on_event;
534 ops->key_event = on_key_event;
536 ops->opt = UG_OPT_INDICATOR_PORTRAIT_ONLY;
541 UG_WIZARD_MODULE_API void UG_MODULE_EXIT (struct ug_module_ops *ops) {
545 struct ug_data *ugd = (struct ug_data *)(ops->priv);
554 vi:ts=4:ai:nowrap:expandtab