Support prediction_hint_data_set interface 57/160657/14
authorJihoon Kim <jihoon48.kim@samsung.com>
Fri, 27 Oct 2017 08:05:19 +0000 (17:05 +0900)
committerJihoon Kim <jihoon48.kim@samsung.com>
Fri, 15 Dec 2017 06:38:44 +0000 (15:38 +0900)
Change-Id: I7d214806cd62e8252844c34c6181a66992d5a665
Signed-off-by: Jihoon Kim <jihoon48.kim@samsung.com>
CMakeLists.txt
ise-default.xml
packaging/ise-default.spec
src/ise.cpp

index 9a1da8f..4a625eb 100644 (file)
@@ -74,6 +74,7 @@ SET(PKGS_CHECK_MODULES
         capi-media-audio-io
         capi-ui-inputmethod
         smartreply
+        key-manager
         )
 
 IF (with_cbhm)
index 87c5b30..7f7e9c2 100644 (file)
     <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
     <privilege>http://tizen.org/privilege/externalstorage</privilege>
     <privilege>http://tizen.org/privilege/mediastorage</privilege>
+    <privilege>http://tizen.org/privilege/keymanager</privilege>
 </privileges>
 </manifest>
index a31005a..ed9c9f9 100644 (file)
@@ -22,6 +22,7 @@ BuildRequires:  pkgconfig(capi-appfw-preference)
 BuildRequires:  pkgconfig(capi-media-audio-io)
 BuildRequires:  pkgconfig(capi-ui-inputmethod)
 BuildRequires:  pkgconfig(smartreply)
+BuildRequires:  pkgconfig(key-manager)
 Requires:       ise-engine-tables
 Requires:       ise-engine-tables-zh
 Requires:       ise-engine-hangul
index 2b83730..53678e9 100644 (file)
@@ -32,6 +32,7 @@
 #ifdef HAVE_CBHM
 #include <cbhm.h>
 #endif
+#include <ckmc/ckmc-manager.h>
 
 #include "ise.h"
 #include "utils.h"
@@ -92,6 +93,11 @@ static bool g_floating_mode = false;
 static bool g_candidate_more_view = false;
 static bool g_ise_created = false;
 
+static bool g_autofill_exist = false;
+static int g_autofill_hint = 0;
+static string g_autofill_string;
+static vector<string> g_lookup_table_strings;
+static vector<string> g_smartreply_strings;
 #ifdef _MOBILE
 static Ecore_Timer *guideline_timer = NULL;
 #endif
@@ -99,6 +105,9 @@ static Ecore_Timer *guideline_timer = NULL;
 static Ecore_Timer *exit_timer = NULL;
 #endif
 
+static string g_app_id;
+static string g_resource_id;
+
 #define SOFT_CANDIDATE_DELETE_TIME (100.0/1000)
 static Ecore_Timer *g_softcandidate_hide_timer = NULL;
 
@@ -144,10 +153,19 @@ class CandidateEventListener: public EventListener
             const MultiEventDesc &multidesc = dynamic_cast<const MultiEventDesc &>(desc);
             switch (multidesc.type) {
                 case MultiEventDesc::CANDIDATE_ITEM_MOUSE_DOWN:
-                    if (multidesc.index < (int)g_smartreply_size)
-                        ise_send_string(g_softcandidate_string[multidesc.index].c_str());
-                    else
-                        ime_select_candidate(multidesc.index - g_smartreply_size);
+                    if (g_autofill_exist) {
+                        if (multidesc.index == 0)
+                            ise_send_string(g_autofill_string.c_str());
+                        else if (multidesc.index < (int)g_smartreply_size + 1)
+                            ise_send_string(g_softcandidate_string[multidesc.index].c_str());
+                        else
+                            ime_select_candidate(multidesc.index - g_smartreply_size - 1);
+                    } else {
+                        if (multidesc.index < (int)g_smartreply_size)
+                            ise_send_string(g_softcandidate_string[multidesc.index].c_str());
+                        else
+                            ime_select_candidate(multidesc.index - g_smartreply_size);
+                    }
                     break;
                 case MultiEventDesc::CANDIDATE_MORE_VIEW_SHOW:
                     // when more parts shows, click on the candidate will
@@ -209,9 +227,28 @@ public :
 
 static CUIEventCallback callback;
 
+static void update_candidate_table()
+{
+    g_softcandidate_string.clear();
+    vector<string>::iterator iter;
+
+    // add autofill string
+    if (g_autofill_exist)
+        g_softcandidate_string.push_back(g_autofill_string);
+
+    // add lookup table string(s)
+    iter = g_lookup_table_strings.begin();
+    for (; iter != g_lookup_table_strings.end(); ++iter)
+    {
+        g_softcandidate_string.push_back(string(iter->c_str()));
+    }
+
+    ise_update_table(g_softcandidate_string);
+}
+
 static void _input_smartreply_notify_cb(void *user_data)
 {
-    vector<string> candidate_strings;
+    g_smartreply_strings.clear();
     char *candidate;
 
     if (input_smartreply_is_enabled()) {
@@ -227,7 +264,7 @@ static void _input_smartreply_notify_cb(void *user_data)
                 SECURE_LOGD("SmartReply = [%d] %s", i, reply);
                 candidate = reply;
                 if (candidate) {
-                    candidate_strings.push_back(string(candidate));
+                    g_smartreply_strings.push_back(string(candidate));
                     g_smartreply_size++;
                 }
             }
@@ -235,8 +272,8 @@ static void _input_smartreply_notify_cb(void *user_data)
             g_smartreply_reply_exist = true;
 
             ise_app_candidate_show();
-            g_softcandidate_string = candidate_strings;
-            ise_update_table(candidate_strings);
+            g_softcandidate_string = g_smartreply_strings;
+            ise_update_table(g_softcandidate_string);
         }
     }
 }
