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