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) {
39 /** todo. implement constructor */
42 MoreOption::~MoreOption() {
43 /** todo. implement destructor */
45 // if(more_option_layout)
46 // evas_object_del(more_option_layout);
49 void MoreOption::Create() {
54 catch(std::exception &e) {
55 PRINTFUNC(DLOG_ERROR, "%s", e.what());
60 void MoreOption::AddLayout() {
63 PRINTFUNC(DLOG_ERROR, "Invalid naviframe.");
66 more_option_layout = eext_more_option_add(nf);
68 if(!more_option_layout)
69 PRINTFUNC(DLOG_ERROR, "It's failed to create layout");
71 evas_object_smart_callback_add(more_option_layout, "more,option,opened",
72 [](void *data, Evas_Object *obj, void *event_info){
73 PRINTFUNC(DLOG_DEBUG, "more option is opened!!! \n");
78 * if more option is completed, stt have to be stopped.
81 MoreOption *opt = (MoreOption *)data;
82 VoiceData *vd = (VoiceData *) opt->voicedata;
84 if (vd->sttmanager->GetCurrent() == STT_STATE_RECORDING ||
85 vd->sttmanager->GetCurrent() == STT_STATE_PROCESSING) {
86 vd->sttmanager->Cancel();
89 catch(is::stt::SttException &e) {
90 PRINTFUNC(DLOG_ERROR, "%s", e.what());
93 opt->option_opened = EINA_TRUE;
96 evas_object_smart_callback_add(more_option_layout, "more,option,closed",
97 [](void *data, Evas_Object *obj, void *event_info){
98 PRINTFUNC(DLOG_DEBUG, "more option is closed!!! \n");
100 MoreOption *opt = (MoreOption *)data;
101 VoiceData *vd = (VoiceData *) opt->voicedata;
103 activate_circle_scroller_for_stt_textbox(vd, EINA_TRUE);
105 opt->option_opened = EINA_FALSE;
108 evas_object_show(more_option_layout);
111 void MoreOption::SetContentLayout(Evas_Object *content) {
116 elm_object_part_content_set(more_option_layout, "elm.swallow.content", content);
118 Elm_Object_Item *nit = NULL;
119 nit = elm_naviframe_item_push(nf, NULL, NULL, NULL, more_option_layout, "empty");
120 elm_naviframe_item_title_enabled_set(nit, EINA_FALSE, EINA_FALSE);
122 elm_naviframe_item_pop_cb_set(nit,
123 [](void *data, Elm_Object_Item *it)->Eina_Bool
125 MoreOption *opt = (MoreOption *)data;
126 VoiceData *vd = (VoiceData *) opt->voicedata;
128 if(vd->disclaimer == 1){
129 PRINTFUNC(DLOG_ERROR, "pop to top"); //inb case of (selector view -> disclaimer view-> stt view)
131 if(opt->option_opened == EINA_FALSE){
132 PRINTFUNC(DLOG_DEBUG, "pop_cb called in STT view\n");
135 if (vd->sttmanager->GetCurrent() == STT_STATE_CREATED ||
136 vd->sttmanager->GetCurrent() == STT_STATE_READY) {
137 PRINTFUNC(DLOG_DEBUG, "STT_STATE_CREATED || STT_STATE_READY\n");
139 } else if (vd->sttmanager->GetCurrent() == STT_STATE_RECORDING) {
140 PRINTFUNC(DLOG_DEBUG, "STT_STATE_RECORDING\n");
141 vd->effector->Stop();
143 vd->sttmanager->Stop();
144 }catch(is::stt::SttException &e){
145 PRINTFUNC(DLOG_ERROR, "reason : %s", e.what());
148 } else if (vd->sttmanager->GetCurrent() == STT_STATE_PROCESSING) {
149 PRINTFUNC(DLOG_DEBUG, "STT_STATE_RECORDING\n");
151 vd->sttmanager->Cancel();
152 }catch(is::stt::SttException &e){
153 PRINTFUNC(DLOG_ERROR, "reason : %s", e.what());
160 elm_naviframe_item_pop_to(elm_naviframe_bottom_item_get(vd->naviframe));
164 _back_to_genlist_for_selector();
169 if(opt->option_opened == EINA_FALSE){
170 PRINTFUNC(DLOG_DEBUG, "pop_cb called in STT view\n");
173 if (vd->sttmanager->GetCurrent() == STT_STATE_CREATED ||
174 vd->sttmanager->GetCurrent() == STT_STATE_READY) {
175 PRINTFUNC(DLOG_DEBUG, "STT_STATE_CREATED || STT_STATE_READY\n");
177 } else if (vd->sttmanager->GetCurrent() == STT_STATE_RECORDING) {
178 PRINTFUNC(DLOG_DEBUG, "STT_STATE_RECORDING\n");
179 vd->effector->Stop();
181 vd->sttmanager->Stop();
182 }catch(is::stt::SttException &e){
183 PRINTFUNC(DLOG_ERROR, "reason : %s", e.what());
186 } else if (vd->sttmanager->GetCurrent() == STT_STATE_PROCESSING) {
187 PRINTFUNC(DLOG_DEBUG, "STT_STATE_RECORDING\n");
189 vd->sttmanager->Cancel();
190 }catch(is::stt::SttException &e){
191 PRINTFUNC(DLOG_ERROR, "reason : %s", e.what());
195 _back_to_genlist_for_selector();
201 PRINTFUNC(DLOG_DEBUG, "naviframe transition, not finished\n");
209 void MoreOption::Update()
211 char lang[6] = {0, };
212 strncpy(lang, ((VoiceData *)voicedata)->kbd_lang , 5);
214 const char* display_lang = get_lang_label(lang);
215 eext_more_option_item_part_text_set(item, "selector,sub_text", display_lang);
218 Evas_Object* MoreOption::AddLanguageIcon(Evas_Object *parent) {
219 Evas_Object *icon = elm_image_add(parent);
221 PRINTFUNC(DLOG_ERROR, "It's failed to add image.");
224 std::string res_path;
225 char *tmp_path = app_get_resource_path();
231 std::string image_path = res_path + "images/prompt_ic_languages.png";
233 elm_image_file_set(icon, image_path.c_str(), NULL);
234 evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
235 evas_object_size_hint_align_set(icon, EVAS_HINT_FILL, EVAS_HINT_FILL);
236 evas_object_show(icon);
241 void MoreOption::AddMorePage() {
244 item = eext_more_option_item_append(more_option_layout);
247 eext_more_option_item_part_text_set(item, "selector,main_text", _("WDS_IME_HEADER_INPUT_LANGUAGES_ABB"));
249 img = AddLanguageIcon(more_option_layout);
251 eext_more_option_item_part_content_set(item, "item,icon", img);
253 evas_object_smart_callback_add(more_option_layout, "item,clicked",
254 [](void *data, Evas_Object *obj, void *event_info)
256 PRINTFUNC(DLOG_DEBUG, "item,clicked");
257 if(g_setting_window == NULL)
258 create_setting_window(obj);
261 evas_object_smart_callback_add(more_option_layout, "item,selected",
262 [](void *data, Evas_Object *obj, void *event_info)
264 PRINTFUNC(DLOG_DEBUG, "item,selected");