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