@@ -1175,11 +1212,50 @@ ise_focus_in(int ic)
     g_keyboard_state.focused_ic = ic;
 }
 
+static string get_autofill_alias()
+{
+    char alias[1024] = { 0 };
+    snprintf(alias, sizeof(alias), "%d", g_autofill_hint);
+
+    return string(alias);
+}
+
+static void save_autofill_data()
+{
+    char *text = NULL;
+    int cursor;
+    ime_get_surrounding_text(-1, -1, &text, &cursor);
+    SECURE_LOGD("surrounding text : %s\n", text);
+    if (!text) return;
+
+    char *password = NULL;
+    ckmc_raw_buffer_s ckmc_data;
+    string alias = get_autofill_alias();
+    ckmc_policy_s ckmc_policy;
+    ckmc_policy.password = password;
+    ckmc_policy.extractable = true;
+
+    ckmc_data.data = (unsigned char *)text;
+    ckmc_data.size = strlen(text);
+
+    if (ckmc_data.size > 0) {
+        // Remove from the key manager
+        ckmc_remove_alias(alias.c_str());
+
+        // Save new data
+        ckmc_save_data(alias.c_str(), ckmc_data, ckmc_policy);
+    }
+
+    free(text);
+}
+
 void
 ise_focus_out(int ic)
 {
     g_keyboard_state.focused_ic = 0;
     _reset_multitap_state(true);
+
+    save_autofill_data();
 }
 
 bool ise_is_guideline_popup_enable_layout(void)
@@ -1836,7 +1912,7 @@ ise_app_candidate_hide()
         return;
     }
 
-    if (g_ic_smartreply != -1)
+    if (g_ic_smartreply != -1 || g_autofill_exist)
         return;
 
     add_softcandidate_hide_timer();
@@ -2229,6 +2305,55 @@ static void ime_app_exit_cb(void *user_data)
 #endif
 }
 
