Support to create thumbnail of the sticker
[platform/core/uifw/capi-ui-sticker.git] / receiver / src / sticker_info.cpp
1 /*
2  * Copyright (c) 2020 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 #include "sticker_info.h"
18 #include <sticker_provider.h>
19 #include <app_common.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22
23 #include "log.h"
24
25 static sticker_provider_h sticker_provider = NULL;
26
27 sticker_data_h
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)
30 {
31     sticker_data_h sticker_data;
32     int ret;
33
34     /* Creates a Sticker data handle */
35     ret = sticker_data_create(&sticker_data);
36     if (ret != STICKER_ERROR_NONE) {
37         /* Error handling */
38         LOGE("Failed to create sticker data");
39     }
40
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) {
44         /* Error handling */
45         LOGE("Failed to set uri");
46     }
47
48     //for (int i = 0; i < len; i++)
49     {
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) {
53             /* Error handling */
54             LOGE("Failed to add keyword");
55         }
56     }
57
58     /* Sets the group name of the sticker */
59     ret = sticker_data_set_group_name(sticker_data, group);
60     if (ret != STICKER_ERROR_NONE) {
61         /* Error handling */
62         LOGE("Failed to set group name");
63     }
64
65     /* Sets the thumbnail local path of the sticker */
66     if (thumbnail) {
67         ret = sticker_data_set_thumbnail(sticker_data, thumbnail);
68         if (ret != STICKER_ERROR_NONE) {
69             /* Error handling */
70             LOGE("Failed to set thumbnail");
71         }
72     }
73
74     /* Sets the description of the sticker */
75     ret = sticker_data_set_description(sticker_data, description);
76     if (ret != STICKER_ERROR_NONE) {
77         /* Error handling */
78         LOGE("Failed to set description");
79     }
80
81     return sticker_data;
82 }
83
84 void
85 insert_sticker_data(const char *filepath, const char *keyword, const char *group, const char *desc, const char *thumbnail)
86 {
87     sticker_data_h data_handle;
88     int ret;
89
90     data_handle = set_sticker_data(STICKER_DATA_URI_LOCAL_PATH, filepath, keyword, 1, group, thumbnail, desc);
91
92     ret = sticker_provider_insert_data(sticker_provider, data_handle);
93     if (ret != STICKER_ERROR_NONE) {
94         LOGE("Failed to insert data. error code : %x. message : %s", ret, get_error_message(ret));
95     }
96     else {
97         LOGI("Succeeded to insert data");
98     }
99
100     /* Destroys a sticker data handle */
101     ret = sticker_data_destroy(data_handle);
102     if (ret != STICKER_ERROR_NONE) {
103         /* Error handling */
104         LOGE("Failed to destroy sticker data");
105     }
106 }
107
108 int create_sticker_provider_handle(void)
109 {
110     int ret;
111     ret = sticker_provider_create(&sticker_provider);
112     if (ret != STICKER_ERROR_NONE) {
113         /* Error handling */
114         LOGE("Failed to create sticker provider");
115     }
116
117     return ret;
118 }
119
120 void destroy_sticker_provider_handle(void)
121 {
122     sticker_provider_destroy(sticker_provider);
123     sticker_provider = NULL;
124 }
125
126 void delete_sticker_data(const char *fileName)
127 {
128     int ret;
129     ret = sticker_provider_delete_data_by_uri(sticker_provider, fileName);
130     if (ret != STICKER_ERROR_NONE)
131         LOGE("Failed to delete sticker. ret : %d", ret);
132 }