eab0275feb61e824508e5fda1f6e25e0f7924645
[platform/core/uifw/inputdelegator.git] / src / MoreOption.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 <assert.h>
20 #include <iostream>
21 #include <stdexcept>
22
23 #include <app.h>
24 #include <app_common.h>
25
26 #include "MoreOption.h"
27 #include "w-input-selector.h"
28 #include "w-input-stt-ise.h"
29 #include "w-input-stt-voice.h"
30
31 extern Evas_Object *g_setting_window;
32
33 MoreOption::MoreOption(Evas_Object *naviframe, void* voicedata)
34         : nf(naviframe)
35         , more_option_layout (NULL)
36         , item (NULL)
37         , option_opened (EINA_FALSE)
38         , voicedata(voicedata) {
39
40         /** todo. implement constructor */
41 }
42
43 MoreOption::~MoreOption() {
44
45         /** todo. implement destructor */
46
47 //      if(more_option_layout)
48 //              evas_object_del(more_option_layout);
49
50 }
51
52 void MoreOption::Create() {
53
54         try {
55                 AddLayout();
56                 AddMorePage();
57         }
58         catch(std::exception &e) {
59                 PRINTFUNC(DLOG_ERROR, "%s", e.what());
60                 assert(0);
61         }
62 }
63
64 void MoreOption::AddLayout() {
65
66         /** validation */
67         if(!nf)
68                 PRINTFUNC(DLOG_ERROR, "Invalid naviframe.");
69
70         /** add layout */
71         more_option_layout = eext_more_option_add(nf);
72
73         if(!more_option_layout)
74                 PRINTFUNC(DLOG_ERROR, "It's failed to create layout");
75
76         evas_object_smart_callback_add(more_option_layout, "more,option,opened",
77                 [](void *data, Evas_Object *obj, void *event_info){
78
79                         PRINTFUNC(DLOG_DEBUG, "more option is opened!!! \n");
80
81                         if(!data) return;
82
83                         /**
84                         * if more option is completed, stt have to be stopped.
85                         *
86                         */
87                         MoreOption *opt = (MoreOption *)data;
88                         VoiceData *vd = (VoiceData *) opt->voicedata;
89                         try {
90                                    if (vd->sttmanager->GetCurrent() == STT_STATE_RECORDING ||
91                                                    vd->sttmanager->GetCurrent() == STT_STATE_PROCESSING) {
92                                                    vd->sttmanager->Cancel();
93                                   }
94                         }
95                         catch(is::stt::SttException &e) {
96                                 PRINTFUNC(DLOG_ERROR, "%s", e.what());
97                         }
98
99                         opt->option_opened = EINA_TRUE;
100
101         }, this);
102
103         evas_object_smart_callback_add(more_option_layout, "more,option,closed",
104                 [](void *data, Evas_Object *obj, void *event_info){
105
106                 PRINTFUNC(DLOG_DEBUG, "more option is closed!!! \n");
107
108                 MoreOption *opt = (MoreOption *)data;
109                 VoiceData *vd = (VoiceData *) opt->voicedata;
110
111                 activate_circle_scroller_for_stt_textbox(vd, EINA_TRUE);
112
113                 opt->option_opened = EINA_FALSE;
114
115
116         }, this);
117
118         evas_object_show(more_option_layout);
119
120
121 }
122
123 void MoreOption::SetContentLayout(Evas_Object *content) {
124
125         /**
126          * Set content layout
127          *
128          */
129         elm_object_part_content_set(more_option_layout, "elm.swallow.content", content);
130
131         Elm_Object_Item *nit = NULL;
132         nit = elm_naviframe_item_push(nf, NULL, NULL, NULL, more_option_layout, "empty");
133         elm_naviframe_item_title_enabled_set(nit, EINA_FALSE, EINA_FALSE);
134
135         elm_naviframe_item_pop_cb_set(nit,
136                 [](void *data, Elm_Object_Item *it)->Eina_Bool
137                 {
138                         MoreOption *opt = (MoreOption *)data;
139                         VoiceData *vd = (VoiceData *) opt->voicedata;
140
141                         if(vd->disclaimer  == 1){
142                                 PRINTFUNC(DLOG_ERROR, "pop to top"); //inb case of (selector view -> disclaimer view-> stt view)
143
144                                 if(opt->option_opened == EINA_FALSE){
145                                         PRINTFUNC(DLOG_DEBUG, "pop_cb called in STT view\n");
146
147                                         if(vd->sttmanager){
148                                                 if (vd->sttmanager->GetCurrent() == STT_STATE_CREATED ||
149                                                                    vd->sttmanager->GetCurrent() == STT_STATE_READY) {
150                                                         PRINTFUNC(DLOG_DEBUG, "STT_STATE_CREATED || STT_STATE_READY\n");
151
152                                                 } else if(vd->sttmanager->GetCurrent() == STT_STATE_RECORDING) {
153                                                         PRINTFUNC(DLOG_DEBUG, "STT_STATE_RECORDING\n");
154                                                         vd->effector->Stop();
155                                                         try{
156                                                                 vd->sttmanager->Stop();
157                                                         }catch(is::stt::SttException &e){
158                                                                 PRINTFUNC(DLOG_ERROR, "reason : %s", e.what());
159                                                         }
160
161                                                 } else if(vd->sttmanager->GetCurrent() == STT_STATE_PROCESSING) {
162                                                         PRINTFUNC(DLOG_DEBUG, "STT_STATE_RECORDING\n");
163                                                         try{
164                                                                 vd->sttmanager->Cancel();
165                                                         }catch(is::stt::SttException &e){
166                                                                 PRINTFUNC(DLOG_ERROR, "reason : %s", e.what());
167                                                         }
168                                                 }
169                                         }
170                                 }
171
172
173                                 elm_naviframe_item_pop_to(elm_naviframe_bottom_item_get(vd->naviframe));
174                                 vd->disclaimer  = 0;
175
176                                 powerUnlock();
177                                 _back_to_genlist_for_selector();
178
179                                 return EINA_TRUE;
180                         }
181
182                         if(opt->option_opened == EINA_FALSE){
183                                 PRINTFUNC(DLOG_DEBUG, "pop_cb called in STT view\n");
184
185                                 if(vd->sttmanager){
186                                         if (vd->sttmanager->GetCurrent() == STT_STATE_CREATED ||
187                                                            vd->sttmanager->GetCurrent() == STT_STATE_READY) {
188                                                 PRINTFUNC(DLOG_DEBUG, "STT_STATE_CREATED || STT_STATE_READY\n");
189
190                                         } else if(vd->sttmanager->GetCurrent() == STT_STATE_RECORDING) {
191                                                 PRINTFUNC(DLOG_DEBUG, "STT_STATE_RECORDING\n");
192                                                 vd->effector->Stop();
193                                                 try{
194                                                         vd->sttmanager->Stop();
195                                                 }catch(is::stt::SttException &e){
196                                                         PRINTFUNC(DLOG_ERROR, "reason : %s", e.what());
197                                                 }
198
199                                         } else if(vd->sttmanager->GetCurrent() == STT_STATE_PROCESSING) {
200                                                 PRINTFUNC(DLOG_DEBUG, "STT_STATE_RECORDING\n");
201                                                 try{
202                                                         vd->sttmanager->Cancel();
203                                                 }catch(is::stt::SttException &e){
204                                                         PRINTFUNC(DLOG_ERROR, "reason : %s", e.what());
205                                                 }
206                                         }
207
208                                         _back_to_genlist_for_selector();
209
210                                         destroy_voice();
211
212                                         return EINA_TRUE;
213                                 } else {
214                                         PRINTFUNC(DLOG_DEBUG, "naviframe transition, not finished\n");
215                                         return EINA_FALSE;
216                                 }
217                         }
218                         return EINA_FALSE;
219                 }, this);
220 }
221
222 void MoreOption::Update()
223 {
224
225            char lang[6] = {0,};
226            strncpy(lang, ((VoiceData *)voicedata)->kbd_lang , 5);
227
228        char* display_lang = get_lang_label(lang);
229            eext_more_option_item_part_text_set(item, "selector,sub_text", display_lang);
230
231 }
232
233
234 Evas_Object* MoreOption::AddLanguageIcon(Evas_Object *parent) {
235
236         Evas_Object *icon = elm_image_add(parent);
237         if (!icon) {
238                 PRINTFUNC(DLOG_ERROR, "It's failed to add image.");
239         }
240
241         std::string res_path;
242         char *tmp_path = app_get_resource_path();
243         if (tmp_path) {
244                 res_path = tmp_path;
245                 free(tmp_path);
246         }
247
248         std::string image_path = res_path + "images/prompt_ic_languages.png";
249
250         elm_image_file_set(icon, image_path.c_str(), NULL);
251         evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
252         evas_object_size_hint_align_set(icon, EVAS_HINT_FILL, EVAS_HINT_FILL);
253         evas_object_show(icon);
254
255         return icon;
256 }
257
258
259 void MoreOption::AddMorePage() {
260
261         Evas_Object *img;
262
263         item  = eext_more_option_item_append(more_option_layout);
264
265         /* Slider content */
266         eext_more_option_item_part_text_set(item, "selector,main_text", _("WDS_IME_HEADER_INPUT_LANGUAGES_ABB"));
267
268         img = AddLanguageIcon(more_option_layout);
269
270         eext_more_option_item_part_content_set(item, "item,icon", img);
271
272         evas_object_smart_callback_add(more_option_layout, "item,clicked",
273         [](void *data, Evas_Object *obj, void *event_info)
274         {
275
276                 PRINTFUNC(DLOG_DEBUG, "item,clicked");
277                 if(g_setting_window == NULL)
278                         create_setting_window(obj);
279         },NULL);
280
281         evas_object_smart_callback_add(more_option_layout, "item,selected",
282         [](void *data, Evas_Object *obj, void *event_info)
283         {
284
285                 PRINTFUNC(DLOG_DEBUG, "item,selected");
286
287                 Eext_Object_Item *selected_item = (Eext_Object_Item *)event_info;
288
289                 //for custom accessibility
290                 if (elm_config_access_get())
291                 {
292                         Evas_Object *panel = elm_object_part_content_get(obj, "elm.swallow.right");
293                         if (!panel) return;
294
295                         Evas_Object *rotary_selector = elm_object_content_get(panel);
296                         if (!rotary_selector) return;
297
298                         Evas_Object *content = (Evas_Object *)edje_object_part_object_get(elm_layout_edje_get(rotary_selector), "content");
299                         if (!content) return;
300
301                         Evas_Object *content_access = elm_access_object_get(content);
302                         if (!content_access) return;
303
304                         if (eext_more_option_item_part_text_get(selected_item, "selector,main_text"))
305                         {
306                                 std::string text;
307                                 if(eext_more_option_item_part_text_get(selected_item, "selector,main_text"))
308                                         text = text + std::string(eext_more_option_item_part_text_get(selected_item, "selector,main_text")) + " ";
309
310                                 if(eext_more_option_item_part_text_get(selected_item, "selector,main_text"))
311                                         text = text + std::string(eext_more_option_item_part_text_get(selected_item, "selector,sub_text"));
312
313                                 elm_access_info_set(content_access, ELM_ACCESS_INFO, text.c_str());
314                         }
315                 }
316         },NULL);
317
318
319 }
320