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 popup = elm_popup_add(voicedata->naviframe);
104 elm_object_style_set(popup, "circle");
105 // uxt_popup_set_rotary_event_enabled(popup, EINA_TRUE);
106 eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, popup_hide_cb, NULL);
107 evas_object_smart_callback_add(popup, "dismissed", popup_hide_finished_cb, NULL);
108 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
110 layout = elm_layout_add(popup);
111 elm_layout_theme_set(layout, "layout", "popup", "content/circle/buttons2");
112 elm_object_domain_translatable_part_text_set(layout, "elm.text", PACKAGE, "IDS_ST_SK_OK");
113 elm_object_content_set(popup, layout);
114 evas_object_show(layout);
116 btn_popup = elm_button_add(popup);
117 elm_object_style_set(btn_popup, "popup/circle/left");
118 elm_object_part_content_set(popup, "button1", btn_popup);
119 elm_access_info_set(btn_popup, ELM_ACCESS_INFO, dgettext(PACKAGE, "IDS_ST_SK_OK"));
120 evas_object_smart_callback_add(btn_popup, "clicked", voice_input_back_disagree_cb, voicedata);
121 evas_object_data_set(btn_popup, "popup", popup);
122 evas_object_show(btn_popup);
124 std::string path_ic_left = path + "/images/tw_ic_popup_btn_delete.png";
125 icon = elm_image_add(btn_popup);
126 elm_image_file_set(icon, path_ic_left.c_str(), NULL);
127 evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
128 elm_object_part_content_set(btn_popup, "elm.swallow.content", icon);
129 evas_object_show(icon);
131 btn_popup = elm_button_add(popup);
132 elm_object_style_set(btn_popup, "popup/circle/right");
133 elm_access_info_set(btn_popup, ELM_ACCESS_INFO, dgettext(PACKAGE, "IDS_ST_SK_OK"));
134 elm_object_part_content_set(popup, "button2", btn_popup);
135 evas_object_smart_callback_add(btn_popup, "clicked", voice_input_back_agree_cb, voicedata);
136 evas_object_data_set(btn_popup, "popup", popup);
137 evas_object_show(btn_popup);
139 std::string path_ic_right = path + "/images/tw_ic_popup_btn_check.png";
140 icon = elm_image_add(btn_popup);
141 elm_image_file_set(icon, path_ic_right.c_str(), NULL);
142 evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
143 elm_object_part_content_set(btn_popup, "elm.swallow.content", icon);
144 evas_object_show(icon);
146 evas_object_show(popup);
148 voicedata->mo->discard_popup_opened = EINA_TRUE;
151 MoreOption::MoreOption(Evas_Object *naviframe, void* voicedata)
153 , more_option_layout(NULL)
155 , option_opened(EINA_FALSE)
156 , voicedata(voicedata)
157 , discard_popup_opened(EINA_FALSE) {
158 /** todo. implement constructor */
159 voice_input_back_agree = false;
162 MoreOption::~MoreOption() {
163 /** todo. implement destructor */
165 if(more_option_layout)
167 PRINTFUNC(DLOG_DEBUG, "del callbacks");
168 evas_object_smart_callback_del(more_option_layout, "item,clicked", moreItemClicked);
169 evas_object_smart_callback_del(more_option_layout, "item,selected", moreItemSelected);
171 evas_object_smart_callback_del(more_option_layout, "more,option,opened", moreOptionOpened);
172 evas_object_smart_callback_del(more_option_layout, "more,option,closed", moreOptionClosed);
176 void MoreOption::Create() {
181 catch(std::exception &e) {
182 PRINTFUNC(DLOG_ERROR, "%s", e.what());
187 void MoreOption::AddLayout() {
190 PRINTFUNC(DLOG_ERROR, "Invalid naviframe.");
193 more_option_layout = eext_more_option_add(nf);
195 if(!more_option_layout){
196 PRINTFUNC(DLOG_ERROR, "It's failed to create layout");
200 evas_object_smart_callback_add(more_option_layout, "more,option,opened", moreOptionOpened, this);
201 evas_object_smart_callback_add(more_option_layout, "more,option,closed", moreOptionClosed, this);
205 evas_object_show(more_option_layout);
208 void MoreOption::SetContentLayout(Evas_Object *content) {
213 elm_object_part_content_set(more_option_layout, "elm.swallow.content", content);
215 Elm_Object_Item *nit = NULL;
216 const char *item_style = NULL;
218 item_style = "empty";
219 nit = elm_naviframe_item_push(nf, NULL, NULL, NULL, more_option_layout, item_style);
220 elm_naviframe_item_title_enabled_set(nit, EINA_FALSE, EINA_FALSE);
222 elm_naviframe_item_pop_cb_set(nit,
223 [](void *data, Elm_Object_Item *it)->Eina_Bool
225 MoreOption *opt = (MoreOption *)data;
226 VoiceData *vd = (VoiceData *) opt->voicedata;
228 if(vd->disclaimer == 1){
229 PRINTFUNC(DLOG_ERROR, "pop to top"); //inb case of (selector view -> disclaimer view-> stt view)
231 if(opt->option_opened == EINA_FALSE){
232 PRINTFUNC(DLOG_DEBUG, "pop_cb called in STT view\n");
235 if (vd->sttmanager->GetCurrent() == STT_STATE_CREATED ||
236 vd->sttmanager->GetCurrent() == STT_STATE_READY) {
237 PRINTFUNC(DLOG_DEBUG, "STT_STATE_CREATED || STT_STATE_READY\n");
239 } else if (vd->sttmanager->GetCurrent() == STT_STATE_RECORDING || vd->sttmanager->GetCurrent() == STT_STATE_PROCESSING) {
240 PRINTFUNC(DLOG_DEBUG, "STT_STATE_RECORDING or STT_STATE_PROCESSING\n");
242 vd->sttmanager->Cancel();
243 }catch(is::stt::SttException &e){
244 PRINTFUNC(DLOG_ERROR, "reason : %s", e.what());
250 if (voice_input_back_agree == false && !is_textblock_empty(vd)){
251 show_discard_popup(vd);
255 elm_naviframe_item_pop_to(elm_naviframe_bottom_item_get(vd->naviframe));
259 _back_to_genlist_for_selector();
266 if (opt->option_opened == EINA_FALSE){
267 PRINTFUNC(DLOG_DEBUG, "pop_cb called in STT view\n");
270 if (vd->sttmanager->GetCurrent() == STT_STATE_CREATED ||
271 vd->sttmanager->GetCurrent() == STT_STATE_READY) {
272 PRINTFUNC(DLOG_DEBUG, "STT_STATE_CREATED || STT_STATE_READY\n");
274 } else if (vd->sttmanager->GetCurrent() == STT_STATE_RECORDING || vd->sttmanager->GetCurrent() == STT_STATE_PROCESSING) {
275 PRINTFUNC(DLOG_DEBUG, "STT_STATE_RECORDING or STT_STATE_PROCESSING\n");
277 vd->sttmanager->Cancel();
278 }catch(is::stt::SttException &e){
279 PRINTFUNC(DLOG_ERROR, "reason : %s", e.what());
284 if (voice_input_back_agree == false && !is_textblock_empty(vd)){
285 show_discard_popup(vd);
289 _back_to_genlist_for_selector();
297 void MoreOption::Update()
299 char lang[6] = {0, };
300 strncpy(lang, ((VoiceData *)voicedata)->kbd_lang , 5);
302 const char* display_lang = get_lang_label(lang);
303 eext_more_option_item_part_text_set(item, "selector,sub_text", display_lang);
308 Evas_Object* MoreOption::AddLanguageIcon(Evas_Object *parent) {
309 Evas_Object *icon = elm_image_add(parent);
311 PRINTFUNC(DLOG_ERROR, "It's failed to add image.");
314 string res_path = get_resource_path();
316 res_path = res_path + "wearable/";
318 res_path = res_path + "tv/";
320 res_path = res_path + "mobile/";
322 std::string image_path = res_path + "images/prompt_ic_languages.png";
324 elm_image_file_set(icon, image_path.c_str(), NULL);
325 evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
326 evas_object_size_hint_align_set(icon, EVAS_HINT_FILL, EVAS_HINT_FILL);
327 evas_object_show(icon);
332 void MoreOption::AddMorePage() {
335 item = eext_more_option_item_append(more_option_layout);
338 eext_more_option_item_part_text_set(item, "selector,main_text", _("WDS_IME_HEADER_INPUT_LANGUAGES_ABB"));
340 img = AddLanguageIcon(more_option_layout);
342 eext_more_option_item_part_content_set(item, "item,icon", img);
344 evas_object_smart_callback_add(more_option_layout, "item,clicked", moreItemClicked, NULL);
345 evas_object_smart_callback_add(more_option_layout, "item,selected", moreItemSelected , NULL);
348 void MoreOption::moreOptionOpened(void *data, Evas_Object * obj, void *event_info)
350 PRINTFUNC(DLOG_DEBUG, "more option is opened!!! \n");
355 * if more option is completed, stt have to be stopped.
358 MoreOption *opt = (MoreOption *)data;
359 VoiceData *vd = (VoiceData *) opt->voicedata;
361 if(vd && vd->setup_timer){
362 ecore_timer_del(vd->setup_timer);
363 vd->setup_timer = NULL;
367 if (vd && vd->sttmanager && (vd->sttmanager->GetCurrent() == STT_STATE_RECORDING ||
368 vd->sttmanager->GetCurrent() == STT_STATE_PROCESSING)) {
369 vd->sttmanager->Cancel();
372 catch(is::stt::SttException &e) {
373 PRINTFUNC(DLOG_ERROR, "%s", e.what());
377 if(vd && vd->layout_main){
378 elm_object_signal_emit((Evas_Object *)vd->layout_main, "idle,state,text,hidden", "elm");
381 opt->option_opened = EINA_TRUE;
384 void MoreOption::moreOptionClosed(void *data, Evas_Object * obj, void *event_info)
386 PRINTFUNC(DLOG_DEBUG, "more option is closed!!! \n");
390 MoreOption *opt = (MoreOption *)data;
391 VoiceData *vd = (VoiceData *) opt->voicedata;
393 if (opt->option_opened == EINA_TRUE && is_textblock_empty(vd)) {
394 restart_listening(2.0);
398 activate_circle_scroller_for_stt_textbox(vd, EINA_TRUE);
400 opt->option_opened = EINA_FALSE;
403 void MoreOption::moreItemClicked(void *data, Evas_Object * obj, void *event_info)
405 PRINTFUNC(DLOG_DEBUG, "item,clicked");
406 if(g_setting_window == NULL)
407 create_setting_window(obj);
410 void MoreOption::moreItemSelected(void *data, Evas_Object * obj, void *event_info)
412 PRINTFUNC(DLOG_DEBUG, "item,selected");
415 Eext_Object_Item *selected_item = (Eext_Object_Item *)event_info;
417 //for custom accessibility
418 if (elm_config_access_get())
420 Evas_Object *panel = elm_object_part_content_get(obj, "elm.swallow.right");
423 Evas_Object *rotary_selector = elm_object_content_get(panel);
424 if (!rotary_selector) return;
426 Evas_Object *content = (Evas_Object *)edje_object_part_object_get(elm_layout_edje_get(rotary_selector), "content");
427 if (!content) return;
429 Evas_Object *content_access = elm_access_object_get(content);
430 if (!content_access) return;
432 if (eext_more_option_item_part_text_get(selected_item, "selector,main_text"))
435 text = text + std::string(gettext("WDS_IME_HEADER_INPUT_LANGUAGES_ABB")) + " ";
437 if(eext_more_option_item_part_text_get(selected_item, "selector,sub_text"))
438 text = text + std::string(eext_more_option_item_part_text_get(selected_item, "selector,sub_text"));
440 elm_access_info_set(content_access, ELM_ACCESS_INFO, text.c_str());
445 void MoreOption::hideCue()
447 Evas_Object *panel_right = NULL;
448 if (!more_option_layout) {
449 PRINTFUNC(DLOG_ERROR, "more_option_layout == NULL");
453 panel_right = elm_object_part_content_get(more_option_layout, "elm.swallow.right");
455 PRINTFUNC(DLOG_ERROR, "panel_right == NULL");
459 elm_object_signal_emit(panel_right, "cue,hide", "elm");
462 void MoreOption::showCue()
464 Evas_Object *panel_right = NULL;
466 if (!more_option_layout) {
467 PRINTFUNC(DLOG_ERROR, "more_option_layout == NULL");
471 panel_right = elm_object_part_content_get(more_option_layout, "elm.swallow.right");
473 PRINTFUNC(DLOG_ERROR, "panel_right == NULL");
477 elm_object_signal_emit(panel_right, "cue,show", "elm");