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