"Add line feed"
[platform/core/uifw/inputdelegator.git] / src / w-input-stt-ise.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
19 #include "Debug.h"
20 #include "w-input-selector.h"
21 #include "w-input-stt-ise.h"
22 #include "w-input-stt-voice.h"
23 #include "w-input-stt-engine.h"
24 #include "voice-recorder.h"
25
26
27 VoiceData *my_voicedata = NULL;
28
29 #define FREE(ptr)       \
30          do { \
31                  if (ptr != NULL) { \
32                          free(ptr); \
33                          ptr = NULL; \
34                  } \
35          } while (0);
36
37 void show_voice_input(Evas_Object *parent, const char *lang, void (*get_string)(char *, int))
38 {
39         PRINTFUNC(DLOG_DEBUG, "show voice");
40         int init = 0;
41
42         destroy_voice();
43
44         //stt_feedback_initialize();
45
46         if (!my_voicedata) {
47                 my_voicedata = new VoiceData;
48                 if (my_voicedata == NULL) {
49                         PRINTFUNC(DLOG_ERROR, "%d::::Heap Overflow, Voice Input cannot be shown!", __LINE__);
50                         return;
51                 }
52                 init_voicedata(my_voicedata);
53         }
54
55         if (my_voicedata) {
56                 init = init_voice(parent, lang, my_voicedata);
57                 if (init) {
58                         if (my_voicedata->naviframe) {
59                                 show_voice_window(my_voicedata->naviframe, my_voicedata);
60                         }
61                 } else {
62                         destroy_voice();
63                         PRINTFUNC(DLOG_ERROR, "%d::::Fail to create Voice window!", __LINE__);
64                         return;
65                 }
66         }
67
68         vconf_notify_key_changed(VCONFKEY_ISE_STT_LANGUAGE, _stt_lang_changed_cb, my_voicedata);
69 }
70
71 void pause_voice()
72 {
73         PRINTFUNC(DLOG_DEBUG, "pause_voice");
74
75         powerUnlock();
76         if (my_voicedata) {
77                 on_stt_pause(my_voicedata);
78         }
79 }
80
81 void resume_voice()
82 {
83         if (my_voicedata) {
84                 PRINTFUNC(DLOG_DEBUG, "resume_voice");
85                 on_stt_resume(my_voicedata);
86         }
87 }
88
89 void destroy_voice()
90 {
91         PRINTFUNC(DLOG_DEBUG, "destroy voice");
92
93         //stt_feedback_deinitialize();  // It disable w-input-selector touch sound. So removed.
94
95         vconf_ignore_key_changed(VCONFKEY_ISE_STT_LANGUAGE, _stt_lang_changed_cb);
96
97         if (my_voicedata) {
98                 on_destroy(my_voicedata);
99                 my_voicedata = NULL;
100         }
101
102         destroy_voice_recorder();
103 }
104
105 int is_lang_supported_by_voice_input(const char *lang)
106 {
107         PRINTFUNC(DLOG_DEBUG, "Is lang %s supported by voice input", lang);
108         char kbd_lang[6];
109
110         if (NULL == lang)
111                 return FALSE;
112
113         strncpy(kbd_lang, lang, sizeof(kbd_lang));
114         kbd_lang[5] = '\0';
115
116         return (is_lang_supported_by_stt(kbd_lang));
117 }
118
119 void ise_show_stt_popup(void *data)
120 {
121         App_Data* ad = (App_Data*)data;
122
123         if (!ad)
124                 return;
125
126         show_voice_input((Evas_Object*)ad->naviframe, NULL, NULL);
127 }
128
129 void set_disclaimer_flag()
130 {
131         PRINTFUNC(DLOG_DEBUG, "set_disclaimer_flag");
132
133         if (my_voicedata) {
134                 my_voicedata->disclaimer = 1;
135         }
136 }