--- /dev/null
+/*
+ * 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());
+}
#ifdef HAVE_CBHM
#include <cbhm.h>
#endif
-#include <ckmc/ckmc-manager.h>
-
+#include "autofill.h"
#include "ise.h"
#include "utils.h"
#include "option.h"
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());
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;
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);
}
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)
}
// 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);