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