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