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