Fix issue that Black screen displayed when exiting Voice input screen
[platform/core/uifw/inputdelegator.git] / src / w-input-stt-voice.cpp
index 0aa4b21..d39c87c 100755 (executable)
@@ -32,6 +32,7 @@
 #include "w-input-stt-voice.h"
 #include "w-input-stt-engine.h"
 #include "w-input-stt-ise.h"
+#include "voice-recorder.h"
 
 using namespace std;
 
@@ -473,7 +474,12 @@ static void on_confirm_button_clicked_cb(void *data, Evas_Object *obj, void *eve
 
        PRINTFUNC(DLOG_DEBUG, "result_text = %s", result_text.c_str());
 
-       reply_to_sender_by_callback(result_text.c_str(), "voice");
+       char *filePath = NULL;
+       voice_recorder *vr = _voice_recorder_get_data();
+       if (!vr)
+               filePath = vr->file_path;
+       char *path[] = {filePath, };
+       reply_to_sender_by_callback(result_text.c_str(), "voice", (const char **)path);
        destroy_voice();
        powerUnlock();
        ui_app_exit();
@@ -563,14 +569,13 @@ static Eina_Bool _idler_cb(void *data)
        Evas_Object *canvas = elm_object_part_content_get(voicedata->layout_main, "EFFECT_BG");
 
        is::ui::WInputSttMicEffect *ieffect = new is::ui::WInputSttMicEffect();
-       if (ieffect)
+       if (ieffect) {
                ieffect->SetSttHandle(voicedata->sttmanager->GetSttHandle());
 
-       is::ui::MicEffector *effector = new is::ui::MicEffector(canvas, voicedata->layout_main, *ieffect);
-       voicedata->ieffect = ieffect;
-       voicedata->effector = effector;
+               is::ui::MicEffector *effector = new is::ui::MicEffector(canvas, voicedata->layout_main, *ieffect);
+               voicedata->ieffect = ieffect;
+               voicedata->effector = effector;
 
-       if (ieffect) {
                ieffect->SetProgressBar(voicedata->progressbar);
                ieffect->SetSttHandle(voicedata->sttmanager->GetSttHandle());
        }
@@ -779,6 +784,9 @@ static Eina_Bool _start_timer_cb(void* data)
                }
                voicedata->start_timer = NULL;
        }
+
+       start_voice_recorder();
+
        return ECORE_CALLBACK_CANCEL;
 }
 
@@ -904,7 +912,8 @@ static char *__get_genlist_title_label(void *data, Evas_Object *obj, const char
 
 char *__get_genlist_item_label(void *data, Evas_Object *obj, const char *part)
 {
-       char text[128] = {0, };
+       const int BUF_LEN = 128;
+       char text[BUF_LEN] = {'\0', };
 
        if(!strcmp(part, "elm.text"))
        {
@@ -919,10 +928,10 @@ char *__get_genlist_item_label(void *data, Evas_Object *obj, const char *part)
                                if(p) {
                                        strncpy(text, s, p-s);
                                } else {
-                                       strncpy(text, s, strlen(s));
+                                       snprintf(text, BUF_LEN, "%s", s);
                                }
                        } else {
-                               strncpy(text, "", strlen(""));
+                               snprintf(text, BUF_LEN, "%s", "");
                        }
                }
                return strdup(text);
@@ -954,11 +963,10 @@ char *__get_genlist_item_label(void *data, Evas_Object *obj, const char *part)
                                if(p) {
                                        strncpy(text, p+1, strlen(s)-(p-s)-2);
                                } else {
-                                       strncpy(text, s, strlen(s));
-                                       text[strlen(s)] = '\0';
+                                       snprintf(text, BUF_LEN, "%s", s);
                                }
                        } else {
-                               strncpy(text, "", strlen(""));
+                               snprintf(text, BUF_LEN, "%s", "");
                        }
                        return strdup(text);
                }
@@ -1623,6 +1631,13 @@ static Evas_Object *create_progressbar(Evas_Object *parent)
        return progressbar;
 }
 
+static Eina_Bool _custom_back_cb(void *data, Elm_Object_Item *it)
+{
+       PRINTFUNC(DLOG_DEBUG, "");
+       _back_to_genlist_for_selector();
+       return EINA_TRUE;
+}
+
 static Evas_Object *create_fullview(Evas_Object *parent, VoiceData *r_voicedata)
 {
        PRINTFUNC(NO_PRINT, "");
@@ -1686,7 +1701,6 @@ static Evas_Object *create_fullview(Evas_Object *parent, VoiceData *r_voicedata)
 
        elm_object_part_content_set(layout_main, "EFFECT_BG", canvas);
 
-
        // MIC Button
        Evas_Object *m_mic_button = elm_button_add(layout_main);
        elm_object_style_set(m_mic_button, "vic/micbutton");
@@ -1762,6 +1776,43 @@ int is_lang_supported_by_stt(char lang[])
        return FALSE;
 }
 
+int init_voicedata(VoiceData *r_voicedata)
+{
+       VoiceData *voicedata = (VoiceData *)r_voicedata;
+       if (!voicedata) {
+               return FALSE;
+       }
+
+       voicedata->voicefw_state = 0;
+       voicedata->voicefw_handle = NULL;
+       voicedata->naviframe = NULL;
+       voicedata->layout_main = NULL;
+       voicedata->progressbar = NULL;
+       voicedata->scroller = NULL;
+       voicedata->main_entry = NULL;
+       voicedata->mic_button = NULL;
+       voicedata->state = STT_STATE_VAL_INIT;
+       voicedata->kbd_lang = NULL;
+       voicedata->start_timer = NULL;
+       voicedata->refresh_timer = NULL;
+       voicedata->progressbar_timer = NULL;
+       voicedata->textblock_timer = NULL;
+       voicedata->guide_text_timer = NULL;
+       voicedata->btn_disabling_timer = NULL;
+       voicedata->power_unlock_timer = NULL;
+
+       voicedata->partial_result = NULL;
+       voicedata->result_type = 0;
+       voicedata->disclaimer = 1;
+       voicedata->mo = NULL;
+       voicedata->sttfeedback = NULL;
+       voicedata->sttmanager = NULL;
+       voicedata->ieffect = NULL;
+       voicedata->effector = NULL;
+
+       return TRUE;
+}
+
 int init_voice(Evas_Object *parent, const char *lang, VoiceData *r_voicedata)
 {
        PRINTFUNC(DLOG_DEBUG, "[init_voice]");
@@ -1808,6 +1859,8 @@ int init_voice(Evas_Object *parent, const char *lang, VoiceData *r_voicedata)
                voicedata->textblock_timer = NULL;
        }
 
+       init_voice_recorder(NULL);
+
        return TRUE;
 }
 
@@ -1818,6 +1871,12 @@ static Eina_Bool init_view(void *data)
        if(voicedata == NULL)
                return ECORE_CALLBACK_CANCEL;
 
+       const char *item_style = NULL;
+       if (_WEARABLE)
+               item_style = "empty";
+       Elm_Object_Item *nf_voice_item = elm_naviframe_item_push(voicedata->naviframe, NULL, NULL, NULL, NULL, item_style);
+       elm_naviframe_item_pop_cb_set(nf_voice_item, _custom_back_cb, NULL);
+
        voicedata->layout_main = create_fullview(voicedata->naviframe, voicedata);
 
        if (voicedata->layout_main) {