Refactor code related to autofill 50/251050/2
authorJihoon Kim <jihoon48.kim@samsung.com>
Thu, 7 Jan 2021 07:35:27 +0000 (16:35 +0900)
committerJihoon Kim <jihoon48.kim@samsung.com>
Tue, 12 Jan 2021 06:31:50 +0000 (15:31 +0900)
Change-Id: If5b8d8f9982755b2ef7d3f8b3b2989b50f9ed76c
Signed-off-by: Jihoon Kim <jihoon48.kim@samsung.com>
src/autofill.cpp
src/include/autofill.h
src/ise.cpp
src/option.cpp

index 2326665..e2bba60 100644 (file)
 
 using namespace std;
 
-static string get_autofill_alias(const char *app_id, const char *res_id, Ecore_IMF_Input_Hints input_hints)
+static bool g_autofill_exist = false;
+static unsigned int g_autofill_hints = 0;
+
+static string g_app_id;
+static string g_resource_id;
+
+void ime_autofill_set_app_id(const char *app_id)
+{
+    g_app_id = string(app_id ? app_id : "");
+}
+
+void ime_autofill_set_resource_id(const char *resource_id)
 {
-    int autofill_hint = input_hints & ECORE_IMF_INPUT_HINT_AUTOFILL_MASK;
+    g_resource_id = string(resource_id ? resource_id : "");
+}
 
+void ime_autofill_set_exist(bool exist)
+{
+    g_autofill_exist = exist;
+}
+
+bool ime_autofill_get_exist()
+{
+    return g_autofill_exist;
+}
+
+void ime_autofill_set_hint(unsigned int autofill_hints)
+{
+    g_autofill_hints = autofill_hints;
+}
+
+unsigned int ime_autofill_get_hint()
+{
+    return g_autofill_hints;
+}
+
+static string get_autofill_alias()
+{
     char alias[1024] = { 0 };
-    snprintf(alias, sizeof(alias), "autofill|%s|%s|%d", app_id ? app_id : "", res_id ? res_id : "", autofill_hint);
+    snprintf(alias, sizeof(alias), "autofill|%s|%s|%d", g_app_id.c_str(), g_resource_id.c_str(), g_autofill_hints);
 
     return string(alias);
 }
 
-Eina_Bool autofill_save_string(const char *app_id, const char *res_id, Ecore_IMF_Input_Hints input_hints, const char *text)
+Eina_Bool ime_autofill_save_string(const char *text)
 {
-    if ((input_hints & ECORE_IMF_INPUT_HINT_AUTOFILL_MASK) == 0)
+    if (g_autofill_hints == 0)
         return EINA_FALSE;
 
     if (!text) return EINA_FALSE;
 
     char *password = NULL;
     ckmc_raw_buffer_s ckmc_data;
-    string alias = get_autofill_alias(app_id, res_id, input_hints);
+    string alias = get_autofill_alias();
     ckmc_policy_s ckmc_policy;
     ckmc_policy.password = password;
     ckmc_policy.extractable = true;
@@ -66,7 +100,7 @@ Eina_Bool autofill_save_string(const char *app_id, const char *res_id, Ecore_IMF
     }
 }
 
