/* * Copyright (c) 2015 Samsung Electronics Co., Ltd * * Licensed under the Flora License, Version 1.1 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://floralicense.org/license/ * * 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 "doc-data-util.h" /* * create a doc_item */ doc_item *doc_data_util_calloc_item(void) { doc_item *ditem = (doc_item *) calloc(1, sizeof(doc_item)); DOC_CHECK_NULL(ditem); return ditem; } /* * destroy a doc_item */ static int _doc_data_util_free_item(doc_item * ditem) { if (ditem) { if (ditem->item) { doc_data_type_free_item((void **) &(ditem->item)); ditem->item = NULL; } DOC_FREE(ditem); } return 0; } int doc_data_util_free_mtype_items(Eina_List ** elist) { void *current = NULL; if (elist && *elist) { doc_dbg("Clear Mitems list."); EINA_LIST_FREE(*elist, current) { if (current) { doc_data_type_free_item((void **) ¤t); current = NULL; } } *elist = NULL; } return 0; } int doc_data_util_free_item(doc_item * item) { DOC_CHECK_VAL(item, -1); _doc_data_util_free_item(item); return 0; } /* * Create a doc_item for selected item */ doc_sel_item_s *doc_data_util_new_sel_item(doc_item * ditem) { DOC_CHECK_NULL(ditem); DOC_CHECK_NULL(ditem->item); doc_sel_item_s *item = (doc_sel_item_s *) calloc(1, sizeof(doc_sel_item_s)); DOC_CHECK_NULL(item); item->uuid = strdup(ditem->item->uuid); item->file_url = strdup(ditem->item->file_url); item->store_type = ditem->store_type; item->sequence = ditem->sequence; return item; } /* * Free a doc_sel_item_s item */ int doc_data_util_free_sel_item(doc_sel_item_s * item) { DOC_CHECK_VAL(item, -1); DOC_FREEIF(item->uuid); DOC_FREEIF(item->file_url); DOC_FREE(item); return 0; } int doc_data_util_create_filter(doc_filter_s * condition, filter_h * filter) { DOC_CHECK_VAL(filter, -1); DOC_CHECK_VAL(condition, -1); int ret = -1; filter_h tmp_filter = NULL; ret = media_filter_create(&tmp_filter); if (ret != MEDIA_CONTENT_ERROR_NONE) { doc_dbgE("Fail to create filter!"); return -1; } if (strlen(condition->cond) > 0) { ret = media_filter_set_condition(tmp_filter, condition->cond, condition->collate_type); if (ret != MEDIA_CONTENT_ERROR_NONE) { doc_dbgE("Fail to set condition!"); goto DOC_DATA_UTIL_FAILED; } } if (strlen(condition->sort_keyword) > 0) { ret = media_filter_set_order(tmp_filter, condition->sort_type, condition->sort_keyword, condition->collate_type); if (ret != MEDIA_CONTENT_ERROR_NONE) { doc_dbgE("Fail to set order!"); goto DOC_DATA_UTIL_FAILED; } } doc_dbg("offset: %d, count: %d", condition->offset, condition->count); if (condition->offset != -1) { ret = media_filter_set_offset(tmp_filter, condition->offset, condition->count); if (ret != MEDIA_CONTENT_ERROR_NONE) { doc_dbgE("Fail to set offset!"); goto DOC_DATA_UTIL_FAILED; } } *filter = tmp_filter; return 0; DOC_DATA_UTIL_FAILED: if (tmp_filter) { media_filter_destroy(tmp_filter); tmp_filter = NULL; *filter = NULL; } return -1; } int doc_data_util_destroy_filter(filter_h filter) { DOC_CHECK_VAL(filter, -1); if (media_filter_destroy(filter) != MEDIA_CONTENT_ERROR_NONE) { doc_dbgE("Failed to destroy filter!"); return -1; } return 0; } bool doc_data_util_clone_media(media_info_h media, doc_media_s ** pitem, bool b_meta) { DOC_CHECK_FALSE(pitem); doc_media_s *item = NULL; *pitem = NULL; item = (doc_media_s *) calloc(1, sizeof(doc_media_s)); DOC_CHECK_FALSE(item); item->gtype = DOC_TYPE_MEDIA; if (media_info_clone(&(item->media_h), media) != MEDIA_CONTENT_ERROR_NONE) { doc_dbgE("Clone media handle error"); goto DOC_DATA_UTIL_FAILED; } if (media_info_get_media_id(media, &(item->uuid)) != MEDIA_CONTENT_ERROR_NONE) { doc_dbgE("Get media id error"); goto DOC_DATA_UTIL_FAILED; } if (media_info_get_display_name(media, &(item->display_name)) != MEDIA_CONTENT_ERROR_NONE) { doc_dbgE("Get media display name error"); goto DOC_DATA_UTIL_FAILED; } if (media_info_get_file_path(media, &(item->file_url)) != MEDIA_CONTENT_ERROR_NONE) { doc_dbgE("Get media file path error"); goto DOC_DATA_UTIL_FAILED; } if (media_info_get_media_type (media, (media_content_type_e *) & (item->type)) != MEDIA_CONTENT_ERROR_NONE) { doc_dbgE("Get media type error"); goto DOC_DATA_UTIL_FAILED; } if (media_info_get_thumbnail_path(media, &(item->thumb_url)) != MEDIA_CONTENT_ERROR_NONE) { doc_dbgE("Get media thumbnail path error"); goto DOC_DATA_UTIL_FAILED; } doc_sdbg("thumb_url: %s", item->thumb_url); if (media_info_get_timeline(media, &(item->mtime)) != MEDIA_CONTENT_ERROR_NONE) { doc_dbgE("Get media modified time error"); goto DOC_DATA_UTIL_FAILED; } /* if (media_info_get_mode(media, (media_content_mode_e *)&(item->mode)) != MEDIA_CONTENT_ERROR_NONE) { doc_dbgE("Get media mode failed!"); goto DOC_DATA_UTIL_FAILED; } */ media_content_storage_e storage_type = 0; if (media_info_get_storage_type(media, &storage_type) != MEDIA_CONTENT_ERROR_NONE) { doc_dbgE("Get storage type failed!"); goto DOC_DATA_UTIL_FAILED; } if (storage_type == MEDIA_CONTENT_STORAGE_INTERNAL) { /* The device's internal storage */ item->storage_type = DOC_PHONE; } else if (storage_type == MEDIA_CONTENT_STORAGE_EXTERNAL) { /* The device's external storage */ item->storage_type = DOC_MMC; } else { doc_dbgE("Undefined mode[%d]!", storage_type); } *pitem = item; return true; DOC_DATA_UTIL_FAILED: doc_data_type_free_item((void **) (&item)); return false; }