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