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