Separate autofill code 46/166646/8
authorJihoon Kim <jihoon48.kim@samsung.com>
Thu, 11 Jan 2018 09:22:45 +0000 (18:22 +0900)
committerJihoon Kim <jihoon48.kim@samsung.com>
Fri, 12 Jan 2018 06:25:45 +0000 (15:25 +0900)
Change-Id: Ib8e67496569844935539635e83b792f6fe3d9f0f
Signed-off-by: Jihoon Kim <jihoon48.kim@samsung.com>
CMakeLists.txt
src/autofill.cpp [new file with mode: 0644]
src/include/autofill.h [new file with mode: 0644]
src/ise.cpp

index 703a7bc..bc0f59b 100644 (file)
@@ -22,6 +22,7 @@ SET(ISE_SRCS
     src/candidate/candidate.cpp
     src/candidate/efl/candidate-efl.cpp
     src/candidate/efl/candidate-multiline-efl.cpp
+    src/autofill.cpp
 
     src/ise-emoticon-list.cpp
     src/ise-emoticon-mode.cpp
diff --git a/src/autofill.cpp b/src/autofill.cpp
new file mode 100644 (file)
index 0000000..0d549fd
--- /dev/null
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2018 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 "autofill.h"
+#include <dlog.h>
+#include <string>
+#include <Ecore_IMF.h>
+#include <ckmc/ckmc-manager.h>
+
+using namespace std;
+
+static string get_autofill_alias(Ecore_IMF_Input_Hints input_hints)
+{
+    int autofill_hint = input_hints & ECORE_IMF_INPUT_HINT_AUTOFILL_MASK;
+
+    char alias[1024] = { 0 };
+    snprintf(alias, sizeof(alias), "%d", autofill_hint);
+
+    return string(alias);
+}
+
+Eina_Bool autofill_save_string(Ecore_IMF_Input_Hints input_hints, const char *text)
+{
+    if ((input_hints & ECORE_IMF_INPUT_HINT_AUTOFILL_MASK) == 0)
+        return EINA_FALSE;
+
+    if (!text) return EINA_FALSE;
+
+    char *password = NULL;
+    ckmc_raw_buffer_s ckmc_data;
+    string alias = get_autofill_alias(input_hints);
+    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);
+
+        return EINA_TRUE;
+    } else {
+        return EINA_FALSE;
+    }
+}
+
+char *autofill_get_string(Ecore_IMF_Input_Hints input_hints)
+{
+    string alias;
+    string autofill_string;
+    char *autofill_data = NULL;
+    char *password = NULL;
+    ckmc_raw_buffer_s *ckmc_data = NULL;
+    int ret;
+
+    int autofill_hint = input_hints & ECORE_IMF_INPUT_HINT_AUTOFILL_MASK;
+    LOGD("input_hints : %x, input_hints & mask : %x\n", input_hints, input_hints & ECORE_IMF_INPUT_HINT_AUTOFILL_MASK);
+
+    if (autofill_hint == 0)
+        return NULL;
+
+    alias = get_autofill_alias(input_hints);
+
+    switch (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;
+    }
+
+    ret = ckmc_get_data(alias.c_str(), password, &ckmc_data);
+    if (CKMC_ERROR_NONE != ret) {
+        LOGW("ckmc_get_data error: %d", ret);
+        return NULL;
+    } else {
+        if (!ckmc_data)
+            return NULL;
+
+        autofill_data = strndup((const char *)ckmc_data->data, ckmc_data->size);
+        SECURE_LOGD("data : '%s', len : %d", autofill_data, ckmc_data->size);
+    }
+
+    if (autofill_data) {
+        autofill_string = string(autofill_data);
+        free(autofill_data);
+    } else {
+        return NULL;
+    }
+
+    return strdup(autofill_string.c_str());
+}
diff --git a/src/include/autofill.h b/src/include/autofill.h
new file mode 100644 (file)
index 0000000..374cb6e
--- /dev/null
@@ -0,0 +1,39 @@
+#ifndef _AUTOFILL_H_
+#define _AUTOFILL_H_
+
+#include <Ecore_IMF.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Save autofill string.
+ *
+ * @since_tizen 5.0
+ *
+ * @privlevel internal
+ *
+ * @param[in] input_hints input hint
+ * @param[in] text autofill string
+ */
+Eina_Bool autofill_save_string(Ecore_IMF_Input_Hints input_hints, const char *text);
+
+/**
+ * @brief Get autofill string.
+ *
+ * @since_tizen 5.0
+ *
+ * @privlevel internal
+ *
+ * @param[in] input_hints input hint
+ *
+ * @return a newly allocated autofill string. Free with free() when no longer needed.
+ */
+char *autofill_get_string(Ecore_IMF_Input_Hints input_hints);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
index fc979ff..d321d73 100644 (file)
@@ -32,8 +32,7 @@
 #ifdef HAVE_CBHM
 #include <cbhm.h>
 #endif
