+/*
+ * Copyright (c) 2020 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 "sticker_info.h"
#include <sticker_provider.h>
#include <app_common.h>
sticker_data_h
set_sticker_data(sticker_data_uri_type_e type, const char* uri, const char* keyword,
-int len, const char* group, const char* thumbnail, const char* description)
+int len, const char* group, const char* thumbnail, const char* description, sticker_data_display_type_e disp_type)
{
sticker_data_h sticker_data;
int ret;
ret = sticker_data_create(&sticker_data);
if (ret != STICKER_ERROR_NONE) {
/* Error handling */
- LOGE("Failed to create sticker data");
+ STLOGE("Failed to create sticker data");
}
/* Sets the URI and URI type of the sticker */
ret = sticker_data_set_uri(sticker_data, type, uri);
if (ret != STICKER_ERROR_NONE) {
/* Error handling */
- LOGE("Failed to set uri");
+ STLOGE("Failed to set uri");
}
//for (int i = 0; i < len; i++)
ret = sticker_data_add_keyword(sticker_data, keyword);
if (ret != STICKER_ERROR_NONE) {
/* Error handling */
- LOGE("Failed to add keyword");
+ STLOGE("Failed to add keyword");
}
}
ret = sticker_data_set_group_name(sticker_data, group);
if (ret != STICKER_ERROR_NONE) {
/* Error handling */
- LOGE("Failed to set group name");
+ STLOGE("Failed to set group name");
}
/* Sets the thumbnail local path of the sticker */
ret = sticker_data_set_thumbnail(sticker_data, thumbnail);
if (ret != STICKER_ERROR_NONE) {
/* Error handling */
- LOGE("Failed to set thumbnail");
+ STLOGE("Failed to set thumbnail");
}
}
ret = sticker_data_set_description(sticker_data, description);
if (ret != STICKER_ERROR_NONE) {
/* Error handling */
- LOGE("Failed to set description");
+ STLOGE("Failed to set description");
+ }
+
+ /* Sets the display type of the sticker.*/
+ ret = sticker_data_set_display_type(sticker_data, disp_type);
+ if (ret != STICKER_ERROR_NONE) {
+ /* Error handling */
+ STLOGE("Failed to set display type");
}
return sticker_data;
}
void
-insert_sticker_data(const char *filepath, const char *keyword, const char *group, const char *desc)
+insert_sticker_data(const char *filepath, const char *keyword, const char *group, const char *desc, const char *thumbnail, const char *disp_type)
{
sticker_data_h data_handle;
int ret;
+ sticker_data_display_type_e display_type;
+
+ if (strcmp(disp_type, "input") == 0)
+ display_type = STICKER_DATA_DISP_EMOJI;
+ else
+ display_type = STICKER_DATA_DISP_WALLPAPER;
- data_handle = set_sticker_data(STICKER_DATA_URI_LOCAL_PATH, filepath, keyword, 1, group, NULL, desc);
+ data_handle = set_sticker_data(STICKER_DATA_URI_LOCAL_PATH, filepath, keyword, 1, group, thumbnail, desc, display_type);
ret = sticker_provider_insert_data(sticker_provider, data_handle);
if (ret != STICKER_ERROR_NONE) {
- LOGE("Failed to insert data. error code : %x. message : %s", ret, get_error_message(ret));
+ STLOGE("Failed to insert data. error code : %x. message : '%s'", ret, get_error_message(ret));
}
else {
- LOGI("Succeeded to insert data");
+ STLOGI("Succeeded to insert data");
}
/* Destroys a sticker data handle */
ret = sticker_data_destroy(data_handle);
if (ret != STICKER_ERROR_NONE) {
/* Error handling */
- LOGE("Failed to destroy sticker data");
+ STLOGE("Failed to destroy sticker data");
}
}
-int create_sticker_provider_handle(void)
+void create_sticker_provider_handle(void)
{
int ret;
ret = sticker_provider_create(&sticker_provider);
if (ret != STICKER_ERROR_NONE) {
/* Error handling */
- LOGE("Failed to create sticker provider");
+ STLOGE("Failed to create sticker provider. error code : 0x%X, message : '%s'", ret, get_error_message(ret));
}
-
- return ret;
}
void destroy_sticker_provider_handle(void)
sticker_provider_destroy(sticker_provider);
sticker_provider = NULL;
}
+
+void delete_sticker_data(const char *fileName)
+{
+ int ret;
+ ret = sticker_provider_delete_data_by_uri(sticker_provider, fileName);
+ if (ret != STICKER_ERROR_NONE)
+ STLOGE("Failed to delete sticker. error code : 0x%X, message : '%s'", ret, get_error_message(ret));
+}
+
+static void _delete_all_stickers_cb(sticker_data_h data_handle, void *user_data)
+{
+ int ret;
+ char *sticker_group = NULL;
+ char *del_group = (char *) user_data;
+
+ ret = sticker_data_get_group_name(data_handle, &sticker_group);
+ if (ret != STICKER_ERROR_NONE)
+ STLOGE("Failed to get group name. error code : 0x%X, message : '%s'", ret, get_error_message(ret));
+
+ if (strcmp(sticker_group, del_group) == 0) {
+ ret = sticker_provider_delete_data(sticker_provider, data_handle);
+ if (ret != STICKER_ERROR_NONE)
+ STLOGE("Failed to delete sticker. error code : 0x%X, message : '%s'", ret, get_error_message(ret));
+ }
+}
+
+bool delete_all_stickers(const char *groupName)
+{
+ int ret;
+ int total_cnt;
+ int result;
+
+ ret = sticker_provider_get_sticker_count(sticker_provider, &total_cnt);
+ if (ret != STICKER_ERROR_NONE)
+ STLOGE("Failed to get sticker count. error code : 0x%X, message : '%s'", ret, get_error_message(ret));
+
+ ret = sticker_provider_data_foreach_all(sticker_provider, 0, total_cnt, &result, _delete_all_stickers_cb, (void *)groupName);
+ if (ret != STICKER_ERROR_NONE)
+ STLOGE("Failed to retrieve all sticker data. error code : 0x%X, message : '%s'", ret, get_error_message(ret));
+
+ return (ret == STICKER_ERROR_NONE);
+}