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