-#include <ckmc/ckmc-manager.h>
-
+#include "autofill.h"
 #include "ise.h"
 #include "utils.h"
 #include "option.h"
@@ -154,12 +153,17 @@ class CandidateEventListener: public EventListener
             switch (multidesc.type) {
                 case MultiEventDesc::CANDIDATE_ITEM_MOUSE_DOWN:
                     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)
+                        if (multidesc.index == 0) {
+                            char *text = autofill_get_string((Ecore_IMF_Input_Hints)g_autofill_hint);
+                            if (text) {
+                                ise_send_string(text);
+                                free(text);
+                            }
+                        } else if (multidesc.index < (int)g_smartreply_size + 1) {
                             ise_send_string(g_softcandidate_string[multidesc.index].c_str());
-                        else
+                        } 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());
@@ -1212,14 +1216,6 @@ 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;
@@ -1232,23 +1228,7 @@ static void save_autofill_data()
     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);
-    }
+    autofill_save_string((Ecore_IMF_Input_Hints)g_autofill_hint, text);
 
     free(text);
 }
@@ -2325,56 +2305,22 @@ static void ime_app_exit_cb(void *user_data)
 static void show_autofill_data(Ecore_IMF_Input_Hints input_hints)
 {
     g_autofill_exist = false;
-    g_autofill_string = string("");
-    string alias;
-
-    LOGD("input_hints : %x, input_hints & mask : %x\n", input_hints, input_hints & ECORE_IMF_INPUT_HINT_AUTOFILL_MASK);
-
-    if (g_autofill_hint == 0)
-        return;
-
-    alias = get_autofill_alias();
+    char *text = autofill_get_string(input_hints);
 
-    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 *ckmc_data = NULL;
-    int ret;
-
-    ret = ckmc_get_data(alias.c_str(), password, &ckmc_data);
-    if (CKMC_ERROR_NONE != ret) {
-        LOGW("ckmc_get_data error: %d", ret);
-        return;
+    if (text) {
+        g_autofill_string = string(text);
+        free(text);
     } else {
-        if (!ckmc_data)
-            return;
-
-        autofill_data = strndup((const char *)ckmc_data->data, ckmc_data->size);
-        SECURE_LOGD("data : '%s', len : %d", autofill_data, ckmc_data->size);
-    }
-
-    if (!autofill_data) {
-        return;
+        g_autofill_string = string("");
     }
+    SECURE_LOGD("autofill string : %s", g_autofill_string.c_str());
 
-    g_autofill_string = string(autofill_data);
-    free(autofill_data);
+    if (g_autofill_string.length() > 0) {
+        g_autofill_exist = true;
 
-    g_autofill_exist = true;
-    ise_app_candidate_show();
-    update_candidate_table();
+        ise_app_candidate_show();
+        update_candidate_table();
+    }
 }
 
 static void ime_app_show_cb(int ic, ime_context_h ime_ctx, void *user_data)
@@ -2430,7 +2376,7 @@ static void ime_app_show_cb(int ic, ime_context_h ime_ctx, void *user_data)
     }
 
     // show autofill data
-    show_autofill_data(iseContext.input_hint);
+    show_autofill_data((Ecore_IMF_Input_Hints)g_autofill_hint);
 
     //g_ise_common->set_keyboard_ise_by_uuid(KEYBD_ISE_UUID);