+static void show_autofill_data(Ecore_IMF_Input_Hints input_hints)
+{
+    g_autofill_exist = false;
+    g_autofill_string = string("");
+    string alias;
+
+    alias = get_autofill_alias();
+
+    LOGD("input_hints : %x, input_hints & mask : %x\n", input_hints, input_hints & ECORE_IMF_INPUT_HINT_AUTOFILL_MASK);
+
+    switch (g_autofill_hint)
+    {
+        case ECORE_IMF_INPUT_HINT_AUTOFILL_NAME:
+            LOGD("autofill type : name");
+            break;
+        case ECORE_IMF_INPUT_HINT_AUTOFILL_POSTAL_ADDRESS:
+            LOGD("autofill type : postal address");
+            break;
+        case ECORE_IMF_INPUT_HINT_AUTOFILL_EMAIL_ADDRESS:
+            LOGD("autofill type : email address");
+            break;
+    }
+
+    char *autofill_data = NULL;
+    char *password = NULL;
+    ckmc_raw_buffer_s *test_data2;
+    int ret;
+
+    ret = ckmc_get_data(alias.c_str(), password, &test_data2);
+    if (CKMC_ERROR_NONE != ret) {
+        LOGW("ckmc_get_data error: %d", ret);
+        return;
+    } else {
+        autofill_data = strndup((const char *)test_data2->data, test_data2->size);
+        SECURE_LOGD("data : '%s', len : %d", autofill_data, test_data2->size);
+    }
+
+    if (!autofill_data) {
+        return;
+    }
+
+    g_autofill_string = string(autofill_data);
+    free(autofill_data);
+
+    g_autofill_exist = true;
+    ise_app_candidate_show();
+    update_candidate_table();
+}
+
 static void ime_app_show_cb(int ic, ime_context_h ime_ctx, void *user_data)
 {
     Ise_Context iseContext;
@@ -2264,6 +2389,26 @@ static void ime_app_show_cb(int ic, ime_context_h ime_ctx, void *user_data)
 
     g_ic = ic;
 
+    g_autofill_hint = iseContext.input_hint & ECORE_IMF_INPUT_HINT_AUTOFILL_MASK;
+
+    LOGD("input hint : %x, autofill hint : %x\n", iseContext.input_hint, g_autofill_hint);
+
+    if (g_autofill_hint == 0) {
+        switch (iseContext.layout) {
+            case ECORE_IMF_INPUT_PANEL_LAYOUT_EMAIL:
+                g_autofill_hint = ECORE_IMF_INPUT_HINT_AUTOFILL_EMAIL_ADDRESS;
+                break;
+            case ECORE_IMF_INPUT_PANEL_LAYOUT_PHONENUMBER:
+                g_autofill_hint = ECORE_IMF_INPUT_HINT_AUTOFILL_PHONE;
+                break;
+            default:
+                break;
+        }
+    }
+
+    // show autofill data
+    show_autofill_data(iseContext.input_hint);
+
     //g_ise_common->set_keyboard_ise_by_uuid(KEYBD_ISE_UUID);
 
     /* Don't update screen until all the information is correctly set */
@@ -2364,6 +2509,17 @@ static void ime_app_focus_out_cb(int context_id, void *user_data)
     g_smartreply_size = 0;
     input_smartreply_deinit();
     g_ic_smartreply = -1;
+
+    g_autofill_exist = false;
+    g_autofill_hint = 0;
+
+    g_app_id = string("");
+    g_resource_id = string("");
+
+    g_autofill_string = string("");
+    g_smartreply_strings.clear();
+    g_lookup_table_strings.clear();
+    g_softcandidate_string.clear();
 }
 
 static void ime_app_layout_set_cb(Ecore_IMF_Input_Panel_Layout layout, void *user_data)
@@ -2487,10 +2643,13 @@ static void ime_app_lookup_table_changed_cb(Eina_List *list, void *user_data)
     void *data;
     Eina_List *l;
 
+    g_lookup_table_strings.clear();
+
     if (list) {
         EINA_LIST_FOREACH(list, l, data) {
             candidate = (char *)data;
             if (candidate) {
+                g_lookup_table_strings.push_back(string(candidate));
                 candidate_strings.push_back(string(candidate));
             }
         }
@@ -2509,8 +2668,7 @@ static void ime_app_lookup_table_changed_cb(Eina_List *list, void *user_data)
         }
     }
 
-    g_softcandidate_string = candidate_strings;
-    ise_update_table(candidate_strings);
+    update_candidate_table();
 }
 
 #ifdef _WEARABLE
@@ -2655,6 +2813,16 @@ static void ime_app_mime_type_set_request_cb(const char *mime_types, void *user_
 #endif
 }
 
+static void ime_app_prediction_hint_data_set_cb(const char *key, const char *value, void *user_data)
+{
+    SECURE_LOGD("key : %s, value : %s\n", key, value);
+
+    if (string(key) == "appid")
+        g_app_id = string(value ? value : "");
+    else if (string(key) == "res_id")
+        g_resource_id = string(value ? value : "");
+}
+
 #ifdef __cplusplus
 extern "C"{
 #endif
@@ -2693,10 +2861,12 @@ EXPORTED void ime_app_main(int argc, char **argv)
 
     ime_event_set_prediction_hint_set_cb(ime_app_prediction_hint_set_cb, NULL);
     ime_event_set_mime_type_set_request_cb(ime_app_mime_type_set_request_cb, NULL);
+    ime_event_set_prediction_hint_data_set_cb(ime_app_prediction_hint_data_set_cb, NULL);
 
 #if DEFER_ISE_CREATION
     ime_set_window_creation_defer_flag(TRUE);
 #endif
+
     ime_run(&basic_callback, NULL);
 }
 #ifdef __cplusplus