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