Extract clipboard code 20/250920/6
authorJihoon Kim <jihoon48.kim@samsung.com>
Tue, 5 Jan 2021 15:31:14 +0000 (00:31 +0900)
committerJihoon Kim <jihoon48.kim@samsung.com>
Wed, 6 Jan 2021 01:37:48 +0000 (10:37 +0900)
Change-Id: Ibe9e1108e28867994c78984161a5a6dbb65aef6a
Signed-off-by: Jihoon Kim <jihoon48.kim@samsung.com>
CMakeLists.txt
src/clipboard.cpp [new file with mode: 0644]
src/include/clipboard.h [new file with mode: 0644]
src/ise.cpp

index fb53741..0412590 100644 (file)
@@ -19,6 +19,7 @@ SET(ISE_SRCS
     src/ise_lang_table.cpp
     src/cji.cpp
     src/sdk.cpp
+    src/clipboard.cpp
     src/candidate-factory.cpp
     src/candidate.cpp
     src/candidate-efl.cpp
diff --git a/src/clipboard.cpp b/src/clipboard.cpp
new file mode 100644 (file)
index 0000000..1cc7dcc
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 2021 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 <scltypes.h>
+#include <dlog.h>
+#include "clipboard.h"
+
+#undef LOG_TAG
+#define LOG_TAG "ISE_DEFAULT"
+
+using namespace scl;
+
+#ifdef HAVE_CBHM
+#include <cbhm.h>
+
+static cbhm_h cbhm_handle;
+#endif
+
+static sclu32 cbhm_sel_type = 0;
+static sclboolean g_set_mime_type = FALSE;
+
+void clipboard_init()
+{
+#ifdef HAVE_CBHM
+    cbhm_open_service(&cbhm_handle);
+#endif
+}
+
+void clipboard_shutdown()
+{
+#ifdef HAVE_CBHM
+    cbhm_close_service(cbhm_handle);
+    cbhm_handle = NULL;
+#endif
+}
+
+bool clipboard_show()
+{
+#ifdef HAVE_CBHM
+    int ret;
+
+    if (g_set_mime_type)
+        ret = cbhm_selection_type_set(cbhm_handle, static_cast<cbhm_sel_type_e>(cbhm_sel_type));
+    else
+        ret = cbhm_selection_type_set(cbhm_handle, CBHM_SEL_TYPE_TEXT);
+
+    if (ret != CBHM_ERROR_NONE)
+        LOGW("Failed to set selection type in cbhm. error : %d\n", ret);
+
+    ret = cbhm_show(cbhm_handle);
+    if (ret != CBHM_ERROR_NONE) {
+        LOGW("cbhm show error : %d\n", ret);
+        return false;
+    }
+    else {
+        LOGD("Show cbhm\n");
+        return true;
+    }
+#endif
+
+    return false;
+}
+
+void clipboard_set_mime_type(bool mime_type)
+{
+    g_set_mime_type = mime_type;
+}
+
+void clipboard_init_sel_type()
+{
+    cbhm_sel_type = 0;
+}
+
+void clipboard_add_sel_type(CLIPBOARD_SEL_TYPE sel_type)
+{
+#ifdef HAVE_CBHM
+    switch(sel_type)
+    {
+    case CLIPBOARD_SEL_TEXT:
+        cbhm_sel_type |= CBHM_SEL_TYPE_TEXT;
+        break;
+    case CLIPBOARD_SEL_IMAGE:
+        cbhm_sel_type |= CBHM_SEL_TYPE_IMAGE;
+        break;
+    default:
+        break;
+    }
+#endif
+}
\ No newline at end of file
diff --git a/src/include/clipboard.h b/src/include/clipboard.h
new file mode 100644 (file)
index 0000000..8fa9d94
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2021 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.
+ *
+ */
+
+#ifndef ISE_CLIPBOARD_H_
+#define ISE_CLIPBOARD_H_
+
+typedef enum {
+    CLIPBOARD_SEL_NONE,
+    CLIPBOARD_SEL_TEXT,
+    CLIPBOARD_SEL_IMAGE
+} CLIPBOARD_SEL_TYPE;
+
+void clipboard_init();
+void clipboard_shutdown();
+bool clipboard_show();
+void clipboard_set_mime_type(bool mime_type);
+
+void clipboard_init_sel_type();
+void clipboard_add_sel_type(CLIPBOARD_SEL_TYPE sel_type);
+
+#endif /* ISE_CLIPBOARD_H_ */
index a7a0992..8c5cced 100644 (file)
@@ -31,9 +31,7 @@
 #include <app_control.h>
 #include <app_preference.h>
 #include <ode/internal-encryption.h>
-#ifdef HAVE_CBHM
-#include <cbhm.h>
-#endif
+#include "clipboard.h"
 #include "autofill.h"
 #include "ise.h"
 #include "utils.h"
@@ -64,12 +62,6 @@ using namespace std;
 static CSCLUI *g_ui = NULL;
 CSCLUI* get_ui() { return g_ui; }
 
-#ifdef HAVE_CBHM
-static cbhm_h cbhm_handle;
-static sclu32 cbhm_sel_type = 0;
-static sclboolean g_set_mime_type = FALSE;
-#endif
-
 static int g_imdata_state = 0;
 
 static sclboolean g_need_send_shift_event = FALSE;
@@ -713,27 +705,6 @@ on_input_mode_changed(const sclchar *key_value, sclulong key_event, sclint key_t
     return ret;
 }
 
-static void show_cbhm()
-{
-#ifdef HAVE_CBHM
-    int ret;
-
-    if (g_set_mime_type)
-        ret = cbhm_selection_type_set(cbhm_handle, static_cast<cbhm_sel_type_e>(cbhm_sel_type));
-    else
-        ret = cbhm_selection_type_set(cbhm_handle, CBHM_SEL_TYPE_TEXT);
-
-    if (ret != CBHM_ERROR_NONE)
-        LOGW("Failed to set selection type in cbhm. error : %d\n", ret);
-
-    ret = cbhm_show(cbhm_handle);
-    if (ret != CBHM_ERROR_NONE)
-        LOGW("cbhm show error : %d\n", ret);
-    else
-        LOGD("Show cbhm\n");
-#endif
-}
-
 SCLEventReturnType CUIEventCallback::on_event_notification(SCLUINotiType noti_type, SclNotiDesc *etc_info)
 {
     CSCLUI *ui = get_ui();
@@ -1305,7 +1276,7 @@ SCLEventReturnType CUIEventCallback::on_event_key_clicked(SclUIEventDesc event_d
 
                 ret = SCL_EVENT_DONE;
             } else if (strcmp(event_desc.key_value, USER_KEYSTRING_CLIPBOARD) == 0) {
-                show_cbhm();
+                clipboard_show();
 
                 ret = SCL_EVENT_DONE;
             } else if (strcmp(event_desc.key_value, USER_KEYSTRING_FLOATING) == 0) {
@@ -1358,7 +1329,7 @@ SCLEventReturnType CUIEventCallback::on_event_key_clicked(SclUIEventDesc event_d
 
                 ret = SCL_EVENT_DONE;
             } else if (strcmp(event_desc.key_value, USER_KEYSTRING_CLIPBOARD) == 0) {
-                show_cbhm();
+                clipboard_show();
                 ret = SCL_EVENT_DONE;
             } else if (strcmp(event_desc.key_value, "Cancel") == 0) {
                 ret = SCL_EVENT_DONE;
@@ -2702,9 +2673,7 @@ static void ime_app_create_cb(void *user_data)
     if (elm_scale)
         elm_app_base_scale_set(atof(elm_scale));
 
-#ifdef HAVE_CBHM
-    cbhm_open_service(&cbhm_handle);
-#endif
+    clipboard_init();
 }
 
 static void ime_app_exit_cb(void *user_data)
@@ -2715,10 +2684,7 @@ static void ime_app_exit_cb(void *user_data)
     if (!engine_loader_dbus_shutdown())
         LOGE("Failed to finalize dbus");
 
-#ifdef HAVE_CBHM
-    cbhm_close_service(cbhm_handle);
-    cbhm_handle = NULL;
-#endif
+    clipboard_shutdown();
 }
 
 static void show_autofill_data(Ecore_IMF_Input_Hints input_hints)
@@ -2825,9 +2791,9 @@ static void ime_app_hide_cb(int ic, void *user_data)
 {
     LOGD("Enter\n");
     ise_hide();
-#ifdef HAVE_CBHM
-    g_set_mime_type = FALSE;
-#endif
+
+    clipboard_set_mime_type(false);
+
     g_ic_smartreply = -1;
 }
 
@@ -2902,9 +2868,7 @@ static void ime_app_focus_out_cb(int context_id, void *user_data)
     LOGD("Enter\n");
     ise_focus_out(context_id);
     g_imdata_state = 0;
-#ifdef HAVE_CBHM
-    g_set_mime_type = FALSE;
-#endif
+    clipboard_set_mime_type(false);
     input_smartreply_deinit();
     g_ic_smartreply = -1;
 
@@ -3252,19 +3216,16 @@ static void ime_app_mime_type_set_request_cb(const char *mime_types, void *user_
 {
     LOGD("mime type : %s\n", mime_types);
 
-#ifdef HAVE_CBHM
-    g_set_mime_type = TRUE;
-    cbhm_sel_type = 0;
+    clipboard_set_mime_type(true);
+    clipboard_init_sel_type();
+
     string str(mime_types), text_key = "text/", image_key = "image/";
 
     if (str.find(text_key) != string::npos)
-        cbhm_sel_type |= CBHM_SEL_TYPE_TEXT;
+        clipboard_add_sel_type(CLIPBOARD_SEL_TEXT);
 
     if (str.find(image_key) != string::npos)
-        cbhm_sel_type |= CBHM_SEL_TYPE_IMAGE;
-
-    LOGD("cbhm_sel_type=0x%x", cbhm_sel_type);
-#endif
+        clipboard_add_sel_type(CLIPBOARD_SEL_IMAGE);
 }
 
 static void ime_app_prediction_hint_data_set_cb(const char *key, const char *value, void *user_data)