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 <dlog.h>
4 #include <app_common.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7
8 static sticker_provider_h sticker_provider = NULL;
9
10 sticker_data_h
11 set_sticker_data(sticker_data_uri_type_e type, const char* uri, const char* keyword,
12 int len, const char* group, const char* thumbnail, const char* description)
13 {
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         dlog_print(DLOG_ERROR, TAG, "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         dlog_print(DLOG_ERROR, TAG, "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             dlog_print(DLOG_ERROR, TAG, "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         dlog_print(DLOG_ERROR, TAG, "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             dlog_print(DLOG_ERROR, TAG, "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         dlog_print(DLOG_ERROR, TAG, "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         dlog_print(DLOG_ERROR, TAG, "Failed to insert data. error code : %x. message : %s", ret, get_error_message(ret));
79     }
80     else {
81         dlog_print(DLOG_INFO, TAG, "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         dlog_print(DLOG_ERROR, TAG, "Failed to destroy sticker data");
89     }
90 }
91
92 void 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         dlog_print(DLOG_ERROR, TAG, "Failed to create sticker provider");
99     }
100 }
101
102 void destroy_sticker_provider_handle(void)
103 {
104     sticker_provider_destroy(sticker_provider);
105     sticker_provider = NULL;
106 }