-char *autofill_get_string(const char *app_id, const char *res_id, Ecore_IMF_Input_Hints input_hints)
+string ime_autofill_get_string()
 {
     string alias;
     string autofill_string;
@@ -75,15 +109,14 @@ char *autofill_get_string(const char *app_id, const char *res_id, Ecore_IMF_Inpu
     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);
+    LOGD("autofill_hints : %x\n", g_autofill_hints);
 
-    if (autofill_hint == 0)
-        return NULL;
+    if (g_autofill_hints == 0)
+        return string("");
 
-    alias = get_autofill_alias(app_id, res_id, input_hints);
+    alias = get_autofill_alias();
 
-    switch (autofill_hint)
+    switch (g_autofill_hints)
     {
         case ECORE_IMF_INPUT_HINT_AUTOFILL_NAME:
             LOGD("autofill type : name");
@@ -99,10 +132,10 @@ char *autofill_get_string(const char *app_id, const char *res_id, Ecore_IMF_Inpu
     ret = ckmc_get_data(alias.c_str(), password, &ckmc_data);
     if (CKMC_ERROR_NONE != ret) {
         LOGW("ckmc_get_data error: %d", ret);
-        return NULL;
+        return string("");
     } else {
         if (!ckmc_data)
-            return NULL;
+            return string("");
 
         autofill_data = strndup((const char *)ckmc_data->data, ckmc_data->size);
         SECURE_LOGD("data : '%s', len : %zu", autofill_data, ckmc_data->size);
@@ -112,13 +145,13 @@ char *autofill_get_string(const char *app_id, const char *res_id, Ecore_IMF_Inpu
         autofill_string = string(autofill_data);
         free(autofill_data);
     } else {
-        return NULL;
+        return string("");
     }
 
-    return strdup(autofill_string.c_str());
+    return autofill_string;
 }
 
-Eina_Bool autofill_clear()
+Eina_Bool ime_autofill_clear()
 {
     int ret = CKMC_ERROR_NONE;
 
index 999f405..baae01d 100644 (file)
@@ -2,10 +2,18 @@
 #define _AUTOFILL_H_
 
 #include <Ecore_IMF.h>
+#include <string>
 
-#ifdef __cplusplus
-extern "C" {
-#endif
+using namespace std;
+
+bool ime_autofill_get_exist();
+void ime_autofill_set_exist(bool exist);
+
+void ime_autofill_set_app_id(const char *app_id);
+void ime_autofill_set_resource_id(const char *resource_id);
+
+void ime_autofill_set_hint(unsigned int input_hints);
+unsigned int ime_autofill_get_hint();
 
 /**
  * @brief Save autofill string.
@@ -14,12 +22,9 @@ extern "C" {
  *
  * @privlevel internal
  *
- * @param[in] app_id application ID
- * @param[in] res_id resource ID
- * @param[in] input_hints input hint
  * @param[in] text autofill string
  */
-Eina_Bool autofill_save_string(const char *app_id, const char *res_id, Ecore_IMF_Input_Hints input_hints, const char *text);
+Eina_Bool ime_autofill_save_string(const char *text);
 
 /**
  * @brief Get autofill string.
@@ -28,13 +33,9 @@ Eina_Bool autofill_save_string(const char *app_id, const char *res_id, Ecore_IMF
  *
  * @privlevel internal
  *
- * @param[in] app_id application ID
- * @param[in] res_id resource ID
- * @param[in] input_hints input hint
- *
- * @return a newly allocated autofill string. Free with free() when no longer needed.
+ * @return autofill string
  */
-char *autofill_get_string(const char *app_id, const char *res_id, Ecore_IMF_Input_Hints input_hints);
+string ime_autofill_get_string();
 
 /**
  * @brief Clear autofill data.
@@ -44,10 +45,6 @@ char *autofill_get_string(const char *app_id, const char *res_id, Ecore_IMF_Inpu
  * @privlevel internal
  *
  */
-Eina_Bool autofill_clear();
-
-#ifdef __cplusplus
-}
-#endif
+Eina_Bool ime_autofill_clear();
 
 #endif
index 8c5cced..8fe98ce 100644 (file)
@@ -83,18 +83,12 @@ 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;
 #if EXIT_ISE_ON_HIDE
 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;
 
@@ -152,13 +146,10 @@ class CandidateEventListener: public EventListener
 
             switch (multidesc.type) {
                 case MultiEventDesc::CANDIDATE_ITEM_MOUSE_DOWN:
-                    if (g_autofill_exist) {
+                    if (ime_autofill_get_exist()) {
                         if (multidesc.index == 0) {
-                            char *text = autofill_get_string(g_app_id.c_str(), g_resource_id.c_str(), (Ecore_IMF_Input_Hints)g_autofill_hint);
-                            if (text) {
-                                ise_send_string(text);
-                                free(text);
-                            }
+                            string autofill_string = ime_autofill_get_string();
+                            ise_send_string(autofill_string.c_str());
                         } else if (multidesc.index < (int)smartreply_size + 1) {
                             ise_send_string(g_softcandidate_string[multidesc.index].c_str());
                             ise_update_table(g_smartreply_strings);
@@ -270,8 +261,8 @@ static void update_candidate_table()
     g_ic_smartreply = -1;
 
     // add autofill string
-    if (g_autofill_exist)
-        g_softcandidate_string.push_back(g_autofill_string);
+    if (ime_autofill_get_exist())
+        g_softcandidate_string.push_back(ime_autofill_get_string());
 
     // add lookup table string(s)
     iter = g_lookup_table_strings.begin();
@@ -1452,14 +1443,14 @@ static void save_autofill_data()
     char *text = NULL;
     int cursor;
 
-    if (g_autofill_hint == 0)
+    if (ime_autofill_get_hint() == 0)
         return;
 
     ime_get_surrounding_text(-1, -1, &text, &cursor);
     SECURE_LOGD("surrounding text : %s\n", text);
     if (!text) return;
 
-    autofill_save_string(g_app_id.c_str(), g_resource_id.c_str(), (Ecore_IMF_Input_Hints)g_autofill_hint, text);
+    ime_autofill_save_string(text);
 
     free(text);
 }
@@ -2221,7 +2212,7 @@ ise_app_candidate_hide()
         return;
     }
 
-    if (g_ic_smartreply != -1 || g_autofill_exist)
+    if (g_ic_smartreply != -1 || ime_autofill_get_exist())
         return;
 
     add_softcandidate_hide_timer();
@@ -2687,21 +2678,15 @@ static void ime_app_exit_cb(void *user_data)
     clipboard_shutdown();
 }
 
-static void show_autofill_data(Ecore_IMF_Input_Hints input_hints)
+static void show_autofill_data()
 {
-    g_autofill_exist = false;
-    char *text = autofill_get_string(g_app_id.c_str(), g_resource_id.c_str(), input_hints);
+    ime_autofill_set_exist(false);
+    string autofill_string = ime_autofill_get_string();
 
-    if (text) {
-        g_autofill_string = string(text);
-        free(text);
-    } else {
-        g_autofill_string = string("");
-    }
-    SECURE_LOGD("autofill string : %s", g_autofill_string.c_str());
+    SECURE_LOGD("autofill string : %s", autofill_string.c_str());
 
-    if (g_autofill_string.length() > 0) {
-        g_autofill_exist = true;
+    if (!autofill_string.empty()) {
+        ime_autofill_set_exist(true);
 
         ise_app_candidate_show();
         update_candidate_table();
@@ -2746,12 +2731,12 @@ 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;
+    ime_autofill_set_hint(iseContext.input_hint & ECORE_IMF_INPUT_HINT_AUTOFILL_MASK);
 
-    LOGD("input hint : %x, autofill hint : %x\n", iseContext.input_hint, g_autofill_hint);
+    LOGD("input hint : %x, autofill hint : %x\n", iseContext.input_hint, ime_autofill_get_hint());
 
     // show autofill data
-    show_autofill_data((Ecore_IMF_Input_Hints)g_autofill_hint);
+    show_autofill_data();
 
     //g_ise_common->set_keyboard_ise_by_uuid(KEYBD_ISE_UUID);
 
@@ -2872,13 +2857,11 @@ static void ime_app_focus_out_cb(int context_id, void *user_data)
     input_smartreply_deinit();
     g_ic_smartreply = -1;
 
-    g_autofill_exist = false;
-    g_autofill_hint = 0;
-
-    g_app_id = string("");
-    g_resource_id = string("");
+    ime_autofill_set_exist(false);
+    ime_autofill_set_hint(0);
+    ime_autofill_set_app_id("");
+    ime_autofill_set_resource_id("");
 
-    g_autofill_string = string("");
     g_smartreply_strings.clear();
     g_lookup_table_strings.clear();
     g_softcandidate_string.clear();
@@ -3233,9 +3216,9 @@ static void ime_app_prediction_hint_data_set_cb(const char *key, const char *val
     SECURE_LOGD("key : %s, value : %s\n", key, value);
 
     if (string(key) == "appid")
-        g_app_id = string(value ? value : "");
+        ime_autofill_set_app_id(value);
     else if (string(key) == "res_id")
-        g_resource_id = string(value ? value : "");
+        ime_autofill_set_resource_id(value);
 }
 
 static void ime_app_autocapital_type_set_cb(uint32_t type, void *user_data)
index aca608a..b318820 100644 (file)
@@ -236,7 +236,7 @@ static void reset_settings_popup_response_ok_cb(void *data, Evas_Object *obj, vo
         vconf_set_bool(VCONFKEY_AUTOPERIOD_ALLOW_BOOL, config_values->auto_punctuate);
     }
 
-    autofill_clear();
+    ime_autofill_clear();
 
     Evas_Object *popup = (Evas_Object *)data;
     if (popup)