Replace sprintf with snprintf
[platform/core/uifw/inputmethod-setting.git] / im_setting_list / input_method_setting_list_ui.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 #define Uses_SCIM_PANEL_AGENT
18 #define Uses_SCIM_CONFIG_PATH
19 #define Uses_SCIM_HELPER_MODULE
20 #define Uses_SCIM_IMENGINE_MODULE
21 #define Uses_SCIM_COMPOSE_KEY
22
23 #include "input_method_setting_list.h"
24 #include <string>
25 #include <app.h>
26 #include <efl_extension.h>
27 #include <vector>
28 #include "isf_control.h"
29 #include <scim.h>
30 #include <scim_setup_module_efl.h>
31
32 #define IM_SETTING_LIST_PACKAGE                      PACKAGE
33 #define IM_SETTING_LIST_LOCALE_DIR                   ("/usr/apps/"PACKAGE_NAME"/res/locale")
34 #define IM_SETTING_LIST_TITLE                   dgettext(PACKAGE, "IDS_IME_BODY_KEYBOARD")
35 #define IM_SETTING_LIST_KEYBOARD_HEADER         dgettext(PACKAGE, "IDS_ST_HEADER_KEYBOARDS")
36 #define IM_SETTING_LIST_POPUP_TITLE             dgettext(PACKAGE, "IDS_ST_BODY_ATTENTION")
37 #define IM_SETTING_LIST_POPUP_CANCEL            dgettext(PACKAGE, "IDS_COM_SK_CANCEL_ABB")
38 #define IM_SETTING_LIST_POPUP_ENABLE            dgettext(PACKAGE, "IDS_ST_BUTTON_ENABLE")
39 #define IM_SETTING_LIST_VIRTUAL_KEYBOARD        dgettext(PACKAGE, "IDS_ST_HEADER_VIRTUAL_KEYBOARD")
40 #define IM_SETTING_LIST_DEFAULT_KEYBOARD        dgettext(PACKAGE, "IDS_ST_HEADER_DEFAULT_KEYBOARD_ABB")
41 #define IM_SETTING_LIST_KEYBOARD_SETTING        dgettext(PACKAGE, "IDS_IME_HEADER_KEYBOARD_SETTINGS_ABB")
42 #define IM_SETTING_LIST_POPUP_TEXT              dgettext(PACKAGE, "IDS_ST_POP_THIS_INPUT_METHOD_MAY_BE_ABLE_TO_COLLECT_ALL_THE"\
43                                                                   "_TEXT_YOU_TYPE_INCLUDING_PERSONAL_DATA_LIKE_PASSWORDS_AND"\
44                                                                   "_CREDIT_CARD_NUMBERS_MSG")
45
46
47 typedef struct list_item_text_s
48 {
49     char main_text[255];
50     char sub_text[255];
51 }list_item_text;
52
53 typedef struct popup_cb_data_s
54 {
55     Evas_Object *popup;
56     void *data;
57 }popup_cb_data;
58
59 typedef struct gen_item_data_s
60 {
61     Elm_Object_Item *gen_item;
62     int chk_status;
63 }gen_item_data;
64
65 typedef enum {
66     ISE_OPTION_MODULE_EXIST_SO = 0,
67     ISE_OPTION_MODULE_NO_EXIST
68 } ISE_OPTION_MODULE_STATE;
69
70 typedef void (*popup_ok_cb)(void *data, Evas_Object *obj, void *event_info);
71 typedef void (*popup_cancel_cb)(void *data, Evas_Object *obj, void *event_info);
72
73 static std::vector<ime_info_s>      g_ime_info_list;
74 static Elm_Genlist_Item_Class       *itc_im_list_keyboard_list = NULL;
75 static Elm_Genlist_Item_Class       *itc_im_list_group = NULL;
76 static Elm_Genlist_Item_Class       *itc_im_list_item = NULL;
77 static Elm_Genlist_Item_Class       *itc_im_list_item_one_line = NULL;
78 static int                          g_active_ime_index = -1;
79 static list_item_text               item_text[2];
80 static std::vector<gen_item_data>   g_gen_item_data;
81
82 static std::vector<String>          _setup_modules;
83 static String                       _mdl_name;
84 static SetupModule                  *_mdl = NULL;
85 static ConfigPointer                _config;
86 static Connection                   _reload_signal_connection;
87 static ISE_OPTION_MODULE_STATE      _ise_option_module_stat = ISE_OPTION_MODULE_NO_EXIST;
88
89 static Ecore_Fd_Handler            *_read_handler             = 0;
90 static HelperAgent                  _helper_agent;
91 static HelperInfo                   _helper_info ("fd491a70-22f5-11e2-89f3-eb5999be869e", "ISF Setting", "", "", SCIM_HELPER_STAND_ALONE);
92
93 void im_setting_list_update_window(void *data);
94
95 static void helper_ise_reload_config (void)
96 {
97     if (_helper_agent.is_connected ())
98         _helper_agent.reload_config ();
99 }
100
101 static Eina_Bool ise_option_view_set_cb (void *data, Elm_Object_Item *it)
102 {
103     if (!data || !_mdl)
104         return EINA_TRUE;
105
106     _mdl->save_config (_config);
107     helper_ise_reload_config ();
108
109     return EINA_TRUE;
110 }
111
112 static ISE_OPTION_MODULE_STATE find_ise_option_module (char *active_ime_appid)
113 {
114     LOGD ("%s", active_ime_appid);
115
116     _ise_option_module_stat = ISE_OPTION_MODULE_NO_EXIST;
117
118     _mdl_name = active_ime_appid + String ("-setup");
119     for (unsigned int i = 0; i < _setup_modules.size (); i++) {
120         if (_mdl_name == _setup_modules[i]) {
121             _ise_option_module_stat = ISE_OPTION_MODULE_EXIST_SO;
122         }
123     }
124
125     return _ise_option_module_stat;
126 }
127
128 static void im_setting_list_text_domain_set(void)
129 {
130    bindtextdomain(IM_SETTING_LIST_PACKAGE, IM_SETTING_LIST_LOCALE_DIR);
131    textdomain(IM_SETTING_LIST_PACKAGE);
132 }
133
134 static Evas_Object *
135 im_setting_list_main_window_create(const char *name)
136 {
137     Evas_Object *eo = NULL;
138     int w = -1, h = -1;
139     eo = elm_win_add(NULL, name, ELM_WIN_BASIC);
140     if (eo) {
141         elm_win_title_set(eo, name);
142         elm_win_borderless_set(eo, EINA_TRUE);
143         elm_win_alpha_set(eo, EINA_FALSE);
144         elm_win_conformant_set(eo, EINA_TRUE);
145         elm_win_autodel_set(eo, EINA_TRUE);
146         elm_win_screen_size_get(eo, NULL, NULL, &w, &h);
147         if(w == -1 || h == -1){
148            LOGD("elm_win_screen_size_get() is failed\n");
149            return NULL;
150         }
151         evas_object_resize(eo, w, h);
152         int rots[4] = {0, 90, 180, 270};
153         elm_win_wm_rotation_available_rotations_set(eo, rots, 4);
154     }
155     return eo;
156 }
157
158 static Evas_Object* im_setting_list_bg_create(Evas_Object *parent)
159 {
160     Evas_Object *bg;
161     if (parent == NULL) return NULL;
162     bg = elm_bg_add(parent);
163     evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
164     elm_win_resize_object_add(parent, bg);
165     evas_object_show(bg);
166     return bg;
167 }
168
169 static void im_setting_list_load_ime_info(void)
170 {
171     ime_info_s *info = NULL;
172     g_ime_info_list.clear();
173     int cnt = isf_control_get_all_ime_info(&info);
174     if(info)
175     {
176         for(int i=0; i<cnt; ++i)
177         {
178             SECURE_LOGD("%s %s %d %d %d", info[i].appid, info[i].label, info[i].is_enabled, info[i].is_preinstalled, info[i].has_option);
179             g_ime_info_list.push_back(info[i]);
180         }
181         free(info);
182     }
183     else
184     {
185         LOGD("isf_control_get_all_ime_info failed\n");
186     }
187 }
188
189 static int im_setting_list_get_active_ime_index(void)
190 {
191     char *active_ime_appid = NULL;
192     isf_control_get_active_ime(&active_ime_appid);
193     std::vector<ime_info_s>::iterator iter = g_ime_info_list.begin();
194     std::vector<ime_info_s>::iterator end = g_ime_info_list.end();
195     for (; iter != end; ++iter)
196     {
197         if(active_ime_appid && (!strcmp(active_ime_appid, iter->appid)))
198         {
199             break;
200         }
201     }
202     if(active_ime_appid)
203     {
204         free(active_ime_appid);
205     }
206     return (iter-g_ime_info_list.begin());
207 }
208
209 static void
210 im_setting_list_app_control_reply_cb(app_control_h request, app_control_h reply, app_control_result_e result, void *user_data)
211 {
212     if (!request || !reply) {
213         LOGD("app_control handle is null");
214         return;
215     }
216     if (result == APP_CONTROL_RESULT_SUCCEEDED) {
217         char *value = NULL;
218         int res = app_control_get_extra_data(reply, "result", &value);
219         if (APP_CONTROL_ERROR_NONE == res && NULL != value) {
220             im_setting_list_update_window(user_data);
221         }
222         if (value){
223             free(value);
224         }
225     }
226 }
227
228 static void im_setting_list_show_ime_selector(void *data)
229 {
230     int ret;
231     app_control_h app_control;
232     const char *app_id = "org.tizen.inputmethod-setting-selector"; // This is temporary. AppId can be got using pkgmgr-info later.
233     ret = app_control_create (&app_control);
234     if (ret != APP_CONTROL_ERROR_NONE) {
235           LOGD("app_control_create returned %d", ret);
236           return;
237     }
238
239     ret = app_control_set_operation (app_control, APP_CONTROL_OPERATION_DEFAULT);
240     if (ret != APP_CONTROL_ERROR_NONE) {
241           LOGD("app_control_set_operation returned %d", ret);
242           app_control_destroy(app_control);
243           return;
244       }
245
246       ret = app_control_set_app_id (app_control, app_id);
247       if (ret != APP_CONTROL_ERROR_NONE) {
248           LOGD("app_control_set_app_id returned %d", ret);
249           app_control_destroy(app_control);
250           return;
251       }
252
253       app_control_add_extra_data(app_control, "caller", "settings");
254       ret = app_control_send_launch_request(app_control, im_setting_list_app_control_reply_cb, data);
255       if (ret != APP_CONTROL_ERROR_NONE) {
256          LOGD("app_control_send_launch_request returned %d, %s\n", ret, get_error_message(ret));
257          app_control_destroy(app_control);
258          return;
259       }
260       app_control_destroy(app_control);
261 }
262
263 static void
264 im_setting_list_check_popup_ok_cb(void *data, Evas_Object *obj, void *event_info)
265 {
266     popup_cb_data *cb_data = (popup_cb_data *)data;
267     int index = (int)reinterpret_cast<long>(cb_data->data);
268     Eina_Bool state = EINA_FALSE;
269     state = g_gen_item_data[index].chk_status;
270     isf_control_set_enable_ime(g_ime_info_list[index].appid, state);
271     evas_object_del(cb_data->popup);
272     delete cb_data;
273 }
274
275 static void
276 im_setting_list_check_popup_cancel_cb(void *data, Evas_Object *obj, void *event_info)
277 {
278     popup_cb_data *cb_data = (popup_cb_data *)data;
279     int index = (int)reinterpret_cast<long>(cb_data->data);
280     Eina_Bool state = g_gen_item_data[index].chk_status;
281     isf_control_set_enable_ime(g_ime_info_list[index].appid, !state);
282     g_gen_item_data[index].chk_status = !state;
283     elm_genlist_item_update(g_gen_item_data[index].gen_item);
284     evas_object_del(cb_data->popup);
285     delete cb_data;
286 }
287
288 static void im_setting_list_show_popup(void *data, Evas_Object *obj, popup_ok_cb ime_setting_list_ok_callback, popup_cancel_cb ime_setting_list_cancel_callback)
289 {
290     int index = (int)reinterpret_cast<long>(data);
291     Evas_Object *top_widget = elm_object_top_widget_get(obj);
292     Evas_Object *popup = elm_popup_add(top_widget);
293     elm_popup_align_set (popup, ELM_NOTIFY_ALIGN_FILL, 0.5);
294     eext_object_event_callback_add (popup, EEXT_CALLBACK_BACK, eext_popup_back_cb, NULL);
295     elm_object_part_text_set(popup, "title,text", IM_SETTING_LIST_POPUP_TITLE);
296
297     char chFormatMsg[255] = {'\0'};
298     char chPopupMsg[255] = {'\0'};
299     snprintf(chFormatMsg, sizeof(chFormatMsg), "%s", IM_SETTING_LIST_POPUP_TEXT);
300     snprintf(chPopupMsg, sizeof(chPopupMsg), chFormatMsg, g_ime_info_list[index].label);
301     elm_object_text_set(popup, chPopupMsg);
302
303     popup_cb_data *cb_data = new popup_cb_data;
304     cb_data->popup = popup;
305     cb_data->data = data;
306
307     Evas_Object *btn_cancel = elm_button_add(popup);
308     elm_object_text_set(btn_cancel, IM_SETTING_LIST_POPUP_CANCEL);
309     elm_object_part_content_set(popup, "button1", btn_cancel);
310     evas_object_smart_callback_add(btn_cancel, "clicked", ime_setting_list_cancel_callback, cb_data);
311
312     Evas_Object *btn_ok = elm_button_add(popup);
313     elm_object_text_set(btn_ok, IM_SETTING_LIST_POPUP_ENABLE);
314     elm_object_part_content_set(popup, "button2", btn_ok);
315     evas_object_smart_callback_add(btn_ok, "clicked", ime_setting_list_ok_callback, cb_data);
316
317     evas_object_show(popup);
318
319 }
320
321 static void im_setting_list_check_button_change_cb(void *data, Evas_Object *obj, void *event_info)
322 {
323     /*save the checked ime*/
324     int index = (int)reinterpret_cast<long>(data);
325     Eina_Bool state = g_gen_item_data[index].chk_status;
326
327     if(!state)
328     {
329         isf_control_set_enable_ime(g_ime_info_list[index].appid, state);
330     }
331     else
332     {
333         im_setting_list_show_popup(data, obj, im_setting_list_check_popup_ok_cb, im_setting_list_check_popup_cancel_cb);
334     }
335 }
336
337 static void
338 im_setting_list_popup_ok_cb(void *data, Evas_Object *obj, void *event_info)
339 {
340     popup_cb_data *cb_data = (popup_cb_data *)data;
341     int index = (int)reinterpret_cast<long>(cb_data->data);
342     Eina_Bool state = g_gen_item_data[index].chk_status;
343     g_gen_item_data[index].chk_status = !state;
344     isf_control_set_enable_ime(g_ime_info_list[index].appid, !state);
345     elm_genlist_item_update(g_gen_item_data[index].gen_item);
346     evas_object_del(cb_data->popup);
347     delete cb_data;
348 }
349
350 static void
351 im_setting_list_popup_cancel_cb(void *data, Evas_Object *obj, void *event_info)
352 {
353     popup_cb_data *cb_data = (popup_cb_data *)data;
354     evas_object_del(cb_data->popup);
355     delete cb_data;
356 }
357
358 static void im_setting_list_item_sel_cb(void *data, Evas_Object *obj, void *event_info)
359 {
360     Elm_Object_Item *item = (Elm_Object_Item *)event_info;
361     elm_genlist_item_selected_set (item, EINA_FALSE);
362
363     int index = (int)reinterpret_cast<long>(data);
364     if(g_ime_info_list[index].is_preinstalled || (index == g_active_ime_index))
365     {
366         return;
367     }
368
369     Evas_Object *ck = elm_object_item_part_content_get (item, "elm.icon.right");
370     if (ck == NULL){
371         ck = elm_object_item_part_content_get (item, "elm.icon");
372     }
373     Eina_Bool state = g_gen_item_data[index].chk_status;
374
375     if(state)
376     {
377         g_gen_item_data[index].chk_status = !state;
378         isf_control_set_enable_ime(g_ime_info_list[index].appid, !state);
379         elm_genlist_item_update(item);
380     }
381     else
382     {
383         im_setting_list_show_popup(data, obj, im_setting_list_popup_ok_cb, im_setting_list_popup_cancel_cb);
384     }
385 }
386
387 static void im_setting_list_set_default_keyboard_item_sel_cb(void *data, Evas_Object *obj, void *event_info)
388 {
389     Elm_Object_Item *item = (Elm_Object_Item *)event_info;
390     elm_genlist_item_selected_set (item, EINA_FALSE);
391     im_setting_list_show_ime_selector(data);
392 }
393
394 static void im_setting_list_keyboard_setting_item_sel_cb(void *data, Evas_Object *obj, void *event_info)
395 {
396     Elm_Object_Item *item = (Elm_Object_Item *)event_info;
397     elm_genlist_item_selected_set (item, EINA_FALSE);
398     Evas_Object *option_content;
399     appdata *ad = (appdata *)data;
400     char *active_ime_appid = NULL;
401     isf_control_get_active_ime(&active_ime_appid);
402
403     if (ad && active_ime_appid && ISE_OPTION_MODULE_EXIST_SO == find_ise_option_module (active_ime_appid)) {
404         if (_mdl) {
405             delete _mdl;
406             _mdl = NULL;
407         }
408
409         if (_mdl_name.length () > 0)
410             _mdl = new SetupModule (String (_mdl_name));
411
412         if (_mdl == NULL || !_mdl->valid ()) {
413             free(active_ime_appid);
414             return;
415         } else {
416             LOGD("keyboard option window is showing");
417             _mdl->load_config (_config);
418             option_content = _mdl->create_ui (ad->conform, ad->naviframe);
419
420             Elm_Object_Item *it = elm_naviframe_item_push (ad->naviframe, IM_SETTING_LIST_KEYBOARD_SETTING, NULL, NULL, option_content, NULL);
421             elm_naviframe_item_pop_cb_set (it, ise_option_view_set_cb, ad);
422         }
423     }
424     else {
425         isf_control_open_ime_option_window();
426     }
427     if (active_ime_appid)
428         free(active_ime_appid);
429 }
430
431 static Evas_Object *im_setting_list_conform_create(Evas_Object *parentWin)
432 {
433     Evas_Object *conform = elm_conformant_add(parentWin);
434     elm_win_indicator_mode_set(parentWin, ELM_WIN_INDICATOR_SHOW);
435     elm_win_indicator_opacity_set(parentWin, ELM_WIN_INDICATOR_OPAQUE);
436     evas_object_size_hint_weight_set(conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
437     evas_object_size_hint_align_set(conform, EVAS_HINT_FILL, EVAS_HINT_FILL);
438     elm_win_resize_object_add(parentWin, conform);
439     evas_object_show(conform);
440     return conform;
441 }
442
443 static Evas_Object *im_setting_list_naviframe_create(Evas_Object* parent)
444 {
445     Evas_Object *naviframe = elm_naviframe_add(parent);
446     elm_naviframe_prev_btn_auto_pushed_set(naviframe, EINA_FALSE);
447     eext_object_event_callback_add(naviframe, EEXT_CALLBACK_BACK, eext_naviframe_back_cb, NULL);
448     evas_object_size_hint_weight_set(naviframe, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
449     evas_object_size_hint_align_set(naviframe, EVAS_HINT_FILL, EVAS_HINT_FILL);
450     elm_object_part_content_set(parent, "elm.swallow.content", naviframe);
451     evas_object_show(naviframe);
452     return naviframe;
453 }
454
455 static Evas_Object *im_setting_list_genlist_create(Evas_Object* parent)
456 {
457     Evas_Object *genlist = elm_genlist_add(parent);
458     evas_object_show(genlist);
459     return genlist;
460 }
461
462 static char *im_setting_list_genlist_group_label_get(void *data, Evas_Object *obj, const char *part)
463 {
464     char *text = (char *)data;
465 #ifdef _MOBILE
466     if (!strcmp(part, "elm.text.main")) {
467 #else
468     if (!strcmp(part, "elm.text")) {
469 #endif
470         return strdup(text);
471     }
472     return NULL;
473 }
474
475 static char *im_setting_list_genlist_keyboard_list_item_label_get(void *data, Evas_Object *obj, const char *part)
476 {
477     int index = (int)reinterpret_cast<long>(data);
478     if (!strcmp(part, "elm.text.main.left.top") ||
479         !strcmp(part, "elm.text.main.left") ||
480         !strcmp(part, "elm.text.main") ||
481         !strcmp(part, "elm.text") ||
482         !strcmp(part, "elm.text.1")) {
483         return strdup(g_ime_info_list[index].label);
484     }
485     return NULL;
486 }
487
488 static Evas_Object *im_setting_list_genlist_keyboard_list_item_icon_get(void *data, Evas_Object *obj, const char *part)
489 {
490     int index = (int)reinterpret_cast<long>(data);
491     if (!strcmp(part, "elm.icon.right") || !strcmp(part, "elm.icon")) {
492         Evas_Object *ck = elm_check_add(obj);
493         elm_object_style_set (ck, "on&off");
494         elm_object_disabled_set(ck, g_ime_info_list[index].is_preinstalled || (index == g_active_ime_index));
495         elm_check_state_set(ck, g_gen_item_data[index].chk_status);
496         evas_object_propagate_events_set (ck, EINA_FALSE);
497         evas_object_size_hint_align_set(ck, EVAS_HINT_FILL, EVAS_HINT_FILL);
498         evas_object_size_hint_weight_set(ck, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
499         elm_check_state_pointer_set(ck, (Eina_Bool *)(&(g_gen_item_data[index].chk_status)));
500         evas_object_pass_events_set(ck, 1);
501         evas_object_smart_callback_add(ck, "changed", im_setting_list_check_button_change_cb, (void *)(index));
502         evas_object_show(ck);
503         return ck;
504     }
505     return NULL;
506 }
507
508 static char *im_setting_list_genlist_item_label_get(void *data, Evas_Object *obj, const char *part)
509 {
510     list_item_text *item_text = (list_item_text *)data;
511     if (!strcmp(part, "elm.text.main.left.top") ||
512         !strcmp(part, "elm.text.main.left") ||
513         !strcmp(part, "elm.text.main") ||
514         !strcmp(part, "elm.text") ||
515         !strcmp(part, "elm.text.1")) {
516         return strdup(item_text->main_text);
517     }
518
519     if (!strcmp(part, "elm.text.sub.left.bottom") ||
520         !strcmp(part, "elm.text.multiline") ||
521         !strcmp(part, "elm.text.2")) {
522         return strdup(item_text->sub_text);
523     }
524     return NULL;
525 }
526
527 static char *im_setting_list_genlist_item_one_line_label_get(void *data, Evas_Object *obj, const char *part)
528 {
529     list_item_text *item_text = (list_item_text *)data;
530     if (!strcmp(part, "elm.text.main.left.top") ||
531         !strcmp(part, "elm.text.main.left") ||
532         !strcmp(part, "elm.text.main") ||
533         !strcmp(part, "elm.text") ||
534         !strcmp(part, "elm.text.1")) {
535         return strdup(item_text->main_text);
536     }
537     return NULL;
538 }
539
540 static void im_setting_list_genlist_item_class_create(int app_type)
541 {
542     if(NULL == itc_im_list_group)
543     {
544         itc_im_list_group = elm_genlist_item_class_new();
545         if(itc_im_list_group)
546         {
547             itc_im_list_group->item_style = "groupindex";
548             itc_im_list_group->func.text_get = im_setting_list_genlist_group_label_get;
549             itc_im_list_group->func.content_get = NULL;
550             itc_im_list_group->func.state_get = NULL;
551             itc_im_list_group->func.del = NULL;
552         }
553     }
554
555     if(NULL == itc_im_list_keyboard_list)
556     {
557         itc_im_list_keyboard_list = elm_genlist_item_class_new();
558         if (itc_im_list_keyboard_list)
559         {
560 #ifdef _MOBILE
561             itc_im_list_keyboard_list->item_style = "1line";
562 #else
563             itc_im_list_keyboard_list->item_style = "1text.1icon.1";
564 #endif
565             itc_im_list_keyboard_list->func.text_get = im_setting_list_genlist_keyboard_list_item_label_get;
566             itc_im_list_keyboard_list->func.content_get = im_setting_list_genlist_keyboard_list_item_icon_get;
567             itc_im_list_keyboard_list->func.state_get = NULL;
568             itc_im_list_keyboard_list->func.del = NULL;
569         }
570     }
571
572     if(app_type == APP_TYPE_SETTING)
573     {
574         if(NULL == itc_im_list_item)
575         {
576             itc_im_list_item = elm_genlist_item_class_new();
577             if (itc_im_list_item)
578             {
579 #ifdef _MOBILE
580                 itc_im_list_item->item_style = "2line.top";
581 #else
582                 itc_im_list_item->item_style = "2text";
583 #endif
584                 itc_im_list_item->func.text_get = im_setting_list_genlist_item_label_get;
585                 itc_im_list_item->func.content_get = NULL;
586                 itc_im_list_item->func.state_get = NULL;
587                 itc_im_list_item->func.del = NULL;
588             }
589         }
590
591         if(NULL == itc_im_list_item_one_line)
592         {
593             itc_im_list_item_one_line = elm_genlist_item_class_new();
594             if (itc_im_list_item_one_line)
595             {
596 #ifdef _MOBILE
597                 itc_im_list_item_one_line->item_style = "1line";
598 #else
599                 itc_im_list_item_one_line->item_style = "1text";
600 #endif
601                 itc_im_list_item_one_line->func.text_get = im_setting_list_genlist_item_one_line_label_get;
602                 itc_im_list_item_one_line->func.content_get = NULL;
603                 itc_im_list_item_one_line->func.state_get = NULL;
604                 itc_im_list_item_one_line->func.del = NULL;
605             }
606         }
607     }
608 }
609
610 static void im_setting_list_add_ime(void *data) {
611     appdata *ad = (appdata *)data;
612     int i = 0;
613     im_setting_list_genlist_item_class_create(ad->app_type);
614
615     if(NULL != ad->genlist)
616     {
617         elm_genlist_clear(ad->genlist);
618     }
619
620     g_active_ime_index = im_setting_list_get_active_ime_index();
621 //    list_item_text item_text;
622     memset(&item_text, 0, sizeof(item_text));
623     if(ad->app_type == APP_TYPE_SETTING)
624     {
625         elm_genlist_item_append(ad->genlist,
626             itc_im_list_group,
627             IM_SETTING_LIST_VIRTUAL_KEYBOARD,
628             NULL,
629             ELM_GENLIST_ITEM_NONE,
630             NULL,
631             NULL);
632
633         snprintf(item_text[0].main_text, sizeof(item_text[0].main_text), "%s", IM_SETTING_LIST_DEFAULT_KEYBOARD);
634         snprintf(item_text[0].sub_text, sizeof(item_text[0].sub_text), "%s", g_ime_info_list[g_active_ime_index].label);
635         elm_genlist_item_append(ad->genlist,
636             itc_im_list_item,
637             (void *)&item_text[0],
638             NULL,
639             ELM_GENLIST_ITEM_NONE,
640             im_setting_list_set_default_keyboard_item_sel_cb,
641             data);
642
643         snprintf(item_text[1].main_text, sizeof(item_text[1].main_text), "%s", IM_SETTING_LIST_KEYBOARD_SETTING);
644         Elm_Object_Item *item = elm_genlist_item_append(ad->genlist,
645             itc_im_list_item_one_line,
646             (void *)&item_text[1],
647             NULL,
648             ELM_GENLIST_ITEM_NONE,
649             im_setting_list_keyboard_setting_item_sel_cb,
650             data);
651
652         elm_object_item_disabled_set(item, !(g_ime_info_list[g_active_ime_index].has_option));
653     }
654
655     elm_genlist_item_append(ad->genlist,
656             itc_im_list_group,
657             IM_SETTING_LIST_KEYBOARD_HEADER,
658             NULL,
659             ELM_GENLIST_ITEM_NONE,
660             NULL,
661             NULL);
662
663     /* keyboard list */
664     int info_list_size = g_ime_info_list.size();
665     for (i = 0; i < info_list_size; i++) {
666         gen_item_data item_data;
667
668         if(g_ime_info_list[i].is_preinstalled || (i == g_active_ime_index)){
669             item_data.chk_status = EINA_TRUE;
670         }else
671         {
672             item_data.chk_status = g_ime_info_list[i].is_enabled;
673         }
674         g_gen_item_data.push_back(item_data);
675
676         Elm_Object_Item *item = elm_genlist_item_append(ad->genlist,
677             itc_im_list_keyboard_list,
678             (void *)(i),
679             NULL,
680             ELM_GENLIST_ITEM_NONE,
681             im_setting_list_item_sel_cb,
682             (void *)(i));
683
684         g_gen_item_data[i].gen_item = item;
685     }
686 }
687
688 static Eina_Bool im_setting_list_navi_item_pop_cb(void *data, Elm_Object_Item *it)
689 {
690     static bool in_exit = false;
691     if (in_exit)
692         return EINA_TRUE;
693     in_exit = true;
694     if (data == NULL)
695         return EINA_TRUE;
696     ui_app_exit();
697     return EINA_TRUE;
698 }
699
700 static void im_setting_list_navi_back_btn_call_cb(void *data, Evas_Object *obj, void *event_info)
701 {
702     evas_object_smart_callback_del(obj, "clicked", im_setting_list_navi_back_btn_call_cb);
703     ui_app_exit();
704 }
705
706 Evas_Object *im_setting_list_list_create(void *data)
707 {
708     appdata *ad = (appdata *)data;
709     ad->conform = im_setting_list_conform_create(ad->win);
710     ad->naviframe = im_setting_list_naviframe_create(ad->conform);
711     ad->genlist = im_setting_list_genlist_create(ad->naviframe);
712     im_setting_list_add_ime(ad);
713
714     /* Add genlist to naviframe */
715     Evas_Object *back_btn = elm_button_add (ad->naviframe);
716     elm_object_style_set (back_btn, "naviframe/back_btn/default");
717     evas_object_smart_callback_add(back_btn, "clicked", im_setting_list_navi_back_btn_call_cb, NULL);
718     Elm_Object_Item *nf_main_item = elm_naviframe_item_push(ad->naviframe,
719                 IM_SETTING_LIST_TITLE,
720                 back_btn,
721                 NULL,
722                 ad->genlist,
723                 NULL);
724     elm_naviframe_item_title_enabled_set(nf_main_item, EINA_TRUE, EINA_TRUE);
725     elm_naviframe_item_pop_cb_set(nf_main_item, im_setting_list_navi_item_pop_cb, ad);
726     elm_object_content_set(ad->conform, ad->naviframe);
727
728     return ad->genlist;
729 }
730
731 void im_setting_list_app_terminate(void *data)
732 {
733     g_ime_info_list.clear();
734     g_gen_item_data.clear();
735     if(NULL != itc_im_list_keyboard_list)
736     {
737         elm_genlist_item_class_free(itc_im_list_keyboard_list);
738         itc_im_list_keyboard_list = NULL;
739     }
740
741     if(NULL != itc_im_list_group)
742     {
743         elm_genlist_item_class_free(itc_im_list_group);
744         itc_im_list_group = NULL;
745     }
746
747     if(NULL != itc_im_list_item)
748     {
749         elm_genlist_item_class_free(itc_im_list_item);
750         itc_im_list_item = NULL;
751     }
752 }
753
754 void im_setting_list_update_window(void *data)
755 {
756     appdata *ad = (appdata *)data;
757     im_setting_list_load_ime_info();
758     im_setting_list_add_ime(ad);
759 }
760
761 static void load_config_module (void)
762 {
763     _config = ConfigBase::get (true, "socket");
764     if (_config.null ()) {
765         std::cerr << "Create dummy config!!!\n";
766         _config = new DummyConfig ();
767     }
768
769     if (_config.null ()) {
770         std::cerr << "Can not create Config Object!\n";
771     }
772 }
773
774 /**
775  * @brief Reload config slot function for HelperAgent.
776  *
777  * @param ic The context of application.
778  * @param ise_uuid The ISE uuid.
779  *
780  * @return void
781  */
782 static void slot_reload_config (const HelperAgent *, int ic, const String &ise_uuid)
783 {
784
785 }
786
787 /**
788  * @brief Handler function for HelperAgent input.
789  *
790  * @param user_data Data to pass when it is called.
791  * @param fd_handler The Ecore Fd handler.
792  *
793  * @return ECORE_CALLBACK_RENEW
794  */
795 static Eina_Bool helper_agent_input_handler (void *user_data, Ecore_Fd_Handler *fd_handler)
796 {
797     if (fd_handler == _read_handler && _helper_agent.has_pending_event ()) {
798         if (!_helper_agent.filter_event ()) {
799             LOGD ("helper_agent.filter_event () failed!!!\n");
800         }
801     } else {
802         LOGD ("helper_agent.has_pending_event () failed!!!\n");
803     }
804
805     return ECORE_CALLBACK_RENEW;
806 }
807
808 void
809 im_setting_list_app_create(void *data)
810 {
811     appdata *ad = (appdata *)data;
812     im_setting_list_text_domain_set();
813     ad->win = im_setting_list_main_window_create(PACKAGE);
814     im_setting_list_bg_create(ad->win);
815     im_setting_list_load_ime_info();
816
817     load_config_module ();
818     scim_get_setup_module_list (_setup_modules);
819
820     /* Connect PanelAgent by HelperAgent */
821     String display_name = String (":13");
822     const char *p = getenv ("DISPLAY");
823     if (p != NULL)
824         display_name = String (p);
825
826     _reload_signal_connection = _helper_agent.signal_connect_reload_config (slot (slot_reload_config));
827     int id = _helper_agent.open_connection (_helper_info, display_name);
828     if (id == -1) {
829         LOGD("open_connection failed!!!!!!\n");
830     } else {
831         int fd = _helper_agent.get_connection_number ();
832         if (fd >= 0)
833             _read_handler = ecore_main_fd_handler_add (fd, ECORE_FD_READ, helper_agent_input_handler, NULL, NULL, NULL);
834     }
835
836     im_setting_list_list_create(ad);
837     evas_object_show(ad->win);
838 }
839