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