2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "sticker_info.h"
18 #include <sticker_provider.h>
19 #include <app_common.h>
25 static sticker_provider_h sticker_provider = NULL;
28 set_sticker_data(sticker_data_uri_type_e type, const char* uri, const char* keyword,
29 int len, const char* group, const char* thumbnail, const char* description, sticker_data_display_type_e disp_type)
31 sticker_data_h sticker_data;
34 /* Creates a Sticker data handle */
35 ret = sticker_data_create(&sticker_data);
36 if (ret != STICKER_ERROR_NONE) {
38 LOGE("Failed to create sticker data");
41 /* Sets the URI and URI type of the sticker */
42 ret = sticker_data_set_uri(sticker_data, type, uri);
43 if (ret != STICKER_ERROR_NONE) {
45 LOGE("Failed to set uri");
48 //for (int i = 0; i < len; i++)
50 /* Adds a keyword of the sticker to the list */
51 ret = sticker_data_add_keyword(sticker_data, keyword);
52 if (ret != STICKER_ERROR_NONE) {
54 LOGE("Failed to add keyword");
58 /* Sets the group name of the sticker */
59 ret = sticker_data_set_group_name(sticker_data, group);
60 if (ret != STICKER_ERROR_NONE) {
62 LOGE("Failed to set group name");
65 /* Sets the thumbnail local path of the sticker */
67 ret = sticker_data_set_thumbnail(sticker_data, thumbnail);
68 if (ret != STICKER_ERROR_NONE) {
70 LOGE("Failed to set thumbnail");
74 /* Sets the description of the sticker */
75 ret = sticker_data_set_description(sticker_data, description);
76 if (ret != STICKER_ERROR_NONE) {
78 LOGE("Failed to set description");
81 /* Sets the display type of the sticker.*/
82 ret = sticker_data_set_display_type(sticker_data, disp_type);
83 if (ret != STICKER_ERROR_NONE) {
85 LOGE("Failed to set display type");
92 insert_sticker_data(const char *filepath, const char *keyword, const char *group, const char *desc, const char *thumbnail, const char *disp_type)
94 sticker_data_h data_handle;
96 sticker_data_display_type_e display_type;
98 if (strcmp(disp_type, "input") == 0)
99 display_type = STICKER_DATA_DISP_EMOJI;
101 display_type = STICKER_DATA_DISP_WALLPAPER;
103 data_handle = set_sticker_data(STICKER_DATA_URI_LOCAL_PATH, filepath, keyword, 1, group, thumbnail, desc, display_type);
105 ret = sticker_provider_insert_data(sticker_provider, data_handle);
106 if (ret != STICKER_ERROR_NONE) {
107 LOGE("Failed to insert data. error code : %x. message : %s", ret, get_error_message(ret));
110 LOGI("Succeeded to insert data");
113 /* Destroys a sticker data handle */
114 ret = sticker_data_destroy(data_handle);
115 if (ret != STICKER_ERROR_NONE) {
117 LOGE("Failed to destroy sticker data");
121 int create_sticker_provider_handle(void)
124 ret = sticker_provider_create(&sticker_provider);
125 if (ret != STICKER_ERROR_NONE) {
127 LOGE("Failed to create sticker provider");
133 void destroy_sticker_provider_handle(void)
135 sticker_provider_destroy(sticker_provider);
136 sticker_provider = NULL;
139 void delete_sticker_data(const char *fileName)
142 ret = sticker_provider_delete_data_by_uri(sticker_provider, fileName);
143 if (ret != STICKER_ERROR_NONE)
144 LOGE("Failed to delete sticker. ret : %d", ret);
147 static void _delete_all_stickers_cb(sticker_data_h data_handle, void *user_data)
150 char *sticker_group = NULL;
151 char *del_group = (char *) user_data;
153 ret = sticker_data_get_group_name(data_handle, &sticker_group);
154 if (ret != STICKER_ERROR_NONE)
155 LOGE("Failed to get group name. ret : %d", ret);
157 if (strcmp(sticker_group, del_group) == 0) {
158 ret = sticker_provider_delete_data(sticker_provider, data_handle);
159 if (ret != STICKER_ERROR_NONE)
160 LOGE("Failed to delete sticker. ret : %d", ret);
164 void delete_all_stickers(const char *groupName)
170 ret = sticker_provider_get_sticker_count(sticker_provider, &total_cnt);
171 if (ret != STICKER_ERROR_NONE)
172 LOGE("Failed to get sticker count. ret : %d", ret);
174 ret = sticker_provider_data_foreach_all(sticker_provider, 0, total_cnt, &result, _delete_all_stickers_cb, (void *)groupName);
175 if (ret != STICKER_ERROR_NONE)
176 LOGE("Failed to retrieve all sticker data. ret : %d", ret);