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.
24 #include <app_common.h>
26 #include "MoreOption.h"
27 #include "w-input-selector.h"
28 #include "w-input-stt-ise.h"
29 #include "w-input-stt-voice.h"
31 extern Evas_Object *g_setting_window;
33 MoreOption::MoreOption(Evas_Object *naviframe, void* voicedata)
35 , more_option_layout (NULL)
37 , option_opened (EINA_FALSE)
38 , voicedata(voicedata) {
40 /** todo. implement constructor */
43 MoreOption::~MoreOption() {
45 /** todo. implement destructor */
47 // if(more_option_layout)
48 // evas_object_del(more_option_layout);
52 void MoreOption::Create() {
58 catch(std::exception &e) {
59 PRINTFUNC(DLOG_ERROR, "%s", e.what());
64 void MoreOption::AddLayout() {
68 PRINTFUNC(DLOG_ERROR, "Invalid naviframe.");
71 more_option_layout = eext_more_option_add(nf);
73 if(!more_option_layout)
74 PRINTFUNC(DLOG_ERROR, "It's failed to create layout");
76 evas_object_smart_callback_add(more_option_layout, "more,option,opened",
77 [](void *data, Evas_Object *obj, void *event_info){
79 PRINTFUNC(DLOG_DEBUG, "more option is opened!!! \n");
84 * if more option is completed, stt have to be stopped.
87 MoreOption *opt = (MoreOption *)data;
88 VoiceData *vd = (VoiceData *) opt->voicedata;
90 if (vd->sttmanager->GetCurrent() == STT_STATE_RECORDING ||
91 vd->sttmanager->GetCurrent() == STT_STATE_PROCESSING) {
92 vd->sttmanager->Cancel();
95 catch(is::stt::SttException &e) {
96 PRINTFUNC(DLOG_ERROR, "%s", e.what());
99 opt->option_opened = EINA_TRUE;
103 evas_object_smart_callback_add(more_option_layout, "more,option,closed",
104 [](void *data, Evas_Object *obj, void *event_info){
106 PRINTFUNC(DLOG_DEBUG, "more option is closed!!! \n");
108 MoreOption *opt = (MoreOption *)data;
109 VoiceData *vd = (VoiceData *) opt->voicedata;
111 activate_circle_scroller_for_stt_textbox(vd, EINA_TRUE);
113 opt->option_opened = EINA_FALSE;
118 evas_object_show(more_option_layout);
123 void MoreOption::SetContentLayout(Evas_Object *content) {
129 elm_object_part_content_set(more_option_layout, "elm.swallow.content", content);
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);
135 elm_naviframe_item_pop_cb_set(nit,
136 [](void *data, Elm_Object_Item *it)->Eina_Bool
138 MoreOption *opt = (MoreOption *)data;
139 VoiceData *vd = (VoiceData *) opt->voicedata;
141 if(vd->disclaimer == 1){
142 PRINTFUNC(DLOG_ERROR, "pop to top"); //inb case of (selector view -> disclaimer view-> stt view)
144 if(opt->option_opened == EINA_FALSE){
145 PRINTFUNC(DLOG_DEBUG, "pop_cb called in STT view\n");
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");
152 } else if(vd->sttmanager->GetCurrent() == STT_STATE_RECORDING) {
153 PRINTFUNC(DLOG_DEBUG, "STT_STATE_RECORDING\n");
154 vd->effector->Stop();
156 vd->sttmanager->Stop();
157 }catch(is::stt::SttException &e){
158 PRINTFUNC(DLOG_ERROR, "reason : %s", e.what());
161 } else if(vd->sttmanager->GetCurrent() == STT_STATE_PROCESSING) {
162 PRINTFUNC(DLOG_DEBUG, "STT_STATE_RECORDING\n");
164 vd->sttmanager->Cancel();
165 }catch(is::stt::SttException &e){
166 PRINTFUNC(DLOG_ERROR, "reason : %s", e.what());
173 elm_naviframe_item_pop_to(elm_naviframe_bottom_item_get(vd->naviframe));
177 _back_to_genlist_for_selector();
182 if(opt->option_opened == EINA_FALSE){
183 PRINTFUNC(DLOG_DEBUG, "pop_cb called in STT view\n");
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");
190 } else if(vd->sttmanager->GetCurrent() == STT_STATE_RECORDING) {
191 PRINTFUNC(DLOG_DEBUG, "STT_STATE_RECORDING\n");
192 vd->effector->Stop();
194 vd->sttmanager->Stop();
195 }catch(is::stt::SttException &e){
196 PRINTFUNC(DLOG_ERROR, "reason : %s", e.what());
199 } else if(vd->sttmanager->GetCurrent() == STT_STATE_PROCESSING) {
200 PRINTFUNC(DLOG_DEBUG, "STT_STATE_RECORDING\n");
202 vd->sttmanager->Cancel();
203 }catch(is::stt::SttException &e){
204 PRINTFUNC(DLOG_ERROR, "reason : %s", e.what());
208 _back_to_genlist_for_selector();
214 PRINTFUNC(DLOG_DEBUG, "naviframe transition, not finished\n");
222 void MoreOption::Update()
226 strncpy(lang, ((VoiceData *)voicedata)->kbd_lang , 5);
228 char* display_lang = get_lang_label(lang);
229 eext_more_option_item_part_text_set(item, "selector,sub_text", display_lang);
234 Evas_Object* MoreOption::AddLanguageIcon(Evas_Object *parent) {
236 Evas_Object *icon = elm_image_add(parent);
238 PRINTFUNC(DLOG_ERROR, "It's failed to add image.");
241 std::string res_path;
242 char *tmp_path = app_get_resource_path();
248 std::string image_path = res_path + "images/prompt_ic_languages.png";
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);
259 void MoreOption::AddMorePage() {
263 item = eext_more_option_item_append(more_option_layout);
266 eext_more_option_item_part_text_set(item, "selector,main_text", _("WDS_IME_HEADER_INPUT_LANGUAGES_ABB"));
268 img = AddLanguageIcon(more_option_layout);
270 eext_more_option_item_part_content_set(item, "item,icon", img);
272 evas_object_smart_callback_add(more_option_layout, "item,clicked",
273 [](void *data, Evas_Object *obj, void *event_info)
276 PRINTFUNC(DLOG_DEBUG, "item,clicked");
277 if(g_setting_window == NULL)
278 create_setting_window(obj);
281 evas_object_smart_callback_add(more_option_layout, "item,selected",
282 [](void *data, Evas_Object *obj, void *event_info)
285 PRINTFUNC(DLOG_DEBUG, "item,selected");
287 Eext_Object_Item *selected_item = (Eext_Object_Item *)event_info;
289 //for custom accessibility
290 if (elm_config_access_get())
292 Evas_Object *panel = elm_object_part_content_get(obj, "elm.swallow.right");
295 Evas_Object *rotary_selector = elm_object_content_get(panel);
296 if (!rotary_selector) return;
298 Evas_Object *content = (Evas_Object *)edje_object_part_object_get(elm_layout_edje_get(rotary_selector), "content");
299 if (!content) return;
301 Evas_Object *content_access = elm_access_object_get(content);
302 if (!content_access) return;
304 if (eext_more_option_item_part_text_get(selected_item, "selector,main_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")) + " ";
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"));
313 elm_access_info_set(content_access, ELM_ACCESS_INFO, text.c_str());