summaryrefslogtreecommitdiff
path: root/main/src/data/ivug-data.c
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/data/ivug-data.c')
-rwxr-xr-xmain/src/data/ivug-data.c683
1 files changed, 0 insertions, 683 deletions
diff --git a/main/src/data/ivug-data.c b/main/src/data/ivug-data.c
deleted file mode 100755
index 4e05214..0000000
--- a/main/src/data/ivug-data.c
+++ /dev/null
@@ -1,683 +0,0 @@
-/*
- * Copyright 2012 Samsung Electronics Co., Ltd
- *
- * Licensed under the Flora License, Version 1.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.tizenopensource.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 "ivug-main.h"
-#include "ivug-common.h"
-
-#include "ivug-data.h"
-#include "ivug-util.h"
-#include "ivug-data-priv.h"
-#include "ivug-data-list.h"
-#include "ivug-data-filter.h"
-
-
-#include <media-svc.h>
-
-static bool
-_ivug_data_set_window_section(Media_List *mList, int start_index, int total_count, int *stp, int *endp)
-{
- IV_ASSERT(mList != NULL);
-
- _Media_List *_mList = (_Media_List *)mList;
-
- //if(total_count > _mList->window_size && start_index > 0) // TODO : IV_ASSERT(start_index > 0); after fix gallery
- if(start_index > 0 && total_count > 0 && start_index <= total_count) // TODO : IV_ASSERT(start_index > 0); after fix gallery
- {
- *stp = (start_index-1) - (_mList->window_size/2);
- if(*stp < 0)
- {
- *stp = 0;
- }
- *endp = (start_index-1) + (_mList->window_size/2);
- if(*endp > total_count-1)
- {
- *endp = total_count-1;
- }
- if(_mList->window_count > 0)
- {
- if(*stp < _mList->left_end) /* load left window */
- {
- if(*endp > _mList->left_end-1)
- {
- *endp = _mList->left_end -1;
- }
- _mList->left_end = *stp;
- }
- if(*endp > _mList->right_end) /* load right window */
- {
- if(*stp < _mList->right_end+1)
- {
- *stp = _mList->right_end +1;
- }
- _mList->right_end = *endp;
- }
- }
- else // first window loding
- {
- MSG_SDATA_HIGH("First window loading");
- _mList->left_end = *stp;
- _mList->right_end = *endp;
- _mList->window_count++;
- }
- MSG_SDATA_HIGH("Window loading [%d~%d]", *stp, *endp);
-
- MSG_SDATA_HIGH("true : _mlist [%d~%d]", _mList->left_end, _mList->right_end);
- return true;
- }
- else
- {
- if(_mList->window_count == 0)
- {
- MSG_SDATA_HIGH("Entire loading");
- _mList->left_end = 0;
- _mList->right_end = total_count-1;
- }
- MSG_SDATA_HIGH("false : _mlist [%d~%d]", _mList->left_end, _mList->right_end);
- return false;
- }
-}
-
-
-static bool
-_ivug_data_add_media_item(Eina_List **list, const char *filepath)
-{
- IV_ASSERT(list != NULL);
-
- int ret = 0;
- Mitem* item = NULL;
-
- if (ivug_is_web_uri(filepath) == false)
- { //local file.
- ret = minfo_get_item(gGetMediaSVCHandle(), filepath, &item); //get cluster id
- if (ret != MB_SVC_ERROR_NONE)
- {
- MSG_SDATA_ERROR("Cannot find file in media db for %s", filepath);
- }
- }
-
- Media_Data* mdata = NULL;
-
- if (item != NULL)
- {
- mdata = ivug_alloc_mediadata_from_mitem(item);
- minfo_destroy_mtype_item(item);
- }
- else
- {
- mdata = ivug_alloc_mediadata_from_filepath(filepath);
- }
-
- if ( mdata == NULL )
- {
- MSG_SDATA_ERROR("Cannot create slide data for %s", filepath);
- return false;
- }
-
- *list = eina_list_append(*list, mdata);
-
- return true;
-
-}
-
-Eina_List *_ivug_data_create_window_size_list(Media_List *mList, int start_index, int total_count)
-{
- IV_ASSERT(mList != NULL);
-
- _Media_List *_mList = (_Media_List *)mList;
- Eina_List* slide_list = NULL;
-
- MSG_SDATA_HIGH("start index is %d", start_index);
-
- if(start_index < 1 || start_index > total_count)
- {
- MSG_SDATA_ERROR("start index is invalid %d", start_index);
- return NULL;
- }
-
-// Eina_List *ivug_list_load_items(List_Filter *filter, int stp, int endp);
-
- int stp = 0, endp = 0;
-
- _ivug_data_set_window_section(mList, start_index, total_count, &stp, &endp);
-
- slide_list = ivug_list_load_items(_mList->filter, stp, endp);
-
- if(slide_list == NULL)
- {
- MSG_SDATA_ERROR("Create list ERROR");
- return NULL;
- }
-
- return slide_list;
-}
-
-static Media_Item *
-_ivug_data_create_list(Media_List *mList, Eina_List **list, const char *filepath, int *start_index, int *total_count)
-{
- IV_ASSERT(mList != NULL);
- IV_ASSERT(filepath != NULL);
-
- MSG_SDATA_HIGH("Creating slide data list");
-
- _Media_List *_mList = (_Media_List *)mList;
- Media_Item *item = NULL;
-
- *total_count = -1;
-
- if(_mList->filter->view_by == IVUG_VIEW_BY_FILE)
- {
- if (filepath == NULL)
- {
- MSG_SDATA_ERROR("file path is NULL");
- return NULL;
- }
-
- // No need to create list. just one file only.
- if ( _ivug_data_add_media_item(list, filepath) == false)
- {
- MSG_SDATA_ERROR("Cannot add file : %s", filepath);
- return NULL;
- }
- *total_count = 1;
- item = *list;
- return item;
- }
- else
- {
- *total_count = ivug_list_get_item_cnt(_mList->filter);
-
- *list = _ivug_data_create_window_size_list(mList, *start_index, *total_count);
- }
-
- if(*list == NULL)
- {
- MSG_SDATA_ERROR("list is NULL");
- return NULL;
- }
-
- if(*total_count == 1)
- {
- item = *list;
- *start_index = 1;
- return item;
- }
- else if(*start_index > 0 && *start_index <= *total_count)
- {
- item = eina_list_nth_list(*list, (*start_index-1)-_mList->left_end);
- }
-
- Media_Data *mdata = NULL;
- bool find = false;
- int index = 0;
-
- if(item != NULL)
- {
- MSG_SDATA_HIGH("start index exist");
- mdata = ivug_data_get_data(item);
-
- if(mdata != NULL)
- {
- if ((mdata)->filepath)
- {
- if(strncmp(filepath, mdata->filepath, strlen(filepath)) == 0)
- {
- MSG_SLIDER_HIGH("Founded Filepath=%s Index=%d", ivug_get_filename(mdata->filepath), *start_index);
- index = *start_index; // recieve from bundle
- find = true;
- }
- }
- if (find == false && mdata->fileurl)
- {
- if (strncmp(filepath, mdata->fileurl, strlen(filepath)) == 0) //match
- {
- MSG_SLIDER_HIGH("Founded Fileurl=%s Index=%d", ivug_get_filename(mdata->fileurl), *start_index);
- index = *start_index; // recieve from bundle
- find = true;
- }
- }
- if(find == false)
- {
- MSG_SLIDER_WARN("param index is not match to real index");
- }
- }
- }
- //check indexed item
- if(item == NULL || find == false) // start index is not exist || can't find filename at window list
- {
- item = ivug_data_find_item(*list, filepath, &index);
-
- if (item == NULL)
- {
- // TODO : find file at whole file list
- MSG_SLIDER_ERROR("Item is not found for file %s", filepath);
- return NULL;
- }
- }
- *start_index = index;
- MSG_SDATA_HIGH("Create slide data list END");
- return item;
-}
-
-Media_List *ivug_data_init_media_list(const ivug_parameter *param)
-{
- _Media_List *_mList = calloc(1, sizeof(_Media_List));
- IV_ASSERT(_mList != NULL);
-
- _mList->window_size = IV_WINDOW_SIZE;
- _mList->window_reload_offset = IV_RELOAD_OFFSET;
- _mList->window_count = 0;
- _mList->left_end = 0;
-
- _mList->filter = ivug_data_filter_create(param);
-
- return (Media_List *)_mList;
-}
-
-Media_Item *
-ivug_data_create_media_list_from_param
- (Media_List *mList, Eina_List **list, const char *filepath, int *start_index, int *total_count)
-{
- IV_ASSERT(mList != NULL);
-
- MSG_SDATA_HIGH("Creating slide data list");
-
- _Media_List *_mList = (_Media_List *)mList;
-
- if(list == NULL)
- {
- return _ivug_data_create_list(mList, &(_mList->header), filepath, start_index, total_count);
- }
- else
- {
- return _ivug_data_create_list(mList, list, filepath, start_index, total_count);
- }
-}
-
-bool ivug_data_set_window_size(Media_List *mList, int size)
-{
- _Media_List *_mList = (_Media_List *)mList;
-
- if(size < 1)
- {
- MSG_SDATA_ERROR("Set window size error, size = %d", size);
- _mList->window_size = 0;
- return false;
- }
-
- _mList->window_size = size;
- return true;
-}
-
-void ivug_data_reset_window_load_count(Media_List *mList)
-{
- _Media_List *_mList = (_Media_List *)mList;
-
- _mList->window_count = 0;
-}
-
-void
-ivug_data_delete_media_list(Media_List *mList)
-{
- IV_ASSERT(mList != NULL);
- _Media_List *_mList = (_Media_List *)mList;
-
- MSG_SDATA_HIGH("Removing all media data");
-
- ivug_list_delete_items(_mList->header);
-
- ivug_data_filter_delete(_mList->filter);
-
- free(_mList);
-}
-
-
-
-#ifdef TRACE_CALLER
-Media_Data *
-dbg_ivug_data_get_data(Media_Item *media_item, const char *func, unsigned int line)
-#else
-Media_Data *
-ivug_data_get_data(Media_Item *media_item)
-#endif // TRACE_CALLER
-{
-#ifdef TRACE_CALLER
- MSG_SDATA_HIGH("Called by %s(%d) Item=0x%08x", func, line, media_item);
-#endif
- IV_ASSERT(media_item != NULL);
-
- Eina_List *item = media_item;
-
- return eina_list_data_get(item);
-
-}
-
-Media_Item *
-ivug_data_get_first(Media_List *mList)
-{
- IV_ASSERT(mList != NULL);
- _Media_List *_mList = (_Media_List *)mList;
-
- return (Media_Item *)_mList->header;
-}
-
-
-Media_Item *
-ivug_data_get_next(Media_Item *media_item)
-{
- IV_ASSERT(media_item != NULL);
-
- Eina_List *item = media_item;
-
- Eina_List *list;
-
- list = eina_list_next(item);
-
- if ( list == NULL )
- {
- MSG_SDATA_ERROR("Next item is NULL");
- return NULL;
- }
-
- return list;
-}
-
-Media_Item *
-ivug_data_get_prev(Media_Item *media_item)
-{
- IV_ASSERT(media_item != NULL);
-
- Eina_List *item = media_item;
-
- Eina_List *list;
-
- list = eina_list_prev(item);
-
- if ( list == NULL )
- {
- MSG_SDATA_ERROR("Prev item is NULL");
- return NULL;
- }
-
- return list;
-}
-
-Media_Item *
-ivug_data_find_item(Eina_List *list, const char* fileuri, int /*OUT*/ *index)
-{
- IV_ASSERT(list != NULL);
- IV_ASSERT(fileuri != NULL);
-
- Eina_List *item;
- Media_Data* mdata;
-
- unsigned int i = 1;
-
- EINA_LIST_FOREACH(list, item, mdata)
- {
- if(mdata == NULL)
- {
- MSG_SDATA_FATAL("sdata cannot be NULL");
- return NULL;
- }
-
- if (mdata->filepath)
- {
- if (strncmp(mdata->filepath, fileuri, strlen(mdata->filepath)) == 0) //match
- {
- MSG_SDATA_HIGH("Founded Filepath=%s Index=%d", ivug_get_filename(mdata->filepath), i);
- *index = i;
- return item;
- }
- }
-
- if (mdata->fileurl)
- {
- if (strncmp(mdata->fileurl, fileuri, strlen(mdata->fileurl)) == 0) //match
- {
- MSG_SDATA_HIGH("Founded Fileuri=%s Index=%d", mdata->fileurl, i);
- *index = i;
- return item;
- }
- }
- i++;
- }
-
- *index = 0;
- return NULL;
-}
-
-
-bool
-ivug_data_delete_media_item(Media_List *mList, Media_Item *media_item)
-{
- IV_ASSERT(mList != NULL);
- IV_ASSERT(media_item != NULL);
-
- _Media_List *_mList = (_Media_List *)mList;
-
- int ret;
-
- Media_Data* mdata;
-
- mdata = (Media_Data*)eina_list_data_get(media_item);
-
- IV_ASSERT(mdata != NULL);
-
- if (uuid_is_valid(mdata->mediaID) == true)
- {
- ret = minfo_delete_media_id(gGetMediaSVCHandle(), mdata->mediaID);
-
- if (ret == MB_SVC_ERROR_NONE)
- {
- if (mdata->filepath)
- {
- if(ivug_remove_file(mdata->filepath) == false)
- {
- MSG_SDATA_ERROR("unlink error , file path =%s", mdata->filepath);
- }
- }
- }
- else
- {
- MSG_SDATA_ERROR("minfo_delete_media_id faild=%d uuid=%s file=%s", ret, uuid_getchar(mdata->mediaID), mdata->filepath);
- goto ERROR;
- }
-
- }
- else
- {
- if (mdata->filepath)
- {
- if(ivug_remove_file(mdata->filepath) == false)
- {
- MSG_SDATA_ERROR("file remove error , file path =%s", mdata->filepath);
- }
- }
- else
- {
- MSG_SDATA_ERROR("delete faild file path is NULL");
- goto ERROR;
- }
-
- }
-
-// TODO : Handle when current is deleted
- ivug_free_mediadata(mdata); // Free data
-
- _mList->header = eina_list_remove_list(_mList->header, media_item);
- _mList->right_end--;
-
- return true;
-
-ERROR:
- ivug_free_mediadata(mdata); // Free data
- _mList->header = eina_list_remove_list(_mList->header, media_item);
- _mList->right_end--;
-
- MSG_SDATA_ERROR("ivug_data_delete_slide faild.");
- return false;
-
-}
-
-/* it delete start ~ end item */
-/* if end is null, it delete until last */
-bool
-ivug_data_delete_window_list(Media_List *mList, Media_Item *start_item, Media_Item *end_item)
-{
- IV_ASSERT(mList != NULL);
- IV_ASSERT(start_item != NULL);
-
- _Media_List *_mList = (_Media_List *)mList;
-
- Media_Item *current = start_item;
- Media_Item *next = NULL;
-
- Media_Data* mdata;
-
- do
- {
- MSG_SDATA_HIGH("delete window list");
- next = eina_list_next(current);
-
- mdata = (Media_Data*)eina_list_data_get(current);
- ivug_free_mediadata(mdata); // Free data
- _mList->header = eina_list_remove_list(_mList->header, current);
- if(end_item == NULL) /* delete right window */
- {
- /* TODO : _mList->right_end--; */
- }
- else /* delete left window */
- {
- /* TODO : _mList->left_end++; */
- }
- current = next;
- }while(current && current != end_item);
-
- if(current) /* delete end item */
- {
- mdata = (Media_Data*)eina_list_data_get(current);
- ivug_free_mediadata(mdata); // Free data
- _mList->header = eina_list_remove_list(_mList->header, current);
- _mList->left_end++; /* this case is delete left window */
- }
-
- _mList->window_count--;
-
- return true;
-}
-
-
-void
-ivug_data_delete_all_window_list(Media_List *mList)
-{
- _Media_List *_mList = (_Media_List *)mList;
-
- ivug_data_delete_window_list(mList, _mList->header, NULL);
-}
-
-
-void ivug_data_append_media_item(Media_List *mList, Eina_List* list)
-{
- IV_ASSERT(mList != NULL);
-
- _Media_List *_mList = (_Media_List *)mList;
-
- MSG_SDATA_HIGH("original : slide_list_count is %d", eina_list_count(_mList->header));
- if(_mList->window_count > 3)
- {
- /* TODO : delete window item */
- //ivug_data_delete_window_list(mList, _mList->header, _mList->contact_point);
- MSG_SDATA_HIGH("after delete : slide_list_count is %d", eina_list_count(_mList->header));
- }
- //_mList->contact_point = eina_list_last(_mList->header);
-
- _mList->header = eina_list_merge(_mList->header, list);
- MSG_SDATA_HIGH("merge next : slide_list_count is %d", eina_list_count(_mList->header));
-
- _mList->window_count++;
-}
-
-void ivug_data_prepend_media_item(Media_List *mList, Eina_List* list)
-{
- IV_ASSERT(mList != NULL);
-
- _Media_List *_mList = (_Media_List *)mList;
-
- MSG_SDATA_HIGH("original : slide_list_count is %d", eina_list_count(_mList->header));
- if(_mList->window_count > 3)
- {
- /* TODO : delete window item */
- //ivug_data_delete_window_list(mList, _mList->contact_point, NULL);
- MSG_SDATA_HIGH("after delete : slide_list_count is %d", eina_list_count(_mList->header));
- }
- //_mList->contact_point = _mList->header;
-
- _mList->header = eina_list_merge(list, _mList->header);
- MSG_SDATA_HIGH("merge prev : slide_list_count is %d", eina_list_count(_mList->header));
-
- _mList->window_count++;
-}
-
-
-Load_State
-ivug_data_set_window_loading(Media_List *mList, int cur_index, int total_count)
-{
- Eina_List* slide_list_prev = NULL;
- Eina_List* slide_list_next = NULL;
- int start = -1;
-
- IV_ASSERT(mList != NULL);
-
- _Media_List *_mList = (_Media_List *)mList;
-
- /* load right widow */
- if(_mList->right_end < total_count-1 && cur_index-1 > _mList->right_end - _mList->window_reload_offset)
- {
- /* start index is basis for view's index(1~total) because +1 needed */
- start = (_mList->right_end+1) + (_mList->window_size/2+1);
- if(start > total_count) // index is 1~total
- {
- start = total_count;
- }
- MSG_SDATA_HIGH("start = %d, _mList->right_end = %d", start, _mList->right_end);
- slide_list_next = _ivug_data_create_window_size_list(mList, start, total_count);
- if(slide_list_next != NULL)
- {
- ivug_data_append_media_item(mList, slide_list_next);
- return IVUG_SLIDER_LOADED_RIGHT;
- }
- }
- /* load left widow */
- else if(_mList->left_end > 0 && cur_index-1 < _mList->left_end + _mList->window_reload_offset)
- {
- /* start index is basis for view's index(1~total) because +1 needed */
- start = (_mList->left_end+1) - (_mList->window_size/2+1);
- if(start < 1) // index is 1~total
- {
- start = 1;
- }
- MSG_SDATA_HIGH("start = %d, _mList->left_end = %d", start, _mList->left_end);
- slide_list_prev = _ivug_data_create_window_size_list(mList, start, total_count);
- if(slide_list_prev != NULL)
- {
- ivug_data_prepend_media_item(mList, slide_list_prev);
- return IVUG_SLIDER_LOADED_LEFT;
- }
- }
- return IVUG_SLIDER_LOADED_NONE;
-}
-