57b71054784a2509b250a32809db0b875e1d770a
[platform/core/api/media-content.git] / src / media_book.c
1 /*
2 * Copyright (c) 2021 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 book_meta_destroy(book_meta_h book)
21 {
22         book_meta_s *_book = (book_meta_s *)book;
23
24         content_retip_if_fail(book);
25
26         g_free(_book->media_id);
27         g_free(_book->author);
28         g_free(_book->publisher);
29         g_free(_book->subject);
30         g_free(_book->date);
31         g_free(_book);
32
33         return MEDIA_CONTENT_ERROR_NONE;
34 }
35
36 int book_meta_clone(book_meta_h *dst, book_meta_h src)
37 {
38         book_meta_s *_src = (book_meta_s *)src;
39
40         content_retip_if_fail(dst);
41         content_retip_if_fail(src);
42
43         book_meta_s *_dst = g_new0(book_meta_s, 1);
44
45         _dst->media_id = g_strdup(_src->media_id);
46         _dst->author = g_strdup(_src->author);
47         _dst->date = g_strdup(_src->date);
48         _dst->publisher = g_strdup(_src->publisher);
49         _dst->subject = g_strdup(_src->subject);
50
51         *dst = (book_meta_h)_dst;
52
53         return MEDIA_CONTENT_ERROR_NONE;
54 }
55
56 int book_meta_get_media_id(book_meta_h book, char **media_id)
57 {
58         book_meta_s *_book = (book_meta_s *)book;
59
60         content_retip_if_fail(book);
61         content_retip_if_fail(media_id);
62
63         *media_id = g_strdup(_book->media_id);
64
65         return MEDIA_CONTENT_ERROR_NONE;
66 }
67
68 int book_meta_get_subject(book_meta_h book, char **subject)
69 {
70         book_meta_s *_book = (book_meta_s *)book;
71
72         content_retip_if_fail(book);
73         content_retip_if_fail(subject);
74
75         *subject = g_strdup(_book->subject);
76
77         return MEDIA_CONTENT_ERROR_NONE;
78 }
79
80 int book_meta_get_author(book_meta_h book, char **author)
81 {
82         book_meta_s *_book = (book_meta_s *)book;
83
84         content_retip_if_fail(book);
85         content_retip_if_fail(author);
86
87         *author = g_strdup(_book->author);
88
89         return MEDIA_CONTENT_ERROR_NONE;
90 }
91
92 int book_meta_get_date(book_meta_h book, char **date)
93 {
94         book_meta_s *_book = (book_meta_s *)book;
95
96         content_retip_if_fail(book);
97         content_retip_if_fail(date);
98
99         *date = g_strdup(_book->date);
100
101         return MEDIA_CONTENT_ERROR_NONE;
102 }
103
104 int book_meta_get_publisher(book_meta_h book, char **publisher)
105 {
106         book_meta_s *_book = (book_meta_s *)book;
107
108         content_retip_if_fail(book);
109         content_retip_if_fail(publisher);
110
111         *publisher = g_strdup(_book->publisher);
112
113         return MEDIA_CONTENT_ERROR_NONE;
114 }
115
116 int book_meta_get_path_with_keyword(const char *keyword, char ***path_list, unsigned int *len)
117 {
118         int ret = MEDIA_CONTENT_ERROR_NONE;
119         GList *book_list = NULL;
120         int i = 0;
121         int result_len = 0;
122
123         content_retip_if_fail(keyword);
124         content_retip_if_fail(path_list);
125         content_retip_if_fail(len);
126
127         ret = media_svc_get_book_by_keyword(_content_get_db_handle(), keyword, _content_get_uid(), &book_list);
128         content_retv_if(ret != MS_MEDIA_ERR_NONE, _content_error_capi(ret));
129
130         result_len = g_list_length(book_list);
131         if (result_len == 0) {
132                 content_info("There is no corresponding eBook");
133                 return MEDIA_CONTENT_ERROR_NONE;
134         }
135
136         *path_list = g_new0(char *, result_len);
137
138         for (i = 0; i < result_len; i++)
139                 (*path_list)[i] = g_strdup((const gchar *)g_list_nth_data(book_list, i));
140
141         g_list_free_full(book_list, g_free);
142
143         *len = result_len;
144
145         return MEDIA_CONTENT_ERROR_NONE;
146 }