#include "w-input-keyboard.h"
#include "w-input-stt-ise.h"
#include "w-input-emoticon.h"
-#include "w-input-smartreply.h"
#include <stt.h>
static Elm_Object_Item *it_empty;
static Elm_Object_Item *it_title;
-static unsigned int g_smartreply_item_size = 0; /* Current Smartreply item size */
static unsigned int g_template_item_size = 0; /* Current Template item size */
Evas_Coord last_step; // 0 ~ 9 for gesture, 10~11 for rotary
void _create_genlist_items(void* user_data);
void _create_header_items(void *user_data);
void _update_genlist_items(void *user_data);
-unsigned int _update_smartreply_items(void *user_data);
unsigned int _update_template_items(void *user_data);
unsigned int _update_user_template_items(void *user_data);
static void _popup_close_cb(void *data, Evas_Object *obj, void *event_info);
static void _popup_back_cb(void *data, Evas_Object *obj, void *event_info);
static void input_type_deinit(void);
-bool __compare_string(const char * src, const char * dst);
-
void _init_app_data(App_Data* app_data)
{
app_data->win_main = NULL;
ise_show_stt_popup(ad);
}
-static void _input_smartreply_notify_cb(void *user_data)
-{
- ecore_main_loop_iterate();
- _update_genlist_items((void *)app_data);
-}
-
static void _input_template_notify_cb(void *user_data)
{
_update_genlist_items((void *)app_data);
input_keyboard_launch(ad->win_main, data);
}
-static void __ise_smartreply_gl_sel(void *data, Evas_Object *obj, void *event_info)
-{
- Elm_Object_Item *item = (Elm_Object_Item *) event_info;
-
- if (item) {
- elm_genlist_item_selected_set(item, EINA_FALSE);
-
- int index = (intptr_t) elm_object_item_data_get(item);
-
- int type;
- char *reply = input_smartreply_get_nth_item(index, &type);
- if (reply) {
- input_smartreply_send_feedback(reply);
- reply_to_sender_by_callback(reply, "smartreply", NULL, NULL);
- free(reply);
- elm_exit();
- }
- }
-}
-
static void __ise_template_gl_sel(void *data, Evas_Object *obj, void *event_info)
{
Elm_Object_Item *item = (Elm_Object_Item *) event_info;
return NULL;
}
-static char * __ise_smartreply_gl_text_get(void *data, Evas_Object *obj, const char *part)
-{
- if(!strcmp(part, "elm.text")) {
- int index;
- char *reply = NULL;
- index = (intptr_t)data;
- if (index < 0)
- return NULL;
-
- reply = input_smartreply_get_nth_item(index, NULL);
- if (reply == NULL)
- return NULL;
-
- return reply;
- }
- return NULL;
-}
-
static void __ise_gl_lang_changed(void *data, Evas_Object *obj, void *event_info)
{
//Update genlist items. The Item texts will be translated in the _gl_text_get().
_create_header_items(user_data);
- if (input_smartreply_is_enabled())
- g_smartreply_item_size = _update_smartreply_items(user_data);
- else
- g_smartreply_item_size = 0;
-
g_template_item_size = _update_template_items(user_data);
if (g_input_template_data.input_template_array_len > 0) {
elm_genlist_item_show(item, ELM_GENLIST_ITEM_SCROLLTO_MIDDLE);
}
-unsigned int _update_smartreply_items(void *user_data)
-{
- App_Data* app_data;
-
- Elm_Object_Item *first;
-
- unsigned int i = 0;
- unsigned int len = 0;
- unsigned int item_size = 0;
-
- app_data = (App_Data *)user_data;
-
- if (app_data == NULL) {
- PRINTFUNC(DLOG_ERROR, "Can not get app_data");
- return item_size;
- }
-
- if (app_data->genlist == NULL) {
- /* smartreply will update when genlist is exist only */
- PRINTFUNC(DLOG_ERROR, "Can not get getlist");
- return item_size;
- }
-
- /* Move to smartreply */
- first = elm_genlist_first_item_get(app_data->genlist);
- elm_genlist_item_next_get(first);
-
- if (input_smartreply_is_enabled() == false)
- return item_size;
-
- /* Append newly added smartreply list */
- len = input_smartreply_get_reply_num();
-
- if (len > 0) {
- const std::vector<TemplateData> template_list = input_template_get_list();
-
- Elm_Genlist_Item_Class *itc;
-
- itc = elm_genlist_item_class_new();
- itc->item_style = "1text";
- itc->func.text_get = __ise_smartreply_gl_text_get;
- itc->func.content_get = NULL;
- itc->func.state_get = NULL;
- itc->func.del = NULL;
-
- for (i = 0; i < len; i++) {
- char *reply = (char *)"hello";
- unsigned int j;
- bool matched;
-
- matched = false;
-
- int type;
- reply = input_smartreply_get_nth_item(i, &type);
- if (reply == NULL)
- continue;
- SECURE_LOGD("SmartReply = [%d]%s", i, reply);
-
- for (j = 0; j < template_list.size(); j++) {
- const char *template_str;
-
- if (template_list[j].use_gettext)
- template_str = gettext(template_list[j].text.c_str());
- else
- template_str = template_list[j].text.c_str();
-
- if (!__compare_string(reply, template_str)) {
- matched = true;
- break;
- }
- }
-
- if (matched == true) {
- free(reply);
- continue;
- }
-
- elm_genlist_item_append(app_data->genlist,
- itc,
- (void *)(uintptr_t)i,
- NULL,
- ELM_GENLIST_ITEM_NONE,
- __ise_smartreply_gl_sel,
- app_data);
-
- item_size++;
- free(reply);
- if (item_size >= 3) {
- break;
- }
- }
- elm_genlist_item_class_free(itc);
- }
- return item_size;
-}
-
static void _drawing_item_clicked_cb(void *data, Evas_Object * obj, void *event_info)
{
PRINTFUNC(DLOG_DEBUG, "%s", __func__);
App_Data* app_data;
Elm_Object_Item *first;
- Elm_Object_Item *menu;
- Elm_Object_Item *pos;
unsigned int i = 0;
unsigned int item_size = 0;
first = elm_genlist_first_item_get(app_data->genlist);
if (first == NULL)
return 0;
- menu = elm_genlist_item_next_get(first);
-
- pos = menu;
- /* move to smartreply next if it need */
- if (input_smartreply_is_enabled()) {
- unsigned int j = 0;
-
- for (j = 0; j < g_smartreply_item_size; j++) {
- if (pos == NULL)
- break;
-
- pos = elm_genlist_item_next_get(pos);
- }
- }
+ elm_genlist_item_next_get(first);
/* Append New Template list */
const std::vector<TemplateData> template_list = input_template_get_list();
itc->func.del = NULL;
for (i = 0; i < template_list.size(); i++) {
- pos = elm_genlist_item_append(app_data->genlist,
+ elm_genlist_item_append(app_data->genlist,
itc,
(void *)(uintptr_t)i,
NULL,
return item_size;
}
-bool __compare_string(const char * smart_str, const char * template_str)
-{
- int src_len = 0;
- int dst_len = 0;
- bool ret = true;
-
- if(!smart_str||!template_str)
- return ret;
-
- src_len = strlen(smart_str);
- dst_len = strlen(template_str);
-
- if(smart_str[src_len-1] == '.')
- src_len--;
-
- while(template_str[dst_len-1] == ' ')
- dst_len--;
- if(template_str[dst_len-1] == '.')
- dst_len--;
-
- dst_len = (dst_len > src_len)? dst_len : src_len;
-
- if(!strncmp(smart_str, template_str, (size_t)dst_len))
- ret = false;
-
- return (ret);
-}
-
bool _app_create(void* user_data)
{
// App_Data* app_data = NULL;
input_keyboard_init(service);
- input_smartreply_init(service);
- input_smartreply_set_notify(_input_smartreply_notify_cb, NULL);
-
- if (input_smartreply_is_enabled())
- input_smartreply_get_reply_async();
-
input_template_init(service);
input_template_set_notify(_input_template_notify_cb, NULL);
free(app_data->shared_res_path);
input_keyboard_deinit();
- input_smartreply_deinit();
input_template_unset_notify();
input_template_deinit();
+++ /dev/null
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "Debug.h"
-
-#include <glib.h>
-#include <stdlib.h>
-#include <string.h>
-#include <locale.h>
-
-#include <dlog.h>
-#include <vconf.h>
-//#include <csc-feature.h>
-#include <smartreply_service.h>
-
-#include "w-input-smartreply.h"
-
-#ifdef SUPPORT_SMART_ACTION
-#include "w-input-smartaction.h"
-#endif
-
-#ifndef INPUT_SMARTREPLY_VCONF
-#define INPUT_SMARTREPLY_VCONF "db/wms/smart_reply"
-#endif
-
-
-typedef struct _InputSmartreplyData InputSmartreplyData;
-
-struct _InputSmartreplyData
-{
- char *caller_id;
- char *sender;
- char *message;
- char *lang;
-
- int enabled;
-
- input_smartreply_changed callback;
- void *user_data;
-
- smartreply_reply_h *candidate_list;
- int candidate_list_len;
- bool enable_location;
-};
-
-
-static void _input_smartreply_get_reply_callback(int handle, int error,
- smartreply_reply_h* candidate_list, int length);
-/* Disable smartreply on/off feature
-static void _input_smartreply_vconf_changed(keynode_t *key, void *data);
-*/
-
-
-static InputSmartreplyData *g_input_smartreply_data = NULL;
-
-static void _input_smartreply_get_reply_callback(int handle, int error,
- smartreply_reply_h* candidate_list, int length)
-{
- if (g_input_smartreply_data == NULL) {
- PRINTFUNC(DLOG_ERROR, "InputSmartreplyData uninitialized");
- return;
- }
-
- if (g_input_smartreply_data->candidate_list) {
- int ret;
-
- ret = smartreply_service_destroy_list(g_input_smartreply_data->candidate_list);
- if (ret != SMARTREPLY_ERROR_NONE)
- PRINTFUNC(DLOG_ERROR, "can not destroy list : %d", ret);
- }
-
- if (error != SMARTREPLY_ERROR_NONE) {
- PRINTFUNC(DLOG_ERROR, "can not get candidate list : %d", error);
-
- g_input_smartreply_data->candidate_list = NULL;
- g_input_smartreply_data->candidate_list_len = 0;
-
- return;
- }
-
- g_input_smartreply_data->candidate_list = candidate_list;
- g_input_smartreply_data->candidate_list_len = length;
-
- if (g_input_smartreply_data->callback)
- g_input_smartreply_data->callback(g_input_smartreply_data->user_data);
-}
-
-static bool _smartreply_check_here_map_support(void)
-{
- return true;
-}
-
-/* Disable smartreply on/off feature
-static void _input_smartreply_vconf_changed(keynode_t *key, void *data)
-{
- int enabled = 0;
-
- if (g_input_smartreply_data == NULL) {
- PRINTFUNC(DLOG_ERROR, "InputSmartreplyData uninitialized");
- return;
- }
-
- enabled = vconf_keynode_get_int(key);
- if (g_input_smartreply_data->enabled == enabled)
- return;
-
- g_input_smartreply_data->enabled = enabled;
-
- if (g_input_smartreply_data->enabled && g_input_smartreply_data->candidate_list == NULL) {
- input_smartreply_get_reply_async();
- return;
- }
-
- if (g_input_smartreply_data->callback)
- g_input_smartreply_data->callback(g_input_smartreply_data->user_data);
-}
-*/
-
-bool input_smartreply_init(app_control_h app_control)
-{
- int ret;
-
- char *caller_id = NULL;
- char *sender = NULL;
- char *message = NULL;
-
- /* Disable smartreply on/off feature
- int enabled = 0;
- */
-
- ret = app_control_get_extra_data(app_control,
- APP_CONTROL_DATA_INPUT_PREDICTION_HINT, &message);
-
- if (ret != APP_CONTROL_ERROR_NONE) {
- PRINTFUNC(DLOG_WARN, "Can not get APP_CONTROL_DATA_INPUT_PREDICTION_HINT %d", ret);
- free(message);
-
- return false;
- }
-
- ret = app_control_get_caller(app_control, &caller_id);
-
- if (ret != APP_CONTROL_ERROR_NONE)
- PRINTFUNC(DLOG_WARN, "Can not get caller id %d", ret);
-
- ret = app_control_get_extra_data(app_control,
- "template_sender", &sender);
-
- if (ret != APP_CONTROL_ERROR_NONE)
- PRINTFUNC(DLOG_WARN, "Can not get template_sender %d", ret);
-
- if (g_input_smartreply_data == NULL) {
- g_input_smartreply_data = (InputSmartreplyData *)calloc(1, sizeof(InputSmartreplyData));
- if (g_input_smartreply_data == NULL) {
- PRINTFUNC(DLOG_ERROR, "Can not alloc InputSmartreplyData");
- if (message)
- free(message);
-
- if (caller_id)
- free(caller_id);
-
- if (sender)
- free(sender);
-
- return false;
- }
- }
-
- if (g_input_smartreply_data->caller_id)
- free(g_input_smartreply_data->caller_id);
-
- if (g_input_smartreply_data->sender)
- free(g_input_smartreply_data->sender);
-
- if (g_input_smartreply_data->message)
- free(g_input_smartreply_data->message);
-
- if (g_input_smartreply_data->lang)
- free(g_input_smartreply_data->lang);
-
- if (g_input_smartreply_data->candidate_list) {
- ret = smartreply_service_destroy_list(g_input_smartreply_data->candidate_list);
- if (ret != SMARTREPLY_ERROR_NONE)
- PRINTFUNC(DLOG_ERROR, "can not destroy list : %d", ret);
- }
-
- g_input_smartreply_data->caller_id = caller_id;
- g_input_smartreply_data->sender = sender;
- g_input_smartreply_data->message = message;
- g_input_smartreply_data->lang = NULL;
-
- g_input_smartreply_data->enabled = 1;
-
- g_input_smartreply_data->callback = NULL;
- g_input_smartreply_data->user_data = NULL;
-
- g_input_smartreply_data->candidate_list = NULL;
- g_input_smartreply_data->candidate_list_len = 0;
-
- g_input_smartreply_data->enable_location = _smartreply_check_here_map_support();
-
-
- /* Disable smartreply on/off feature
- ret = vconf_get_int(INPUT_SMARTREPLY_VCONF, &enabled);
- if (ret == -1)
- PRINTFUNC(DLOG_ERROR, "can not get vconf : %s", INPUT_SMARTREPLY_VCONF);
-
- g_input_smartreply_data->enabled = enabled;
-
- ret = vconf_notify_key_changed(INPUT_SMARTREPLY_VCONF,
- _input_smartreply_vconf_changed, NULL);
- if (ret == -1)
- PRINTFUNC(DLOG_ERROR, "Can not create vconf notify : %s", INPUT_SMARTREPLY_VCONF);
- */
-
- return true;
-}
-
-void input_smartreply_deinit(void)
-{
- if (g_input_smartreply_data == NULL) {
- PRINTFUNC(DLOG_WARN, "InputSmartreplyData uninitialized");
- return;
- }
-
- if (g_input_smartreply_data->caller_id)
- free(g_input_smartreply_data->caller_id);
-
- if (g_input_smartreply_data->sender)
- free(g_input_smartreply_data->sender);
-
- if (g_input_smartreply_data->message)
- free(g_input_smartreply_data->message);
-
-
- if (g_input_smartreply_data->candidate_list) {
- int ret;
-
- ret = smartreply_service_destroy_list(g_input_smartreply_data->candidate_list);
- if (ret != SMARTREPLY_ERROR_NONE)
- PRINTFUNC(DLOG_ERROR, "can not destroy list : %d", ret);
- }
-
- input_smartreply_unset_notify();
-
- /* Disable smartreply on/off feature
- vconf_ignore_key_changed(INPUT_SMARTREPLY_VCONF,
- _input_smartreply_vconf_changed);
- */
-
- free(g_input_smartreply_data);
- g_input_smartreply_data = NULL;
-
- return;
-}
-
-bool input_smartreply_get_reply(void)
-{
- int ret;
-
- smartreply_reply_h *candidate_list = NULL;
- int candidate_list_len = 0;
-
- if (g_input_smartreply_data == NULL) {
- PRINTFUNC(DLOG_ERROR, "InputSmartreplyData uninitialized");
- return false;
- }
-
- if (g_input_smartreply_data->message == NULL) {
- PRINTFUNC(DLOG_ERROR, "message is empty");
- return false;
- }
-
- if (g_input_smartreply_data->enabled == 0) {
- PRINTFUNC(DLOG_WARN, "Smartreply is disabled");
- return false;
- }
-
- ret = smartreply_service_get_replies(g_input_smartreply_data->caller_id,
- g_input_smartreply_data->sender,
- g_input_smartreply_data->message,
- &candidate_list,
- &candidate_list_len);
-
- if (ret != SMARTREPLY_ERROR_NONE) {
- PRINTFUNC(DLOG_ERROR, "Can not get replies : %d", ret);
- return false;
- }
-
- if (g_input_smartreply_data->candidate_list) {
- ret = smartreply_service_destroy_list(g_input_smartreply_data->candidate_list);
- if (ret != SMARTREPLY_ERROR_NONE)
- PRINTFUNC(DLOG_ERROR, "can not destroy list : %d", ret);
- }
-
- g_input_smartreply_data->candidate_list = candidate_list;
- g_input_smartreply_data->candidate_list_len = candidate_list_len;
-
- return true;
-}
-
-bool input_smartreply_get_reply_async(void)
-{
- if (g_input_smartreply_data == NULL) {
- PRINTFUNC(DLOG_ERROR, "InputSmartreplyData uninitialized");
- return false;
- }
-
- if (g_input_smartreply_data->message == NULL) {
- PRINTFUNC(DLOG_ERROR, "message is empty");
- return false;
- }
-
- if (g_input_smartreply_data->enabled == 0) {
- PRINTFUNC(DLOG_WARN, "Smartreply is disabled");
- return false;
- }
-
- smartreply_service_get_replies_async(g_input_smartreply_data->caller_id,
- g_input_smartreply_data->sender,
- g_input_smartreply_data->message,
- _input_smartreply_get_reply_callback);
-
- return true;
-}
-
-int input_smartreply_get_reply_num(void)
-{
- if (g_input_smartreply_data == NULL) {
- PRINTFUNC(DLOG_ERROR, "InputSmartreplyData uninitialized");
- return 0;
- }
-
- if (g_input_smartreply_data->enabled == 0) {
- PRINTFUNC(DLOG_WARN, "Smartreply is disabled");
- return 0;
- }
-
- return g_input_smartreply_data->candidate_list_len;
-}
-
-char *input_smartreply_get_nth_item(int index, int *type)
-{
- int ret;
- char *message = NULL;
-
- if (g_input_smartreply_data == NULL) {
- PRINTFUNC(DLOG_ERROR, "InputSmartreplyData uninitialized");
- return NULL;
- }
-
- if (g_input_smartreply_data->candidate_list == NULL) {
- PRINTFUNC(DLOG_ERROR, "Can not get candidate list");
- return NULL;
- }
-
- if (g_input_smartreply_data->enabled == 0) {
- PRINTFUNC(DLOG_WARN, "Smartreply is disabled");
- return NULL;
- }
-
-
- ret = smartreply_service_get_nth_reply_message(g_input_smartreply_data->candidate_list,
- index,
- &message);
-
- if (ret != SMARTREPLY_ERROR_NONE) {
- PRINTFUNC(DLOG_ERROR, "Can not get message from index %d : %d", index, ret);
- return NULL;
- }
-
- return message;
-}
-
-bool input_smartreply_send_feedback(const char *str)
-{
- int ret;
-
- if (g_input_smartreply_data == NULL) {
- PRINTFUNC(DLOG_ERROR, "InputSmartreplyData uninitialized");
- return false;
- }
-
- if (str == NULL) {
- PRINTFUNC(DLOG_ERROR, "str is empty");
- return false;
- }
-
- ret = smartreply_service_record_user_reply(g_input_smartreply_data->caller_id,
- g_input_smartreply_data->sender,
- g_input_smartreply_data->message,
- str);
-
- if (ret != SMARTREPLY_ERROR_NONE) {
- PRINTFUNC(DLOG_ERROR, "Can not send feedback : %d", ret);
- return false;
- }
-
- return true;
-}
-
-
-
-void input_smartreply_set_notify(input_smartreply_changed callback,
- void *user_data)
-{
- if (callback == NULL) {
- PRINTFUNC(DLOG_ERROR, "empty callback function");
- return;
- }
-
- if (g_input_smartreply_data == NULL) {
- PRINTFUNC(DLOG_WARN, "InputSmartreplyData uninitialized");
- return;
- }
-
- g_input_smartreply_data->callback = callback;
- g_input_smartreply_data->user_data = user_data;
-}
-
-
-void input_smartreply_unset_notify(void)
-{
- if (g_input_smartreply_data == NULL) {
- PRINTFUNC(DLOG_WARN, "InputSmartreplyData uninitialized");
- return;
- }
-
- g_input_smartreply_data->callback = NULL;
- g_input_smartreply_data->user_data = NULL;
-}
-
-bool input_smartreply_is_enabled(void)
-{
- if (g_input_smartreply_data == NULL) {
- PRINTFUNC(DLOG_WARN, "InputSmartreplyData uninitialized");
- return false;
- }
-
- if (g_input_smartreply_data->enabled)
- return true;
-
- return false;
-}