Add code for checking profile to support TV profile
[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 #ifdef _WEARABLE
37         , item(NULL)
38 #endif
39         , option_opened(EINA_FALSE)
40         , voicedata(voicedata) {
41         /** todo. implement constructor */
42 }
43
44 MoreOption::~MoreOption() {
45         /** todo. implement destructor */
46
47 //      if(more_option_layout)
48 //              evas_object_del(more_option_layout);
49 }
50
51 void MoreOption::Create() {
52         try {
53                 AddLayout();
54                 AddMorePage();
55         }
56         catch(std::exception &e) {
57                 PRINTFUNC(DLOG_ERROR, "%s", e.what());
58                 assert(0);
59         }
60 }
61
62 void MoreOption::AddLayout() {
63         /** validation */
64         if(!nf)
65                 PRINTFUNC(DLOG_ERROR, "Invalid naviframe.");
66
67         /** add layout */
68         more_option_layout = eext_more_option_add(nf);
69
70         if(!more_option_layout)
71                 PRINTFUNC(DLOG_ERROR, "It's failed to create layout");
72
73         evas_object_smart_callback_add(more_option_layout, "more,option,opened",
74                 [](void *data, Evas_Object *obj, void *event_info){
75                         PRINTFUNC(DLOG_DEBUG, "more option is opened!!! \n");
76
77                         if(!data) return;
78
79                         /**
80                         * if more option is completed, stt have to be stopped.
81                         *
82                         */
83                         MoreOption *opt = (MoreOption *)data;
84                         VoiceData *vd = (VoiceData *) opt->voicedata;
85                         try {
86                                    if (vd->sttmanager->GetCurrent() == STT_STATE_RECORDING ||
87                                                    vd->sttmanager->GetCurrent() == STT_STATE_PROCESSING) {
88                                                    vd->sttmanager->Cancel();
89                                   }
90                         }
91                         catch(is::stt::SttException &e) {
92                                 PRINTFUNC(DLOG_ERROR, "%s", e.what());
93                         }
94
95                         opt->option_opened = EINA_TRUE;
96         }, this);
97
98         evas_object_smart_callback_add(more_option_layout, "more,option,closed",
99                 [](void *data, Evas_Object *obj, void *event_info){
100                 PRINTFUNC(DLOG_DEBUG, "more option is closed!!! \n");
101
102                 MoreOption *opt = (MoreOption *)data;
103                 VoiceData *vd = (VoiceData *) opt->voicedata;
104
105                 activate_circle_scroller_for_stt_textbox(vd, EINA_TRUE);
106
107                 opt->option_opened = EINA_FALSE;
108         }, this);
109
110         evas_object_show(more_option_layout);
111 }
112
113 void MoreOption::SetContentLayout(Evas_Object *content) {
114         /**
115          * Set content layout
116          *
117          */
118         elm_object_part_content_set(more_option_layout, "elm.swallow.content", content);
119
120         Elm_Object_Item *nit = NULL;
121         nit = elm_naviframe_item_push(nf, NULL, NULL, NULL, more_option_layout, "empty");
122         elm_naviframe_item_title_enabled_set(nit, EINA_FALSE, EINA_FALSE);
123
124         elm_naviframe_item_pop_cb_set(nit,
125                 [](void *data, Elm_Object_Item *it)->Eina_Bool
126                 {
127                         MoreOption *opt = (MoreOption *)data;
128                         VoiceData *vd = (VoiceData *) opt->voicedata;
129
130                         if(vd->disclaimer  == 1){
131                                 PRINTFUNC(DLOG_ERROR, "pop to top"); //inb case of (selector view -> disclaimer view-> stt view)
132
133                                 if(opt->option_opened == EINA_FALSE){
134                                         PRINTFUNC(DLOG_DEBUG, "pop_cb called in STT view\n");
135
136                                         if(vd->sttmanager){
137                                                 if (vd->sttmanager->GetCurrent() == STT_STATE_CREATED ||
138                                                                    vd->sttmanager->GetCurrent() == STT_STATE_READY) {
139                                                         PRINTFUNC(DLOG_DEBUG, "STT_STATE_CREATED || STT_STATE_READY\n");
140
141                                                 } else if (vd->sttmanager->GetCurrent() == STT_STATE_RECORDING) {
142                                                         PRINTFUNC(DLOG_DEBUG, "STT_STATE_RECORDING\n");
143                                                         vd->effector->Stop();
144                                                         try{
145                                                                 vd->sttmanager->Stop();
146                                                         }catch(is::stt::SttException &e){
147                                                                 PRINTFUNC(DLOG_ERROR, "reason : %s", e.what());
148                                                         }
149
150                                                 } else if (vd->sttmanager->GetCurrent() == STT_STATE_PROCESSING) {
151                                                         PRINTFUNC(DLOG_DEBUG, "STT_STATE_RECORDING\n");
152                                                         try{
153                                                                 vd->sttmanager->Cancel();
154                                                         }catch(is::stt::SttException &e){
155                                                                 PRINTFUNC(DLOG_ERROR, "reason : %s", e.what());
156                                                         }
157                                                 }
158                                         }
159                                 }
160
161
162                                 elm_naviframe_item_pop_to(elm_naviframe_bottom_item_get(vd->naviframe));
163                                 vd->disclaimer  = 0;
164
165                                 powerUnlock();
166                                 _back_to_genlist_for_selector();
167
168                                 return EINA_TRUE;
169                         }
170
171                         if(opt->option_opened == EINA_FALSE){
172                                 PRINTFUNC(DLOG_DEBUG, "pop_cb called in STT view\n");
173
174                                 if(vd->sttmanager){
175                                         if (vd->sttmanager->GetCurrent() == STT_STATE_CREATED ||
176                                                            vd->sttmanager->GetCurrent() == STT_STATE_READY) {
177                                                 PRINTFUNC(DLOG_DEBUG, "STT_STATE_CREATED || STT_STATE_READY\n");
178
179                                         } else if (vd->sttmanager->GetCurrent() == STT_STATE_RECORDING) {
180                                                 PRINTFUNC(DLOG_DEBUG, "STT_STATE_RECORDING\n");
181                                                 vd->effector->Stop();
182                                                 try{
183                                                         vd->sttmanager->Stop();
184                                                 }catch(is::stt::SttException &e){
185                                                         PRINTFUNC(DLOG_ERROR, "reason : %s", e.what());
186                                                 }
187
188                                         } else if (vd->sttmanager->GetCurrent() == STT_STATE_PROCESSING) {
189                                                 PRINTFUNC(DLOG_DEBUG, "STT_STATE_RECORDING\n");
190                                                 try{
191                                                         vd->sttmanager->Cancel();
192                                                 }catch(is::stt::SttException &e){
193                                                         PRINTFUNC(DLOG_ERROR, "reason : %s", e.what());
194                                                 }
195                                         }
196
197                                         _back_to_genlist_for_selector();
198
199                                         destroy_voice();
200
201                                         return EINA_TRUE;
202                                 } else {
203                                         PRINTFUNC(DLOG_DEBUG, "naviframe transition, not finished\n");
204                                         return EINA_FALSE;
205                                 }
206                         }
207                         return EINA_FALSE;
208                 }, this);
209 }
210
211 void MoreOption::Update()
212 {
213         char lang[6] = {0, };
214         strncpy(lang, ((VoiceData *)voicedata)->kbd_lang , 5);
215
216         const char* display_lang = get_lang_label(lang);
217         eext_more_option_item_part_text_set(item, "selector,sub_text", display_lang);
218 }
219
220 Evas_Object* MoreOption::AddLanguageIcon(Evas_Object *parent) {
221         Evas_Object *icon = elm_image_add(parent);
222         if (!icon) {
223                 PRINTFUNC(DLOG_ERROR, "It's failed to add image.");
224         }
225
226         std::string res_path;
227         char *tmp_path = app_get_resource_path();
228         if (tmp_path) {
229                 res_path = tmp_path;
230                 free(tmp_path);
231         }
232
233         std::string image_path = res_path + "images/prompt_ic_languages.png";
234
235         elm_image_file_set(icon, image_path.c_str(), NULL);
236         evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
237         evas_object_size_hint_align_set(icon, EVAS_HINT_FILL, EVAS_HINT_FILL);
238         evas_object_show(icon);
239
240         return icon;
241 }
242
243 void MoreOption::AddMorePage() {
244         Evas_Object *img;
245
246         item  = eext_more_option_item_append(more_option_layout);
247
248         /* Slider content */
249         eext_more_option_item_part_text_set(item, "selector,main_text", _("WDS_IME_HEADER_INPUT_LANGUAGES_ABB"));
250
251         img = AddLanguageIcon(more_option_layout);
252
253         eext_more_option_item_part_content_set(item, "item,icon", img);
254
255         evas_object_smart_callback_add(more_option_layout, "item,clicked",
256         [](void *data, Evas_Object *obj, void *event_info)
257         {
258                 PRINTFUNC(DLOG_DEBUG, "item,clicked");
259                 if(g_setting_window == NULL)
260                         create_setting_window(obj);
261         }, NULL);
262
263         evas_object_smart_callback_add(more_option_layout, "item,selected",
264         [](void *data, Evas_Object *obj, void *event_info)
265         {
266                 PRINTFUNC(DLOG_DEBUG, "item,selected");
267         }, NULL);
268 }
269