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