Apply tizen coding rule
[platform/core/api/media-content.git] / src / media_bookmark.c
1 /*
2 * Copyright (c) 2011 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
18 #include <media_info_private.h>
19
20
21 int media_bookmark_insert_to_db(const char *media_id, time_t time, const char *thumbnail_path)
22 {
23         int ret = MEDIA_CONTENT_ERROR_NONE;
24         char *sql = NULL;
25
26         if (STRING_VALID(media_id)) {
27                 sql = sqlite3_mprintf(INSERT_BOOKMARK_TO_BOOKMARK, media_id, time, thumbnail_path);
28                 ret = _content_query_sql(sql);
29                 SQLITE3_SAFE_FREE(sql);
30         } else {
31                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
32                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
33         }
34
35         return ret;
36 }
37
38 int media_bookmark_delete_from_db(int bookmark_id)
39 {
40         int ret = MEDIA_CONTENT_ERROR_NONE;
41         char *query_str = NULL;
42
43         if (bookmark_id < 0) {
44                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
45                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
46         }
47
48         query_str = sqlite3_mprintf(DELETE_BOOKMARK_FROM_BOOKMARK, bookmark_id);
49
50         ret = _content_query_sql(query_str);
51
52         SQLITE3_SAFE_FREE(query_str);
53
54         return ret;
55 }
56
57 int media_bookmark_get_bookmark_count_from_db(filter_h filter, int *bookmark_count)
58 {
59         int ret = MEDIA_CONTENT_ERROR_NONE;
60
61         if (bookmark_count == NULL) {
62                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
63                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
64         }
65
66         ret = _media_db_get_group_count(filter, MEDIA_GROUP_BOOKMARK, bookmark_count);
67
68         return ret;
69 }
70
71 int media_bookmark_destroy(media_bookmark_h bookmark)
72 {
73         int ret = MEDIA_CONTENT_ERROR_NONE;
74         media_bookmark_s *_bookmark = (media_bookmark_s*)bookmark;
75
76         if (_bookmark) {
77                 SAFE_FREE(_bookmark->media_id);
78                 SAFE_FREE(_bookmark->thumbnail_path);
79                 free(_bookmark);
80                 ret = MEDIA_CONTENT_ERROR_NONE;
81         } else {
82                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
83                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
84         }
85
86         return ret;
87 }
88 int media_bookmark_clone(media_bookmark_h *dst, media_bookmark_h src)
89 {
90         int ret = MEDIA_CONTENT_ERROR_NONE;
91
92         if ((src != NULL)) {
93                 media_bookmark_s *_src = (media_bookmark_s*)src;
94                 media_bookmark_s *_dst = (media_bookmark_s*)calloc(1, sizeof(media_bookmark_s));
95                 media_content_retvm_if(_dst == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
96
97                 _dst->bookmark_id = _src->bookmark_id;
98
99                 if (STRING_VALID(_src->media_id)) {
100                         _dst->media_id = (char *)strdup(_src->media_id);
101                         if (_dst->media_id == NULL) {
102                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
103                                 media_bookmark_destroy((media_bookmark_h)_dst);
104                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
105                         }
106                 }
107
108                 _dst->marked_time = _src->marked_time;
109
110                 if (STRING_VALID(_src->thumbnail_path)) {
111                         _dst->thumbnail_path = (char*)strdup(_src->thumbnail_path);
112                         if (_dst->thumbnail_path == NULL) {
113                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
114                                 media_bookmark_destroy((media_bookmark_h)_dst);
115                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
116                         }
117                 }
118
119                 *dst = (media_bookmark_h)_dst;
120
121                 ret = MEDIA_CONTENT_ERROR_NONE;
122         } else {
123                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
124                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
125         }
126
127         return ret;
128 }
129
130 int media_bookmark_get_bookmark_id(media_bookmark_h bookmark, int *bookmark_id)
131 {
132         int ret = MEDIA_CONTENT_ERROR_NONE;
133         media_bookmark_s *_bookmark = (media_bookmark_s*)bookmark;
134
135         if (_bookmark) {
136                 *bookmark_id = _bookmark->bookmark_id;
137                 ret = MEDIA_CONTENT_ERROR_NONE;
138         } else {
139                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
140                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
141         }
142
143         return ret;
144 }
145
146 int media_bookmark_get_marked_time(media_bookmark_h bookmark, time_t* marked_time)
147 {
148         int ret = MEDIA_CONTENT_ERROR_NONE;
149         media_bookmark_s *_bookmark = (media_bookmark_s*)bookmark;
150
151         if (_bookmark) {
152                 *marked_time = _bookmark->marked_time;
153                 ret = MEDIA_CONTENT_ERROR_NONE;
154         } else {
155                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
156                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
157         }
158
159         return ret;
160 }
161
162 int media_bookmark_get_thumbnail_path(media_bookmark_h bookmark, char **path)
163 {
164         int ret = MEDIA_CONTENT_ERROR_NONE;
165         media_bookmark_s *_bookmark = (media_bookmark_s*)bookmark;
166
167         if (_bookmark) {
168                 if (STRING_VALID(_bookmark->thumbnail_path)) {
169                         *path = strdup(_bookmark->thumbnail_path);
170                         media_content_retvm_if(*path == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
171                 } else {
172                         *path = NULL;
173                 }
174
175                 ret = MEDIA_CONTENT_ERROR_NONE;
176         } else {
177                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
178                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
179         }
180
181         return ret;
182 }