remove the smartreply and template feature
[platform/core/uifw/inputdelegator.git] / src / w-input-keyboard.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 <Elementary.h>
21
22 #include <stdlib.h>
23
24 #include "w-input-keyboard.h"
25 #include "w-input-selector.h"
26
27 extern InputKeyboardData g_input_keyboard_data;
28 extern App_Data* app_data;
29
30 Evas_Object *entry;
31
32 static void input_keyboard_app_control_send_reply_cb(app_control_h request, app_control_h reply,
33                                                 app_control_result_e result, void *user_data);
34
35 static void input_keyboard_app_control_send_reply_cb(app_control_h request, app_control_h reply,
36                                                 app_control_result_e result, void *user_data)
37 {
38         char *feedback = NULL;
39         if (result == APP_CONTROL_RESULT_SUCCEEDED) {
40                 if (reply) {
41                         int ret;
42                         ret = app_control_get_extra_data(reply,
43                                         "template_feedback", &feedback);
44                 }
45                 reply_to_sender_by_callback(feedback, "keyboard");
46                 free(feedback);
47                 elm_exit();
48         }
49 }
50
51
52 bool input_keyboard_init(app_control_h app_control)
53 {
54         int ret = -1;
55         char *default_text = NULL;
56         char *guide_text = NULL;
57
58         input_keyboard_deinit();
59
60         ret = app_control_get_extra_data(app_control, APP_CONTROL_DATA_INPUT_DEFAULT_TEXT, &default_text);
61         if (ret == APP_CONTROL_ERROR_NONE) {
62                 g_input_keyboard_data.default_text = default_text;
63         }
64         ret = app_control_get_extra_data(app_control, APP_CONTROL_DATA_INPUT_GUIDE_TEXT, &guide_text);
65         if (ret == APP_CONTROL_ERROR_NONE) {
66                 g_input_keyboard_data.guide_text = guide_text;
67         }
68
69         return true;
70 }
71
72 void input_keyboard_deinit(void)
73 {
74         if (g_input_keyboard_data.guide_text)
75                 free(g_input_keyboard_data.guide_text);
76
77         if (g_input_keyboard_data.default_text)
78                 free(g_input_keyboard_data.default_text);
79
80         g_input_keyboard_data.default_text = NULL;
81         g_input_keyboard_data.guide_text = NULL;
82
83         return;
84 }
85
86 void btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
87 {
88         app_control_h app_control;
89         int ret = app_control_create(&app_control);
90         if (ret != APP_CONTROL_ERROR_NONE) {
91                 PRINTFUNC(DLOG_ERROR, "Can not create app_control : %d", ret);
92                 return;
93         }
94
95         const char *getText = elm_entry_entry_get(entry);
96         LOGD("button key clicked!! : getText = %s", getText);
97
98         char *app_id = NULL;
99         app_control_get_caller(app_data->source_app_control, &app_id);
100         if (app_id != NULL)
101                 app_control_set_app_id(app_control, app_id);
102         app_control_set_operation(app_control, APP_CONTROL_OPERATION_DEFAULT);
103         set_source_caller_app_id(app_control);
104         free(app_id);
105         reply_to_sender_by_callback(getText, "keyboard");
106         elm_exit();
107 }
108
109 static Eina_Bool custom_back_cb(void *data, Elm_Object_Item *it)
110 {
111         _back_to_genlist_for_selector();
112         return EINA_TRUE;
113 }
114
115 void create_fullscreen_editor(void *data)
116 {
117         App_Data *ad = (App_Data *)data;
118
119         Evas_Object *box = elm_box_add(ad->naviframe);
120         evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
121         evas_object_show(box);
122         elm_win_resize_object_add(ad->naviframe, box);
123
124         entry = elm_entry_add(box);
125         elm_entry_single_line_set(entry, EINA_TRUE);
126         elm_entry_scrollable_set(entry, EINA_TRUE);
127         elm_scroller_policy_set(entry, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
128         elm_object_part_text_set(entry, "elm.guide", g_input_keyboard_data.guide_text);
129         elm_entry_entry_set(entry, g_input_keyboard_data.default_text);
130         elm_entry_cursor_end_set(entry);
131         evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
132         evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
133         evas_object_show(entry);
134         elm_box_pack_end(box, entry);
135
136         Evas_Object *btn = elm_button_add(box);
137         elm_object_text_set(btn, "SEND");
138         evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, 0.5);
139         evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
140         evas_object_smart_callback_add(btn, "clicked", btn_clicked_cb, NULL);
141         evas_object_show(btn);
142         elm_box_pack_end(box, btn);
143         evas_object_resize(ad->naviframe, 360, 360);
144         evas_object_show(ad->naviframe);
145
146         Elm_Object_Item *nf_item = elm_naviframe_item_push(ad->naviframe, NULL, NULL, NULL, box, "empty");
147         elm_naviframe_item_pop_cb_set(nf_item, custom_back_cb, NULL);
148 }
149
150 bool input_keyboard_launch(Evas_Object *window, void *data) {
151         if (window == NULL) {
152                 PRINTFUNC(DLOG_ERROR, "Can not get window");
153                 return false;
154         }
155         create_fullscreen_editor(data);
156         return true;
157 }
158