808891e839b31494877d307550b6e3b714c6bab1
[platform/core/uifw/inputdelegator.git] / src / w-input-selector.cpp
1 /*
2  * Copyright (c) 2016 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 #include "Debug.h"
18
19 #include <app.h>
20 #include <dlog.h>
21 #include <Eina.h>
22 #include <string>
23 #include <vconf.h>
24 #include <vconf-keys.h>
25 #include <stdint.h>
26 #include <system_info.h>
27
28 #include "w-input-selector.h"
29 #include "w-input-template.h"
30 #include "w-input-keyboard.h"
31 #include "w-input-stt-ise.h"
32 #include "w-input-emoticon.h"
33 #include "w-input-smartreply.h"
34
35 #include <stt.h>
36
37
38 using namespace std;
39
40 App_Data* app_data = NULL;
41
42 InputKeyboardData g_input_keyboard_data;
43 InputTypeData g_input_type_data;
44 InputTemplateData g_input_template_data;
45
46
47 static Elm_Object_Item *it_empty;
48 static Elm_Object_Item *it_title;
49
50 static unsigned int g_smartreply_item_size = 0;         /* Current Smartreply item size */
51 static unsigned int g_template_item_size = 0;           /* Current Template item size */
52
53 Evas_Coord last_step; // 0 ~ 9 for gesture, 10~11 for rotary
54
55 tizen_profile_t _get_tizen_profile()
56 {
57         static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN;
58         if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
59                 return profile;
60
61         char *profileName;
62         system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
63         switch (*profileName)
64         {
65                 case 'm':
66                 case 'M':
67                         profile = TIZEN_PROFILE_MOBILE;
68                         break;
69                 case 'w':
70                 case 'W':
71                         profile = TIZEN_PROFILE_WEARABLE;
72                         break;
73                 case 't':
74                 case 'T':
75                         profile = TIZEN_PROFILE_TV;
76                         break;
77                 case 'i':
78                 case 'I':
79                         profile = TIZEN_PROFILE_IVI;
80                         break;
81                 default: // common or unknown ==> ALL ARE COMMON.
82                         profile = TIZEN_PROFILE_COMMON;
83         }
84         free(profileName);
85
86         return profile;
87 }
88
89 void _init_app_data(App_Data* app_data);
90 static void _app_language_changed(app_event_info_h event_info, void *user_data);
91
92 Evas_Object* _create_genlist(Evas_Object* parent);
93 void _create_genlist_items(void* user_data);
94 void _create_header_items(void *user_data);
95 void _update_genlist_items(void *user_data);
96 unsigned int _update_smartreply_items(void *user_data);
97 unsigned int _update_template_items(void *user_data);
98 unsigned int _update_user_template_items(void *user_data);
99 static void _popup_close_cb(void *data, Evas_Object *obj, void *event_info);
100 static void _popup_back_cb(void *data, Evas_Object *obj, void *event_info);
101 static void input_type_deinit(void);
102
103 bool __compare_string(const char * src, const char * dst);
104
105 void _init_app_data(App_Data* app_data)
106 {
107         app_data->win_main = NULL;
108         app_data->layout_main = NULL;
109         app_data->conform = NULL;
110         app_data->naviframe = NULL;
111         app_data->genlist = NULL;
112
113         app_data->res_path = NULL;
114 }
115
116 Evas_Object* load_edj(Evas_Object* parent, const char* file, const char* group)
117 {
118         Evas_Object* window;
119         Evas_Object* content;
120         int ret;
121
122         window = elm_layout_add(parent);
123         if (window) {
124                 ret = elm_layout_file_set(window, file, group);
125                 if (!ret) {
126                         evas_object_del(window);
127                         return NULL;
128                 }
129
130                 content = elm_layout_add(parent);
131                 elm_layout_theme_set(content, "layout", "application", "default");
132                 elm_object_part_content_set(window, "elm.swallow.content", content);
133
134                 evas_object_size_hint_weight_set(window, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
135         }
136         return window;
137 }
138
139 void init_customizing_theme(void)
140 {
141         string stt_edj_path = get_resource_path();
142         string app_edj_path = get_resource_path();
143
144         if (_WEARABLE) {
145                 stt_edj_path = stt_edj_path + STT_EDJ_FILE_WEARABLE;
146                 app_edj_path = app_edj_path + APP_EDJ_FILE_WEARABLE;
147         } else if (_TV) {
148                 stt_edj_path = stt_edj_path + STT_EDJ_FILE_TV;
149                 app_edj_path = app_edj_path + APP_EDJ_FILE_TV;
150         } else {
151                 stt_edj_path = stt_edj_path + STT_EDJ_FILE_MOBILE;
152                 app_edj_path = app_edj_path + APP_EDJ_FILE_MOBILE;
153         }
154
155         elm_theme_extension_add(NULL, stt_edj_path.c_str());
156         elm_theme_extension_add(NULL, app_edj_path.c_str());
157 }
158
159 static Eina_Bool back_cb(void *data, Elm_Object_Item *it)
160 {
161         reply_to_sender_by_callback_for_back();
162         ui_app_exit();
163         return EINA_FALSE;
164 }
165
166 static void _stt_clicked_cb(void *data, Evas_Object * obj, void *event_info)
167 {
168         App_Data* ad = (App_Data*)data;
169
170         PRINTFUNC(DLOG_DEBUG, "");
171
172         if (!ad)
173                 return;
174
175         ise_show_stt_popup(ad);
176 }
177
178 static void _input_smartreply_notify_cb(void *user_data)
179 {
180         ecore_main_loop_iterate();
181         _update_genlist_items((void *)app_data);
182 }
183
184 static void _input_template_notify_cb(void *user_data)
185 {
186         _update_genlist_items((void *)app_data);
187 }
188
189 static void _emoticon_clicked_cb(void *data, Evas_Object * obj, void *event_info)
190 {
191         App_Data* ad = (App_Data*)data;
192
193         PRINTFUNC(DLOG_DEBUG, "");
194
195         if (!ad)
196                 return;
197
198         ise_show_emoticon_list(ad);
199 }
200
201 static void _keyboard_clicked_cb(void *data, Evas_Object * obj, void *event_info)
202 {
203         App_Data* ad = (App_Data *)data;
204
205         PRINTFUNC(DLOG_DEBUG, "");
206
207         if (!ad)
208                 return;
209
210         input_keyboard_launch(ad->win_main, data);
211 }
212
213 static void __ise_smartreply_gl_sel(void *data, Evas_Object *obj, void *event_info)
214 {
215         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
216
217         if (item) {
218                 elm_genlist_item_selected_set(item, EINA_FALSE);
219
220                 int index = (intptr_t) elm_object_item_data_get(item);
221
222                 int type;
223                 char *reply = input_smartreply_get_nth_item(index, &type);
224                 if (reply) {
225                         input_smartreply_send_feedback(reply);
226                         reply_to_sender_by_callback(reply, "smartreply", NULL, NULL);
227                         free(reply);
228                         elm_exit();
229                 }
230         }
231 }
232
233 static void __ise_template_gl_sel(void *data, Evas_Object *obj, void *event_info)
234 {
235         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
236         int index = 0;
237
238         if (item) {
239                 elm_genlist_item_selected_set(item, EINA_FALSE);
240
241                 index = (uintptr_t) elm_object_item_data_get(item);
242                 const std::vector<TemplateData>  template_list = input_template_get_list();
243
244                 if (index < (int)template_list.size()) {
245                         reply_to_sender_by_callback(gettext(template_list[index].text.c_str()), "template", NULL, NULL);
246                         ui_app_exit();
247                 }
248         }
249 }
250
251 static void __ise_user_template_gl_sel(void *data, Evas_Object *obj, void *event_info)
252 {
253         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
254         int index = 0;
255
256         if (item) {
257                 elm_genlist_item_selected_set(item, EINA_FALSE);
258
259                 index = (uintptr_t) elm_object_item_data_get(item);
260
261                 if (index < (int)g_input_template_data.input_template_array_len) {
262                         reply_to_sender_by_callback(g_input_template_data.input_template_array[index], "user_template", NULL, NULL);
263                         ui_app_exit();
264                 }
265         }
266 }
267
268 static char * __ise_template_gl_text_get(void *data, Evas_Object *obj, const char *part)
269 {
270         if (!strcmp(part, "elm.text")) {
271                 unsigned int index = (uintptr_t)data;
272                 const std::vector<TemplateData>  template_list = input_template_get_list();
273
274                 if (index < template_list.size()) {
275                         if (template_list[index].use_gettext) {
276                                 return strdup(gettext(template_list[index].text.c_str()));
277                         } else {
278                                 Eina_Strbuf *buf = NULL;
279                                 const char *str = NULL;
280                                 char *markup = NULL;
281
282                                 buf = eina_strbuf_new();
283                                 if (buf) {
284                                         eina_strbuf_append(buf, template_list[index].text.c_str());
285                                         eina_strbuf_replace_all(buf, "\n", "");
286                                         eina_strbuf_replace_all(buf, "\r", "");
287
288                                         str = eina_strbuf_string_get(buf);
289
290                                         if (str) {
291                                                 markup = elm_entry_utf8_to_markup(str);
292                                         }
293                                         eina_strbuf_free(buf);
294                                 }
295                                 return markup;
296                         }
297                 }
298         }
299         return NULL;
300 }
301
302 static char * __ise_user_template_gl_text_get(void *data, Evas_Object *obj, const char *part)
303 {
304         if (!strcmp(part, "elm.text")) {
305                 unsigned int index = (uintptr_t)data;
306                 if (index < (unsigned int)g_input_template_data.input_template_array_len) {
307                         if (g_input_template_data.input_template_array[index] != NULL) {
308                                 return strdup(g_input_template_data.input_template_array[index]);
309                         }
310                 }
311         }
312         return NULL;
313 }
314
315 static Evas_Object * __ise_gl_2button_content_get(void *data, Evas_Object *obj, const char *part)
316 {
317         char *first_input_type = *(g_input_type_data.input_type_array + 0);
318         char *second_input_type = *(g_input_type_data.input_type_array + 1);
319
320         if (!strcmp(part, "elm.icon.1") ||  (!strcmp(part, "elm.icon.2"))) {
321                 Evas_Object* btn = elm_button_add(obj);
322                 evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
323                 evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
324
325                 Evas_Object* ic = elm_image_add(btn);
326                 elm_image_resizable_set(ic, EINA_TRUE, EINA_TRUE);
327                 string path = get_resource_path();
328                 if (_WEARABLE)
329                         path = path + "wearable/";
330                 else if (_TV)
331                         path = path + "tv/";
332                 else
333                         path = path + "mobile/";
334
335                 if (!strcmp(part, "elm.icon.1")) {
336                         string path_ic;
337                         if (!strcmp(first_input_type, "input_voice")) {
338                                 elm_object_style_set(btn, "ime_button_stt");
339                                 path_ic = path + "images/w_mode_stt_ic.png";
340                                 evas_object_smart_callback_add(btn, "clicked", _stt_clicked_cb, app_data);
341                                 elm_atspi_accessible_name_set(btn, "IDS_IME_MBODY_VOICE_INPUT");
342                                 elm_atspi_accessible_translation_domain_set(btn, PACKAGE);
343                         } else if (!strcmp(first_input_type, "input_emoticon")) {
344                                 elm_object_style_set(btn, "ime_button_emoticon");
345                                 path_ic = path + "images/Delta_w_mode_emoticon_ic.png";
346                                 evas_object_smart_callback_add(btn, "clicked", _emoticon_clicked_cb, app_data);
347                                 elm_atspi_accessible_name_set(btn, "IDS_COM_HEADER_EMOTICON");
348                                 elm_atspi_accessible_translation_domain_set(btn, PACKAGE);
349                         } else if (!strcmp(first_input_type, "input_keyboard")) {
350                                 elm_object_style_set(btn, "ime_button_keyboard");
351                                 path_ic = path + "images/w_mode_keyboard_ic.png";
352                                 evas_object_propagate_events_set(btn, EINA_FALSE);
353                                 evas_object_smart_callback_add(btn, "clicked", _keyboard_clicked_cb, app_data);
354                                 elm_atspi_accessible_name_set(btn, "IDS_COM_OPT_KEYBOARD");
355                                 elm_atspi_accessible_translation_domain_set(btn, PACKAGE);
356                         }
357                         elm_image_file_set(ic, path_ic.c_str(), NULL);
358                         elm_object_content_set(btn, ic);
359                         evas_object_layer_set(btn, 32000);
360                 } else if (!strcmp(part, "elm.icon.2")){
361                         string path_ic;
362                         if (!strcmp(second_input_type, "input_voice")) {
363                                 elm_object_style_set(btn, "ime_button_stt");
364                                 path_ic = path + "images/w_mode_stt_ic.png";
365                                 evas_object_smart_callback_add(btn, "clicked", _stt_clicked_cb, app_data);
366                                 elm_atspi_accessible_name_set(btn, "IDS_IME_MBODY_VOICE_INPUT");
367                                 elm_atspi_accessible_translation_domain_set(btn, PACKAGE);
368                         } else if (!strcmp(second_input_type, "input_emoticon")) {
369                                 elm_object_style_set(btn, "ime_button_emoticon");
370                                 path_ic = path + "images/Delta_w_mode_emoticon_ic.png";
371                                 evas_object_smart_callback_add(btn, "clicked", _emoticon_clicked_cb, app_data);
372                                 elm_atspi_accessible_name_set(btn, "IDS_COM_HEADER_EMOTICON");
373                                 elm_atspi_accessible_translation_domain_set(btn, PACKAGE);
374                         } else if (!strcmp(second_input_type, "input_keyboard")) {
375                                 elm_object_style_set(btn, "ime_button_keyboard");
376                                 path_ic = path + "images/w_mode_keyboard_ic.png";
377                                 evas_object_propagate_events_set(btn, EINA_FALSE);
378                                 evas_object_smart_callback_add(btn, "clicked", _keyboard_clicked_cb, app_data);
379                                 elm_atspi_accessible_name_set(btn, "IDS_COM_OPT_KEYBOARD");
380                                 elm_atspi_accessible_translation_domain_set(btn, PACKAGE);
381                         }
382                         elm_image_file_set(ic, path_ic.c_str(), NULL);
383                         elm_object_content_set(btn, ic);
384                         evas_object_layer_set(btn, 32000);
385                 }
386                 return btn;
387         } else if (!strcmp(part, "elm.icon.1.touch_area") ||  (!strcmp(part, "elm.icon.2.touch_area"))) {
388                 Evas_Object* btn = elm_button_add(obj);
389                 elm_object_style_set(btn, "touch_area");
390                 evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
391                 evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
392                 string path = get_resource_path();
393                 if (!strcmp(part, "elm.icon.1.touch_area")) {
394                         evas_object_layer_set(btn, 32000);
395                         if (!strcmp(first_input_type, "input_voice")) {
396                                 evas_object_smart_callback_add(btn, "clicked", _stt_clicked_cb, app_data);
397                                 elm_atspi_accessible_name_set(btn, "IDS_IME_MBODY_VOICE_INPUT");
398                                 elm_atspi_accessible_translation_domain_set(btn, PACKAGE);
399                         } else if (!strcmp(first_input_type, "input_emoticon")) {
400                                 evas_object_smart_callback_add(btn, "clicked", _emoticon_clicked_cb, app_data);
401                                 elm_atspi_accessible_name_set(btn, "IDS_COM_HEADER_EMOTICON");
402                                 elm_atspi_accessible_translation_domain_set(btn, PACKAGE);
403                         } else if (!strcmp(first_input_type, "input_keyboard")) {
404                                 evas_object_propagate_events_set(btn, EINA_FALSE);
405                                 evas_object_smart_callback_add(btn, "clicked", _keyboard_clicked_cb, app_data);
406                                 elm_atspi_accessible_name_set(btn, "IDS_COM_OPT_KEYBOARD");
407                                 elm_atspi_accessible_translation_domain_set(btn, PACKAGE);
408                         }
409                 } else if (!strcmp(part, "elm.icon.2.touch_area")){
410                         evas_object_layer_set(btn, 32000);
411                         if (!strcmp(second_input_type, "input_voice")) {
412                                 evas_object_smart_callback_add(btn, "clicked", _stt_clicked_cb, app_data);
413                                 elm_atspi_accessible_name_set(btn, "IDS_IME_MBODY_VOICE_INPUT");
414                                 elm_atspi_accessible_translation_domain_set(btn, PACKAGE);
415                         } else if (!strcmp(second_input_type, "input_emoticon")) {
416                                 evas_object_smart_callback_add(btn, "clicked", _emoticon_clicked_cb, app_data);
417                                 elm_atspi_accessible_name_set(btn, "IDS_COM_HEADER_EMOTICON");
418                                 elm_atspi_accessible_translation_domain_set(btn, PACKAGE);
419                         } else if (!strcmp(second_input_type, "input_keyboard")) {
420                                 evas_object_propagate_events_set(btn, EINA_FALSE);
421                                 evas_object_smart_callback_add(btn, "clicked", _keyboard_clicked_cb, app_data);
422                                 elm_atspi_accessible_name_set(btn, "IDS_COM_OPT_KEYBOARD");
423                                 elm_atspi_accessible_translation_domain_set(btn, PACKAGE);
424                         }
425                 }
426                 return btn;
427         } else if (!strcmp(part, "base")) {
428                 Evas_Object* btn = elm_button_add(obj);
429                 elm_object_style_set(btn, "ime_transparent");
430                 return btn;
431         }
432         return NULL;
433 }
434
435 static Evas_Object * __ise_gl_3button_content_get(void *data, Evas_Object *obj, const char *part)
436 {
437         if (!strcmp(part, "elm.icon.1") ||  (!strcmp(part, "elm.icon.2")) ||  (!strcmp(part, "elm.icon.3"))) {
438                 Evas_Object* btn = elm_button_add(obj);
439                 evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
440                 evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
441                 Evas_Object* ic = elm_image_add(btn);
442                 elm_image_resizable_set(ic, EINA_TRUE, EINA_TRUE);
443                 string path = get_resource_path();
444                 if (_WEARABLE)
445                         path = path + "wearable/";
446                 else if (_TV)
447                         path = path + "tv/";
448                 else
449                         path = path + "mobile/";
450
451                 if (!strcmp(part, "elm.icon.1")) {
452                         elm_object_style_set(btn, "ime_button_stt");
453                         string path_ic = path + "images/w_mode_stt_ic.png";
454                         elm_image_file_set(ic, path_ic.c_str(), NULL);
455                         elm_object_content_set(btn, ic);
456                         evas_object_layer_set(btn, 32000);
457                         evas_object_smart_callback_add(btn, "clicked", _stt_clicked_cb, app_data);
458                         elm_atspi_accessible_name_set(btn, "IDS_IME_MBODY_VOICE_INPUT");
459                         elm_atspi_accessible_translation_domain_set(btn, PACKAGE);
460
461                 } else if (!strcmp(part, "elm.icon.2")){
462                         elm_object_style_set(btn, "ime_button_emoticon");
463                         string path_ic = path + "images/Delta_w_mode_emoticon_ic.png";
464                         elm_image_file_set(ic, path_ic.c_str(), NULL);
465                         elm_object_content_set(btn, ic);
466                         evas_object_layer_set(btn, 32000);
467                         evas_object_smart_callback_add(btn, "clicked", _emoticon_clicked_cb, app_data);
468                         elm_atspi_accessible_name_set(btn, "IDS_COM_HEADER_EMOTICON");
469                         elm_atspi_accessible_translation_domain_set(btn, PACKAGE);
470
471                 } else if (!strcmp(part, "elm.icon.3")){
472                         elm_object_style_set(btn, "ime_button_keyboard");
473                         string path_ic = path + "images/w_mode_keyboard_ic.png";
474                         elm_image_file_set(ic, path_ic.c_str(), NULL);
475                         elm_object_content_set(btn, ic);
476                         evas_object_layer_set(btn, 32000);
477                         evas_object_propagate_events_set(btn, EINA_FALSE);
478                         evas_object_smart_callback_add(btn, "clicked", _keyboard_clicked_cb, app_data);
479                         elm_atspi_accessible_name_set(btn, "IDS_COM_OPT_KEYBOARD");
480                         elm_atspi_accessible_translation_domain_set(btn, PACKAGE);
481                 }
482
483                 return btn;
484         } else if (!strcmp(part, "elm.icon.1.touch_area") ||  (!strcmp(part, "elm.icon.2.touch_area")) ||  (!strcmp(part, "elm.icon.3.touch_area"))) {
485                 Evas_Object* btn = elm_button_add(obj);
486                 elm_object_style_set(btn, "touch_area");
487                 evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
488                 evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
489                 string path = get_resource_path();
490                 if (!strcmp(part, "elm.icon.1.touch_area")) {
491                         evas_object_layer_set(btn, 32000);
492                         evas_object_smart_callback_add(btn, "clicked", _stt_clicked_cb, app_data);
493                         elm_atspi_accessible_name_set(btn, "IDS_IME_MBODY_VOICE_INPUT");
494                         elm_atspi_accessible_translation_domain_set(btn, PACKAGE);
495
496                 } else if (!strcmp(part, "elm.icon.2.touch_area")){
497                         evas_object_layer_set(btn, 32000);
498                         evas_object_smart_callback_add(btn, "clicked", _emoticon_clicked_cb, app_data);
499                         elm_atspi_accessible_name_set(btn, "IDS_COM_HEADER_EMOTICON");
500                         elm_atspi_accessible_translation_domain_set(btn, PACKAGE);
501                 } else if (!strcmp(part, "elm.icon.3.touch_area")) {
502                         evas_object_layer_set(btn, 32000);
503                         evas_object_propagate_events_set(btn, EINA_FALSE);
504                         evas_object_smart_callback_add(btn, "clicked", _keyboard_clicked_cb, app_data);
505                         elm_atspi_accessible_name_set(btn, "IDS_COM_OPT_KEYBOARD");
506                         elm_atspi_accessible_translation_domain_set(btn, PACKAGE);
507                 }
508
509                 return btn;
510         } else if (!strcmp(part, "base")) {
511                 Evas_Object* btn = elm_button_add(obj);
512                 elm_object_style_set(btn, "ime_transparent");
513                 return btn;
514         }
515         return NULL;
516 }
517
518 static char * __ise_smartreply_gl_text_get(void *data, Evas_Object *obj, const char *part)
519 {
520         if(!strcmp(part, "elm.text")) {
521                 int index;
522                 char *reply = NULL;
523                 index = (intptr_t)data;
524                 if (index < 0)
525                         return NULL;
526
527                 reply = input_smartreply_get_nth_item(index, NULL);
528                 if (reply == NULL)
529                         return NULL;
530
531                 return reply;
532         }
533         return NULL;
534 }
535
536 static void __ise_gl_lang_changed(void *data, Evas_Object *obj, void *event_info)
537 {
538         //Update genlist items. The Item texts will be translated in the _gl_text_get().
539         elm_genlist_realized_items_update(obj);
540 }
541
542 static char * __ise_drawing_text_get(void *data, Evas_Object *obj, const char *part)
543 {
544         if(!strcmp(part, "elm.text")) {
545                 return(strdup(gettext("WDS_IME_MBODY_DRAWING_M_EMOTICON_ABB")));
546         }
547         return NULL;
548 }
549
550 static Evas_Object * __ise_drawing_content_get(void *data, Evas_Object *obj, const char *part)
551 {
552         if (!strcmp(part, "elm.icon")) {
553                 Evas_Object* btn = elm_button_add(obj);
554                 evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
555                 evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
556                 Evas_Object* ic = elm_image_add(btn);
557                 elm_image_resizable_set(ic, EINA_TRUE, EINA_TRUE);
558                 string path = get_resource_path();
559                 if (_WEARABLE)
560                         path = path + "wearable/";
561                 else if (_TV)
562                         path = path + "tv/";
563                 else
564                         path = path + "mobile/";
565                 elm_object_style_set(btn, "ime_button_drawing");
566                 string path_ic = path + "images/wi_drawing_icon.png";
567                 elm_image_file_set(ic, path_ic.c_str(), NULL);
568                 elm_object_content_set(btn, ic);
569                 evas_object_layer_set(btn, 32000);
570                 return btn;
571         }
572         return NULL;
573 }
574
575 void set_source_caller_app_id(app_control_h app_control)
576 {
577         if (!app_control){
578                 PRINTFUNC(DLOG_ERROR, "can't get app_control");
579                 return;
580         }
581
582         char *caller = NULL;
583         app_control_get_caller(app_data->source_app_control, &caller);
584
585         if (caller){
586                 PRINTFUNC(DLOG_DEBUG, "caller = %s", caller);
587                 app_control_add_extra_data(app_control, "caller_appid", caller);
588                 free(caller);
589         }
590 }
591
592 void reply_to_sender_by_callback(const char *value, const char *type, const char *path[], const char *cursor_position)
593 {
594         PRINTFUNC(DLOG_DEBUG, "");
595
596         app_control_h app_control;
597
598         if (app_control_create(&app_control) == 0) {
599                 int ret;
600
601                 if (value)
602                         app_control_add_extra_data(app_control, APP_CONTROL_DATA_TEXT, value);
603
604                 if (type)
605                         app_control_add_extra_data(app_control, "reply_type", type);
606
607                 if (path != NULL) {
608                         app_control_add_extra_data_array(app_control, APP_CONTROL_DATA_PATH, path, 1);
609                 }
610
611                 if (cursor_position != NULL)
612                         app_control_add_extra_data(app_control, "cursor_position_get", cursor_position);
613
614                 set_source_caller_app_id(app_control);
615
616                 ret = app_control_reply_to_launch_request(app_control, app_data->source_app_control, APP_CONTROL_RESULT_SUCCEEDED);
617                 if (ret != APP_CONTROL_ERROR_NONE)
618                         PRINTFUNC(DLOG_ERROR, "reply failed : %d", ret);
619
620                 app_control_destroy(app_control);
621                 app_control_destroy(app_data->source_app_control);
622                 app_data->source_app_control = NULL;
623         }
624 }
625
626 void reply_to_sender_by_callback_for_back()
627 {
628         PRINTFUNC(DLOG_DEBUG, "");
629
630         app_control_h app_control;
631
632         if (app_control_create(&app_control) == 0) {
633                 int ret;
634
635                 app_control_add_extra_data(app_control, "back_to_composer", "yes");
636
637                 ret = app_control_reply_to_launch_request(app_control, app_data->source_app_control, APP_CONTROL_RESULT_SUCCEEDED);
638                 if (ret != APP_CONTROL_ERROR_NONE)
639                         PRINTFUNC(DLOG_ERROR, "reply failed : %d", ret);
640
641                 app_control_destroy(app_control);
642                 app_control_destroy(app_data->source_app_control);
643                 app_data->source_app_control = NULL;
644         }
645 }
646
647 char* get_resource_path()
648 {
649         if (NULL == app_data->res_path) {
650                 app_data->res_path = app_get_resource_path();
651                 PRINTFUNC(DLOG_INFO, "set resource path = %s", app_data->res_path);
652         }
653         return (app_data->res_path);
654 }
655
656 char* get_shared_resource_path()
657 {
658         if (NULL == app_data->shared_res_path) {
659                 app_data->shared_res_path = app_get_shared_resource_path();
660                 PRINTFUNC(DLOG_INFO, "set shared resource path = %s", app_data->shared_res_path);
661         }
662         return (app_data->shared_res_path);
663 }
664
665 void show_gl_focus(Eina_Bool bVisible){
666         if (app_data->genlist == NULL)
667                 return;
668
669         if (bVisible == EINA_TRUE){
670                 elm_object_signal_emit(app_data->genlist, "elm,state,focus_bg,enable", "elm");
671                 //elm_layout_theme_set(app_data->genlist, "genlist", "base", "focus_bg");
672                 //elm_object_signal_emit(app_data->genlist, "elm,state,focus_bg,show", "elm");
673         } else {
674                 elm_object_signal_emit(app_data->genlist, "elm,state,focus_bg,disable", "elm");
675                 //elm_layout_theme_set(app_data->genlist, "genlist", "base", "default");
676                 //elm_object_signal_emit(app_data->genlist, "elm,state,focus_bg,hide", "elm");
677         }
678 }
679
680 void show_popup_toast(const char *text, bool check_img)
681 {
682         PRINTFUNC(DLOG_ERROR, "show_popup_toast");
683
684         Evas_Object *popup;
685
686         popup = elm_popup_add(app_data->win_main);
687         elm_object_style_set(popup, "toast/circle");
688         elm_popup_orient_set(popup, ELM_POPUP_ORIENT_BOTTOM);
689         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
690
691         if (check_img) {
692                 string path = get_resource_path();
693                 if (_WEARABLE)
694                         path = path + "wearable/";
695                 else if (_TV)
696                         path = path + "tv/";
697                 else
698                         path = path + "mobile/";
699                 string path_ic = path + "/images/toast_check_icon.png";
700                 Evas_Object * img = elm_image_add(popup);
701                 elm_image_file_set(img, path_ic.c_str(), NULL);
702                 elm_object_part_content_set(popup, "toast,icon", img);
703         }
704         if (text) {
705                 elm_object_part_text_set(popup, "elm.text", text);
706         }
707
708         eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, _popup_back_cb, NULL);
709         evas_object_smart_callback_add(popup, "dismissed", _popup_close_cb, NULL);
710         evas_object_smart_callback_add(popup, "block,clicked", _popup_back_cb, NULL);
711
712         elm_popup_timeout_set(popup, 2.0);
713         evas_object_show(popup);
714 }
715
716 static void _popup_close_cb(void *data, Evas_Object *obj, void *event_info)
717 {
718         if (obj){
719                 evas_object_hide(obj);
720                 evas_object_del(obj);
721         }
722 }
723
724 static void _popup_back_cb(void *data, Evas_Object *obj, void *event_info)
725 {
726         if (obj)
727                 elm_popup_dismiss(obj);
728 }
729
730
731 void _back_to_genlist_for_selector()
732 {
733         PRINTFUNC(DLOG_DEBUG, "");
734
735         if (!app_data) return;
736
737         if (_WEARABLE) {
738                 Evas_Object *circle_genlist = (Evas_Object *) evas_object_data_get(app_data->genlist, "circle");
739                 eext_rotary_object_event_activated_set(circle_genlist, EINA_TRUE);
740         }
741         if (app_data->app_type == APP_TYPE_STT || app_data->app_type == APP_TYPE_EMOTICON || app_data->app_type == APP_TYPE_KEYBOARD){
742                 PRINTFUNC(DLOG_DEBUG, "launched as STT/EMOTICON/KEYBOARD mode, So exit here.");
743                 reply_to_sender_by_callback(NULL, NULL, NULL, NULL);
744                 ui_app_exit();
745         }
746 }
747
748 static void _item_realized(void *data, Evas_Object *obj, void *event_info) //called when list scrolled
749 {
750         PRINTFUNC(DLOG_DEBUG, "%s", __func__);
751 }
752
753 Evas_Object* _create_genlist(Evas_Object* navi)
754 {
755         Evas_Object* genlist = elm_genlist_add(navi);
756         if (NULL == genlist)
757                 return NULL;
758
759         elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
760         if (_WEARABLE) {
761                 Evas_Object* circle_object_genlist = eext_circle_object_genlist_add(genlist, app_data->circle_surface);
762                 eext_circle_object_genlist_scroller_policy_set(circle_object_genlist, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF);
763                 evas_object_data_set(genlist, "circle", (void *) circle_object_genlist);
764                 eext_rotary_object_event_activated_set(circle_object_genlist, EINA_TRUE);
765         }
766         evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
767         evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
768
769         evas_object_smart_callback_add(genlist, "language,changed", __ise_gl_lang_changed, genlist);
770         evas_object_show(genlist);
771
772 //      uxt_genlist_set_bottom_margin_enabled(genlist, EINA_TRUE);
773
774         show_gl_focus(EINA_FALSE);
775
776         const char *item_style = NULL;
777         if (_WEARABLE)
778                 item_style = "empty";
779         Elm_Object_Item *nf_main_item = elm_naviframe_item_push(navi,
780             NULL,
781             NULL,
782             NULL,
783             genlist,
784             item_style);
785
786         elm_naviframe_item_pop_cb_set(nf_main_item, back_cb, app_data);
787         evas_object_smart_callback_add(genlist, "realized", _item_realized, NULL);
788
789         return genlist;
790 }
791
792 static void _item_position_changed_cb(void *data, Evas_Object *obj, void *event_info)
793 {
794         if (!obj) return;
795         if (!data) return;
796
797         Evas_Object *genlist = (Evas_Object *)obj;
798         Elm_Object_Item *gen_item = (Elm_Object_Item *)data;
799
800         Evas_Coord y;
801         elm_scroller_region_get(genlist, NULL, &y, NULL, NULL);
802
803 //      PRINTFUNC(DLOG_DEBUG,"y=%d",y);
804
805         if (250 > y && y >= 100){
806                 if (last_step == 0) return;
807                 last_step = 0;
808                 elm_object_item_signal_emit(gen_item, "elm,action,ime,0.0", "elm");
809                 show_gl_focus(EINA_TRUE);
810         } else if (100 > y && y >= 50){
811                 if (last_step == 1) return;
812                 last_step = 1;
813                 elm_object_item_signal_emit(gen_item, "elm,action,ime,0.1", "elm");
814                 show_gl_focus(EINA_TRUE);
815         } else if (y < 50 && y >=0){
816                 if (last_step == 2) return;
817                 last_step = 2;
818                 elm_object_item_signal_emit(gen_item, "elm,action,ime,0.9", "elm");
819                 show_gl_focus(EINA_FALSE);
820         }
821 }
822
823 void _create_genlist_items(void* user_data)
824 {
825         App_Data* app_data = (App_Data*) user_data;
826
827         if (NULL == app_data->genlist) {
828                 app_data->genlist = _create_genlist(app_data->naviframe);
829                 if (NULL == app_data->genlist)
830                 return;
831         }
832
833         elm_genlist_clear(app_data->genlist);
834
835         Elm_Genlist_Item_Class * itc0 = elm_genlist_item_class_new();
836         itc0->item_style = NULL;
837         itc0->func.text_get = NULL;
838         itc0->func.content_get = NULL;
839         itc0->func.state_get = NULL;
840         itc0->func.del = NULL;
841
842         Elm_Genlist_Item_Class * itc1 = elm_genlist_item_class_new();
843         if (g_input_type_data.input_type_array_len == 2){
844                 itc1->item_style = "2button_flat";
845                 itc1->func.text_get = NULL;
846                 itc1->func.content_get = __ise_gl_2button_content_get;
847                 itc1->func.state_get = NULL;
848                 itc1->func.del = NULL;
849         } else {
850                 itc1->item_style = "3button_flat";
851                 itc1->func.text_get = NULL;
852                 itc1->func.content_get = __ise_gl_3button_content_get;
853                 itc1->func.state_get = NULL;
854                 itc1->func.del = NULL;
855         }
856
857         // dummy title for empty space
858         it_empty = elm_genlist_item_append(app_data->genlist, itc0,
859                         NULL, NULL,
860                         ELM_GENLIST_ITEM_NONE,
861                         NULL, NULL);
862
863         if (app_data->app_type != APP_TYPE_REPLY) {
864                 // 3 Buttons
865                 it_title = elm_genlist_item_append(app_data->genlist, itc1,
866                                 NULL, NULL,
867                                 ELM_GENLIST_ITEM_NONE,
868                                 NULL, NULL);
869         }
870
871         elm_genlist_item_select_mode_set(it_title, ELM_OBJECT_SELECT_MODE_NONE);
872
873         g_template_item_size = _update_template_items(app_data);
874
875         Elm_Object_Item *item = elm_genlist_item_next_get(it_title);
876         elm_genlist_item_show(item, ELM_GENLIST_ITEM_SCROLLTO_MIDDLE);
877
878         evas_object_smart_callback_add(app_data->genlist, "elm,item,position,changed", _item_position_changed_cb, it_title);
879
880         elm_genlist_item_class_free(itc0);
881         elm_genlist_item_class_free(itc1);
882 }
883
884 void _create_header_items(void *user_data)
885 {
886         Elm_Genlist_Item_Class * itc0 = elm_genlist_item_class_new();
887         itc0->item_style = "title";
888         itc0->func.text_get = NULL;
889         itc0->func.content_get = NULL;
890         itc0->func.state_get = NULL;
891         itc0->func.del = NULL;
892
893         Elm_Genlist_Item_Class * itc1 = elm_genlist_item_class_new();
894         if (g_input_type_data.input_type_array_len == 2) {
895                 itc1->item_style = "2button_flat";
896                 itc1->func.text_get = NULL;
897                 itc1->func.content_get = __ise_gl_2button_content_get;
898                 itc1->func.state_get = NULL;
899                 itc1->func.del = NULL;
900         } else {
901                 itc1->item_style = "3button_flat";
902                 itc1->func.text_get = NULL;
903                 itc1->func.content_get = __ise_gl_3button_content_get;
904                 itc1->func.state_get = NULL;
905                 itc1->func.del = NULL;
906         }
907
908         // dummy title for empty space
909         it_empty = elm_genlist_item_append(app_data->genlist, itc0,
910                                 NULL, NULL,
911                                 ELM_GENLIST_ITEM_NONE,
912                                 NULL, NULL);
913
914         // 3 Buttons
915         it_title = elm_genlist_item_append(app_data->genlist, itc1,
916                                                         NULL, NULL,
917                                                         ELM_GENLIST_ITEM_NONE,
918                                                         NULL, NULL);
919
920         elm_genlist_item_select_mode_set(it_title, ELM_OBJECT_SELECT_MODE_NONE);
921
922         elm_genlist_item_class_free(itc0);
923         elm_genlist_item_class_free(itc1);
924 }
925
926 void _update_genlist_items(void *user_data)
927 {
928         elm_genlist_clear(app_data->genlist);
929
930         _create_header_items(user_data);
931
932         if (input_smartreply_is_enabled())
933                 g_smartreply_item_size = _update_smartreply_items(user_data);
934         else
935                 g_smartreply_item_size = 0;
936
937         g_template_item_size = _update_template_items(user_data);
938
939         if (g_input_template_data.input_template_array_len > 0) {
940                 _update_user_template_items(user_data);
941         }
942
943         /* Update genlist item position */
944         Elm_Object_Item *item = elm_genlist_item_next_get(it_title);
945         elm_genlist_item_show(item, ELM_GENLIST_ITEM_SCROLLTO_MIDDLE);
946 }
947
948 unsigned int _update_smartreply_items(void *user_data)
949 {
950         App_Data* app_data;
951
952         Elm_Object_Item *first;
953
954         unsigned int i = 0;
955         unsigned int len = 0;
956         unsigned int item_size = 0;
957
958         app_data = (App_Data *)user_data;
959
960         if (app_data == NULL) {
961                 PRINTFUNC(DLOG_ERROR, "Can not get app_data");
962                 return item_size;
963         }
964
965         if (app_data->genlist == NULL) {
966                 /* smartreply will update when genlist is exist only */
967                 PRINTFUNC(DLOG_ERROR, "Can not get getlist");
968                 return item_size;
969         }
970
971         /* Move to smartreply */
972         first = elm_genlist_first_item_get(app_data->genlist);
973         elm_genlist_item_next_get(first);
974
975         if (input_smartreply_is_enabled() == false)
976                 return item_size;
977
978         /* Append newly added smartreply list */
979         len = input_smartreply_get_reply_num();
980
981         if (len > 0) {
982                 const std::vector<TemplateData>  template_list = input_template_get_list();
983
984                 Elm_Genlist_Item_Class *itc;
985
986                 itc = elm_genlist_item_class_new();
987                 itc->item_style = "1text";
988                 itc->func.text_get = __ise_smartreply_gl_text_get;
989                 itc->func.content_get = NULL;
990                 itc->func.state_get = NULL;
991                 itc->func.del = NULL;
992
993                 for (i = 0; i < len; i++) {
994                         char *reply = (char *)"hello";
995                         unsigned int j;
996                         bool matched;
997
998                         matched = false;
999
1000                         int type;
1001                         reply = input_smartreply_get_nth_item(i, &type);
1002                         if (reply == NULL)
1003                                 continue;
1004                         SECURE_LOGD("SmartReply = [%d]%s", i, reply);
1005
1006                         for (j = 0; j < template_list.size(); j++) {
1007                                 const char *template_str;
1008
1009                                 if (template_list[j].use_gettext)
1010                                         template_str = gettext(template_list[j].text.c_str());
1011                                 else
1012                                         template_str = template_list[j].text.c_str();
1013
1014                                 if (!__compare_string(reply, template_str)) {
1015                                         matched = true;
1016                                         break;
1017                                 }
1018                         }
1019
1020                         if (matched == true)
1021                                 continue;
1022
1023                         elm_genlist_item_append(app_data->genlist,
1024                                                 itc,
1025                                                 (void *)(uintptr_t)i,
1026                                                 NULL,
1027                                                 ELM_GENLIST_ITEM_NONE,
1028                                                 __ise_smartreply_gl_sel,
1029                                                 app_data);
1030
1031                         item_size++;
1032                         if (item_size >= 3)
1033                                 break;
1034                 }
1035                 elm_genlist_item_class_free(itc);
1036         }
1037         return item_size;
1038 }
1039
1040 static void _drawing_item_clicked_cb(void *data, Evas_Object * obj, void *event_info)
1041 {
1042         PRINTFUNC(DLOG_DEBUG, "%s", __func__);
1043         App_Data* ad = (App_Data*) data;
1044         if (!ad)
1045                 return;
1046
1047         launch_drawing_app(ad);
1048 }
1049
1050 unsigned int _update_template_items(void *user_data)
1051 {
1052         App_Data* app_data;
1053
1054         Elm_Object_Item *first;
1055         Elm_Object_Item *menu;
1056         Elm_Object_Item *pos;
1057
1058         unsigned int i = 0;
1059         unsigned int item_size = 0;
1060
1061         app_data = (App_Data *)user_data;
1062
1063         if (app_data == NULL) {
1064                 PRINTFUNC(DLOG_ERROR, "Can not get app_data");
1065                 return item_size;
1066         }
1067
1068         if (app_data->genlist == NULL) {
1069                 /* smartreply will update when genlist is exist only */
1070                 PRINTFUNC(DLOG_ERROR, "Can not get getlist");
1071                 return item_size;
1072         }
1073
1074         first = elm_genlist_first_item_get(app_data->genlist);
1075         if (first == NULL)
1076                 return 0;
1077         menu = elm_genlist_item_next_get(first);
1078
1079         pos = menu;
1080         /* move to smartreply next if it need */
1081         if (input_smartreply_is_enabled()) {
1082                 unsigned int j = 0;
1083
1084                 for (j = 0; j < g_smartreply_item_size; j++) {
1085                         if (pos == NULL)
1086                                 break;
1087
1088                         pos = elm_genlist_item_next_get(pos);
1089                 }
1090         }
1091
1092         /* Append New Template list */
1093         const std::vector<TemplateData> template_list = input_template_get_list();
1094
1095         if (template_list.size() > 0) {
1096                 Elm_Genlist_Item_Class *itc;
1097
1098                 itc = elm_genlist_item_class_new();
1099
1100                 itc->item_style = "1text";
1101                 itc->func.text_get = __ise_template_gl_text_get;
1102                 itc->func.content_get = NULL;
1103                 itc->func.state_get = NULL;
1104                 itc->func.del = NULL;
1105
1106                 for (i = 0; i < template_list.size(); i++) {
1107                         pos = elm_genlist_item_append(app_data->genlist,
1108                                         itc,
1109                                         (void *)(uintptr_t)i,
1110                                         NULL,
1111                                         ELM_GENLIST_ITEM_NONE,
1112                                         __ise_template_gl_sel,
1113                                         app_data);
1114                         item_size++;
1115                 }
1116                 elm_genlist_item_class_free(itc);
1117
1118                 // drawing button (+)
1119                 if (app_data->mime_type == MIME_TYPE_ALL && app_data->app_type == APP_TYPE_SELECT_MODE) {
1120                         Elm_Genlist_Item_Class *itc;
1121                         itc = elm_genlist_item_class_new();
1122
1123                         itc->item_style = "1text.1icon";
1124                         itc->func.text_get = __ise_drawing_text_get;;
1125                         itc->func.content_get = __ise_drawing_content_get;
1126                         itc->func.state_get = NULL;
1127                         itc->func.del = NULL;
1128
1129                         elm_genlist_item_append(app_data->genlist,
1130                                         itc,
1131                                         NULL,
1132                                         NULL,
1133                                         ELM_GENLIST_ITEM_NONE,
1134                                         _drawing_item_clicked_cb,
1135                                         app_data);
1136
1137                         elm_genlist_item_class_free(itc);
1138                 }
1139
1140                 // dummy item for empty space
1141                 Elm_Genlist_Item_Class * itc0 = elm_genlist_item_class_new();
1142                 itc0->item_style = "title";
1143                 itc0->func.text_get = NULL;
1144                 itc0->func.content_get = NULL;
1145                 itc0->func.state_get = NULL;
1146                 itc0->func.del = NULL;
1147
1148                 if (g_input_template_data.input_template_array_len < 1) {
1149                         it_empty = elm_genlist_item_append(app_data->genlist, itc0,
1150                                 NULL, NULL,
1151                                 ELM_GENLIST_ITEM_NONE,
1152                                 NULL, NULL);
1153                 }
1154                 elm_genlist_item_class_free(itc0);
1155         }
1156
1157         return item_size;
1158 }
1159
1160 unsigned int _update_user_template_items(void *user_data)
1161 {
1162         App_Data* app_data;
1163
1164         Elm_Object_Item *first;
1165
1166         unsigned int i = 0;
1167         unsigned int item_size = 0;
1168
1169         app_data = (App_Data *)user_data;
1170
1171         if (app_data == NULL) {
1172                 PRINTFUNC(DLOG_ERROR, "Can not get app_data");
1173                 return item_size;
1174         }
1175
1176         if (app_data->genlist == NULL) {
1177                 /* smartreply will update when genlist is exist only */
1178                 PRINTFUNC(DLOG_ERROR, "Can not get getlist");
1179                 return item_size;
1180         }
1181
1182         first = elm_genlist_first_item_get(app_data->genlist);
1183         if (first == NULL)
1184                 return 0;
1185
1186         if (g_input_template_data.input_template_array_len > 0) {
1187                 Elm_Genlist_Item_Class *itc;
1188
1189                 itc = elm_genlist_item_class_new();
1190
1191                 itc->item_style = "1text";
1192                 itc->func.text_get = __ise_user_template_gl_text_get;
1193                 itc->func.content_get = NULL;
1194                 itc->func.state_get = NULL;
1195                 itc->func.del = NULL;
1196
1197                 for (i = 0; i < (unsigned int)g_input_template_data.input_template_array_len; i++) {
1198                         elm_genlist_item_append(app_data->genlist,
1199                                         itc,
1200                                         (void *)(uintptr_t)i,
1201                                         NULL,
1202                                         ELM_GENLIST_ITEM_NONE,
1203                                         __ise_user_template_gl_sel,
1204                                         app_data);
1205                         item_size++;
1206                 }
1207                 elm_genlist_item_class_free(itc);
1208
1209                 // dummy item for empty space
1210                 Elm_Genlist_Item_Class * itc0 = elm_genlist_item_class_new();
1211                 itc0->item_style = "title";
1212                 itc0->func.text_get = NULL;
1213                 itc0->func.content_get = NULL;
1214                 itc0->func.state_get = NULL;
1215                 itc0->func.del = NULL;
1216
1217                 it_empty = elm_genlist_item_append(app_data->genlist, itc0,
1218                                 NULL, NULL,
1219                                 ELM_GENLIST_ITEM_NONE,
1220                                 NULL, NULL);
1221                 elm_genlist_item_class_free(itc0);
1222         }
1223
1224         return item_size;
1225 }
1226
1227 bool __compare_string(const char * smart_str, const char * template_str)
1228 {
1229         int src_len = 0;
1230         int dst_len = 0;
1231         bool ret = true;
1232
1233         if(!smart_str||!template_str)
1234                 return ret;
1235
1236         src_len = strlen(smart_str);
1237         dst_len = strlen(template_str);
1238
1239         if(smart_str[src_len-1] == '.')
1240                 src_len--;
1241
1242         while(template_str[dst_len-1] == ' ')
1243                 dst_len--;
1244         if(template_str[dst_len-1] == '.')
1245                 dst_len--;
1246
1247         dst_len = (dst_len > src_len)? dst_len : src_len;
1248
1249         if(!strncmp(smart_str, template_str, (size_t)dst_len))
1250                 ret = false;
1251
1252         return (ret);
1253 }
1254
1255 bool _app_create(void* user_data)
1256 {
1257         int width = 1000, height = 1000;
1258 //      App_Data* app_data = NULL;
1259         Evas_Object* layout = NULL;
1260         Evas_Object* conform = NULL;
1261         Evas_Object* bg = NULL;
1262         Evas_Object* window = NULL;
1263         Eext_Circle_Surface *surface = NULL;
1264
1265         if (!user_data) {
1266                 return false;
1267         }
1268
1269         _app_language_changed(NULL, NULL);
1270
1271         app_data = (App_Data*)user_data;
1272
1273         elm_app_base_scale_set(1.3);
1274
1275         window = elm_win_add(NULL, PACKAGE, ELM_WIN_BASIC);
1276         if (window) {
1277                 init_customizing_theme();
1278
1279                 elm_win_title_set(window, PACKAGE);
1280                 elm_win_borderless_set(window, EINA_TRUE);
1281 //              ecore_x_window_size_get(ecore_x_window_root_first_get(), &width, &height);
1282                 evas_object_resize(window, width, height);
1283                 elm_win_indicator_mode_set(window, ELM_WIN_INDICATOR_SHOW);
1284         } else {
1285                 LOGE("elm_win_add() is failed.");
1286                 return false;
1287         }
1288
1289         bg = elm_bg_add(window);
1290         evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1291         elm_win_resize_object_add(window, bg);
1292         evas_object_show(bg);
1293
1294         layout = elm_layout_add(window);
1295         elm_layout_theme_set(layout, "layout", "application", "default");
1296         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1297
1298         conform = elm_conformant_add(window);
1299         if (_WEARABLE)
1300                 surface = eext_circle_surface_conformant_add(conform);
1301
1302         evas_object_size_hint_weight_set(conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1303
1304         elm_win_resize_object_add(window, conform);
1305         elm_object_content_set(conform, layout);
1306
1307         evas_object_show(layout);
1308         evas_object_show(conform);
1309         evas_object_show(window);
1310         app_data->win_main = window;
1311         app_data->conform = conform;
1312         app_data->layout_main = layout;
1313         app_data->circle_surface = surface;
1314         app_data->app_type = APP_TYPE_SELECT_MODE;
1315
1316         Evas_Object *naviframe = elm_naviframe_add(layout);
1317         elm_naviframe_prev_btn_auto_pushed_set(naviframe, EINA_FALSE);
1318         eext_object_event_callback_add(naviframe, EEXT_CALLBACK_BACK, eext_naviframe_back_cb, NULL);
1319         elm_object_part_content_set(layout, "elm.swallow.content", naviframe);
1320         evas_object_show(naviframe);
1321
1322         app_data->naviframe = naviframe;
1323
1324         return true;
1325 }
1326
1327 void _app_service(app_control_h service, void* user_data)
1328 {
1329         int ret;
1330         char *context = NULL;
1331         char **input_type_array = NULL;
1332         int input_type_array_len = -1;
1333         bool is_extra_data_array = false;
1334         char *mime_type = NULL;
1335         char **user_template_array = NULL;
1336         int user_template_array_len = -1;
1337
1338         app_control_clone(&(app_data->source_app_control), service);
1339         app_data->reply_type = REPLY_APP_NORMAL;
1340         app_data->mime_type = MIME_TYPE_ALL;
1341
1342         ret = app_control_get_extra_data_array(service, "user_template", &user_template_array, &user_template_array_len);
1343         g_input_template_data.input_template_array = user_template_array;
1344         g_input_template_data.input_template_array_len = user_template_array_len;
1345
1346         ret = app_control_get_mime(service, &mime_type);
1347         if (ret != APP_CONTROL_ERROR_NONE) {
1348                 LOGD("Fail to get mime type : %d", ret);
1349         } else {
1350                 if (mime_type) {
1351                         LOGD("mime type = %s", mime_type);
1352                         if (!strncmp(mime_type, "image/", strlen("image/"))) {
1353                                 app_data->mime_type = MIME_TYPE_IMAGE;
1354                                 app_data->app_type = APP_TYPE_DRAWING;
1355                                 launch_drawing_app((void *)app_data);
1356                                 if (mime_type)
1357                                         free(mime_type);
1358                                 goto ACTIVATE;
1359                         } else if (!strncmp(mime_type, "audio/", strlen("audio/"))) {
1360                                 app_data->mime_type = MIME_TYPE_AUDIO;
1361                                 app_data->app_type = APP_TYPE_STT;
1362                                 _stt_clicked_cb((void *)app_data, NULL, NULL);
1363                                 if (mime_type)
1364                                         free(mime_type);
1365                                 goto ACTIVATE;
1366                         } else if (!strncmp(mime_type, "text/", strlen("text/"))) {
1367                                 app_data->mime_type = MIME_TYPE_TEXT;
1368                         }
1369                 }
1370         }
1371         if (mime_type)
1372                 free(mime_type);
1373
1374         if (_TV || _MOBILE) {
1375                 app_data->app_type = APP_TYPE_KEYBOARD;
1376                 input_keyboard_init(service);
1377                 _keyboard_clicked_cb((void *)app_data, NULL, NULL);
1378                 goto ACTIVATE;
1379         }
1380
1381         ret = app_control_is_extra_data_array(service, APP_CONTROL_DATA_INPUT_TYPE, &is_extra_data_array);
1382         if ( is_extra_data_array == true) {
1383                 ret = app_control_get_extra_data_array(service, APP_CONTROL_DATA_INPUT_TYPE, &input_type_array, &input_type_array_len);
1384                 g_input_type_data.input_type_array = input_type_array;
1385                 g_input_type_data.input_type_array_len = input_type_array_len;
1386         } else {
1387                 ret = app_control_get_extra_data(service, APP_CONTROL_DATA_INPUT_TYPE, &context);
1388                 if (ret == APP_CONTROL_ERROR_NONE) {
1389                         if (!strcmp(context, "input_voice")) {
1390                                 app_data->app_type = APP_TYPE_STT;
1391                                 _stt_clicked_cb((void *)app_data, NULL, NULL);
1392                                 goto ACTIVATE;
1393                         } else if (!strcmp(context, "input_recording")) {
1394                                 app_data->app_type = APP_TYPE_RECORDING;
1395                                 _stt_clicked_cb((void *)app_data, NULL, NULL);
1396                                 goto ACTIVATE;
1397                         } else if (!strcmp(context, "input_emoticon")) {
1398                                 app_data->app_type = APP_TYPE_EMOTICON;
1399                                 _emoticon_clicked_cb((void *)app_data, NULL, NULL);
1400                                 goto ACTIVATE;
1401                         } else if (!strcmp(context, "input_keyboard")) {
1402                                 app_data->app_type = APP_TYPE_KEYBOARD;
1403                                 input_keyboard_init(service);
1404                                 _keyboard_clicked_cb((void *)app_data, NULL, NULL);
1405                                 goto ACTIVATE;
1406                         } else if (!strcmp(context, "input_drawing")) {
1407                                 app_data->app_type = APP_TYPE_DRAWING;
1408                                 _drawing_item_clicked_cb((void *)app_data, NULL, NULL);
1409                                 goto ACTIVATE;
1410                         } else if (!strcmp(context, "input_reply")) {
1411                                 app_data->app_type = APP_TYPE_REPLY;
1412                         }
1413                 }
1414         }
1415
1416         if (app_data->genlist == NULL)
1417                 app_data->genlist = _create_genlist(app_data->naviframe);
1418
1419         input_keyboard_init(service);
1420
1421         input_smartreply_init(service);
1422         input_smartreply_set_notify(_input_smartreply_notify_cb, NULL);
1423
1424         if (input_smartreply_is_enabled())
1425                 input_smartreply_get_reply_async();
1426
1427         input_template_init(service);
1428         input_template_set_notify(_input_template_notify_cb,  NULL);
1429
1430         _create_genlist_items(app_data);
1431
1432 ACTIVATE :
1433         elm_win_activate(app_data->win_main);
1434
1435         if (context)
1436                 free(context);
1437 }
1438
1439 void _app_pause(void* user_data)
1440 {
1441         PRINTFUNC(DLOG_DEBUG, "");
1442         pause_voice();
1443 }
1444
1445 void _app_resume(void* user_data)
1446 {
1447         PRINTFUNC(DLOG_DEBUG, "");
1448         resume_voice();
1449 }
1450
1451 void _app_terminate(void* user_data)
1452 {
1453         App_Data* app_data = NULL;
1454         app_data = (App_Data*)user_data;
1455
1456         if (app_data->genlist){
1457                 evas_object_smart_callback_del(app_data->genlist, "elm,item,position,changed", _item_position_changed_cb);
1458         }
1459
1460         if (app_data->res_path)
1461                 free(app_data->res_path);
1462
1463         if (app_data->shared_res_path)
1464                 free(app_data->shared_res_path);
1465
1466         input_keyboard_deinit();
1467         input_smartreply_deinit();
1468
1469         input_template_unset_notify();
1470         input_template_deinit();
1471
1472         input_type_deinit();
1473 }
1474
1475 static int init_i18n(const char *domain, const char *dir, char *lang_str)
1476 {
1477         if (setlocale(LC_ALL, "") == NULL) {
1478                 PRINTFUNC(DLOG_INFO, "Some environment variable is invalid, setlocale(LC_ALL, \"\") has returns\ed a null pointer");
1479                 if (setlocale(LC_ALL, lang_str) == NULL)
1480                         return -1;
1481         }
1482         if (bindtextdomain(domain, dir) == NULL)
1483                 return -1;
1484         if (textdomain(domain) == NULL)
1485                 return -1;
1486
1487         return 0;
1488 }
1489
1490 /**
1491  * @brief Set language and locale.
1492  *
1493  * @return void
1494  */
1495 static void _app_language_changed(app_event_info_h event_info, void *user_data)
1496 {
1497         char* lang_str = vconf_get_str(VCONFKEY_LANGSET);
1498         if (lang_str) {
1499                 setenv("LANG", lang_str, 1);
1500                 setenv("LC_MESSAGES", lang_str, 1);
1501         } else {
1502                 setenv("LANG", "en_GB.utf8", 1);
1503                 setenv("LC_MESSAGES", "en_GB.utf8", 1);
1504                 lang_str = strdup("en_GB.UTF-8");
1505         }
1506
1507         init_i18n(PACKAGE, LOCALEDIR, lang_str);
1508
1509         if (lang_str) {
1510                 elm_language_set(lang_str);
1511                 free(lang_str);
1512         }
1513 }
1514
1515 void input_type_deinit(void)
1516 {
1517         int i = 0;
1518         char **data_array = NULL;
1519
1520         data_array = g_input_type_data.input_type_array;
1521         if (data_array) {
1522                 for (i = 0; i < g_input_type_data.input_type_array_len; i++) {
1523                         if (*(data_array + i))
1524                                 free(*(data_array + i));
1525                 }
1526                 free(data_array);
1527         }
1528         g_input_type_data.input_type_array = NULL;
1529         g_input_type_data.input_type_array_len = 0;
1530 }
1531
1532 EXPORTED int main(int argc, char* argv[])
1533 {
1534         App_Data app_data = {0, };
1535         ui_app_lifecycle_callback_s event_callback = {0, };
1536         app_event_handler_h handlers[5] = {NULL, };
1537
1538         event_callback.create = _app_create;
1539         event_callback.terminate = _app_terminate;
1540         event_callback.pause = _app_pause;
1541         event_callback.resume = _app_resume;
1542         event_callback.app_control = _app_service;
1543
1544         ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, NULL, &app_data);
1545         ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, NULL, &app_data);
1546         ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, NULL, &app_data);
1547         ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, _app_language_changed, &app_data);
1548         ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, NULL, &app_data);
1549
1550         _init_app_data(&app_data);
1551
1552         int ret = ui_app_main(argc, argv, &event_callback, &app_data);
1553         if (ret != APP_ERROR_NONE) {
1554                 LOGD("ui_app_main() is failed. err = %d", ret);
1555         }
1556
1557         return ret;
1558 }