summaryrefslogtreecommitdiff
path: root/src/doc-data-util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/doc-data-util.c')
-rw-r--r--src/doc-data-util.c234
1 files changed, 234 insertions, 0 deletions
diff --git a/src/doc-data-util.c b/src/doc-data-util.c
new file mode 100644
index 0000000..406f50a
--- /dev/null
+++ b/src/doc-data-util.c
@@ -0,0 +1,234 @@
+/*
+* Copyright (c) 2000-2015 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 "doc-data-util.h"
+
+/*
+* create a gitem
+*/
+doc_item *doc_data_util_calloc_geitem(void)
+{
+ doc_item *gitem = (doc_item*)calloc(1, sizeof(doc_item));
+ DOC_CHECK_NULL(gitem);
+ return gitem;
+}
+
+/*
+* destroy a doc_item
+*/
+static int _doc_data_util_free_geitem(doc_item* gitem)
+{
+ if (gitem) {
+ if (gitem->item) {
+ doc_data_type_free_geitem((void **)&(gitem->item));
+ gitem->item = NULL;
+ }
+ DOC_FREE(gitem);
+ }
+ 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_geitem((void **)&current);
+ current = NULL;
+ }
+ }
+
+ *elist = NULL;
+ }
+
+ return 0;
+}
+
+int doc_data_util_free_item(doc_item *gitem)
+{
+ DOC_CHECK_VAL(gitem, -1);
+
+ _doc_data_util_free_geitem(gitem);
+ return 0;
+}
+
+/*
+* Create a gitem for selected item
+*/
+doc_sel_item_s* doc_data_util_new_sel_item(doc_item *gitem)
+{
+ DOC_CHECK_NULL(gitem);
+ DOC_CHECK_NULL(gitem->item);
+ doc_sel_item_s *item = (doc_sel_item_s *)calloc(1, sizeof(doc_sel_item_s));
+ DOC_CHECK_NULL(item);
+ item->uuid = strdup(gitem->item->uuid);
+ item->file_url = strdup(gitem->item->file_url);
+ item->store_type = gitem->store_type;
+ item->sequence = gitem->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_geitem((void **)(&item));
+ return false;
+}
+