2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <media_info_private.h>
18 #include <media_util_private.h>
19 #include <media_uhd.h>
21 int media_uhd_get_media_count_from_db(filter_h filter, int *media_count)
23 content_retip_if_fail(media_count);
25 return _media_db_get_group_item_count(NULL, filter, MEDIA_GROUP_UHD, media_count);
28 int media_uhd_foreach_media_from_db(filter_h filter, media_uhd_cb callback, void *user_data)
30 content_retip_if_fail(callback);
32 return _media_db_get_uhd(filter, callback, user_data);
35 int media_uhd_destroy(media_uhd_h uhd)
37 media_uhd_s *_uhd = (media_uhd_s*)uhd;
39 content_retip_if_fail(uhd);
41 g_free(_uhd->media_id);
42 g_free(_uhd->storage_id);
44 g_free(_uhd->content_id);
45 g_free(_uhd->content_title);
46 g_free(_uhd->file_name);
47 g_free(_uhd->release_date);
50 return MEDIA_CONTENT_ERROR_NONE;
53 int media_uhd_clone(media_uhd_h *dst, media_uhd_h src)
55 media_uhd_s *_src = (media_uhd_s*)src;
57 content_retip_if_fail(dst);
58 content_retip_if_fail(src);
60 media_uhd_s *_dst = g_new0(media_uhd_s, 1);
62 _dst->media_id = g_strdup(_src->media_id);
63 _dst->storage_id = g_strdup(_src->storage_id);
64 _dst->path = g_strdup(_src->path);
65 _dst->content_id = g_strdup(_src->content_id);
66 _dst->content_title = g_strdup(_src->content_title);
67 _dst->release_date = g_strdup(_src->release_date);
68 _dst->file_name = g_strdup(_src->file_name);
69 _dst->size = _src->size;
70 _dst->modified_time = _src->modified_time;
71 _dst->played_position = _src->played_position;
72 _dst->sub_type = _src->sub_type;
73 _dst->played_count = _src->played_count;
75 *dst = (media_uhd_h)_dst;
77 return MEDIA_CONTENT_ERROR_NONE;
80 int media_uhd_get_uhd_from_db(const char *media_id, media_uhd_h *uhd)
82 int ret = MEDIA_CONTENT_ERROR_NONE;
83 char *select_query = NULL;
84 sqlite3_stmt *stmt = NULL;
86 content_retip_if_fail(STRING_VALID(media_id));
87 content_retip_if_fail(uhd);
89 select_query = sqlite3_mprintf(SELECT_UHD_FROM_UHD, media_id);
91 ret = _content_get_result(select_query, &stmt);
92 SQLITE3_SAFE_FREE(select_query);
93 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
95 media_uhd_s *_uhd = NULL;
97 if (sqlite3_step(stmt) == SQLITE_ROW) {
98 _uhd = g_new0(media_uhd_s, 1);
100 _media_uhd_item_get_detail(stmt, (media_uhd_h)_uhd);
102 *uhd = (media_uhd_h)_uhd;
104 content_error("Nonexistent media id[%s]", media_id);
105 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
108 SQLITE3_FINALIZE(stmt);
113 int media_uhd_get_media_id(media_uhd_h uhd, char **media_id)
115 media_uhd_s *_uhd = (media_uhd_s*)uhd;
117 content_retip_if_fail(uhd);
118 content_retip_if_fail(media_id);
120 *media_id = g_strdup(_uhd->media_id);
122 return MEDIA_CONTENT_ERROR_NONE;
125 int media_uhd_get_storage_id(media_uhd_h uhd, char **storage_id)
127 media_uhd_s *_uhd = (media_uhd_s*)uhd;
129 content_retip_if_fail(uhd);
130 content_retip_if_fail(storage_id);
132 *storage_id = g_strdup(_uhd->storage_id);
134 return MEDIA_CONTENT_ERROR_NONE;
137 int media_uhd_get_path(media_uhd_h uhd, char **path)
139 media_uhd_s *_uhd = (media_uhd_s*)uhd;
141 content_retip_if_fail(uhd);
142 content_retip_if_fail(path);
144 *path = g_strdup(_uhd->path);
146 return MEDIA_CONTENT_ERROR_NONE;
149 int media_uhd_get_size(media_uhd_h uhd, unsigned long long *size)
151 media_uhd_s *_uhd = (media_uhd_s*)uhd;
153 content_retip_if_fail(uhd);
154 content_retip_if_fail(size);
158 return MEDIA_CONTENT_ERROR_NONE;
161 int media_uhd_get_content_id(media_uhd_h uhd, char **content_id)
163 media_uhd_s *_uhd = (media_uhd_s*)uhd;
165 content_retip_if_fail(uhd);
166 content_retip_if_fail(content_id);
168 *content_id = g_strdup(_uhd->content_id);
170 return MEDIA_CONTENT_ERROR_NONE;
173 int media_uhd_get_content_title(media_uhd_h uhd, char **content_title)
175 media_uhd_s *_uhd = (media_uhd_s*)uhd;
177 content_retip_if_fail(uhd);
178 content_retip_if_fail(content_title);
180 *content_title = g_strdup(_uhd->content_title);
182 return MEDIA_CONTENT_ERROR_NONE;
185 int media_uhd_get_file_name(media_uhd_h uhd, char **file_name)
187 media_uhd_s *_uhd = (media_uhd_s*)uhd;
189 content_retip_if_fail(uhd);
190 content_retip_if_fail(file_name);
192 *file_name = g_strdup(_uhd->file_name);
194 return MEDIA_CONTENT_ERROR_NONE;
197 int media_uhd_get_release_date(media_uhd_h uhd, char **release_date)
199 media_uhd_s *_uhd = (media_uhd_s*)uhd;
201 content_retip_if_fail(uhd);
202 content_retip_if_fail(release_date);
204 *release_date = g_strdup(_uhd->release_date);
206 return MEDIA_CONTENT_ERROR_NONE;
209 int media_uhd_get_modified_time(media_uhd_h uhd, time_t *modified_time)
211 media_uhd_s *_uhd = (media_uhd_s*)uhd;
213 content_retip_if_fail(uhd);
214 content_retip_if_fail(modified_time);
216 *modified_time = _uhd->modified_time;
218 return MEDIA_CONTENT_ERROR_NONE;
221 int media_uhd_get_played_position(media_uhd_h uhd, int *played_position)
223 media_uhd_s *_uhd = (media_uhd_s*)uhd;
225 content_retip_if_fail(uhd);
226 content_retip_if_fail(played_position);
228 *played_position = _uhd->played_position;
230 return MEDIA_CONTENT_ERROR_NONE;
233 int media_uhd_get_sub_type(media_uhd_h uhd, int *sub_type)
235 media_uhd_s *_uhd = (media_uhd_s*)uhd;
237 content_retip_if_fail(uhd);
238 content_retip_if_fail(sub_type);
240 *sub_type = _uhd->sub_type;
242 return MEDIA_CONTENT_ERROR_NONE;
245 int media_uhd_get_played_count(media_uhd_h uhd, int *played_count)
247 media_uhd_s *_uhd = (media_uhd_s*)uhd;
249 content_retip_if_fail(uhd);
250 content_retip_if_fail(played_count);
252 *played_count = _uhd->played_count;
254 return MEDIA_CONTENT_ERROR_NONE;
257 int media_uhd_set_played_position(media_uhd_h uhd, int played_position)
259 media_uhd_s *_uhd = (media_uhd_s*)uhd;
261 content_retip_if_fail(uhd);
262 content_retip_if_fail(played_position);
264 _uhd->played_position = played_position;
266 return MEDIA_CONTENT_ERROR_NONE;
269 int media_uhd_set_content_title(media_uhd_h uhd, const char *content_title)
271 media_uhd_s *_uhd = (media_uhd_s*)uhd;
273 content_retip_if_fail(uhd);
274 content_retip_if_fail(STRING_VALID(content_title));
276 g_free(_uhd->content_title);
277 _uhd->content_title = g_strdup(content_title);
279 return MEDIA_CONTENT_ERROR_NONE;
282 int media_uhd_set_release_date(media_uhd_h uhd, const char *release_date)
284 media_uhd_s *_uhd = (media_uhd_s*)uhd;
286 content_retip_if_fail(uhd);
287 content_retip_if_fail(STRING_VALID(release_date));
289 g_free(_uhd->release_date);
290 _uhd->release_date = g_strdup(release_date);
292 return MEDIA_CONTENT_ERROR_NONE;
295 int media_uhd_set_sub_type(media_uhd_h uhd, int sub_type)
297 media_uhd_s *_uhd = (media_uhd_s*)uhd;
299 content_retip_if_fail(uhd);
300 content_retip_if_fail(sub_type >= 0);
302 _uhd->sub_type = sub_type;
304 return MEDIA_CONTENT_ERROR_NONE;
307 int media_uhd_set_played_count(media_uhd_h uhd, int played_count)
309 media_uhd_s *_uhd = (media_uhd_s*)uhd;
311 content_retip_if_fail(uhd);
313 _uhd->played_count = played_count;
315 return MEDIA_CONTENT_ERROR_NONE;
318 int media_uhd_update_to_db(media_uhd_h uhd)
320 int ret = MEDIA_CONTENT_ERROR_NONE;
321 media_uhd_s *_uhd = (media_uhd_s*)uhd;
322 char *update_query = NULL;
324 content_retip_if_fail(uhd);
325 content_retip_if_fail(STRING_VALID(_uhd->media_id));
326 content_retip_if_fail(STRING_VALID(_uhd->path));
328 update_query = sqlite3_mprintf(UPDATE_UHD_META_FROM_UHD, _uhd->content_title, _uhd->release_date, _uhd->played_position, _uhd->sub_type, _uhd->played_count, _uhd->media_id);
330 ret = _content_query_sql(update_query);
331 sqlite3_free(update_query);