1 #include "sticker_info.h"
2 #include <sticker_provider.h>
3 #include <app_common.h>
12 static sticker_provider_h sticker_provider = NULL;
13 static bool need_to_retrive = false;
16 set_sticker_data(sticker_data_uri_type_e type, const char* uri, const char* keyword,
17 int len, const char* group, const char* thumbnail, const char* description)
19 sticker_data_h sticker_data;
22 /* Creates a Sticker data handle */
23 ret = sticker_data_create(&sticker_data);
24 if (ret != STICKER_ERROR_NONE) {
26 LOGE("Failed to create sticker data");
29 /* Sets the URI and URI type of the sticker */
30 ret = sticker_data_set_uri(sticker_data, type, uri);
31 if (ret != STICKER_ERROR_NONE) {
33 LOGE("Failed to set uri");
36 //for (int i = 0; i < len; i++)
38 /* Adds a keyword of the sticker to the list */
39 ret = sticker_data_add_keyword(sticker_data, keyword);
40 if (ret != STICKER_ERROR_NONE) {
42 LOGE("Failed to add keyword");
46 /* Sets the group name of the sticker */
47 ret = sticker_data_set_group_name(sticker_data, group);
48 if (ret != STICKER_ERROR_NONE) {
50 LOGE("Failed to set group name");
53 /* Sets the thumbnail local path of the sticker */
55 ret = sticker_data_set_thumbnail(sticker_data, thumbnail);
56 if (ret != STICKER_ERROR_NONE) {
58 LOGE("Failed to set thumbnail");
62 /* Sets the description of the sticker */
63 ret = sticker_data_set_description(sticker_data, description);
64 if (ret != STICKER_ERROR_NONE) {
66 LOGE("Failed to set description");
73 insert_sticker_data(const char *filepath, const char *keyword, const char *group, const char *desc)
75 sticker_data_h data_handle;
78 data_handle = set_sticker_data(STICKER_DATA_URI_LOCAL_PATH, filepath, keyword, 1, group, NULL, desc);
80 ret = sticker_provider_insert_data(sticker_provider, data_handle);
81 if (ret != STICKER_ERROR_NONE) {
82 LOGE("Failed to insert data. error code : %x. message : %s", ret, get_error_message(ret));
85 LOGI("Succeeded to insert data");
88 /* Destroys a sticker data handle */
89 ret = sticker_data_destroy(data_handle);
90 if (ret != STICKER_ERROR_NONE) {
92 LOGE("Failed to destroy sticker data");
96 int create_sticker_provider_handle(void)
99 ret = sticker_provider_create(&sticker_provider);
100 if (ret != STICKER_ERROR_NONE) {
102 LOGE("Failed to create sticker provider");
108 void destroy_sticker_provider_handle(void)
110 sticker_provider_destroy(sticker_provider);
111 sticker_provider = NULL;
114 static void _sticker_foreach_cb(sticker_data_h data_handle, void *user_data)
117 char *del_file = (char *)user_data;
118 sticker_data_uri_type_e type;
121 if (!need_to_retrive)
124 ret = sticker_data_get_uri(data_handle, &type, &uri);
125 if (ret != STICKER_ERROR_NONE)
126 LOGE("Failed to get sticker uri");
128 int result = (string(uri)).find(del_file);
130 LOGI("Delete sticker (%s)", uri);
131 need_to_retrive = false;
133 ret = sticker_provider_delete_data(sticker_provider, data_handle);
134 if (ret != STICKER_ERROR_NONE)
135 LOGE("Failed to delete sticker");
139 void delete_sticker_data(const char *fileName)
145 need_to_retrive = true;
147 while (result == count && need_to_retrive) {
149 ret = sticker_provider_data_foreach_all(sticker_provider, offset, count, &result, _sticker_foreach_cb, (void *)fileName);
151 if (ret != STICKER_ERROR_NONE) {
152 LOGE("Failed to retrieve sticker");