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