2 * Copyright 2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
18 #include <media_content.h>
22 #include "mf-media-content.h"
24 mf_condition_s *mf_media_content_condition_create(const char *condition)
26 mf_condition_s *filter = NULL;
28 filter = (mf_condition_s *)calloc(1, sizeof(mf_condition_s));
34 memset(filter, 0, sizeof(mf_condition_s));
36 mf_debug("condition [%s]", condition);
37 filter->cond = condition;
38 filter->collate_type = MEDIA_CONTENT_COLLATE_DEFAULT;
39 filter->sort_type = MEDIA_CONTENT_ORDER_DESC;
40 filter->sort_keyword = MEDIA_MODIFIED_TIME;
41 filter->with_meta = true;
46 void mf_media_conte_free_condition(mf_condition_s **condition)
48 mf_retm_if(condition == NULL, "condition is NULL");
50 SAFE_FREE_CHAR((*condition)->cond);
51 SAFE_FREE_CHAR(*condition);
55 int mf_media_content_create_filter(filter_h *filter, mf_condition_s *condition)
57 mf_retvm_if(filter == NULL, -1, "filter is NULL");
58 mf_retvm_if(condition == NULL, -1, "condition is NULL");
60 int ret = MEDIA_CONTENT_ERROR_NONE;
61 filter_h tmp_filter = NULL;
62 ret = media_filter_create(&tmp_filter);
63 if(ret != MEDIA_CONTENT_ERROR_NONE) {
64 mf_debug("Fail to create filter");
67 if (condition->cond) {
68 ret = media_filter_set_condition(tmp_filter, condition->cond,
69 condition->collate_type);
70 if(ret != MEDIA_CONTENT_ERROR_NONE) {
71 mf_debug("Fail to set condition");
76 if (condition->sort_keyword) {
77 ret = media_filter_set_order(tmp_filter, condition->sort_type,
78 condition->sort_keyword,
79 condition->collate_type);
80 if(ret != MEDIA_CONTENT_ERROR_NONE) {
81 mf_debug("Fail to set order");
86 mf_debug("offset is %d, count is %d", condition->offset, condition->count);
87 if (condition->offset != -1 && condition->count != -1 &&
88 condition->count > condition->offset) {
89 ret = media_filter_set_offset(tmp_filter, condition->offset,
91 if(ret != MEDIA_CONTENT_ERROR_NONE) {
92 mf_debug("Fail to set offset");
100 media_filter_destroy(tmp_filter);
106 int mf_media_content_destroy_filter(filter_h filter)
108 mf_retvm_if(filter == NULL, -1, "filter is NULL");
109 int ret = MEDIA_CONTENT_ERROR_NONE;
110 ret = media_filter_destroy(filter);
115 int mf_media_content_data_get(void *data, char *condition, bool (*func) (media_info_h media, void *data))
118 mf_condition_s *temp_condition = NULL;
119 filter_h filter = NULL;
120 temp_condition = mf_media_content_condition_create(condition);
123 ret = mf_media_content_create_filter(&filter, temp_condition);
126 mf_debug("Create filter failed");
127 mf_media_conte_free_condition(&temp_condition);
132 ret = media_info_foreach_media_from_db(filter,
136 mf_debug("media_info_foreach_media_from_db failed: %d", ret);
138 mf_debug("media_info_foreach_media_from_db success!", ret);
141 mf_media_content_destroy_filter(filter);
142 mf_media_conte_free_condition(&temp_condition);
148 void mf_media_content_scan_file(const char *path)
150 mf_retm_if(path == NULL, "path is NULL");
152 media_content_scan_file(path);
155 void mf_media_content_scan_folder(const char *path)
157 mf_retm_if(path == NULL, "path is NULL");
159 media_content_scan_folder(path, NULL, NULL);