Merge branch 'tizen_5.5' into tizen
[platform/core/uifw/capi-ui-sticker.git] / receiver / src / sticker_info.cpp
1 #include "sticker_info.h"
2 #include <sticker_provider.h>
3 #include <app_common.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6
7 #include "log.h"
8
9 static sticker_provider_h sticker_provider = NULL;
10
11 sticker_data_h
12 set_sticker_data(sticker_data_uri_type_e type, const char* uri, const char* keyword,
13 int len, const char* group, const char* thumbnail, const char* description)
14 {
15     sticker_data_h sticker_data;
16     int ret;
17
18     /* Creates a Sticker data handle */
19     ret = sticker_data_create(&sticker_data);
20     if (ret != STICKER_ERROR_NONE) {
21         /* Error handling */
22         LOGE("Failed to create sticker data");
23     }
24
25     /* Sets the URI and URI type of the sticker */
26     ret = sticker_data_set_uri(sticker_data, type, uri);
27     if (ret != STICKER_ERROR_NONE) {
28         /* Error handling */
29         LOGE("Failed to set uri");
30     }
31
32     //for (int i = 0; i < len; i++)
33     {
34         /* Adds a keyword of the sticker to the list */
35         ret = sticker_data_add_keyword(sticker_data, keyword);
36         if (ret != STICKER_ERROR_NONE) {
37             /* Error handling */
38             LOGE("Failed to add keyword");
39         }
40     }
41
42     /* Sets the group name of the sticker */
43     ret = sticker_data_set_group_name(sticker_data, group);
44     if (ret != STICKER_ERROR_NONE) {
45         /* Error handling */
46         LOGE("Failed to set group name");
47     }
48
49     /* Sets the thumbnail local path of the sticker */
50     if (thumbnail) {
51         ret = sticker_data_set_thumbnail(sticker_data, thumbnail);
52         if (ret != STICKER_ERROR_NONE) {
53             /* Error handling */
54             LOGE("Failed to set thumbnail");
55         }
56     }
57
58     /* Sets the description of the sticker */
59     ret = sticker_data_set_description(sticker_data, description);
60     if (ret != STICKER_ERROR_NONE) {
61         /* Error handling */
62         LOGE("Failed to set description");
63     }
64
65     return sticker_data;
66 }
67
68 void
69 insert_sticker_data(const char *filepath, const char *keyword, const char *group, const char *desc)
70 {
71     sticker_data_h data_handle;
72     int ret;
73
74     data_handle = set_sticker_data(STICKER_DATA_URI_LOCAL_PATH, filepath, keyword, 1, group, NULL, desc);
75
76     ret = sticker_provider_insert_data(sticker_provider, data_handle);
77     if (ret != STICKER_ERROR_NONE) {
78         LOGE("Failed to insert data. error code : %x. message : %s", ret, get_error_message(ret));
79     }
80     else {
81         LOGI("Succeeded to insert data");
82     }
83
84     /* Destroys a sticker data handle */
85     ret = sticker_data_destroy(data_handle);
86     if (ret != STICKER_ERROR_NONE) {
87         /* Error handling */
88         LOGE("Failed to destroy sticker data");
89     }
90 }
91
92 int create_sticker_provider_handle(void)
93 {
94     int ret;
95     ret = sticker_provider_create(&sticker_provider);
96     if (ret != STICKER_ERROR_NONE) {
97         /* Error handling */
98         LOGE("Failed to create sticker provider");
99     }
100
101     return ret;
102 }
103
104 void destroy_sticker_provider_handle(void)
105 {
106     sticker_provider_destroy(sticker_provider);
107     sticker_provider = NULL;
108 }