51a15af6bc59deb2e571c537b60585c803c106e8
[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         // 3 Buttons
832         it_title = elm_genlist_item_append(app_data->genlist, itc1,
833                         NULL, NULL,
834                         ELM_GENLIST_ITEM_NONE,
835                         NULL, NULL);
836
837         elm_genlist_item_select_mode_set(it_title, ELM_OBJECT_SELECT_MODE_NONE);
838
839         g_template_item_size = _update_template_items(app_data);
840
841         Elm_Object_Item *item = elm_genlist_item_next_get(it_title);
842         elm_genlist_item_show(item, ELM_GENLIST_ITEM_SCROLLTO_MIDDLE);
843
844         evas_object_smart_callback_add(app_data->genlist, "elm,item,position,changed", _item_position_changed_cb, it_title);
845
846         elm_genlist_item_class_free(itc0);
847         elm_genlist_item_class_free(itc1);
848 }
849
850 void _create_header_items(void *user_data)
851 {
852         Elm_Genlist_Item_Class * itc0 = elm_genlist_item_class_new();
853         itc0->item_style = "title";
854         itc0->func.text_get = NULL;
855         itc0->func.content_get = NULL;
856         itc0->func.state_get = NULL;
857         itc0->func.del = NULL;
858
859         Elm_Genlist_Item_Class * itc1 = elm_genlist_item_class_new();
860         if (g_input_type_data.input_type_array_len == 2) {
861                 itc1->item_style = "2button_flat";
862                 itc1->func.text_get = NULL;
863                 itc1->func.content_get = __ise_gl_2button_content_get;
864                 itc1->func.state_get = NULL;
865                 itc1->func.del = NULL;
866         } else {
867                 itc1->item_style = "3button_flat";
868                 itc1->func.text_get = NULL;
869                 itc1->func.content_get = __ise_gl_3button_content_get;
870                 itc1->func.state_get = NULL;
871                 itc1->func.del = NULL;
872         }
873
874         // dummy title for empty space
875         it_empty = elm_genlist_item_append(app_data->genlist, itc0,
876                                 NULL, NULL,
877                                 ELM_GENLIST_ITEM_NONE,
878                                 NULL, NULL);
879
880         // 3 Buttons
881         it_title = elm_genlist_item_append(app_data->genlist, itc1,
882                                                         NULL, NULL,
883                                                         ELM_GENLIST_ITEM_NONE,
884                                                         NULL, NULL);
885
886         elm_genlist_item_select_mode_set(it_title, ELM_OBJECT_SELECT_MODE_NONE);
887
888         elm_genlist_item_class_free(itc0);
889         elm_genlist_item_class_free(itc1);
890 }
891
892 void _update_genlist_items(void *user_data)
893 {
894         elm_genlist_clear(app_data->genlist);
895
896         _create_header_items(user_data);
897
898         if (input_smartreply_is_enabled())
899                 g_smartreply_item_size = _update_smartreply_items(user_data);
900         else
901                 g_smartreply_item_size = 0;
902
903         g_template_item_size = _update_template_items(user_data);
904
905         /* Update genlist item position */
906         Elm_Object_Item *item = elm_genlist_item_next_get(it_title);
907         elm_genlist_item_show(item, ELM_GENLIST_ITEM_SCROLLTO_MIDDLE);
908 }
909
910 unsigned int _update_smartreply_items(void *user_data)
911 {
912         App_Data* app_data;
913
914         Elm_Object_Item *first;
915
916         unsigned int i = 0;
917         unsigned int len = 0;
918         unsigned int item_size = 0;
919
920         app_data = (App_Data *)user_data;
921
922         if (app_data == NULL) {
923                 PRINTFUNC(DLOG_ERROR, "Can not get app_data");
924                 return item_size;
925         }
926
927         if (app_data->genlist == NULL) {
928                 /* smartreply will update when genlist is exist only */
929                 PRINTFUNC(DLOG_ERROR, "Can not get getlist");
930                 return item_size;
931         }
932
933         /* Move to smartreply */
934         first = elm_genlist_first_item_get(app_data->genlist);
935         elm_genlist_item_next_get(first);
936
937         if (input_smartreply_is_enabled() == false)
938                 return item_size;
939
940         /* Append newly added smartreply list */
941         len = input_smartreply_get_reply_num();
942
943         if (len > 0) {
944                 const std::vector<TemplateData>  template_list = input_template_get_list();
945
946                 Elm_Genlist_Item_Class *itc;
947
948                 itc = elm_genlist_item_class_new();
949                 itc->item_style = "1text";
950                 itc->func.text_get = __ise_smartreply_gl_text_get;
951                 itc->func.content_get = NULL;
952                 itc->func.state_get = NULL;
953                 itc->func.del = NULL;
954
955                 for (i = 0; i < len; i++) {
956                         char *reply = (char *)"hello";
957                         unsigned int j;
958                         bool matched;
959
960                         matched = false;
961
962                         int type;
963                         reply = input_smartreply_get_nth_item(i, &type);
964                         if (reply == NULL)
965                                 continue;
966                         SECURE_LOGD("SmartReply = [%d]%s", i, reply);
967
968                         for (j = 0; j < template_list.size(); j++) {
969                                 const char *template_str;
970
971                                 if (template_list[j].use_gettext)
972                                         template_str = gettext(template_list[j].text.c_str());
973                                 else
974                                         template_str = template_list[j].text.c_str();
975
976                                 if (!__compare_string(reply, template_str)) {
977                                         matched = true;
978                                         break;
979                                 }
980                         }
981
982                         if (matched == true)
983                                 continue;
984
985                         elm_genlist_item_append(app_data->genlist,
986                                                 itc,
987                                                 (void *)(uintptr_t)i,
988                                                 NULL,
989                                                 ELM_GENLIST_ITEM_NONE,
990                                                 __ise_smartreply_gl_sel,
991                                                 app_data);
992
993                         item_size++;
994                         if (item_size >= 3)
995                                 break;
996                 }
997                 elm_genlist_item_class_free(itc);
998         }
999         return item_size;
1000 }
1001
1002 static void _drawing_item_clicked_cb(void *data, Evas_Object * obj, void *event_info)
1003 {
1004         PRINTFUNC(DLOG_DEBUG, "%s", __func__);
1005         App_Data* ad = (App_Data*) data;
1006         if (!ad)
1007                 return;
1008
1009         launch_drawing_app(ad);
1010 }
1011
1012 unsigned int _update_template_items(void *user_data)
1013 {
1014         App_Data* app_data;
1015
1016         Elm_Object_Item *first;
1017         Elm_Object_Item *menu;
1018         Elm_Object_Item *pos;
1019
1020         unsigned int i = 0;
1021         unsigned int item_size = 0;
1022
1023         app_data = (App_Data *)user_data;
1024
1025         if (app_data == NULL) {
1026                 PRINTFUNC(DLOG_ERROR, "Can not get app_data");
1027                 return item_size;
1028         }
1029
1030         if (app_data->genlist == NULL) {
1031                 /* smartreply will update when genlist is exist only */
1032                 PRINTFUNC(DLOG_ERROR, "Can not get getlist");
1033                 return item_size;
1034         }
1035
1036         first = elm_genlist_first_item_get(app_data->genlist);
1037         if (first == NULL)
1038                 return 0;
1039         menu = elm_genlist_item_next_get(first);
1040
1041         pos = menu;
1042         /* move to smartreply next if it need */
1043         if (input_smartreply_is_enabled()) {
1044                 unsigned int j = 0;
1045
1046                 for (j = 0; j < g_smartreply_item_size; j++) {
1047                         if (pos == NULL)
1048                                 break;
1049
1050                         pos = elm_genlist_item_next_get(pos);
1051                 }
1052         }
1053
1054         /* Append New Template list */
1055         const std::vector<TemplateData> template_list = input_template_get_list();
1056
1057         if (template_list.size() > 0) {
1058                 Elm_Genlist_Item_Class *itc;
1059
1060                 itc = elm_genlist_item_class_new();
1061
1062                 itc->item_style = "1text";
1063                 itc->func.text_get = __ise_template_gl_text_get;
1064                 itc->func.content_get = NULL;
1065                 itc->func.state_get = NULL;
1066                 itc->func.del = NULL;
1067
1068                 for (i = 0; i < template_list.size(); i++) {
1069                         pos = elm_genlist_item_append(app_data->genlist,
1070                                         itc,
1071                                         (void *)(uintptr_t)i,
1072                                         NULL,
1073                                         ELM_GENLIST_ITEM_NONE,
1074                                         __ise_template_gl_sel,
1075                                         app_data);
1076                         item_size++;
1077                 }
1078                 elm_genlist_item_class_free(itc);
1079
1080                 // drawing button (+)
1081                 if (app_data->mime_type == MIME_TYPE_ALL) {
1082                         Elm_Genlist_Item_Class *itc;
1083                         itc = elm_genlist_item_class_new();
1084
1085                         itc->item_style = "1text.1icon";
1086                         itc->func.text_get = __ise_drawing_text_get;;
1087                         itc->func.content_get = __ise_drawing_content_get;
1088                         itc->func.state_get = NULL;
1089                         itc->func.del = NULL;
1090
1091                         elm_genlist_item_append(app_data->genlist,
1092                                         itc,
1093                                         NULL,
1094                                         NULL,
1095                                         ELM_GENLIST_ITEM_NONE,
1096                                         _drawing_item_clicked_cb,
1097                                         app_data);
1098
1099                         elm_genlist_item_class_free(itc);
1100                 }
1101
1102                 // dummy item for empty space
1103                 Elm_Genlist_Item_Class * itc0 = elm_genlist_item_class_new();
1104                 itc0->item_style = "title";
1105                 itc0->func.text_get = NULL;
1106                 itc0->func.content_get = NULL;
1107                 itc0->func.state_get = NULL;
1108                 itc0->func.del = NULL;
1109
1110                 it_empty = elm_genlist_item_append(app_data->genlist, itc0,
1111                                 NULL, NULL,
1112                                 ELM_GENLIST_ITEM_NONE,
1113                                 NULL, NULL);
1114                 elm_genlist_item_class_free(itc0);
1115         }
1116
1117         return item_size;
1118 }
1119
1120 bool __compare_string(const char * smart_str, const char * template_str)
1121 {
1122         int src_len = 0;
1123         int dst_len = 0;
1124         bool ret = true;
1125
1126         if(!smart_str||!template_str)
1127                 return ret;
1128
1129         src_len = strlen(smart_str);
1130         dst_len = strlen(template_str);
1131
1132         if(smart_str[src_len-1] == '.')
1133                 src_len--;
1134
1135         while(template_str[dst_len-1] == ' ')
1136                 dst_len--;
1137         if(template_str[dst_len-1] == '.')
1138                 dst_len--;
1139
1140         dst_len = (dst_len > src_len)? dst_len : src_len;
1141
1142         if(!strncmp(smart_str, template_str, (size_t)dst_len))
1143                 ret = false;
1144
1145         return (ret);
1146 }
1147
1148 bool _app_create(void* user_data)
1149 {
1150         int width = 1000, height = 1000;
1151 //      App_Data* app_data = NULL;
1152         Evas_Object* layout = NULL;
1153         Evas_Object* conform = NULL;
1154         Evas_Object* bg = NULL;
1155         Evas_Object* window = NULL;
1156         Eext_Circle_Surface *surface = NULL;
1157
1158         if (!user_data) {
1159                 return false;
1160         }
1161
1162         _app_language_changed(NULL, NULL);
1163
1164         app_data = (App_Data*)user_data;
1165
1166         elm_app_base_scale_set(1.3);
1167
1168         window = elm_win_add(NULL, PACKAGE, ELM_WIN_BASIC);
1169         if (window) {
1170                 init_customizing_theme();
1171
1172                 elm_win_title_set(window, PACKAGE);
1173                 elm_win_borderless_set(window, EINA_TRUE);
1174 //              ecore_x_window_size_get(ecore_x_window_root_first_get(), &width, &height);
1175                 evas_object_resize(window, width, height);
1176                 elm_win_indicator_mode_set(window, ELM_WIN_INDICATOR_SHOW);
1177         } else {
1178                 LOGE("elm_win_add() is failed.");
1179                 return false;
1180         }
1181
1182         bg = elm_bg_add(window);
1183         evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1184         elm_win_resize_object_add(window, bg);
1185         evas_object_show(bg);
1186
1187         layout = elm_layout_add(window);
1188         elm_layout_theme_set(layout, "layout", "application", "default");
1189         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1190
1191         conform = elm_conformant_add(window);
1192         if (_WEARABLE)
1193                 surface = eext_circle_surface_conformant_add(conform);
1194
1195         evas_object_size_hint_weight_set(conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1196
1197         elm_win_resize_object_add(window, conform);
1198         elm_object_content_set(conform, layout);
1199
1200         evas_object_show(layout);
1201         evas_object_show(conform);
1202         evas_object_show(window);
1203         app_data->win_main = window;
1204         app_data->conform = conform;
1205         app_data->layout_main = layout;
1206         app_data->circle_surface = surface;
1207         app_data->app_type = APP_TYPE_SELECT_MODE;
1208
1209         Evas_Object *naviframe = elm_naviframe_add(layout);
1210         elm_naviframe_prev_btn_auto_pushed_set(naviframe, EINA_FALSE);
1211         eext_object_event_callback_add(naviframe, EEXT_CALLBACK_BACK, eext_naviframe_back_cb, NULL);
1212         elm_object_part_content_set(layout, "elm.swallow.content", naviframe);
1213         evas_object_show(naviframe);
1214
1215         app_data->naviframe = naviframe;
1216
1217         return true;
1218 }
1219
1220 void _app_service(app_control_h service, void* user_data)
1221 {
1222         int ret;
1223         char *context = NULL;
1224         char **input_type_array = NULL;
1225         int input_type_array_len = -1;
1226         bool is_extra_data_array = false;
1227         char *mime_type = NULL;
1228
1229         app_control_clone(&(app_data->source_app_control), service);
1230         app_data->reply_type = REPLY_APP_NORMAL;
1231         app_data->mime_type = MIME_TYPE_ALL;
1232
1233         ret = app_control_get_mime(service, &mime_type);
1234         if (ret != APP_CONTROL_ERROR_NONE) {
1235                 LOGD("Fail to get mime type : %d", ret);
1236         } else {
1237                 if (mime_type) {
1238                         LOGD("mime type = %s", mime_type);
1239                         if (!strncmp(mime_type, "image/", strlen("image/"))) {
1240                                 app_data->mime_type = MIME_TYPE_IMAGE;
1241                                 app_data->app_type = APP_TYPE_DRAWING;
1242                                 launch_drawing_app((void *)app_data);
1243                                 if (mime_type)
1244                                         free(mime_type);
1245                                 goto ACTIVATE;
1246                         } else if (!strncmp(mime_type, "audio/", strlen("audio/"))) {
1247                                 app_data->mime_type = MIME_TYPE_AUDIO;
1248                                 app_data->app_type = APP_TYPE_STT;
1249                                 _stt_clicked_cb((void *)app_data, NULL, NULL);
1250                                 if (mime_type)
1251                                         free(mime_type);
1252                                 goto ACTIVATE;
1253                         } else if (!strncmp(mime_type, "text/", strlen("text/"))) {
1254                                 app_data->mime_type = MIME_TYPE_TEXT;
1255                         }
1256                 }
1257         }
1258         if (mime_type)
1259                 free(mime_type);
1260
1261         if (_TV || _MOBILE) {
1262                 app_data->app_type = APP_TYPE_KEYBOARD;
1263                 input_keyboard_init(service);
1264                 _keyboard_clicked_cb((void *)app_data, NULL, NULL);
1265                 goto ACTIVATE;
1266         }
1267
1268         ret = app_control_is_extra_data_array(service, APP_CONTROL_DATA_INPUT_TYPE, &is_extra_data_array);
1269         if ( is_extra_data_array == true) {
1270                 ret = app_control_get_extra_data_array(service, APP_CONTROL_DATA_INPUT_TYPE, &input_type_array, &input_type_array_len);
1271                 g_input_type_data.input_type_array = input_type_array;
1272                 g_input_type_data.input_type_array_len = input_type_array_len;
1273         } else {
1274                 ret = app_control_get_extra_data(service, APP_CONTROL_DATA_INPUT_TYPE, &context);
1275                 if (ret == APP_CONTROL_ERROR_NONE) {
1276                         if (!strcmp(context, "input_voice")) {
1277                                 app_data->app_type = APP_TYPE_STT;
1278                                 _stt_clicked_cb((void *)app_data, NULL, NULL);
1279                                 goto ACTIVATE;
1280                         } else if (!strcmp(context, "input_emoticon")) {
1281                                 app_data->app_type = APP_TYPE_EMOTICON;
1282                                 _emoticon_clicked_cb((void *)app_data, NULL, NULL);
1283                                 goto ACTIVATE;
1284                         } else if (!strcmp(context, "input_keyboard")) {
1285                                 app_data->app_type = APP_TYPE_KEYBOARD;
1286                                 input_keyboard_init(service);
1287                                 _keyboard_clicked_cb((void *)app_data, NULL, NULL);
1288                                 goto ACTIVATE;
1289                         } else if (!strcmp(context, "input_reply")) {
1290                                 app_data->app_type = APP_TYPE_REPLY;
1291                         }
1292                 }
1293         }
1294
1295         if (app_data->genlist == NULL)
1296                 app_data->genlist = _create_genlist(app_data->naviframe);
1297
1298         input_keyboard_init(service);
1299
1300         input_smartreply_init(service);
1301         input_smartreply_set_notify(_input_smartreply_notify_cb, NULL);
1302
1303         if (input_smartreply_is_enabled())
1304                 input_smartreply_get_reply_async();
1305
1306         input_template_init(service);
1307         input_template_set_notify(_input_template_notify_cb,  NULL);
1308
1309         _create_genlist_items(app_data);
1310
1311 ACTIVATE :
1312         elm_win_activate(app_data->win_main);
1313
1314         if (context)
1315                 free(context);
1316 }
1317
1318
1319 void _app_pause(void* user_data)
1320 {
1321         PRINTFUNC(DLOG_DEBUG, "");
1322         pause_voice();
1323 }
1324
1325 void _app_resume(void* user_data)
1326 {
1327         PRINTFUNC(DLOG_DEBUG, "");
1328         resume_voice();
1329 }
1330
1331 void _app_terminate(void* user_data)
1332 {
1333         App_Data* app_data = NULL;
1334         app_data = (App_Data*)user_data;
1335
1336         if (app_data->genlist){
1337                 evas_object_smart_callback_del(app_data->genlist, "elm,item,position,changed", _item_position_changed_cb);
1338         }
1339
1340         if (app_data->res_path)
1341                 free(app_data->res_path);
1342
1343         if (app_data->shared_res_path)
1344                 free(app_data->shared_res_path);
1345
1346         input_keyboard_deinit();
1347         input_smartreply_deinit();
1348
1349         input_template_unset_notify();
1350         input_template_deinit();
1351
1352         input_type_deinit();
1353 }
1354
1355 static int init_i18n(const char *domain, const char *dir, char *lang_str)
1356 {
1357         if (setlocale(LC_ALL, "") == NULL) {
1358                 PRINTFUNC(DLOG_INFO, "Some environment variable is invalid, setlocale(LC_ALL, \"\") has returns\ed a null pointer");
1359                 if (setlocale(LC_ALL, lang_str) == NULL)
1360                         return -1;
1361         }
1362         if (bindtextdomain(domain, dir) == NULL)
1363                 return -1;
1364         if (textdomain(domain) == NULL)
1365                 return -1;
1366
1367         return 0;
1368 }
1369
1370 /**
1371  * @brief Set language and locale.
1372  *
1373  * @return void
1374  */
1375 static void _app_language_changed(app_event_info_h event_info, void *user_data)
1376 {
1377         char* lang_str = vconf_get_str(VCONFKEY_LANGSET);
1378         if (lang_str) {
1379                 setenv("LANG", lang_str, 1);
1380                 setenv("LC_MESSAGES", lang_str, 1);
1381         } else {
1382                 setenv("LANG", "en_GB.utf8", 1);
1383                 setenv("LC_MESSAGES", "en_GB.utf8", 1);
1384                 lang_str = strdup("en_GB.UTF-8");
1385         }
1386
1387         init_i18n(PACKAGE, LOCALEDIR, lang_str);
1388
1389         if (lang_str) {
1390                 elm_language_set(lang_str);
1391                 free(lang_str);
1392         }
1393 }
1394
1395 void input_type_deinit(void)
1396 {
1397         int i = 0;
1398         char **data_array = NULL;
1399
1400         data_array = g_input_type_data.input_type_array;
1401         if (data_array) {
1402                 for (i = 0; i < g_input_type_data.input_type_array_len; i++) {
1403                         if (*(data_array + i))
1404                                 free(*(data_array + i));
1405                 }
1406                 free(data_array);
1407         }
1408         g_input_type_data.input_type_array = NULL;
1409         g_input_type_data.input_type_array_len = 0;
1410 }
1411
1412 EXPORTED int main(int argc, char* argv[])
1413 {
1414         App_Data app_data = {0, };
1415         ui_app_lifecycle_callback_s event_callback = {0, };
1416         app_event_handler_h handlers[5] = {NULL, };
1417
1418         event_callback.create = _app_create;
1419         event_callback.terminate = _app_terminate;
1420         event_callback.pause = _app_pause;
1421         event_callback.resume = _app_resume;
1422         event_callback.app_control = _app_service;
1423
1424         ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, NULL, &app_data);
1425         ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, NULL, &app_data);
1426         ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, NULL, &app_data);
1427         ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, _app_language_changed, &app_data);
1428         ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, NULL, &app_data);
1429
1430         _init_app_data(&app_data);
1431
1432         int ret = ui_app_main(argc, argv, &event_callback, &app_data);
1433         if (ret != APP_ERROR_NONE) {
1434                 LOGD("ui_app_main() is failed. err = %d", ret);
1435         }
1436
1437         return ret;
1438 }