summaryrefslogtreecommitdiff
path: root/src/media_bookmark.c
blob: 04bb17a6ef8313c4335ec9aa7652a058fdbef437 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
/*
* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


#include <media_content.h>
#include <media_info_private.h>
#include <media-svc.h>

int media_bookmark_foreach_bookmark_from_db (filter_h filter, media_bookmark_cb callback, void *user_data);
int media_bookmark_get_media_id(media_bookmark_h bookmark, char **media_id);

int media_bookmark_insert_to_db(const char *media_id, time_t time, const char *thumbnail_path)
{
	int ret = MEDIA_CONTENT_ERROR_NONE;
	char *sql = NULL;

	if(STRING_VALID(media_id))
	{
		sql = sqlite3_mprintf(INSERT_BOOKMARK_TO_BOOKMARK, media_id, time, thumbnail_path);
		ret = _content_query_sql(sql);
		sqlite3_free(sql);
	}
	else
	{
		media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
		ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
	}

	return ret;
}

int media_bookmark_delete_from_db(int bookmark_id)
{
	int ret = MEDIA_CONTENT_ERROR_NONE;
	char *query_str = NULL;

	if(bookmark_id < 0)
	{
		media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
		return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
	}

	query_str = sqlite3_mprintf(DELETE_BOOKMARK_FROM_BOOKMARK, bookmark_id);

	ret = _content_query_sql(query_str);

	sqlite3_free(query_str);

	return ret;
}

int media_bookmark_get_bookmark_count_from_db(filter_h filter, int *bookmark_count)
{
	int ret = MEDIA_CONTENT_ERROR_NONE;

	media_content_debug_func();

	if (bookmark_count == NULL)
	{
		media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
		return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
	}

	ret = _media_db_get_group_count(filter, MEDIA_GROUP_BOOKMARK, bookmark_count);

	return ret;
}

int media_bookmark_foreach_bookmark_from_db (filter_h filter, media_bookmark_cb callback, void *user_data)
{
	int ret = MEDIA_CONTENT_ERROR_NONE;

	media_content_debug_func();

	if(callback == NULL)
	{
		media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
		return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
	}

	ret = _media_db_get_bookmark(NULL, filter, callback, user_data);

	return ret;
}

int media_bookmark_destroy(media_bookmark_h bookmark)
{
	int ret = MEDIA_CONTENT_ERROR_NONE;
	media_bookmark_s *_bookmark = (media_bookmark_s*)bookmark;

	if(_bookmark)
	{
		SAFE_FREE(_bookmark->media_id);
		SAFE_FREE(_bookmark->thumbnail_path);
		free(_bookmark);
		ret = MEDIA_CONTENT_ERROR_NONE;
	}
	else
	{
		media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
		ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
	}

	return ret;
}
int media_bookmark_clone(media_bookmark_h *dst, media_bookmark_h src)
{
	int ret = MEDIA_CONTENT_ERROR_NONE;

	if((src != NULL))
	{
		media_bookmark_s *_src = (media_bookmark_s*)src;
		media_bookmark_s *_dst = (media_bookmark_s*)calloc(1, sizeof(media_bookmark_s));

		if(NULL == _dst)
		{
			media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
			return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
		}

		_dst->bookmark_id = _src->bookmark_id;

		if(STRING_VALID(_src->media_id))
		{
			_dst->media_id = (char*)strdup(_src->media_id);
			if(_dst->media_id == NULL)
			{
				media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
				media_bookmark_destroy((media_bookmark_h)_dst);
				return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
			}
		}

		_dst->marked_time = _src->marked_time;

		if(STRING_VALID(_src->thumbnail_path))
		{
			_dst->thumbnail_path = (char*)strdup(_src->thumbnail_path);
			if(_dst->thumbnail_path == NULL)
			{
				media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
				media_bookmark_destroy((media_bookmark_h)_dst);
				return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
			}
		}

		*dst = (media_bookmark_h)_dst;

		ret = MEDIA_CONTENT_ERROR_NONE;
	}
	else
	{
		media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
		ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
	}

	return ret;
}

int media_bookmark_get_bookmark_id(media_bookmark_h bookmark, int *bookmark_id)
{
	int ret = MEDIA_CONTENT_ERROR_NONE;
	media_bookmark_s *_bookmark = (media_bookmark_s*)bookmark;

	if(_bookmark)
	{
		*bookmark_id = _bookmark->bookmark_id;
		ret = MEDIA_CONTENT_ERROR_NONE;
	}
	else
	{
		media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
		ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
	}

	return ret;
}

int media_bookmark_get_media_id(media_bookmark_h bookmark, char **media_id)
{
	int ret = MEDIA_CONTENT_ERROR_NONE;
	media_bookmark_s *_bookmark = (media_bookmark_s*)bookmark;

	if(_bookmark)
	{
		if(STRING_VALID(_bookmark->media_id))
		{
			*media_id = strdup(_bookmark->media_id);
			if(*media_id == NULL)
			{
				media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
				return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
			}
		}
		else
		{
			*media_id = NULL;
		}

		ret = MEDIA_CONTENT_ERROR_NONE;
	}
	else
	{
		media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
		ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
	}

	return ret;
}

int media_bookmark_get_marked_time(media_bookmark_h bookmark, time_t* marked_time)
{
	int ret = MEDIA_CONTENT_ERROR_NONE;
	media_bookmark_s *_bookmark = (media_bookmark_s*)bookmark;

	if(_bookmark)
	{
		*marked_time = _bookmark->marked_time;
		ret = MEDIA_CONTENT_ERROR_NONE;
	}
	else
	{
		media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
		ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
	}

	return ret;
}

int media_bookmark_get_thumbnail_path(media_bookmark_h bookmark, char **path)
{
	int ret = MEDIA_CONTENT_ERROR_NONE;
	media_bookmark_s *_bookmark = (media_bookmark_s*)bookmark;

	if(_bookmark)
	{
		if(STRING_VALID(_bookmark->thumbnail_path))
		{
			*path = strdup(_bookmark->thumbnail_path);
			if(*path == NULL)
			{
				media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
				return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
			}
		}
		else
		{
			*path = NULL;
		}

		ret = MEDIA_CONTENT_ERROR_NONE;
	}
	else
	{
		media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
		ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
	}

	return ret;
}