Remove global variables
[platform/core/uifw/ise-default.git] / src / ise-stt-mode.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 <vconf.h>
18 #include <stdio.h>
19 #include <Ecore.h>
20 #include <dlog.h>
21 #include <app.h>
22 #include <string.h>
23 #include <stt.h>
24 #include <unistd.h>
25
26 #include "ise.h"
27 #include "utils.h"
28 #include "config.h"
29 #include "candidate-factory.h"
30 #include "ise-stt-mode.h"
31 #include "ise-stt-option.h"
32 #include "ise-stt-common.h"
33
34 #define _EDJ(x)  elm_layout_edje_get(x)
35
36 #define STT_EDJ_FILE "edje/" PROFILE_NAME"/w-input-stt.edj"
37
38 static VoiceData *my_voicedata = NULL;
39
40 #ifndef _TV
41 static void set_guide_text(VoiceData *vd, const char* text, bool translatable = false);
42 #endif
43
44 void voice_result_string_flush()
45 {
46     if (my_voicedata && my_voicedata->partial_result) {
47         SECURE_LOGD("***** result_text : %s *******", my_voicedata->partial_result);
48         const int BUF_LEN = 256;
49         char retStr[BUF_LEN] = {0};
50         snprintf(retStr, BUF_LEN, "%s", my_voicedata->partial_result);
51         ise_send_string(retStr);
52     }
53 }
54
55 void ise_stt_stop()
56 {
57     if (my_voicedata != NULL) {
58         try {
59             my_voicedata->state = STT_STATE_VAL_INIT;
60             my_voicedata->sttmanager->Stop();
61         }
62         catch (is::stt::SttException &e) {
63         }
64     }
65 }
66
67 void send_result_text(void *data)
68 {
69     if (!data)
70         return;
71
72     VoiceData* voicedata = (VoiceData*)data;
73     SECURE_LOGD("result_text = %s", voicedata->partial_result);
74     ise_update_preedit_string(voicedata->partial_result);
75 }
76
77 void voice_get_string(const char *keyValue, VoiceData *voicedata)
78 {
79     if (!voicedata)
80         return;
81
82     char* strbuf = NULL;
83
84     strbuf = elm_entry_utf8_to_markup(keyValue);
85
86     SECURE_LOGD("text : %s, voicedata->partial_result=%s", strbuf, voicedata->partial_result);
87
88     if (strbuf) {
89         if (voicedata->partial_result) { // partial_result is not Null so replace
90             if (strcmp(voicedata->partial_result, strbuf)) {
91                 // different replace
92                 LOGD("different replace");
93
94                 voicedata->stt_results.pop_back();
95                 voicedata->stt_results.push_back(strbuf);
96
97                 free(voicedata->partial_result);
98                 voicedata->partial_result = strdup(strbuf);
99            }
100         } else { // partial_result is Null so first case
101             LOGD("first push");
102             voicedata->stt_results.push_back(strbuf);
103             voicedata->partial_result = strdup(strbuf);
104         }
105     }
106
107     send_result_text(voicedata);
108
109     if (strbuf)
110         free(strbuf);
111
112     LOGD("ends");
113 }
114
115 static Eina_Bool _recognition_failure_cb(void *data)
116 {
117     VoiceData *voicedata = (VoiceData *) data;
118     if (!voicedata) return ECORE_CALLBACK_CANCEL;
119
120     voicedata->state = STT_STATE_VAL_INIT;
121     set_animation_state(voicedata);
122     voicedata->refresh_timer = NULL;
123
124     return ECORE_CALLBACK_CANCEL;
125 }
126
127 #ifndef _TV
128 static Eina_Bool change_guide_text(void *data){
129     VoiceData *voicedata = (VoiceData *) data;
130     if (!voicedata || !voicedata->sttmanager) return ECORE_CALLBACK_CANCEL;
131
132     stt_state_e state = voicedata->sttmanager->GetCurrent();
133     if (state == STT_STATE_RECORDING || state == STT_STATE_PROCESSING)
134         elm_object_domain_translatable_part_text_set(voicedata->layout_main, "elm.text", PACKAGE, SK_TAP_TO_PAUSE);
135
136     return ECORE_CALLBACK_CANCEL;
137 }
138
139 static void set_guide_text(VoiceData *vd, const char* text, bool translatable)
140 {
141 #ifdef _WEARABLE
142     elm_object_signal_emit(vd->layout_main, "idle,state,guide_text,bottom", "elm");
143 #else
144     elm_object_signal_emit(vd->layout_main, "idle,state,guide_text,up", "elm");
145 #endif
146
147     if (translatable)
148         elm_object_domain_translatable_part_text_set(vd->layout_main, "elm.text", PACKAGE, text);
149     else
150         elm_object_part_text_set(vd->layout_main, "elm.text", text);
151
152     if (!strcmp(text, SK_SPEAK_NOW)) {
153         if (vd->guide_text_timer == NULL)
154             vd->guide_text_timer = ecore_timer_add(1.0, change_guide_text, vd);
155     }
156 }
157 #endif
158
159 void start_by_press(VoiceData *voicedata)
160 {
161     LOGD("start_by_press ");
162 #ifdef _TV
163     edje_object_signal_emit(_EDJ(voicedata->layout_main), "mouse,clicked,1", "MIC_ICON");
164 #else
165     edje_object_signal_emit(_EDJ(voicedata->layout_main), "mouse,clicked,1", "background");
166 #endif
167 }
168
169 static void on_mic_button_press_cb(void *data, Evas_Object *obj, void *event_info)
170 {
171     LOGD("on_mic_button_press_cb");
172     VoiceData *voicedata = (VoiceData *)data;
173     if (!voicedata) return;
174
175     if (voicedata->sttmanager != NULL &&
176         (voicedata->sttmanager->GetCurrent() == STT_STATE_RECORDING
177         || voicedata->sttmanager->GetCurrent() == STT_STATE_PROCESSING)) {
178         try {
179             voicedata->state = STT_STATE_VAL_INIT;
180             voicedata->sttmanager->Stop();
181 #ifdef _TV
182             edje_object_signal_emit(_EDJ(voicedata->layout_main), "elm,state,init", "elm");
183             elm_object_part_text_set(voicedata->layout_main, "switch.text", "Off");
184 #endif
185         }
186         catch (is::stt::SttException &e) {
187         }
188
189         if (voicedata->effector)
190             voicedata->effector->Stop(true);
191
192         if (NULL != voicedata->start_timer) {
193             ecore_timer_del(voicedata->start_timer);
194             voicedata->start_timer = NULL;
195         }
196         if (NULL != voicedata->guide_text_timer) {
197             ecore_timer_del(voicedata->guide_text_timer);
198             voicedata->guide_text_timer = NULL;
199         }
200         if (NULL != voicedata->init_timer) {
201             ecore_timer_del(voicedata->init_timer);
202             voicedata->init_timer = NULL;
203         }
204         if (NULL != voicedata->refresh_timer) {
205             ecore_timer_del(voicedata->refresh_timer);
206             voicedata->refresh_timer = NULL;
207         }
208     } else {
209         if (NULL != voicedata->guide_text_timer) {
210             ecore_timer_del(voicedata->guide_text_timer);
211             voicedata->guide_text_timer = NULL;
212         }
213 #ifdef _TV
214         elm_object_part_text_set(voicedata->layout_main, "switch.text", "On");
215         edje_object_signal_emit(_EDJ(voicedata->layout_main), "mouse,clicked,1", "MIC_ICON");
216 #else
217         edje_object_signal_emit(_EDJ(voicedata->layout_main), "mouse,clicked,1", "background");
218 #endif
219     }
220 }
221
222 static Eina_Bool _mic_button_enable_cb(void *data)
223 {
224     VoiceData* voicedata = (VoiceData*)data;
225     if (!voicedata) return ECORE_CALLBACK_CANCEL;
226
227     voicedata->btn_disabling_timer = NULL;
228
229     Evas_Object *button = (Evas_Object *)voicedata->mic_button;
230     elm_object_disabled_set(button, EINA_FALSE);
231
232     return ECORE_CALLBACK_CANCEL;
233 }
234
235 void init_customizing_theme(void)
236 {
237     char *resource_path = app_get_resource_path();
238     if (resource_path) {
239         std::string stt_edj_path = resource_path;
240         stt_edj_path = stt_edj_path + STT_EDJ_FILE;
241         elm_theme_extension_add(NULL, stt_edj_path.c_str());
242         free(resource_path);
243     }
244 }
245
246 bool _app_stt_initialize(VoiceData *voice_data)
247 {
248     LOGD("_app_stt_initialize ");
249     VoiceData *vd = (VoiceData *)voice_data;
250     if (!vd) return false;
251
252     try {
253         if (vd->sttmanager) {
254             vd->sttmanager->Cancel();
255             delete vd->sttmanager;
256             vd->sttmanager = NULL;
257         }
258
259         if (vd->sttfeedback) {
260             delete vd->sttfeedback;
261             vd->sttfeedback = NULL;
262         }
263
264         vd->sttfeedback = new is::stt::SttFeedback();
265         if (vd->sttfeedback) {
266             vd->sttfeedback->SetVoiceData(vd);
267
268             vd->sttmanager = new is::stt::SttManager(*(vd->sttfeedback));
269             if (vd->sttmanager)
270                 vd->sttmanager->Prepare();
271             else
272                 LOGW("Failed to allocate SttManager");
273         } else {
274             LOGW("Failed to allocate SttFeedback");
275         }
276     } catch(std::exception &e) {
277         LOGD("%s", e.what());
278         return false;
279     }
280
281     return true;
282 }
283
284 static Eina_Bool _idler_cb(void *data)
285 {
286     LOGD("_idler_cb");
287     if (!data) return ECORE_CALLBACK_CANCEL;
288
289     if (my_voicedata == NULL) {
290         LOGD("_idler_cb : my_voicedata is null");
291         return ECORE_CALLBACK_CANCEL;
292     }
293
294     VoiceData *voicedata = (VoiceData *)data;
295
296     if (true == _app_stt_initialize(voicedata)) {
297         LOGD("_app_stt_initialize None Error");
298         voicedata->voicefw_state = 1;
299         voicedata->state = STT_STATE_VAL_INIT;
300     } else {
301         voicedata->voicefw_state = 0;
302         LOGD("Initialization Fail!<br>Check STT-daemon is running");
303     }
304
305     Evas_Object *canvas = elm_object_part_content_get(voicedata->layout_main, "EFFECT_BG");
306
307     is::ui::WInputSttMicEffect *ieffect = new is::ui::WInputSttMicEffect();
308     if (ieffect && voicedata->sttmanager) {
309         ieffect->SetSttHandle(voicedata->sttmanager->GetSttHandle());
310     }
311
312     is::ui::MicEffector *effector = new is::ui::MicEffector(canvas, voicedata->layout_main, *ieffect);
313     voicedata->ieffect = ieffect;
314     voicedata->effector = effector;
315
316     if (ieffect && voicedata->progressbar) {
317         ieffect->SetProgressBar(voicedata->progressbar);
318     }
319
320     elm_access_highlight_set(voicedata->mic_button);
321
322     return ECORE_CALLBACK_CANCEL;
323 }
324
325 /**
326  * @brief - function to send the signal to edc
327  *               to change the animation as per stt state
328  * @param - Ug data
329  */
330 void set_animation_state(VoiceData *voicedata)
331 {
332     if (voicedata->state == STT_STATE_VAL_INIT) {
333 #if 0
334         if (voicedata->sttmanager->GetCurrent() == STT_STATE_READY) {
335             set_guide_text(voicedata, "", false);
336             //_elm_access_say(voicedata->layout_main, _(SK_INIT));
337         } else {
338             PRINTFUNC(DLOG_DEBUG, "SK_NETWORK_ERROR [%d]", voicedata->sttmanager->GetCurrent());
339             set_guide_text(voicedata, _(SK_NETWORK_ERROR));
340             //_elm_access_say(voicedata->layout_main, _(SK_NETWORK_CONNECTION_ERROR));
341         }
342 #endif
343
344         if (voicedata->effector)
345             voicedata->effector->Stop(true);
346 #ifndef _TV
347         set_guide_text(voicedata, SK_TAP_TO_SPEAK, true);
348 #endif
349     } else if (voicedata->state == STT_STATE_VAL_LISTENING) {
350 #ifndef _TV
351         set_guide_text(voicedata, SK_SPEAK_NOW, true);
352 #endif
353         if (voicedata->effector)
354             voicedata->effector->Start();
355
356     } else if (voicedata->state == STT_STATE_VAL_PROCESSING) {
357 #ifndef _TV
358         set_guide_text(voicedata, "");
359 #endif
360         if (voicedata->effector)
361             voicedata->effector->Stop();
362
363     } else {
364 #ifndef _TV
365         set_guide_text(voicedata, _(SK_RECOGNITION_FAILED));
366 #endif
367         //_elm_access_say(voicedata->layout_main, _(SK_RECOGNITION_FAILED));
368
369         voicedata->state = STT_STATE_VAL_NOT_RECOGNISED;
370
371         if (voicedata->refresh_timer) {
372              ecore_timer_del(voicedata->refresh_timer);
373         }
374
375         if (voicedata->effector)
376             voicedata->effector->Stop(true);
377
378         voicedata->refresh_timer = ecore_timer_add(2.0, _recognition_failure_cb, voicedata);
379     }
380 }
381
382 void show_error_message(VoiceData *vd, stt_error_e reason)
383 {
384 #ifndef _TV
385     if (reason == STT_ERROR_OUT_OF_NETWORK) {
386         set_guide_text(vd, _(SK_NETWORK_ERROR));
387         vd->state = STT_STATE_VAL_INIT;
388     } else {
389         set_guide_text(vd, _(SK_STT_BUSY));
390         vd->state = STT_STATE_VAL_INIT;
391     }
392 #else
393         vd->state = STT_STATE_VAL_INIT;
394 #endif
395 }
396
397 static Eina_Bool _start_timer_cb(void* data)
398 {
399     LOGD("_start_timer_cb");
400
401     VoiceData *voicedata = (VoiceData *) data;
402     if (!voicedata) return ECORE_CALLBACK_CANCEL;
403
404     try {
405         voicedata->state = STT_STATE_VAL_PREPARE_LISTENING;
406         if (voicedata->sttmanager)
407             voicedata->sttmanager->Start();
408     }
409     catch (is::stt::SttException &e) {
410 #ifndef _TV
411         if (e.GetEcode() == STT_ERROR_OUT_OF_NETWORK)
412         {
413             set_guide_text(voicedata, _(SK_NETWORK_ERROR));
414             voicedata->state = STT_STATE_VAL_INIT;
415         } else {
416             set_guide_text(voicedata, _(SK_STT_BUSY));
417             voicedata->state = STT_STATE_VAL_INIT;
418         }
419 #else
420         voicedata->state = STT_STATE_VAL_INIT;
421 #endif
422     }
423
424     voicedata->start_timer = NULL;
425
426     return ECORE_CALLBACK_CANCEL;
427 }
428
429 /**
430  * @brief - cancel button press callback for cross button
431  * @param -
432  */
433
434 void on_initial_anim_press_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
435 {
436     LOGD("on_initial_anim_press_cb");
437     VoiceData *vd = (VoiceData *)data;
438     if (vd == NULL || vd->sttmanager == NULL)
439         return;
440
441     int tempVal = vd->sttmanager->GetCurrent();
442     if (tempVal == STT_STATE_CREATED) {
443         LOGD("IGNORE TOUCH event before STT READY. STT is preparing");
444         return;
445     }
446
447     LOGD("SttManager State : %d", vd->sttmanager->GetCurrent());
448     LOGD("Ui Voice State : %d", vd->state);
449
450     switch (vd->state) {
451         case STT_STATE_VAL_INIT:
452             LOGD("%s", "STT_STATE_VAL_INIT");
453             get_stt_default_language(vd);
454             vd->sttmanager->SetLanguage(std::string(vd->kbd_lang));
455
456             if (vd->start_timer) {
457                 ecore_timer_del(vd->start_timer);
458                 vd->start_timer = NULL;
459             }
460
461             vd->start_timer = ecore_timer_add(0.0, _start_timer_cb, vd);
462             break;
463
464         case STT_STATE_VAL_LISTENING :
465             LOGD("%s", "STT_STATE_VAL_LISTENING");
466             try {
467                 vd->state = STT_STATE_VAL_PREPARE_PROCESSING;
468                 vd->sttmanager->Stop();
469
470                 /**
471                 * Cuased touch reponse time, it can be called to stop animator.
472                 *
473                 */
474 #ifndef _TV
475                 set_guide_text(vd, "");
476 #endif
477
478                 if (vd->effector)
479                     vd->effector->Stop();
480             }
481             catch (is::stt::SttException &e) {
482                 LOGD("%s", e.what());
483                 if (e.GetEcode() != STT_ERROR_INVALID_STATE) {
484 #ifndef _TV
485                     set_guide_text(vd, _(SK_RECOGNITION_FAILED));
486 #endif
487                     vd->state = STT_STATE_VAL_INIT;
488
489                     if (vd->effector)
490                         vd->effector->Stop(true);
491                 }
492             }
493             break;
494
495         case STT_STATE_VAL_PROCESSING:
496             LOGD("%s", "STT_STATE_VAL_PROCESSING");
497             try {
498                 //vd->state = STT_STATE_VAL_PREPARE_CANCEL;
499                 vd->sttmanager->Cancel();
500             }
501             catch (is::stt::SttException &e) {
502             }
503             if (vd->effector)
504                 vd->effector->Stop(true);
505
506             break;
507
508         case STT_STATE_VAL_NOT_RECOGNISED:
509             LOGD("%s", "STT_STATE_VAL_NOT_RECOGNISED");
510             vd->state = STT_STATE_VAL_INIT ;
511             break;
512         default:
513             LOGD("default [%d]", vd->state);
514             break;
515     }
516 }
517
518 static Evas_Object *create_progressbar(Evas_Object *parent)
519 {
520     Evas_Object *progressbar = NULL;
521
522     progressbar = elm_progressbar_add(parent);
523     elm_object_style_set(progressbar, "voice_input/process/small");
524     elm_progressbar_pulse(progressbar, EINA_TRUE);
525
526     evas_object_size_hint_align_set(progressbar, EVAS_HINT_FILL, EVAS_HINT_FILL);
527     evas_object_size_hint_weight_set(progressbar, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
528
529     //ea_theme_object_color_replace(progressbar, "B065L6", "AO012");
530
531     evas_object_show(progressbar);
532
533     return progressbar;
534 }
535
536 int init_voicedata(VoiceData *r_voicedata)
537 {
538     VoiceData *voicedata = (VoiceData *)r_voicedata;
539     if (!voicedata) {
540         return FALSE;
541     }
542
543     voicedata->voicefw_state = 0;
544     voicedata->voicefw_handle = NULL;
545     voicedata->win = NULL;
546     voicedata->layout_main = NULL;
547     voicedata->progressbar = NULL;
548     voicedata->scroller = NULL;
549     voicedata->main_entry = NULL;
550     voicedata->mic_button = NULL;
551     voicedata->state = STT_STATE_VAL_INIT;
552     voicedata->kbd_lang = NULL;
553     voicedata->start_timer = NULL;
554     voicedata->refresh_timer = NULL;
555     voicedata->progressbar_timer = NULL;
556     voicedata->textblock_timer = NULL;
557     voicedata->guide_text_timer = NULL;
558     voicedata->btn_disabling_timer = NULL;
559     voicedata->power_unlock_timer = NULL;
560     voicedata->init_timer = NULL;
561
562     voicedata->stt_results.clear();
563     voicedata->partial_result = NULL;
564     voicedata->result_type = 0;
565     voicedata->disclaimer = 0;
566     voicedata->sttfeedback = NULL;
567     voicedata->sttmanager = NULL;
568     voicedata->ieffect = NULL;
569     voicedata->effector = NULL;
570
571     return TRUE;
572 }
573
574 int init_voice(Evas_Object *parent, const char *lang, VoiceData *r_voicedata)
575 {
576     LOGD("init_voice");
577
578     VoiceData *voicedata = (VoiceData *)r_voicedata;
579     if (!voicedata) {
580         return FALSE;
581     }
582
583     if (!parent) {
584         LOGD("Parent is NULL\n");
585         return FALSE;
586     } else {
587         LOGD("Parent is there");
588     }
589
590     voicedata->voicefw_state = 0;
591
592     /* Set Voice Language */
593     if (voicedata->kbd_lang) {
594         free(voicedata->kbd_lang);
595         voicedata->kbd_lang = NULL;
596     }
597
598     //stt_get_default_language(my_voicedata->voicefw_handle, &my_voicedata->kbd_lang);
599     get_stt_default_language(voicedata);
600     if (NULL == voicedata->kbd_lang || FALSE == is_lang_supported_by_stt(voicedata->kbd_lang)) {
601         voicedata->kbd_lang = strdup("en_US");
602     }
603
604     LOGD("Voice input active language is : %s", voicedata->kbd_lang);
605
606     voicedata->win = parent;
607
608     if (NULL == voicedata->win) {
609         return FALSE;
610     }
611
612     if (NULL != voicedata->textblock_timer) {
613         ecore_timer_del(voicedata->textblock_timer);
614         voicedata->textblock_timer = NULL;
615     }
616     LOGD("init_voice end");
617
618     return TRUE;
619 }
620
621 Evas_Object *create_fullview(Evas_Object *win, VoiceData *r_voicedata)
622 {
623     LOGD("create_fullview");
624
625     VoiceData *voicedata = r_voicedata;
626
627     int ret;
628     init_customizing_theme();
629
630     Evas_Object *layout_main = elm_layout_add(win);
631     evas_object_size_hint_weight_set(layout_main, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
632     evas_object_size_hint_align_set(layout_main, EVAS_HINT_FILL, EVAS_HINT_FILL);
633
634     voicedata->layout_main = layout_main;
635
636     std::string edj_path;
637     char *resource_path = app_get_resource_path();
638     if (resource_path) {
639         edj_path = resource_path;
640         free(resource_path);
641         resource_path = NULL;
642     }
643     edj_path = edj_path + STT_EDJ_FILE;
644     LOGD("edj_path = %s", edj_path.c_str());
645
646     ret = elm_layout_file_set(layout_main, edj_path.c_str(), "mic_control");
647     LOGD("elm_layout_file_set result = %d", ret);
648
649     //Canvas for Cairo effect
650     Evas_Object *canvas = evas_object_image_filled_add(evas_object_evas_get(layout_main));
651     evas_object_propagate_events_set(canvas, EINA_TRUE);
652     evas_object_image_alpha_set(canvas, EINA_TRUE);
653     evas_object_size_hint_align_set(canvas, EVAS_HINT_FILL, EVAS_HINT_FILL);
654     evas_object_size_hint_weight_set(canvas, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
655
656     int y = 0;
657     Candidate *candidate = get_candidate();
658     if (candidate && candidate->get_visible()){
659 #ifdef _WEARABLE
660         ise_app_candidate_hide();
661         candidate->hide();
662 #else
663         y = candidate->get_height();
664 #endif
665     }
666     read_ise_config_values();
667     CONFIG_VALUES *config_values = get_config_values();
668     if (config_values && config_values->floating_mode)
669         y += FLOATING_TITLE_BAR_HEIGHT;
670     evas_object_move(layout_main, 0, y);
671     elm_object_part_content_set(layout_main, "EFFECT_BG", canvas);
672
673     // MIC Button
674     Evas_Object *m_mic_button = elm_button_add(layout_main);
675     elm_object_style_set(m_mic_button, "vic/micbutton");
676     elm_object_part_content_set(layout_main, "MIC", m_mic_button);
677
678     elm_object_disabled_set(m_mic_button, EINA_TRUE);
679     evas_object_smart_callback_add(m_mic_button, "clicked", on_mic_button_press_cb, (void *) voicedata);
680
681     voicedata->mic_button = m_mic_button;
682
683     if (voicedata->btn_disabling_timer == NULL) {
684         voicedata->btn_disabling_timer = ecore_timer_add(2.0, _mic_button_enable_cb, voicedata);
685     }
686
687     if (voicedata->init_timer == NULL) {
688         voicedata->init_timer = ecore_timer_add(0.6, _idler_cb, voicedata);
689     }
690
691     // Progress Bar
692     Evas_Object *progress_bar = create_progressbar(layout_main);
693     elm_object_part_content_set(layout_main, "PROGRESS_BAR", progress_bar);
694     voicedata->progressbar = progress_bar;
695
696     // add callback
697     elm_object_signal_callback_add(layout_main, "idle,state,pulse,visible", "", on_initial_anim_press_cb, voicedata);
698
699     CSCLUI *ui = get_ui();
700     if (ui) {
701         SCLDisplayMode display_mode = ui->get_display_mode();
702         if (display_mode >= 0 && display_mode < DISPLAYMODE_MAX) {
703             const char *input_mode = ui->get_input_mode();
704             if (input_mode) {
705                 SclSize rect = ui->get_input_mode_size(input_mode, display_mode);
706                 CONFIG_VALUES *config_values = get_config_values();
707                 if (config_values && config_values->floating_mode)
708                     evas_object_resize(layout_main, rect.width * FLOATING_SCALE_RATE, rect.height * FLOATING_SCALE_RATE);
709                 else
710                     evas_object_resize(layout_main, rect.width, rect.height);
711             }
712         }
713     }
714
715     evas_object_layer_set(layout_main, 32000);
716
717     return layout_main;
718 }
719
720 Eina_Bool init_view(void *data)
721 {
722     LOGD("init_view");
723
724     VoiceData *voicedata = (VoiceData *)data;
725
726     if (voicedata == NULL) {
727         LOGD("init_view : voicedata == NULL");
728         return ECORE_CALLBACK_CANCEL;
729     }
730
731     voicedata->layout_main = create_fullview(voicedata->win, voicedata);
732
733     if (voicedata->layout_main) {
734         evas_object_show(voicedata->layout_main);
735     }
736
737     return ECORE_CALLBACK_CANCEL;
738 }
739
740 Evas_Object *show_voice_window(Evas_Object *parent, VoiceData *r_voicedata)
741 {
742     LOGD("show_voice_window");
743
744     VoiceData *voicedata = (VoiceData *)r_voicedata;
745     if (!voicedata) {
746         return NULL;
747     }
748
749     if (!parent) {
750         LOGD("Parent is NULL\n");
751         return NULL;
752     } else {
753         LOGD("Parent is there");
754     }
755
756     if (NULL != voicedata->layout_main) {
757         evas_object_del((voicedata)->layout_main);
758         (voicedata)->layout_main = NULL;
759     }
760
761     if (NULL != voicedata->effector) {
762         delete (voicedata->effector);
763         (voicedata)->effector = NULL;
764     }
765
766     if (NULL != voicedata->ieffect) {
767         delete (voicedata->ieffect);
768         voicedata->ieffect = NULL;
769     }
770
771     init_view((void *)voicedata);
772     return voicedata->layout_main;
773 }
774
775 void on_destroy(VoiceData *r_voicedata)
776 {
777     LOGD("on_destroy");
778
779     VoiceData *voicedata = (VoiceData *)r_voicedata;
780
781     if (NULL != voicedata) {
782         if (NULL != voicedata->layout_main) {
783             evas_object_del(voicedata->layout_main);
784             voicedata->layout_main = NULL;
785         }
786
787         if (NULL != voicedata->win) {
788             voicedata->win = NULL;
789         }
790
791         if (NULL != voicedata->start_timer) {
792             ecore_timer_del(voicedata->start_timer);
793             voicedata->start_timer = NULL;
794         }
795
796         if (NULL != voicedata->refresh_timer) {
797             ecore_timer_del(voicedata->refresh_timer);
798             voicedata->refresh_timer = NULL;
799         }
800
801         if (NULL != voicedata->progressbar_timer) {
802             ecore_timer_del(voicedata->progressbar_timer);
803             voicedata->progressbar_timer = NULL;
804             elm_progressbar_pulse(voicedata->progressbar, EINA_FALSE);
805         }
806
807         if (NULL != voicedata->textblock_timer) {
808             ecore_timer_del(voicedata->textblock_timer);
809             voicedata->textblock_timer = NULL;
810         }
811
812         if (NULL != voicedata->guide_text_timer) {
813             ecore_timer_del(voicedata->guide_text_timer);
814             voicedata->guide_text_timer = NULL;
815         }
816
817         if (NULL != voicedata->btn_disabling_timer) {
818             ecore_timer_del(voicedata->btn_disabling_timer);
819             voicedata->btn_disabling_timer = NULL;
820         }
821
822         if (NULL != voicedata->power_unlock_timer) {
823             ecore_timer_del(voicedata->power_unlock_timer);
824             voicedata->power_unlock_timer = NULL;
825         }
826
827         if (NULL != voicedata->init_timer) {
828             ecore_timer_del(voicedata->init_timer);
829             voicedata->init_timer = NULL;
830         }
831
832         if (voicedata->kbd_lang) {
833             free(voicedata->kbd_lang);
834             voicedata->kbd_lang = NULL;
835         }
836
837         if (voicedata->ieffect) {
838             delete voicedata->ieffect;
839             voicedata->ieffect = NULL;
840         }
841
842         if (voicedata->effector) {
843             delete voicedata->effector;
844             voicedata->effector = NULL;
845         }
846
847         if (voicedata->sttmanager) {
848             delete voicedata->sttmanager;
849             voicedata->sttmanager = NULL;
850         }
851
852         if (voicedata->sttfeedback) {
853             delete voicedata->sttfeedback;
854             voicedata->sttfeedback = NULL;
855         }
856
857         delete voicedata;
858     }
859 }
860
861 void destroy_voice()
862 {
863     LOGD("destroy_voice");
864     vconf_ignore_key_changed(VCONFKEY_ISE_STT_LANGUAGE, _stt_lang_changed_cb);
865
866     if (my_voicedata) {
867         on_destroy(my_voicedata);
868         my_voicedata = NULL;
869     }
870 }
871
872 void show_voice_input(Evas_Object *parent, const char *lang, void (*get_string)(char *, int))
873 {
874     LOGD("show_voice_input");
875     int init = 0;
876
877     destroy_voice();
878
879     if (!my_voicedata) {
880         my_voicedata = new VoiceData;
881         if (my_voicedata == NULL) {
882             LOGD("%d::::Heap Overflow, Voice Input cannot be shown!", __LINE__);
883             return;
884         }
885         init_voicedata(my_voicedata);
886     }
887
888     if (my_voicedata) {
889         init = init_voice(parent, lang, my_voicedata);
890         if (init) {
891             if (my_voicedata->win) {
892                 //ise_stt_start(my_voicedata);
893                 show_voice_window(my_voicedata->win, my_voicedata);
894             }
895         } else {
896             destroy_voice();
897             LOGD("%d::::Fail to create Voice window!", __LINE__);
898             return;
899         }
900     }
901
902     vconf_notify_key_changed(VCONFKEY_ISE_STT_LANGUAGE, _stt_lang_changed_cb, my_voicedata);
903 }
904
905 void ise_show_stt_mode(Evas_Object *win)
906 {
907     if (!win)
908         return;
909
910     show_voice_input(win, NULL, NULL);
911
912     const int BUF_LEN = 256;
913     static char buf[BUF_LEN] = {0};
914     snprintf(buf, BUF_LEN, "%s", gettext("IDS_ST_SK_CANCEL"));
915     CSCLUI *ui = get_ui();
916     if (ui)
917         ui->set_string_substitution("Cancel", buf);
918 }
919
920 void ise_hide_stt_mode()
921 {
922     destroy_voice();
923     CSCLUI *ui = get_ui();
924     if (ui)
925         ui->unset_string_substitution("Cancel");
926 }