Update package version to 1.10.8
[platform/core/uifw/ise-default.git] / src / clipboard.cpp
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <scltypes.h>
19 #include <dlog.h>
20 #include "clipboard.h"
21
22 #undef LOG_TAG
23 #define LOG_TAG "ISE_DEFAULT"
24
25 using namespace scl;
26
27 #ifdef HAVE_CBHM
28 #include <cbhm.h>
29
30 static cbhm_h cbhm_handle = NULL;
31 #endif
32
33 static sclu32 cbhm_sel_type = 0;
34 static sclboolean g_set_mime_type = FALSE;
35
36 void clipboard_init()
37 {
38 #ifdef HAVE_CBHM
39     cbhm_open_service(&cbhm_handle);
40 #endif
41 }
42
43 void clipboard_shutdown()
44 {
45 #ifdef HAVE_CBHM
46     cbhm_close_service(cbhm_handle);
47     cbhm_handle = NULL;
48 #endif
49 }
50
51 bool clipboard_show()
52 {
53 #ifdef HAVE_CBHM
54     int ret;
55
56     if (g_set_mime_type)
57         ret = cbhm_selection_type_set(cbhm_handle, static_cast<cbhm_sel_type_e>(cbhm_sel_type));
58     else
59         ret = cbhm_selection_type_set(cbhm_handle, CBHM_SEL_TYPE_TEXT);
60
61     if (ret != CBHM_ERROR_NONE)
62         LOGW("Failed to set selection type in cbhm. error : %d\n", ret);
63
64     ret = cbhm_show(cbhm_handle);
65     if (ret != CBHM_ERROR_NONE) {
66         LOGW("cbhm show error : %d\n", ret);
67         return false;
68     }
69     else {
70         LOGD("Show cbhm\n");
71         return true;
72     }
73 #endif
74
75     return false;
76 }
77
78 void clipboard_set_mime_type(bool mime_type)
79 {
80     g_set_mime_type = mime_type;
81 }
82
83 void clipboard_init_sel_type()
84 {
85     cbhm_sel_type = 0;
86 }
87
88 void clipboard_add_sel_type(CLIPBOARD_SEL_TYPE sel_type)
89 {
90 #ifdef HAVE_CBHM
91     switch(sel_type)
92     {
93     case CLIPBOARD_SEL_TEXT:
94         cbhm_sel_type |= CBHM_SEL_TYPE_TEXT;
95         break;
96     case CLIPBOARD_SEL_IMAGE:
97         cbhm_sel_type |= CBHM_SEL_TYPE_IMAGE;
98         break;
99     default:
100         break;
101     }
102 #endif
103 }