Remove code for tos
[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
34 #include <stt.h>
35
36
37 using namespace std;
38
39 App_Data* app_data = NULL;
40
41 InputKeyboardData g_input_keyboard_data;
42 InputTypeData g_input_type_data;
43
44 static Elm_Object_Item *it_empty;
45 static Elm_Object_Item *it_title;
46
47 static unsigned int g_template_item_size = 0;           /* Current Template item size */
48
49 Evas_Coord last_step; // 0 ~ 9 for gesture, 10~11 for rotary
50
51 tizen_profile_t _get_tizen_profile()
52 {
53    static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN;
54    if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
55      return profile;
56
57    char *profileName;
58    system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
59    switch (*profileName)
60      {
61       case 'm':
62       case 'M':
63          profile = TIZEN_PROFILE_MOBILE;
64          break;
65       case 'w':
66       case 'W':
67          profile = TIZEN_PROFILE_WEARABLE;
68          break;
69       case 't':
70       case 'T':
71          profile = TIZEN_PROFILE_TV;
72          break;
73       case 'i':
74       case 'I':
75          profile = TIZEN_PROFILE_IVI;
76          break;
77       default: // common or unknown ==> ALL ARE COMMON.
78          profile = TIZEN_PROFILE_COMMON;
79      }
80    free(profileName);
81
82    return profile;
83 }
84
85
86 void _init_app_data(App_Data* app_data);
87 static void _app_language_changed(app_event_info_h event_info, void *user_data);
88
89 Evas_Object* _create_genlist(Evas_Object* parent);
90 void _create_genlist_items(void* user_data);
91 void _create_header_items(void *user_data);
92 void _update_genlist_items(void *user_data);
93 unsigned int _update_template_items(void *user_data);
94 static void _popup_close_cb(void *data, Evas_Object *obj, void *event_info);
95 static void _popup_back_cb(void *data, Evas_Object *obj, void *event_info);
96 static void input_type_deinit(void);
97
98 void _init_app_data(App_Data* app_data)
99 {
100         app_data->win_main = NULL;
101         app_data->layout_main = NULL;
102         app_data->conform = NULL;
103         app_data->naviframe = NULL;
104         app_data->genlist = NULL;
105
106         app_data->res_path = NULL;
107 }
108
109 Evas_Object* load_edj(Evas_Object* parent, const char* file, const char* group)
110 {
111         Evas_Object* window;
112         Evas_Object* content;
113         int ret;
114
115         window = elm_layout_add(parent);
116         if (window) {
117                 ret = elm_layout_file_set(window, file, group);
118                 if (!ret) {
119                         evas_object_del(window);
120                         return NULL;
121                 }
122
123                 content = elm_layout_add(parent);
124                 elm_layout_theme_set(content, "layout", "application", "default");
125                 elm_object_part_content_set(window, "elm.swallow.content", content);
126
127                 evas_object_size_hint_weight_set(window, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
128         }
129         return window;
130 }
131
132 void init_customizing_theme(void)
133 {
134         string stt_edj_path = get_resource_path();
135         string app_edj_path = get_resource_path();
136
137         stt_edj_path = stt_edj_path + STT_EDJ_FILE;
138         app_edj_path = app_edj_path + APP_EDJ_FILE;
139
140         elm_theme_extension_add(NULL, stt_edj_path.c_str());
141         elm_theme_extension_add(NULL, app_edj_path.c_str());
142 }
143
144
145 static Eina_Bool back_cb(void *data, Elm_Object_Item *it)
146 {
147         reply_to_sender_by_callback_for_back();
148         elm_exit();
149         return EINA_FALSE;
150 }
151
152 static void _stt_clicked_cb(void *data, Evas_Object * obj, void *event_info)
153 {
154         App_Data* ad = (App_Data*)data;
155
156         PRINTFUNC(DLOG_DEBUG, "");
157
158         if(!ad)
159                 return;
160
161         ise_show_stt_popup(ad);
162 }
163
164 static void _input_template_notify_cb(void *user_data)
165 {
166         _update_genlist_items((void *)app_data);
167 }
168
169 static void _emoticon_clicked_cb(void *data, Evas_Object * obj, void *event_info)
170 {
171         App_Data* ad = (App_Data*)data;
172
173         PRINTFUNC(DLOG_DEBUG, "");
174
175         if(!ad)
176                 return;
177
178         ise_show_emoticon_list(ad);
179 }
180
181 static void _keyboard_clicked_cb(void *data, Evas_Object * obj, void *event_info)
182 {
183         App_Data* ad = (App_Data *)data;
184
185         PRINTFUNC(DLOG_DEBUG, "");
186
187         if (!ad)
188                 return;
189
190         input_keyboard_launch(ad->win_main, data);
191 }
192
193 static void __ise_template_gl_sel(void *data, Evas_Object *obj, void *event_info)
194 {
195         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
196         int index = 0;
197
198         if (item) {
199                 elm_genlist_item_selected_set(item, EINA_FALSE);
200
201                 index = (uintptr_t) elm_object_item_data_get(item);
202                 const std::vector<TemplateData>  template_list = input_template_get_list();
203
204                 if (index < (int)template_list.size()) {
205                         reply_to_sender_by_callback(gettext(template_list[index].text.c_str()), "template");
206                         elm_exit();
207                 }
208         }
209 }
210
211 static char * __ise_template_gl_text_get(void *data, Evas_Object *obj, const char *part)
212 {
213         if(!strcmp(part, "elm.text")) {
214                 unsigned int index = (uintptr_t)data;
215                 const std::vector<TemplateData>  template_list = input_template_get_list();
216
217                 if(index < template_list.size()) {
218                         if(template_list[index].use_gettext) {
219                                 return strdup(gettext(template_list[index].text.c_str()));
220                         } else {
221                                 Eina_Strbuf *buf = NULL;
222                                 const char *str = NULL;
223                                 char *markup = NULL;
224
225                                 buf = eina_strbuf_new();
226                                 if(buf) {
227                                         eina_strbuf_append(buf, template_list[index].text.c_str());
228                                         eina_strbuf_replace_all(buf, "\n", "");
229                                         eina_strbuf_replace_all(buf, "\r", "");
230
231                                         str = eina_strbuf_string_get(buf);
232
233                                         if (str) {
234                                                 markup = elm_entry_utf8_to_markup(str);
235                                         }
236                                         eina_strbuf_free(buf);
237                                 }
238                                 return markup;
239                         }
240                 }
241         }
242         return NULL;
243 }
244
245 static Evas_Object * __ise_gl_2button_content_get(void *data, Evas_Object *obj, const char *part)
246 {
247         char *first_input_type = *(g_input_type_data.input_type_array + 0);
248         char *second_input_type = *(g_input_type_data.input_type_array + 1);
249
250         if (!strcmp(part, "elm.icon.1") ||  (!strcmp(part, "elm.icon.2"))) {
251                 Evas_Object* btn = elm_button_add(obj);
252                 evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
253                 evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
254
255                 Evas_Object* ic = elm_image_add(btn);
256                 elm_image_resizable_set(ic, EINA_TRUE, EINA_TRUE);
257                 string path = get_resource_path();
258                 if (!strcmp(part, "elm.icon.1")) {
259                         string path_ic;
260                         if(!strcmp(first_input_type, "input_voice")) {
261                                 elm_object_style_set(btn, "ime_button_stt");
262                                 path_ic = path + "images/w_mode_stt_ic.png";
263                         } else if (!strcmp(first_input_type, "input_emoticon")) {
264                                 elm_object_style_set(btn, "ime_button_emoticon");
265                                 path_ic = path + "images/Delta_w_mode_emoticon_ic.png";
266                         } else if (!strcmp(first_input_type, "input_keyboard")) {
267                                 elm_object_style_set(btn, "ime_button_keyboard");
268                                 path_ic = path + "images/w_mode_keyboard_ic.png";
269                                 evas_object_propagate_events_set(btn, EINA_FALSE);
270                         }
271                         elm_image_file_set(ic, path_ic.c_str(), NULL);
272                         elm_object_content_set(btn, ic);
273                         evas_object_layer_set(btn, 32000);
274                 } else if (!strcmp(part, "elm.icon.2")){
275                         string path_ic;
276                         if(!strcmp(second_input_type, "input_voice")) {
277                                 elm_object_style_set(btn, "ime_button_stt");
278                                 path_ic = path + "images/w_mode_stt_ic.png";
279                         } else if (!strcmp(second_input_type, "input_emoticon")) {
280                                 elm_object_style_set(btn, "ime_button_emoticon");
281                                 path_ic = path + "images/Delta_w_mode_emoticon_ic.png";
282                         } else if (!strcmp(second_input_type, "input_keyboard")) {
283                                 elm_object_style_set(btn, "ime_button_keyboard");
284                                 path_ic = path + "images/w_mode_keyboard_ic.png";
285                                 evas_object_propagate_events_set(btn, EINA_FALSE);
286                         }
287                         elm_image_file_set(ic, path_ic.c_str(), NULL);
288                         elm_object_content_set(btn, ic);
289                         evas_object_layer_set(btn, 32000);
290                 }
291                 return btn;
292         } else if (!strcmp(part, "elm.icon.1.touch_area") ||  (!strcmp(part, "elm.icon.2.touch_area"))) {
293                 Evas_Object* btn = elm_button_add(obj);
294                 elm_object_style_set(btn, "touch_area");
295                 evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
296                 evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
297                 string path = get_resource_path();
298                 if (!strcmp(part, "elm.icon.1.touch_area")) {
299                         evas_object_layer_set(btn, 32000);
300                         if(!strcmp(first_input_type, "input_voice")) {
301                                 evas_object_smart_callback_add(btn, "clicked", _stt_clicked_cb, app_data);
302                         } else if (!strcmp(first_input_type, "input_emoticon")) {
303                                 evas_object_smart_callback_add(btn, "clicked", _emoticon_clicked_cb, app_data);
304                         } else if (!strcmp(first_input_type, "input_keyboard")) {
305                                 evas_object_propagate_events_set(btn, EINA_FALSE);
306                                 evas_object_smart_callback_add(btn, "clicked", _keyboard_clicked_cb, app_data);
307                         }
308                 } else if (!strcmp(part, "elm.icon.2.touch_area")){
309                         evas_object_layer_set(btn, 32000);
310                         if(!strcmp(second_input_type, "input_voice")) {
311                                 evas_object_smart_callback_add(btn, "clicked", _stt_clicked_cb, app_data);
312                         } else if (!strcmp(second_input_type, "input_emoticon")) {
313                                 evas_object_smart_callback_add(btn, "clicked", _emoticon_clicked_cb, app_data);
314                         } else if (!strcmp(second_input_type, "input_keyboard")) {
315                                 evas_object_propagate_events_set(btn, EINA_FALSE);
316                                 evas_object_smart_callback_add(btn, "clicked", _keyboard_clicked_cb, app_data);
317                         }
318                 }
319                 return btn;
320         } else if (!strcmp(part, "base")) {
321                 Evas_Object* btn = elm_button_add(obj);
322                 elm_object_style_set(btn, "ime_transparent");
323                 return btn;
324         }
325         return NULL;
326 }
327
328 static Evas_Object * __ise_gl_3button_content_get(void *data, Evas_Object *obj, const char *part)
329 {
330         if (!strcmp(part, "elm.icon.1") ||  (!strcmp(part, "elm.icon.2")) ||  (!strcmp(part, "elm.icon.3"))) {
331                 Evas_Object* btn = elm_button_add(obj);
332                 evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
333                 evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
334                 Evas_Object* ic = elm_image_add(btn);
335                 elm_image_resizable_set(ic, EINA_TRUE, EINA_TRUE);
336                 string path = get_resource_path();
337                 if (!strcmp(part, "elm.icon.1")) {
338                         elm_object_style_set(btn, "ime_button_stt");
339                         string path_ic = path + "images/w_mode_stt_ic.png";
340                         elm_image_file_set(ic, path_ic.c_str(), NULL);
341                         elm_object_content_set(btn, ic);
342                         evas_object_layer_set(btn, 32000);
343
344                 } else if (!strcmp(part, "elm.icon.2")){
345                         elm_object_style_set(btn, "ime_button_emoticon");
346                         string path_ic = path + "images/Delta_w_mode_emoticon_ic.png";
347                         elm_image_file_set(ic, path_ic.c_str(), NULL);
348                         elm_object_content_set(btn, ic);
349                         evas_object_layer_set(btn, 32000);
350
351                 } else if (!strcmp(part, "elm.icon.3")){
352                         elm_object_style_set(btn, "ime_button_keyboard");
353                         string path_ic = path + "images/w_mode_keyboard_ic.png";
354                         elm_image_file_set(ic, path_ic.c_str(), NULL);
355                         elm_object_content_set(btn, ic);
356                         evas_object_layer_set(btn, 32000);
357                         evas_object_propagate_events_set(btn, EINA_FALSE);
358                 }
359
360                 return btn;
361         } else if (!strcmp(part, "elm.icon.1.touch_area") ||  (!strcmp(part, "elm.icon.2.touch_area")) ||  (!strcmp(part, "elm.icon.3.touch_area"))) {
362                 Evas_Object* btn = elm_button_add(obj);
363                 elm_object_style_set(btn, "touch_area");
364                 evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
365                 evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
366                 string path = get_resource_path();
367                 if (!strcmp(part, "elm.icon.1.touch_area")) {
368                         evas_object_layer_set(btn, 32000);
369                         evas_object_smart_callback_add(btn, "clicked", _stt_clicked_cb, app_data);
370
371                 } else if (!strcmp(part, "elm.icon.2.touch_area")){
372                         evas_object_layer_set(btn, 32000);
373                         evas_object_smart_callback_add(btn, "clicked", _emoticon_clicked_cb, app_data);
374                 } else if (!strcmp(part, "elm.icon.3.touch_area")) {
375                         evas_object_layer_set(btn, 32000);
376                         evas_object_propagate_events_set(btn, EINA_FALSE);
377                         evas_object_smart_callback_add(btn, "clicked", _keyboard_clicked_cb, app_data);
378                 }
379
380                 return btn;
381         } else if (!strcmp(part, "base")) {
382                 Evas_Object* btn = elm_button_add(obj);
383                 elm_object_style_set(btn, "ime_transparent");
384                 return btn;
385         }
386         return NULL;
387 }
388
389
390 static void __ise_gl_lang_changed(void *data, Evas_Object *obj, void *event_info)
391 {
392         //Update genlist items. The Item texts will be translated in the _gl_text_get().
393         elm_genlist_realized_items_update(obj);
394 }
395
396 void set_source_caller_app_id(app_control_h app_control)
397 {
398         if(!app_control){
399                 PRINTFUNC(DLOG_ERROR, "can't get app_control");
400                 return;
401         }
402
403         char *caller = NULL;
404         app_control_get_caller(app_data->source_app_control, &caller);
405
406         if(caller){
407                 PRINTFUNC(DLOG_DEBUG, "caller = %s", caller);
408                 app_control_add_extra_data(app_control, "caller_appid", caller);
409                 free(caller);
410         }
411 }
412
413 void reply_to_sender_by_callback(const char *value, const char *type)
414 {
415         PRINTFUNC(DLOG_DEBUG, "");
416
417         app_control_h app_control;
418
419         if(app_control_create(&app_control) == 0) {
420                 int ret;
421
422                 if (value)
423                         app_control_add_extra_data(app_control, APP_CONTROL_DATA_TEXT, value);
424
425                 if (type)
426                         app_control_add_extra_data(app_control, "reply_type", type);
427
428                 set_source_caller_app_id(app_control);
429
430                 ret = app_control_reply_to_launch_request(app_control, app_data->source_app_control, APP_CONTROL_RESULT_SUCCEEDED);
431                 if (ret != APP_CONTROL_ERROR_NONE)
432                         PRINTFUNC(DLOG_ERROR, "reply failed : %d", ret);
433
434                 app_control_destroy(app_control);
435                 app_control_destroy(app_data->source_app_control);
436                 app_data->source_app_control = NULL;
437         }
438 }
439
440 void reply_to_sender_by_callback_for_back()
441 {
442         PRINTFUNC(DLOG_DEBUG, "");
443
444         app_control_h app_control;
445
446         if(app_control_create(&app_control) == 0) {
447                 int ret;
448
449                 app_control_add_extra_data(app_control, "back_to_composer", "yes");
450
451                 ret = app_control_reply_to_launch_request(app_control, app_data->source_app_control, APP_CONTROL_RESULT_SUCCEEDED);
452                 if (ret != APP_CONTROL_ERROR_NONE)
453                         PRINTFUNC(DLOG_ERROR, "reply failed : %d", ret);
454
455                 app_control_destroy(app_control);
456                 app_control_destroy(app_data->source_app_control);
457                 app_data->source_app_control = NULL;
458         }
459 }
460
461 char* get_resource_path()
462 {
463         if(NULL == app_data->res_path) {
464                 app_data->res_path = app_get_resource_path();
465                 PRINTFUNC(DLOG_INFO, "set resource path = %s", app_data->res_path);
466         }
467         return (app_data->res_path);
468 }
469
470 char* get_shared_resource_path()
471 {
472         if(NULL == app_data->shared_res_path) {
473                 app_data->shared_res_path = app_get_shared_resource_path();
474                 PRINTFUNC(DLOG_INFO, "set shared resource path = %s", app_data->shared_res_path);
475         }
476         return (app_data->shared_res_path);
477 }
478
479 void show_gl_focus(Eina_Bool bVisible){
480         if(app_data->genlist == NULL)
481                 return;
482
483         if(bVisible == EINA_TRUE){
484                 elm_object_signal_emit(app_data->genlist, "elm,state,focus_bg,enable", "elm");
485                 //elm_layout_theme_set(app_data->genlist, "genlist", "base", "focus_bg");
486                 //elm_object_signal_emit(app_data->genlist, "elm,state,focus_bg,show", "elm");
487         } else {
488                 elm_object_signal_emit(app_data->genlist, "elm,state,focus_bg,disable", "elm");
489                 //elm_layout_theme_set(app_data->genlist, "genlist", "base", "default");
490                 //elm_object_signal_emit(app_data->genlist, "elm,state,focus_bg,hide", "elm");
491         }
492 }
493
494 void show_popup_toast(const char *text, bool check_img)
495 {
496         PRINTFUNC(DLOG_ERROR, "show_popup_toast");
497
498         Evas_Object *popup;
499
500         popup = elm_popup_add(app_data->win_main);
501         elm_object_style_set(popup, "toast/circle");
502         elm_popup_orient_set(popup, ELM_POPUP_ORIENT_BOTTOM);
503         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
504
505         if (check_img) {
506                 string path = get_resource_path();
507                 string path_ic = path + "/images/toast_check_icon.png";
508                 Evas_Object * img = elm_image_add(popup);
509                 elm_image_file_set(img, path_ic.c_str(), NULL);
510                 elm_object_part_content_set(popup, "toast,icon", img);
511         }
512         if(text) {
513                 elm_object_part_text_set(popup, "elm.text", text);
514         }
515
516         eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, _popup_back_cb, NULL);
517         evas_object_smart_callback_add(popup, "dismissed", _popup_close_cb, NULL);
518         evas_object_smart_callback_add(popup, "block,clicked", _popup_back_cb, NULL);
519
520         elm_popup_timeout_set(popup, 2.0);
521         evas_object_show(popup);
522 }
523
524 static void _popup_close_cb(void *data, Evas_Object *obj, void *event_info)
525 {
526         if(obj){
527                 evas_object_hide(obj);
528                 evas_object_del(obj);
529         }
530 }
531
532 static void _popup_back_cb(void *data, Evas_Object *obj, void *event_info)
533 {
534         if(obj)
535                 elm_popup_dismiss(obj);
536 }
537
538
539 void _back_to_genlist_for_selector()
540 {
541         PRINTFUNC(DLOG_DEBUG, "");
542
543         if(!app_data) return;
544
545         if(app_data->app_type == APP_TYPE_STT || app_data->app_type == APP_TYPE_EMOTICON){
546                 PRINTFUNC(DLOG_DEBUG, "launched as STT/EMOTICON mode, So exit here.");
547                 reply_to_sender_by_callback(NULL, NULL);
548                 elm_exit();
549         }
550 #ifdef _WEARABLE
551         Evas_Object *circle_genlist = (Evas_Object *) evas_object_data_get(app_data->genlist, "circle");
552         eext_rotary_object_event_activated_set(circle_genlist, EINA_TRUE);
553 #endif
554 }
555
556 static void _item_realized(void *data, Evas_Object *obj, void *event_info) //called when list scrolled
557 {
558         PRINTFUNC(DLOG_DEBUG, "%s", __func__);
559 }
560
561 Evas_Object* _create_genlist(Evas_Object* navi)
562 {
563         Evas_Object* genlist = elm_genlist_add(navi);
564         if(NULL == genlist)
565                 return NULL;
566
567         elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
568 #ifdef _WEARABLE
569         Evas_Object* circle_object_genlist = eext_circle_object_genlist_add(genlist, app_data->circle_surface);
570         eext_circle_object_genlist_scroller_policy_set(circle_object_genlist, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF);
571         evas_object_data_set(genlist, "circle", (void *) circle_object_genlist);
572         eext_rotary_object_event_activated_set(circle_object_genlist, EINA_TRUE);
573 #endif
574         evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
575         evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
576
577         evas_object_smart_callback_add(genlist, "language,changed", __ise_gl_lang_changed, genlist);
578         evas_object_show(genlist);
579
580 //      uxt_genlist_set_bottom_margin_enabled(genlist, EINA_TRUE);
581
582         show_gl_focus(EINA_FALSE);
583
584         Elm_Object_Item *nf_main_item = elm_naviframe_item_push(navi,
585             NULL,
586             NULL,
587             NULL,
588             genlist,
589             "empty");
590
591         elm_naviframe_item_pop_cb_set(nf_main_item, back_cb, app_data);
592         evas_object_smart_callback_add(genlist, "realized", _item_realized, NULL);
593
594         return genlist;
595 }
596
597 static void _item_position_changed_cb(void *data, Evas_Object *obj, void *event_info)
598 {
599         if(!obj) return;
600         if(!data) return;
601
602         Evas_Object *genlist = (Evas_Object *)obj;
603         Elm_Object_Item *gen_item = (Elm_Object_Item *)data;
604
605         Evas_Coord y;
606         elm_scroller_region_get(genlist, NULL, &y, NULL, NULL);
607
608 //      PRINTFUNC(DLOG_DEBUG,"y=%d",y);
609
610         if (250 > y && y >= 100){
611                 if (last_step == 0) return;
612                 last_step = 0;
613                 elm_object_item_signal_emit(gen_item, "elm,action,ime,0.0", "elm");
614                 show_gl_focus(EINA_TRUE);
615         } else if (100 > y && y >= 50){
616                 if (last_step == 1) return;
617                 last_step = 1;
618                 elm_object_item_signal_emit(gen_item, "elm,action,ime,0.1", "elm");
619                 show_gl_focus(EINA_TRUE);
620         } else if (y < 50 && y >=0){
621                 if (last_step == 2) return;
622                 last_step = 2;
623                 elm_object_item_signal_emit(gen_item, "elm,action,ime,0.9", "elm");
624                 show_gl_focus(EINA_FALSE);
625         }
626 }
627
628 static char *
629 _main_menu_title_text_get(void *data, Evas_Object *obj, const char *part)
630 {
631         char buf[1024];
632
633         snprintf(buf, 1023, "%s", "Select method");
634         return strdup(buf);
635 }
636
637 void _create_genlist_items(void* user_data)
638 {
639         App_Data* app_data = (App_Data*) user_data;
640
641         if(NULL == app_data->genlist) {
642                 app_data->genlist = _create_genlist(app_data->naviframe);
643                 if(NULL == app_data->genlist)
644                 return;
645         }
646
647         elm_genlist_clear(app_data->genlist);
648
649         Elm_Genlist_Item_Class * itc0 = elm_genlist_item_class_new();
650         itc0->item_style = "title";
651         itc0->func.text_get = _main_menu_title_text_get;
652         itc0->func.content_get = NULL;
653         itc0->func.state_get = NULL;
654         itc0->func.del = NULL;
655
656         Elm_Genlist_Item_Class * itc1 = elm_genlist_item_class_new();
657         if(g_input_type_data.input_type_array_len == 2){
658                 itc1->item_style = "2button_flat";
659                 itc1->func.text_get = NULL;
660                 itc1->func.content_get = __ise_gl_2button_content_get;
661                 itc1->func.state_get = NULL;
662                 itc1->func.del = NULL;
663         } else {
664                 itc1->item_style = "3button_flat";
665                 itc1->func.text_get = NULL;
666                 itc1->func.content_get = __ise_gl_3button_content_get;
667                 itc1->func.state_get = NULL;
668                 itc1->func.del = NULL;
669         }
670
671         // dummy title for empty space
672         it_empty = elm_genlist_item_append(app_data->genlist, itc0,
673                         NULL, NULL,
674                         ELM_GENLIST_ITEM_NONE,
675                         NULL, NULL);
676
677         // 3 Buttons
678         it_title = elm_genlist_item_append(app_data->genlist, itc1,
679                         NULL, NULL,
680                         ELM_GENLIST_ITEM_NONE,
681                         NULL, NULL);
682
683         elm_genlist_item_select_mode_set(it_title, ELM_OBJECT_SELECT_MODE_NONE);
684
685         g_template_item_size = _update_template_items(app_data);
686
687         Elm_Object_Item *item = elm_genlist_item_next_get(it_title);
688         elm_genlist_item_show(item, ELM_GENLIST_ITEM_SCROLLTO_MIDDLE);
689
690         evas_object_smart_callback_add(app_data->genlist, "elm,item,position,changed", _item_position_changed_cb, it_title);
691
692         elm_genlist_item_class_free(itc0);
693         elm_genlist_item_class_free(itc1);
694 }
695
696 void _create_header_items(void *user_data)
697 {
698         Elm_Genlist_Item_Class * itc0 = elm_genlist_item_class_new();
699         itc0->item_style = "title";
700         itc0->func.text_get = NULL;
701         itc0->func.content_get = NULL;
702         itc0->func.state_get = NULL;
703         itc0->func.del = NULL;
704
705         Elm_Genlist_Item_Class * itc1 = elm_genlist_item_class_new();
706         if (g_input_type_data.input_type_array_len == 2) {
707                 itc1->item_style = "2button_flat";
708                 itc1->func.text_get = NULL;
709                 itc1->func.content_get = __ise_gl_2button_content_get;
710                 itc1->func.state_get = NULL;
711                 itc1->func.del = NULL;
712         } else {
713                 itc1->item_style = "3button_flat";
714                 itc1->func.text_get = NULL;
715                 itc1->func.content_get = __ise_gl_3button_content_get;
716                 itc1->func.state_get = NULL;
717                 itc1->func.del = NULL;
718         }
719
720         // dummy title for empty space
721         it_empty = elm_genlist_item_append(app_data->genlist, itc0,
722                                 NULL, NULL,
723                                 ELM_GENLIST_ITEM_NONE,
724                                 NULL, NULL);
725
726         // 3 Buttons
727         it_title = elm_genlist_item_append(app_data->genlist, itc1,
728                                                         NULL, NULL,
729                                                         ELM_GENLIST_ITEM_NONE,
730                                                         NULL, NULL);
731
732         elm_genlist_item_select_mode_set(it_title, ELM_OBJECT_SELECT_MODE_NONE);
733
734         elm_genlist_item_class_free(itc0);
735         elm_genlist_item_class_free(itc1);
736 }
737
738 void _update_genlist_items(void *user_data)
739 {
740         elm_genlist_clear(app_data->genlist);
741
742         _create_header_items(user_data);
743
744         g_template_item_size = _update_template_items(user_data);
745
746         /* Update genlist item position */
747         Elm_Object_Item *item = elm_genlist_item_next_get(it_title);
748         elm_genlist_item_show(item, ELM_GENLIST_ITEM_SCROLLTO_MIDDLE);
749 }
750
751 unsigned int _update_template_items(void *user_data)
752 {
753         App_Data* app_data;
754
755         Elm_Object_Item *first;
756
757         unsigned int i = 0;
758         unsigned int item_size = 0;
759
760         app_data = (App_Data *)user_data;
761
762         if (app_data == NULL) {
763                 PRINTFUNC(DLOG_ERROR, "Can not get app_data");
764                 return item_size;
765         }
766
767         if (app_data->genlist == NULL) {
768                 /* smartreply will update when genlist is exist only */
769                 PRINTFUNC(DLOG_ERROR, "Can not get getlist");
770                 return item_size;
771         }
772
773         first = elm_genlist_first_item_get(app_data->genlist);
774         if (first == NULL)
775                 return 0;
776         elm_genlist_item_next_get(first);
777
778         /* Append New Template list */
779         const std::vector<TemplateData> template_list = input_template_get_list();
780
781         if (template_list.size() > 0) {
782                 Elm_Genlist_Item_Class *itc;
783
784                 itc = elm_genlist_item_class_new();
785
786                 itc->item_style = "1text";
787                 itc->func.text_get = __ise_template_gl_text_get;
788                 itc->func.content_get = NULL;
789                 itc->func.state_get = NULL;
790                 itc->func.del = NULL;
791
792                 for (i = 0; i < template_list.size(); i++) {
793                         elm_genlist_item_append(app_data->genlist,
794                                         itc,
795                                         (void *)(uintptr_t)i,
796                                         NULL,
797                                         ELM_GENLIST_ITEM_NONE,
798                                         __ise_template_gl_sel,
799                                         app_data);
800                         item_size++;
801                 }
802                 elm_genlist_item_class_free(itc);
803         }
804
805         return item_size;
806 }
807
808 bool _app_create(void* user_data)
809 {
810         int width = 1000, height = 1000;
811 //      App_Data* app_data = NULL;
812         Evas_Object* layout = NULL;
813         Evas_Object* conform = NULL;
814         Evas_Object* bg = NULL;
815         Evas_Object* window = NULL;
816 #ifdef _WEARABLE
817         Eext_Circle_Surface *surface;
818 #endif
819         if (!user_data) {
820                 return false;
821         }
822
823         _app_language_changed(NULL, NULL);
824
825         app_data = (App_Data*)user_data;
826
827         elm_app_base_scale_set(1.3);
828
829         window = elm_win_add(NULL, PACKAGE, ELM_WIN_BASIC);
830         if (window) {
831                 init_customizing_theme();
832
833                 elm_win_title_set(window, PACKAGE);
834                 elm_win_borderless_set(window, EINA_TRUE);
835 //              ecore_x_window_size_get(ecore_x_window_root_first_get(), &width, &height);
836                 evas_object_resize(window, width, height);
837                 elm_win_indicator_mode_set(window, ELM_WIN_INDICATOR_SHOW);
838         } else {
839                 LOGE("elm_win_add() is failed.");
840                 return false;
841         }
842
843         bg = elm_bg_add(window);
844         evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
845         elm_win_resize_object_add(window, bg);
846         evas_object_show(bg);
847
848         layout = elm_layout_add(window);
849         elm_layout_theme_set(layout, "layout", "application", "default");
850         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
851
852         conform = elm_conformant_add(window);
853 #ifdef _WEARABLE
854         surface = eext_circle_surface_conformant_add(conform);
855 #endif
856         evas_object_size_hint_weight_set(conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
857
858
859         elm_win_resize_object_add(window, conform);
860         elm_object_content_set(conform, layout);
861
862         evas_object_show(layout);
863         evas_object_show(conform);
864         evas_object_show(window);
865         app_data->win_main = window;
866         app_data->conform = conform;
867         app_data->layout_main = layout;
868 #ifdef _WEARABLE
869         app_data->circle_surface = surface;
870 #endif
871         app_data->app_type = APP_TYPE_SELECT_MODE;
872
873         Evas_Object *naviframe = elm_naviframe_add(layout);
874         elm_naviframe_prev_btn_auto_pushed_set(naviframe, EINA_FALSE);
875         eext_object_event_callback_add(naviframe, EEXT_CALLBACK_BACK, eext_naviframe_back_cb, NULL);
876         elm_object_part_content_set(layout, "elm.swallow.content", naviframe);
877         evas_object_show(naviframe);
878
879         app_data->naviframe = naviframe;
880
881         return true;
882 }
883
884 void _app_service(app_control_h service, void* user_data)
885 {
886         int ret;
887         char *context = NULL;
888         char **input_type_array = NULL;
889         int input_type_array_len = -1;
890         bool is_extra_data_array = false;
891
892         app_control_clone(&(app_data->source_app_control), service);
893         app_data->reply_type = REPLY_APP_NORMAL;
894
895         ret = app_control_is_extra_data_array(service, APP_CONTROL_DATA_INPUT_TYPE, &is_extra_data_array);
896         if( is_extra_data_array == true) {
897                 ret = app_control_get_extra_data_array(service, APP_CONTROL_DATA_INPUT_TYPE, &input_type_array, &input_type_array_len);
898                 g_input_type_data.input_type_array = input_type_array;
899                 g_input_type_data.input_type_array_len = input_type_array_len;
900         } else {
901                 ret = app_control_get_extra_data(service, APP_CONTROL_DATA_INPUT_TYPE, &context);
902                 if (ret == APP_CONTROL_ERROR_NONE) {
903                         if (!strcmp(context, "input_voice")) {
904                                 app_data->app_type = APP_TYPE_STT;
905                                 _stt_clicked_cb((void *)app_data, NULL, NULL);
906                                 goto ACTIVATE;
907                         } else if (!strcmp(context, "input_emoticon")) {
908                                 app_data->app_type = APP_TYPE_EMOTICON;
909                                 _emoticon_clicked_cb((void *)app_data, NULL, NULL);
910                                 goto ACTIVATE;
911                         } else if (!strcmp(context, "input_keyboard")) {
912                                 app_data->app_type = APP_TYPE_KEYBOARD;
913                                 input_keyboard_init(service);
914                                 _keyboard_clicked_cb((void *)app_data, NULL, NULL);
915                                 goto ACTIVATE;
916                         } else if (!strcmp(context, "input_reply")) {
917                                 app_data->app_type = APP_TYPE_REPLY;
918                         }
919                 }
920         }
921
922         if (app_data->genlist == NULL)
923                 app_data->genlist = _create_genlist(app_data->naviframe);
924
925         input_keyboard_init(service);
926
927         input_template_init(service);
928         input_template_set_notify(_input_template_notify_cb,  NULL);
929
930         _create_genlist_items(app_data);
931
932 ACTIVATE :
933         elm_win_activate(app_data->win_main);
934
935         if(context)
936                 free(context);
937 }
938
939
940 void _app_pause(void* user_data)
941 {
942         PRINTFUNC(DLOG_DEBUG, "");
943         pause_voice();
944 }
945
946 void _app_resume(void* user_data)
947 {
948         PRINTFUNC(DLOG_DEBUG, "");
949 }
950
951 void _app_terminate(void* user_data)
952 {
953         App_Data* app_data = NULL;
954         app_data = (App_Data*)user_data;
955
956         if(app_data->genlist){
957                 evas_object_smart_callback_del(app_data->genlist, "elm,item,position,changed", _item_position_changed_cb);
958         }
959
960         if(app_data->res_path)
961                 free(app_data->res_path);
962
963         if(app_data->shared_res_path)
964                 free(app_data->shared_res_path);
965
966         input_keyboard_deinit();
967
968         input_template_unset_notify();
969         input_template_deinit();
970
971         input_type_deinit();
972 }
973
974 static int init_i18n(const char *domain, const char *dir, char *lang_str)
975 {
976         if (setlocale(LC_ALL, "") == NULL) {
977                 PRINTFUNC(DLOG_INFO, "Some environment variable is invalid, setlocale(LC_ALL, \"\") has returns\ed a null pointer");
978                 if (setlocale(LC_ALL, lang_str) == NULL)
979                         return -1;
980         }
981         if (bindtextdomain(domain, dir) == NULL)
982                 return -1;
983         if (textdomain(domain) == NULL)
984                 return -1;
985
986         return 0;
987 }
988
989 /**
990  * @brief Set language and locale.
991  *
992  * @return void
993  */
994 static void _app_language_changed(app_event_info_h event_info, void *user_data)
995 {
996         char* lang_str = vconf_get_str(VCONFKEY_LANGSET);
997         if (lang_str) {
998                 setenv("LANG", lang_str, 1);
999                 setenv("LC_MESSAGES", lang_str, 1);
1000         } else {
1001                 setenv("LANG", "en_GB.utf8", 1);
1002                 setenv("LC_MESSAGES", "en_GB.utf8", 1);
1003                 lang_str = strdup("en_GB.UTF-8");
1004         }
1005
1006         init_i18n(PACKAGE, LOCALEDIR, lang_str);
1007
1008         if (lang_str) {
1009                 elm_language_set(lang_str);
1010                 free(lang_str);
1011         }
1012 }
1013
1014 void input_type_deinit(void)
1015 {
1016         int i = 0;
1017         char **data_array = NULL;
1018
1019         data_array = g_input_type_data.input_type_array;
1020         if (data_array) {
1021                 for (i = 0; i < g_input_type_data.input_type_array_len; i++) {
1022                         if (*(data_array + i))
1023                                 free(*(data_array + i));
1024                 }
1025                 free(data_array);
1026         }
1027         g_input_type_data.input_type_array = NULL;
1028         g_input_type_data.input_type_array_len = 0;
1029 }
1030
1031 EXPORTED int main(int argc, char* argv[])
1032 {
1033         App_Data app_data = {0, };
1034         ui_app_lifecycle_callback_s event_callback = {0, };
1035         app_event_handler_h handlers[5] = {NULL, };
1036
1037         event_callback.create = _app_create;
1038         event_callback.terminate = _app_terminate;
1039         event_callback.pause = _app_pause;
1040         event_callback.resume = _app_resume;
1041         event_callback.app_control = _app_service;
1042
1043         ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, NULL, &app_data);
1044         ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, NULL, &app_data);
1045         ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, NULL, &app_data);
1046         ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, _app_language_changed, &app_data);
1047         ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, NULL, &app_data);
1048
1049         _init_app_data(&app_data);
1050
1051         int ret = ui_app_main(argc, argv, &event_callback, &app_data);
1052         if (ret != APP_ERROR_NONE) {
1053                 LOGD("ui_app_main() is failed. err = %d", ret);
1054         }
1055
1056         return ret;
1057 }