Add parameter for ebook db
[platform/core/api/media-content.git] / src / media_image.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 int image_meta_destroy(image_meta_h image)
21 {
22         image_meta_s *_image = (image_meta_s*)image;
23
24         content_retip_if_fail(image);
25
26         g_free(_image->media_id);
27         g_free(_image->date_taken);
28         g_free(_image->exposure_time);
29         g_free(_image->model);
30         g_free(_image);
31
32         return MEDIA_CONTENT_ERROR_NONE;
33 }
34
35 int image_meta_clone(image_meta_h *dst, image_meta_h src)
36 {
37         image_meta_s *_src = (image_meta_s*)src;
38
39         content_retip_if_fail(dst);
40         content_retip_if_fail(src);
41
42         image_meta_s *_dst = g_new0(image_meta_s, 1);
43
44         _dst->media_id = g_strdup(_src->media_id);
45         _dst->date_taken = g_strdup(_src->date_taken);
46         _dst->exposure_time = g_strdup(_src->exposure_time);
47         _dst->model = g_strdup(_src->model);
48         _dst->fnumber = _src->fnumber;
49         _dst->iso = _src->iso;
50         _dst->width = _src->width;
51         _dst->height = _src->height;
52         _dst->orientation = _src->orientation;
53
54         *dst = (image_meta_h)_dst;
55
56         return MEDIA_CONTENT_ERROR_NONE;
57 }
58
59 int image_meta_get_media_id(image_meta_h image, char **media_id)
60 {
61         image_meta_s *_image = (image_meta_s*)image;
62
63         content_retip_if_fail(image);
64         content_retip_if_fail(media_id);
65
66         *media_id = g_strdup(_image->media_id);
67
68         return MEDIA_CONTENT_ERROR_NONE;
69 }
70
71 int image_meta_get_width(image_meta_h image, int *width)
72 {
73         image_meta_s *_image = (image_meta_s*)image;
74
75         content_retip_if_fail(image);
76         content_retip_if_fail(width);
77
78         *width = _image->width;
79
80         return MEDIA_CONTENT_ERROR_NONE;
81 }
82 int image_meta_get_height(image_meta_h image, int *height)
83 {
84         image_meta_s *_image = (image_meta_s*)image;
85
86         content_retip_if_fail(image);
87         content_retip_if_fail(height);
88
89         *height = _image->height;
90
91         return MEDIA_CONTENT_ERROR_NONE;
92 }
93
94 int image_meta_get_orientation(image_meta_h image, media_content_orientation_e* orientation)
95 {
96         image_meta_s *_image = (image_meta_s*)image;
97
98         content_retip_if_fail(image);
99         content_retip_if_fail(orientation);
100
101         *orientation = _image->orientation;
102
103         return MEDIA_CONTENT_ERROR_NONE;
104 }
105
106 int image_meta_get_date_taken(image_meta_h image, char **date_taken)
107 {
108         image_meta_s *_image = (image_meta_s*)image;
109
110         content_retip_if_fail(image);
111         content_retip_if_fail(date_taken);
112
113         *date_taken = g_strdup(_image->date_taken);
114
115         return MEDIA_CONTENT_ERROR_NONE;
116 }
117
118 int image_meta_get_exposure_time(image_meta_h image, char **exposure_time)
119 {
120         image_meta_s *_image = (image_meta_s*)image;
121
122         content_retip_if_fail(image);
123         content_retip_if_fail(exposure_time);
124
125         *exposure_time = g_strdup(_image->exposure_time);
126
127         return MEDIA_CONTENT_ERROR_NONE;
128 }
129
130 int image_meta_get_fnumber(image_meta_h image, double *fnumber)
131 {
132         image_meta_s *_image = (image_meta_s*)image;
133
134         content_retip_if_fail(image);
135         content_retip_if_fail(fnumber);
136
137         *fnumber = _image->fnumber;
138
139         return MEDIA_CONTENT_ERROR_NONE;
140 }
141
142 int image_meta_get_iso(image_meta_h image, int *iso)
143 {
144         image_meta_s *_image = (image_meta_s*)image;
145
146         content_retip_if_fail(image);
147         content_retip_if_fail(iso);
148
149         *iso = _image->iso;
150
151         return MEDIA_CONTENT_ERROR_NONE;
152 }
153
154 int image_meta_get_model(image_meta_h image, char **model)
155 {
156         image_meta_s *_image = (image_meta_s*)image;
157
158         content_retip_if_fail(image);
159         content_retip_if_fail(model);
160
161         *model = g_strdup(_image->model);
162
163         return MEDIA_CONTENT_ERROR_NONE;
164 }
165
166 int image_meta_set_orientation(image_meta_h image, media_content_orientation_e orientation)
167 {
168         content_warn("DEPRECATION WARNING: image_meta_set_orientation() is deprecated and will be removed from next release.");
169         image_meta_s *_image = (image_meta_s*)image;
170
171         content_retip_if_fail(image);
172         content_retvm_if(orientation < MEDIA_CONTENT_ORIENTATION_NOT_AVAILABLE || orientation > MEDIA_CONTENT_ORIENTATION_ROT_270, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid orientation");
173
174         _image->orientation = orientation;
175
176         return MEDIA_CONTENT_ERROR_NONE;
177 }
178
179 int image_meta_update_to_db(image_meta_h image)
180 {
181         int ret = MEDIA_CONTENT_ERROR_NONE;
182         content_warn("DEPRECATION WARNING: image_meta_update_to_db() is deprecated and will be removed from next release.");
183         image_meta_s *_image = (image_meta_s*)image;
184         char *sql = NULL;
185
186         content_retip_if_fail(image);
187         content_retip_if_fail(STRING_VALID(_image->media_id));
188
189 #ifdef _USE_TVPD_MODE
190                 char *storage_id = NULL;
191                 ret = _media_db_get_storage_id_by_media_id(_image->media_id, &storage_id);
192                 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
193                 sql = sqlite3_mprintf(UPDATE_IMAGE_META_FROM_MEDIA, storage_id, _image->orientation, _image->media_id);
194                 g_free(storage_id);
195 #else
196                 sql = sqlite3_mprintf(UPDATE_IMAGE_META_FROM_MEDIA, _image->orientation, _image->media_id);
197 #endif
198                 ret = _content_query_sql(sql);
199                 SQLITE3_SAFE_FREE(sql);
200
201         return ret;
202 }