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