2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
25 #include <app_common.h>
27 #include "MoreOption.h"
28 #include "w-input-selector.h"
29 #include "w-input-stt-ise.h"
30 #include "w-input-stt-voice.h"
34 extern Evas_Object *g_setting_window;
35 static bool voice_input_back_agree = false;
38 popup_hide_cb(void *data, Evas_Object *obj, void *event_info)
41 elm_popup_dismiss(obj);
45 popup_hide_finished_cb(void *data, Evas_Object *obj, void *event_info)
51 static void voice_input_back_disagree_cb(void *data, Evas_Object *obj, void *event_info)
56 VoiceData *voicedata = (VoiceData *)data;
57 Evas_Object *popup = (Evas_Object *)evas_object_data_get(obj, "popup");
59 voicedata->mo->discard_popup_opened = EINA_FALSE;
62 elm_popup_dismiss(popup);
65 static void voice_input_back_agree_cb(void *data, Evas_Object *obj, void *event_info)
70 VoiceData *voicedata = (VoiceData *)data;
71 Evas_Object *popup = (Evas_Object *)evas_object_data_get(obj, "popup");
73 voicedata->mo->discard_popup_opened = EINA_FALSE;
76 elm_popup_dismiss(popup);
78 if(voicedata->naviframe){
79 voice_input_back_agree = true;
81 if(voicedata->disclaimer == 1){
82 voicedata->disclaimer = 0;
83 elm_naviframe_item_pop_to(elm_naviframe_bottom_item_get(voicedata->naviframe));
85 elm_naviframe_item_pop(voicedata->naviframe);
90 static void show_discard_popup(void *data)
94 VoiceData *voicedata = (VoiceData *)data;
96 Evas_Object *popup = NULL;
97 Evas_Object *layout = NULL;
98 Evas_Object *btn_popup = NULL;
99 Evas_Object *icon = NULL;
101 std::string path = get_resource_path();
103 path = path + "wearable/";
107 path = path + "mobile/";
109 popup = elm_popup_add(voicedata->naviframe);
110 elm_object_style_set(popup, "circle");
111 eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, popup_hide_cb, NULL);
112 evas_object_smart_callback_add(popup, "dismissed", popup_hide_finished_cb, NULL);
113 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
115 layout = elm_layout_add(popup);
116 elm_layout_theme_set(layout, "layout", "popup", "content/circle/buttons2");
117 elm_object_domain_translatable_part_text_set(layout, "elm.text", PACKAGE, "WDS_WNOTI_POP_ALL_CHANGES_WILL_BE_DISCARDED");
118 elm_object_content_set(popup, layout);
119 evas_object_show(layout);
121 btn_popup = elm_button_add(popup);
122 elm_object_style_set(btn_popup, "popup/circle/left");
123 elm_object_part_content_set(popup, "button1", btn_popup);
124 elm_access_info_set(btn_popup, ELM_ACCESS_INFO, dgettext(PACKAGE, "IDS_ST_SK_OK"));
125 evas_object_smart_callback_add(btn_popup, "clicked", voice_input_back_disagree_cb, voicedata);
126 evas_object_data_set(btn_popup, "popup", popup);
127 evas_object_show(btn_popup);
129 std::string path_ic_left = path + "/images/tw_ic_popup_btn_delete.png";
130 icon = elm_image_add(btn_popup);
131 elm_image_file_set(icon, path_ic_left.c_str(), NULL);
132 evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
133 elm_object_part_content_set(btn_popup, "elm.swallow.content", icon);
134 evas_object_show(icon);
136 btn_popup = elm_button_add(popup);
137 elm_object_style_set(btn_popup, "popup/circle/right");
138 elm_access_info_set(btn_popup, ELM_ACCESS_INFO, dgettext(PACKAGE, "IDS_ST_SK_OK"));
139 elm_object_part_content_set(popup, "button2", btn_popup);
140 evas_object_smart_callback_add(btn_popup, "clicked", voice_input_back_agree_cb, voicedata);
141 evas_object_data_set(btn_popup, "popup", popup);
142 evas_object_show(btn_popup);
144 std::string path_ic_right = path + "/images/tw_ic_popup_btn_check.png";
145 icon = elm_image_add(btn_popup);
146 elm_image_file_set(icon, path_ic_right.c_str(), NULL);
147 evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
148 elm_object_part_content_set(btn_popup, "elm.swallow.content", icon);
149 evas_object_show(icon);
151 evas_object_show(popup);
153 voicedata->mo->discard_popup_opened = EINA_TRUE;
156 MoreOption::MoreOption(Evas_Object *naviframe, void* voicedata)
158 , more_option_layout(NULL)
160 , option_opened(EINA_FALSE)
161 , voicedata(voicedata)
162 , discard_popup_opened(EINA_FALSE) {
163 /** todo. implement constructor */
164 voice_input_back_agree = false;
167 MoreOption::~MoreOption() {
168 /** todo. implement destructor */
170 if(more_option_layout)
172 PRINTFUNC(DLOG_DEBUG, "del callbacks");
173 evas_object_smart_callback_del(more_option_layout, "item,clicked", moreItemClicked);
174 evas_object_smart_callback_del(more_option_layout, "item,selected", moreItemSelected);
176 evas_object_smart_callback_del(more_option_layout, "more,option,opened", moreOptionOpened);
177 evas_object_smart_callback_del(more_option_layout, "more,option,closed", moreOptionClosed);
181 void MoreOption::Create() {
186 catch(std::exception &e) {
187 PRINTFUNC(DLOG_ERROR, "%s", e.what());
192 void MoreOption::AddLayout() {
195 PRINTFUNC(DLOG_ERROR, "Invalid naviframe.");
198 more_option_layout = eext_more_option_add(nf);
200 if(!more_option_layout){
201 PRINTFUNC(DLOG_ERROR, "It's failed to create layout");
205 evas_object_smart_callback_add(more_option_layout, "more,option,opened", moreOptionOpened, this);
206 evas_object_smart_callback_add(more_option_layout, "more,option,closed", moreOptionClosed, this);
210 evas_object_show(more_option_layout);
213 void MoreOption::SetContentLayout(Evas_Object *content) {
218 elm_object_part_content_set(more_option_layout, "elm.swallow.content", content);
220 Elm_Object_Item *nit = NULL;
221 const char *item_style = NULL;
223 item_style = "empty";
224 nit = elm_naviframe_item_push(nf, NULL, NULL, NULL, more_option_layout, item_style);
225 elm_naviframe_item_title_enabled_set(nit, EINA_FALSE, EINA_FALSE);
227 elm_naviframe_item_pop_cb_set(nit,
228 [](void *data, Elm_Object_Item *it)->Eina_Bool
230 MoreOption *opt = (MoreOption *)data;
231 VoiceData *vd = (VoiceData *) opt->voicedata;
233 if(vd->disclaimer == 1){
234 PRINTFUNC(DLOG_ERROR, "pop to top"); //inb case of (selector view -> disclaimer view-> stt view)
236 if(opt->option_opened == EINA_FALSE){
237 PRINTFUNC(DLOG_DEBUG, "pop_cb called in STT view\n");
240 if (vd->sttmanager->GetCurrent() == STT_STATE_CREATED ||
241 vd->sttmanager->GetCurrent() == STT_STATE_READY) {
242 PRINTFUNC(DLOG_DEBUG, "STT_STATE_CREATED || STT_STATE_READY\n");
244 } else if (vd->sttmanager->GetCurrent() == STT_STATE_RECORDING || vd->sttmanager->GetCurrent() == STT_STATE_PROCESSING) {
245 PRINTFUNC(DLOG_DEBUG, "STT_STATE_RECORDING or STT_STATE_PROCESSING\n");
247 vd->sttmanager->Cancel();
248 }catch(is::stt::SttException &e){
249 PRINTFUNC(DLOG_ERROR, "reason : %s", e.what());
255 if (voice_input_back_agree == false && !is_textblock_empty(vd)){
256 show_discard_popup(vd);
260 elm_naviframe_item_pop_to(elm_naviframe_bottom_item_get(vd->naviframe));
264 _back_to_genlist_for_selector();
271 if (opt->option_opened == EINA_FALSE){
272 PRINTFUNC(DLOG_DEBUG, "pop_cb called in STT view\n");
275 if (vd->sttmanager->GetCurrent() == STT_STATE_CREATED ||
276 vd->sttmanager->GetCurrent() == STT_STATE_READY) {
277 PRINTFUNC(DLOG_DEBUG, "STT_STATE_CREATED || STT_STATE_READY\n");
279 } else if (vd->sttmanager->GetCurrent() == STT_STATE_RECORDING || vd->sttmanager->GetCurrent() == STT_STATE_PROCESSING) {
280 PRINTFUNC(DLOG_DEBUG, "STT_STATE_RECORDING or STT_STATE_PROCESSING\n");
282 vd->sttmanager->Cancel();
283 }catch(is::stt::SttException &e){
284 PRINTFUNC(DLOG_ERROR, "reason : %s", e.what());
289 if (voice_input_back_agree == false && !is_textblock_empty(vd)){
290 show_discard_popup(vd);
294 _back_to_genlist_for_selector();
302 void MoreOption::Update()
304 char lang[6] = {0, };
305 strncpy(lang, ((VoiceData *)voicedata)->kbd_lang , 5);
307 const char* display_lang = get_lang_label(lang);
308 eext_more_option_item_part_text_set(item, "selector,sub_text", display_lang);
313 Evas_Object* MoreOption::AddLanguageIcon(Evas_Object *parent) {
314 Evas_Object *icon = elm_image_add(parent);
316 PRINTFUNC(DLOG_ERROR, "It's failed to add image.");
319 string res_path = get_resource_path();
321 res_path = res_path + "wearable/";
323 res_path = res_path + "tv/";
325 res_path = res_path + "mobile/";
327 std::string image_path = res_path + "images/prompt_ic_languages.png";
329 elm_image_file_set(icon, image_path.c_str(), NULL);
330 evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
331 evas_object_size_hint_align_set(icon, EVAS_HINT_FILL, EVAS_HINT_FILL);
332 evas_object_show(icon);
337 void MoreOption::AddMorePage() {
340 item = eext_more_option_item_append(more_option_layout);
343 eext_more_option_item_part_text_set(item, "selector,main_text", _("WDS_IME_HEADER_INPUT_LANGUAGES_ABB"));
345 img = AddLanguageIcon(more_option_layout);
347 eext_more_option_item_part_content_set(item, "item,icon", img);
349 evas_object_smart_callback_add(more_option_layout, "item,clicked", moreItemClicked, NULL);
350 evas_object_smart_callback_add(more_option_layout, "item,selected", moreItemSelected , NULL);
353 void MoreOption::moreOptionOpened(void *data, Evas_Object * obj, void *event_info)
355 PRINTFUNC(DLOG_DEBUG, "more option is opened!!! \n");
360 * if more option is completed, stt have to be stopped.
363 MoreOption *opt = (MoreOption *)data;
364 VoiceData *vd = (VoiceData *) opt->voicedata;
366 if(vd && vd->setup_timer){
367 ecore_timer_del(vd->setup_timer);
368 vd->setup_timer = NULL;
372 if (vd && vd->sttmanager && (vd->sttmanager->GetCurrent() == STT_STATE_RECORDING ||
373 vd->sttmanager->GetCurrent() == STT_STATE_PROCESSING)) {
374 vd->sttmanager->Cancel();
377 catch(is::stt::SttException &e) {
378 PRINTFUNC(DLOG_ERROR, "%s", e.what());
382 if(vd && vd->layout_main){
383 elm_object_signal_emit((Evas_Object *)vd->layout_main, "idle,state,text,hidden", "elm");
386 opt->option_opened = EINA_TRUE;
389 void MoreOption::moreOptionClosed(void *data, Evas_Object * obj, void *event_info)
391 PRINTFUNC(DLOG_DEBUG, "more option is closed!!! \n");
395 MoreOption *opt = (MoreOption *)data;
396 VoiceData *vd = (VoiceData *) opt->voicedata;
398 if (opt->option_opened == EINA_TRUE && is_textblock_empty(vd)) {
399 restart_listening(2.0);
403 activate_circle_scroller_for_stt_textbox(vd, EINA_TRUE);
405 opt->option_opened = EINA_FALSE;
408 void MoreOption::moreItemClicked(void *data, Evas_Object * obj, void *event_info)
410 PRINTFUNC(DLOG_DEBUG, "item,clicked");
411 if(g_setting_window == NULL)
412 create_setting_window(obj);
415 void MoreOption::moreItemSelected(void *data, Evas_Object * obj, void *event_info)
417 PRINTFUNC(DLOG_DEBUG, "item,selected");
420 Eext_Object_Item *selected_item = (Eext_Object_Item *)event_info;
422 //for custom accessibility
423 if (elm_config_access_get())
425 Evas_Object *panel = elm_object_part_content_get(obj, "elm.swallow.right");
428 Evas_Object *rotary_selector = elm_object_content_get(panel);
429 if (!rotary_selector) return;
431 Evas_Object *content = (Evas_Object *)edje_object_part_object_get(elm_layout_edje_get(rotary_selector), "content");
432 if (!content) return;
434 Evas_Object *content_access = elm_access_object_get(content);
435 if (!content_access) return;
437 if (eext_more_option_item_part_text_get(selected_item, "selector,main_text"))
440 text = text + std::string(gettext("WDS_IME_HEADER_INPUT_LANGUAGES_ABB")) + " ";
442 if(eext_more_option_item_part_text_get(selected_item, "selector,sub_text"))
443 text = text + std::string(eext_more_option_item_part_text_get(selected_item, "selector,sub_text"));
445 elm_access_info_set(content_access, ELM_ACCESS_INFO, text.c_str());
450 void MoreOption::hideCue()
452 Evas_Object *panel_right = NULL;
453 if (!more_option_layout) {
454 PRINTFUNC(DLOG_ERROR, "more_option_layout == NULL");
458 panel_right = elm_object_part_content_get(more_option_layout, "elm.swallow.right");
460 PRINTFUNC(DLOG_ERROR, "panel_right == NULL");
464 elm_object_signal_emit(panel_right, "cue,hide", "elm");
467 void MoreOption::showCue()
469 Evas_Object *panel_right = NULL;
471 if (!more_option_layout) {
472 PRINTFUNC(DLOG_ERROR, "more_option_layout == NULL");
476 panel_right = elm_object_part_content_get(more_option_layout, "elm.swallow.right");
478 PRINTFUNC(DLOG_ERROR, "panel_right == NULL");
482 elm_object_signal_emit(panel_right, "cue,show", "elm");