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