2 * Copyright 2012 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://www.tizenopensource.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.
17 #include <media-svc.h>
18 #include <visual-svc.h>
19 #include "ge-db-handler.h"
22 #include "ge-strings.h"
24 static int ge_all_count = 0;
25 static Eina_List* ge_db_item_list = NULL;
26 static Eina_List* ge_item_selected_list = NULL;
28 #define ALBUM_ALL_LEN 4
29 #define GE_DB_FILE_LEN_MAX 1024
31 static int _ge_db_elist_ite_fn(Mitem *item, void *user_data)
33 Eina_List **list = (Eina_List **)user_data;
34 *list = eina_list_append(*list, item);
38 static int _ge_db_cluster_elist_ite_fn(Mcluster *cluster, void *user_data)
40 Eina_List **list = (Eina_List **)user_data;
41 *list = eina_list_append(*list, cluster);
48 static ge_item* _ge_db_new_item(void)
50 ge_item* gitem = (ge_item*)calloc(1, sizeof(ge_item));
58 static int _ge_db_destroy_item(ge_item* gitem)
64 ge_db_destroy_mtype_item(gitem->item);
70 free(gitem->_reserved);
71 gitem->_reserved = NULL;
74 gitem->elm_item = NULL;
75 gitem->checked = false;
76 gitem->check_obj = NULL;
83 static int _ge_db_clear_mtype_items_list(Eina_List **elist)
87 if (elist && *elist) {
88 ge_dbg("Clear Mitems list.");
89 EINA_LIST_FREE(*elist, current) {
91 ge_db_destroy_mtype_item(current);
102 static int _ge_db_clear_items_list(void)
104 ge_item* current = NULL;
108 ge_dbg("Clear items list.");
109 EINA_LIST_FREE(ge_db_item_list, current)
111 _ge_db_destroy_item(current);
115 ge_db_item_list = NULL;
117 return GE_DB_SUCCESS;
120 static int _ge_db_free_cluster(ge_cluster* gcluster)
122 GE_CHECK_VAL(gcluster, GE_DB_FAIL);
123 if(gcluster->cluster)
125 ge_db_destroy_mtype_item(gcluster->cluster);
126 gcluster->cluster = NULL;
128 if(gcluster->_reserved)
130 free(gcluster->_reserved);
131 gcluster->_reserved = NULL;
134 return GE_DB_SUCCESS;
137 /* Free memory allocated for 'All' album */
138 static int _ge_db_free_cluster_all(ge_cluster* gcluster)
140 GE_CHECK_VAL(gcluster, GE_DB_FAIL);
141 GE_CHECK_VAL(gcluster->cluster, GE_DB_FAIL);
143 if(gcluster->cluster->display_name)
145 free(gcluster->cluster->display_name);
146 gcluster->cluster->display_name = NULL;
149 if(gcluster->_reserved)
151 free(gcluster->_reserved);
152 gcluster->_reserved = NULL;
155 free(gcluster->cluster);
156 gcluster->cluster = NULL;
158 return GE_DB_SUCCESS;
161 static int _ge_db_clear_clusters_list(ge_ugdata* ugd)
163 GE_CHECK_VAL(ugd, GE_DB_FAIL);
164 ge_cluster* current = NULL;
165 Eina_List* tmp_list = NULL;
167 _ge_set_current_album(NULL);
169 if(ugd->cluster_list)
171 if(ugd->cluster_list->clist)
173 ge_dbg("Clear clusters list.");
174 tmp_list = ugd->cluster_list->clist;
175 EINA_LIST_FREE(tmp_list, current)
179 if(current->cluster &&
180 current->cluster->uuid &&
181 !g_strcmp0(current->cluster->uuid, GE_ALBUM_ALL_ID))
183 _ge_db_free_cluster_all(current);
187 _ge_db_free_cluster(current);
192 ugd->cluster_list->clist = NULL;
195 free(ugd->cluster_list);
196 ugd->cluster_list = NULL;
199 return GE_DB_SUCCESS;
202 static ge_cluster_list* _ge_db_new_clusters_list(void)
204 ge_cluster_list* clus_list = (ge_cluster_list*)calloc(1, sizeof(ge_cluster_list));
205 GE_CHECK_NULL(clus_list);
209 static ge_cluster* _ge_db_new_cluster(void)
211 ge_cluster* gcluster = (ge_cluster*)calloc(1, sizeof(ge_cluster));
212 GE_CHECK_NULL(gcluster);
216 /* Create 'All' album */
217 static ge_cluster* _ge_db_new_cluster_all(ge_ugdata* ugd, int count)
220 ge_cluster* gcluster = _ge_db_new_cluster();
221 GE_CHECK_NULL(gcluster);
223 /* Pass -1 to get a mcluster from libmedia-info, not a real record in DB */
224 Mcluster* cluster = ge_db_new_mcluster(ugd, NULL);
232 cluster->uuid = strdup(GE_ALBUM_ALL_ID);
233 cluster->display_name = strdup(GE_ALBUM_ALL_NAME);
234 cluster->count = count;
235 gcluster->cluster = cluster;
242 /* Case 1: Carema shot[0], All[1], ...; Case 2: All[0], ... */
243 static int _ge_db_get_clusters_list(ge_ugdata* ugd)
245 GE_CHECK_VAL(ugd, -1);
247 int local_item_cnt = 0;
248 Eina_List *item_list = NULL;
249 Mcluster *f_data = NULL;
250 ge_cluster * default_cluster = NULL;
251 ge_cluster* gcluster = NULL;
254 minfo_cluster_filter filter;
255 minfo_item_filter item_filter;
257 /* Get real albums */
258 memset(&filter, 0x00, sizeof(minfo_cluster_filter));
259 filter.cluster_type = MINFO_CLUSTER_TYPE_ALL;
260 filter.sort_type = MINFO_CLUSTER_SORT_BY_NAME_ASC;
261 filter.start_pos = GE_GET_ALL_RECORDS;
262 filter.end_pos = GE_GET_ALL_RECORDS;
264 err = minfo_get_cluster_list(ugd->db_handle, filter,
265 _ge_db_cluster_elist_ite_fn, &item_list);
266 if(err == MB_SVC_ERROR_DB_NO_RECORD) {
267 ge_dbgE("No record");
269 _ge_db_clear_mtype_items_list(&item_list);
271 } else if(err != 0) {
272 ge_dbgE("minfo_get_cluster_list failed(%d)!", err);
274 _ge_db_clear_mtype_items_list(&item_list);
278 Eina_List* clist = ugd->cluster_list->clist;
280 EINA_LIST_FREE(item_list, f_data) {
281 if (f_data == NULL || f_data->uuid == NULL) {
282 /* Invalid data, next one */
283 ge_dbgE("Invalid Mcluster!");
286 ge_dbg("Cluster ID: %s.", f_data->uuid);
288 /* only image is valid in setas mode. */
289 if (ugd->file_type_mode == GE_File_Select_Type_Image ||
290 ugd->file_type_mode == GE_File_Select_Type_Video) {
291 memset(&item_filter,0x00,sizeof(minfo_item_filter));
292 if(ugd->file_type_mode == GE_File_Select_Type_Image)
293 item_filter.file_type = MINFO_ITEM_IMAGE;
295 item_filter.file_type = MINFO_ITEM_VIDEO;
296 item_filter.sort_type = MINFO_MEDIA_SORT_BY_DATE_DESC;
297 item_filter.start_pos = GE_GET_ALL_RECORDS;
298 item_filter.end_pos = GE_GET_ALL_RECORDS;
299 item_filter.with_meta = false;
301 err = minfo_get_item_cnt(ugd->db_handle, f_data->uuid,
302 item_filter, &medias_cnt);
303 if(err == 0 || err == MB_SVC_ERROR_DB_NO_RECORD) {
304 f_data->count = medias_cnt;
306 ge_dbgW("minfo_get_cluster_cnt[err:%d]", err);
311 if(f_data->count == 0) {
312 /* Skip empty album, next one */
313 ge_dbgW("local album is empty, skipping it.");
314 ge_db_destroy_mtype_item(f_data);
318 gcluster = _ge_db_new_cluster();
319 if(gcluster == NULL) {
320 ge_dbgE("_ge_db_new_cluster failed!");
321 ge_db_destroy_mtype_item(f_data);
325 gcluster->cluster = f_data;
327 length += f_data->count;
328 local_item_cnt += f_data->count;
330 if (ge_db_is_default_album(ugd, f_data)) {
332 * Default album: Camera Shot
333 * Now Camera Shot is located in Phone.
334 * If user can determine the location of default album,
335 * here we should get the path and check it's in Phone or MMC.
337 default_cluster = gcluster;
338 clist = eina_list_prepend(clist, gcluster);
340 clist = eina_list_append(clist, gcluster);
342 ugd->cluster_list->clist = clist;
344 ge_dbg("Get local clusters list Done!");
346 /* Create "All" album if any file exists */
347 gcluster = _ge_db_new_cluster_all(ugd, local_item_cnt);
348 GE_CHECK_VAL(gcluster, -1);
351 clist = eina_list_append_relative(clist, gcluster,
354 clist= eina_list_prepend(clist, gcluster);
356 ugd->cluster_list->clist = clist;
357 ge_dbg("Cluster All added!");
363 static int _ge_db_get_selected_item_id_list(Eina_List **sel_id_list)
365 GE_CHECK_VAL(sel_id_list, -1);
366 GE_CHECK_VAL(ge_item_selected_list, -1);
367 ge_item *gitem = NULL;
368 char *item_id = NULL;
370 /* Save ID of selected items */
371 EINA_LIST_FREE(ge_item_selected_list, gitem) {
372 if (gitem && gitem->item && gitem->item->uuid) {
373 item_id = strdup(gitem->item->uuid);
374 *sel_id_list = eina_list_append(*sel_id_list,
379 ge_db_selected_list_finalize();
383 /* Free list of selected IDs */
384 static int __ge_db_free_selected_id_list(Eina_List **sel_id_list)
386 GE_CHECK_VAL(sel_id_list, -1);
387 if (*sel_id_list == NULL) {
388 ge_dbg("sel_id_list is empty!");
393 EINA_LIST_FREE(*sel_id_list, p_id) {
395 ge_dbgE("Invalid p_id!");
405 /* Check ID is in the list or not */
406 static bool _ge_db_check_selected_id(Eina_List **sel_id_list, const char *id)
408 GE_CHECK_FALSE(sel_id_list);
410 Eina_List *tmp_elist = NULL;
413 if (eina_list_count(*sel_id_list) == 0) {
414 ge_dbgE("sel_id_list is empty!");
418 EINA_LIST_FOREACH(*sel_id_list, tmp_elist, p_id) {
420 ge_dbgE("Invalid p_id!");
423 if (g_strcmp0(id, p_id)) {
428 *sel_id_list = eina_list_remove(*sel_id_list, p_id);
437 * get a new cluster from media service by cluster id
439 Mcluster* ge_db_new_mcluster(ge_ugdata* ugd, const char *cluster_id)
442 Mcluster* mcluster = NULL;
443 int ret = minfo_get_cluster(ugd->db_handle, NULL, cluster_id, &mcluster);
446 ge_dbgE("minfo_get_cluster failed(%d)!", ret);
453 * get a new item from media service by item id
455 Mitem* ge_db_new_mitem(ge_ugdata* ugd, const char *item_id)
459 /*new API, to use media id to get item. */
460 int ret = minfo_get_item_by_id(ugd->db_handle, item_id, &mitem);
463 ge_dbgE("minfo_get_item_by_id failed(%d)!", ret);
470 int ge_db_update_items_cnt(ge_ugdata* ugd, ge_cluster *album)
472 GE_CHECK_VAL(album, GE_DB_FAIL);
473 GE_CHECK_VAL(album->cluster, GE_DB_FAIL);
474 GE_CHECK_VAL(album->cluster->uuid, GE_DB_FAIL);
475 GE_CHECK_VAL(ugd, GE_DB_FAIL);
476 minfo_item_filter filter;
480 memset(&filter,0x00,sizeof(minfo_item_filter));
481 if(ugd->file_type_mode == GE_File_Select_Type_Image)
483 filter.file_type = MINFO_ITEM_IMAGE;
485 else if(ugd->file_type_mode == GE_File_Select_Type_Video)
487 filter.file_type = MINFO_ITEM_VIDEO;
491 filter.file_type = MINFO_ITEM_IMAGE | MINFO_ITEM_VIDEO;
493 filter.sort_type = MINFO_MEDIA_SORT_BY_DATE_DESC;
494 filter.start_pos = GE_GET_ALL_RECORDS;
495 filter.end_pos = GE_GET_ALL_RECORDS;
496 filter.with_meta = false;
498 if(g_strcmp0(album->cluster->uuid, GE_ALBUM_ALL_ID)) {
500 err = minfo_get_item_cnt(ugd->db_handle, album->cluster->uuid,
501 filter, &item_count);
504 ge_dbg("minfo_get_item_cnt failed(%d)!", err);
510 ge_dbg("all media count");
512 * Fixme: Use better API.
513 * No way to set filter if call minfo_get_all_item_cnt to get all count,
514 * So get item list firstly, then get all items count.
516 Eina_List* itemlist = NULL;
517 err = minfo_get_all_item_list(ugd->db_handle,
518 MINFO_CLUSTER_TYPE_LOCAL_ALL,
519 filter, _ge_db_elist_ite_fn,
522 if(err < 0 || itemlist == NULL) {
523 ge_dbg("minfo_get_all_item_list failed(%d)!", err);
525 _ge_db_clear_mtype_items_list(&itemlist);
530 EINA_LIST_FREE(itemlist, item) {
533 ge_db_destroy_mtype_item(item);
539 ge_dbg("cluster media count : old=%d, new=%d", album->cluster->count, item_count);
540 album->cluster->count = item_count;
542 return GE_DB_SUCCESS;
545 int ge_db_get_clusters_list(ge_ugdata* ugd)
547 GE_CHECK_VAL(ugd, GE_DB_FAIL);
548 int n_entire_items = 0;
550 _ge_db_clear_clusters_list(ugd);
552 ugd->cluster_list = _ge_db_new_clusters_list();
553 n_entire_items = _ge_db_get_clusters_list(ugd);
554 ge_dbg("Total media items count:%d", n_entire_items);
555 if(n_entire_items <= 0)//if error code is returned, negative value is possible
560 return GE_DB_SUCCESS;
563 /* Clear items list */
564 int ge_db_clear_items_list(void)
566 return _ge_db_clear_items_list();
569 int ge_db_get_items_list(ge_ugdata* ugd, ge_cluster *album, int start_pos, int end_pos)
571 GE_CHECK_VAL(album, GE_DB_FAIL);
572 GE_CHECK_VAL(album->cluster, GE_DB_FAIL);
573 GE_CHECK_VAL(album->cluster->uuid, GE_DB_FAIL);
574 GE_CHECK_VAL(ugd, -1);
575 Eina_List* itemlist = NULL;
576 minfo_item_filter filter;
579 ge_dbg("--start_pos[%d], end_pos[%d]--", start_pos, end_pos);
580 memset(&filter,0x00,sizeof(minfo_item_filter));
581 if(ugd->file_type_mode == GE_File_Select_Type_Image)
583 filter.file_type = MINFO_ITEM_IMAGE;
585 else if(ugd->file_type_mode == GE_File_Select_Type_Video)
587 filter.file_type = MINFO_ITEM_VIDEO;
591 filter.file_type = MINFO_ITEM_IMAGE | MINFO_ITEM_VIDEO;
593 filter.sort_type = MINFO_MEDIA_SORT_BY_DATE_DESC;
594 filter.start_pos = start_pos;
595 filter.end_pos = end_pos;
596 filter.with_meta = true;
598 if(start_pos == (GE_FIRST_VIEW_END_POS+1) && end_pos == GE_GET_UNTIL_LAST_RECORD)
600 /* Keep medias_elist and medias_cnt unchanged */
601 ge_dbg("Gridview append idler; Keep ge_db_item_list unchanged.");
605 /*Clear item list before new one got */
606 _ge_db_clear_items_list();
609 if(g_strcmp0(album->cluster->uuid, GE_ALBUM_ALL_ID)) {
611 ge_dbg("--Real album--");
612 err = minfo_get_item_list(ugd->db_handle, album->cluster->uuid,
613 filter, _ge_db_elist_ite_fn, &itemlist);
615 else //add "All" album
617 ge_dbg("--Album All--");
618 err = minfo_get_all_item_list(ugd->db_handle,
619 MINFO_CLUSTER_TYPE_LOCAL_ALL,
620 filter, _ge_db_elist_ite_fn,
624 if((err == 0) && (itemlist != NULL))
627 ge_item* gitem = NULL;
628 EINA_LIST_FREE(itemlist, item)
630 if (item == NULL || item->uuid == NULL) {
631 ge_dbgE("Invalid item!");
635 gitem = _ge_db_new_item();
637 ge_dbgE("_gl_db_new_item() failed");
638 ge_db_destroy_mtype_item(item);
644 ge_db_item_list = eina_list_append(ge_db_item_list, gitem);
649 ge_all_count = eina_list_count(ge_db_item_list);
655 _ge_db_clear_mtype_items_list(&itemlist);
657 if(start_pos == (GE_FIRST_VIEW_END_POS+1) && end_pos == GE_GET_UNTIL_LAST_RECORD)
659 /* Keep medias_elist and medias_cnt unchanged */
660 ge_all_count = eina_list_count(ge_db_item_list);
661 ge_dbg("Gridview append idler.");
668 ge_dbg("DB all count : %d, ge_db_item_list=%p", ge_all_count, ge_db_item_list);
673 /* Update items list, especially used in thumbnails edit view */
674 int ge_db_update_items_list(ge_ugdata* ugd, ge_cluster *album)
676 GE_CHECK_VAL(album, -1);
677 GE_CHECK_VAL(album->cluster, -1);
678 GE_CHECK_VAL(album->cluster->uuid, GE_DB_FAIL);
679 GE_CHECK_VAL(ugd, -1);
680 Eina_List* itemlist = NULL;
681 minfo_item_filter filter;
683 ge_dbg("Update content of %s", album->cluster->display_name);
684 int view_mode = _ge_get_view_mode();
685 Eina_List *sel_id_list = NULL;
687 if (view_mode == GE_ThumbnailEdit_Mode &&
688 ugd->file_select_mode != GE_File_Select_One) {
689 ge_dbg("Edit view for multiple selection.");
690 /* Get ID list of selected items */
691 _ge_db_get_selected_item_id_list(&sel_id_list);
694 memset(&filter,0x00,sizeof(minfo_item_filter));
695 if(ugd->file_type_mode == GE_File_Select_Type_Image)
696 filter.file_type = MINFO_ITEM_IMAGE;
697 else if(ugd->file_type_mode == GE_File_Select_Type_Video)
698 filter.file_type = MINFO_ITEM_VIDEO;
700 filter.file_type = MINFO_ITEM_IMAGE | MINFO_ITEM_VIDEO;
701 filter.sort_type = MINFO_MEDIA_SORT_BY_DATE_DESC;
702 filter.start_pos = GE_GET_ALL_RECORDS;
703 filter.end_pos = GE_GET_ALL_RECORDS;
704 filter.with_meta = true;
706 /*Clear item list before new one got */
707 _ge_db_clear_items_list();
709 if(g_strcmp0(album->cluster->uuid, GE_ALBUM_ALL_ID))
710 err = minfo_get_item_list(ugd->db_handle, album->cluster->uuid,
711 filter, _ge_db_elist_ite_fn, &itemlist);
713 err = minfo_get_all_item_list(ugd->db_handle,
714 MINFO_CLUSTER_TYPE_LOCAL_ALL,
715 filter, _ge_db_elist_ite_fn,
718 if ((err != 0) || (itemlist == NULL)) {
719 ge_dbgE("(err != 0) || (itemlist == NULL)");
722 _ge_db_clear_mtype_items_list(&itemlist);
727 bool b_selected = false;
729 ge_item* gitem = NULL;
730 EINA_LIST_FREE(itemlist, item) {
731 if (item == NULL || item->uuid == NULL) {
732 ge_dbgE("Invalid item!");
735 gitem = _ge_db_new_item();
737 ge_dbgE("_gl_db_new_item() failed");
738 ge_db_destroy_mtype_item(item);
744 ge_db_item_list = eina_list_append(ge_db_item_list, gitem);
747 b_selected = _ge_db_check_selected_id(&sel_id_list,
751 /* Set checkbox state */
752 gitem->checked = true;
753 /* Append gitem to selected list */
754 ge_db_selected_list_append(gitem);
762 /* Clear list of selected ID */
764 __ge_db_free_selected_id_list(&sel_id_list);
766 ge_all_count = eina_list_count(ge_db_item_list);
767 ge_dbg("DB all count : %d, ge_db_item_list=%p", ge_all_count,
773 int ge_db_get_first_several_items(ge_ugdata* ugd, ge_cluster *album,
774 ge_item* items[], int *item_count,
775 minfo_media_sort_type sort_type)
777 GE_CHECK_VAL(item_count, -1);
778 GE_CHECK_VAL(items, -1);
779 GE_CHECK_VAL(album, -1);
780 GE_CHECK_VAL(album->cluster, -1);
781 GE_CHECK_VAL(album->cluster->uuid, -1);
782 GE_CHECK_VAL(ugd, -1);
783 minfo_item_filter filter;
784 Eina_List *item_list = NULL;
787 ge_item* gitem = NULL;
792 ge_dbgE("*item_count <= 0");
795 memset(&filter,0x00,sizeof(minfo_item_filter));
796 if(ugd->file_type_mode == GE_File_Select_Type_Image)
798 filter.file_type = MINFO_ITEM_IMAGE;
800 else if(ugd->file_type_mode == GE_File_Select_Type_Video)
802 filter.file_type = MINFO_ITEM_VIDEO;
806 filter.file_type = MINFO_ITEM_IMAGE | MINFO_ITEM_VIDEO;
808 filter.sort_type = sort_type;
809 filter.start_pos = 0;
810 filter.end_pos = (*item_count == 1 ? 1 : (*item_count - 1));
811 filter.with_meta = false;
813 if(g_strcmp0(album->cluster->uuid, GE_ALBUM_ALL_ID)) {
815 err = minfo_get_item_list(ugd->db_handle, album->cluster->uuid,
816 filter, _ge_db_elist_ite_fn, &item_list);
817 if(err != 0 || item_list == NULL)
819 ge_dbgE("minfo_get_item_list failed(%d)", err);
823 else //add "All" album
825 err = minfo_get_all_item_list(ugd->db_handle,
826 MINFO_CLUSTER_TYPE_LOCAL_ALL,
827 filter, _ge_db_elist_ite_fn,
829 if(err != 0 || item_list == NULL)
831 ge_dbgE("minfo_get_all_item_list failed(%d)", err);
836 EINA_LIST_FREE(item_list, item) {
838 ge_dbgE("Invalid Mitem!");
842 if(result_cnt <= *item_count) {
844 gitem = _ge_db_new_item();
846 ge_dbgE("_ge_db_new_item failed!");
847 ge_db_destroy_mtype_item(item);
852 items[result_cnt-1] = gitem;
854 ge_db_destroy_mtype_item(item);
859 if(*item_count > result_cnt)
860 *item_count = result_cnt;
862 ge_dbg("First %d items of [%s]", *item_count, album->cluster->display_name);
869 _ge_db_clear_mtype_items_list(&item_list);
873 int ge_db_del_media_id(ge_ugdata* ugd, const char *media_id)
875 GE_CHECK_VAL(media_id, GE_DB_FAIL);
876 int ret = minfo_delete_media_id(ugd->db_handle, media_id);
879 ge_dbgE("minfo_delete_media_id failed(%d)!", ret);
883 return GE_DB_SUCCESS;
886 int ge_db_item_list_remove(ge_item* gitem)
888 GE_CHECK_VAL(gitem, GE_DB_FAIL);
889 GE_CHECK_VAL(gitem->item, GE_DB_FAIL);
890 GE_CHECK_VAL(gitem->item->uuid, GE_DB_FAIL);
891 ge_item* current = NULL;
894 EINA_LIST_FOREACH(ge_db_item_list, l, current)
897 if(current == NULL || current->item == NULL ||
898 current->item->uuid == NULL) {
899 ge_dbgE("Invalid gitem!");
902 if(!g_strcmp0(current->item->uuid, gitem->item->uuid))
904 ge_db_item_list = eina_list_remove(ge_db_item_list, current);
906 _ge_db_destroy_item(current);
911 return GE_DB_SUCCESS;
914 int ge_db_destroy_mtype_item(void* item)
916 GE_CHECK_VAL(item, GE_DB_FAIL);
917 int ret = minfo_destroy_mtype_item(item);
920 ge_dbgE("minfo_destroy_mtype_item failed(%d)!", ret);
924 return GE_DB_SUCCESS;
927 int ge_db_destroy_item(ge_item * gitem)
929 GE_CHECK_VAL(gitem, GE_DB_FAIL);
931 _ge_db_destroy_item(gitem);
932 return GE_DB_SUCCESS;
935 int ge_db_get_item_by_index(ge_item** gitem, int idx)
937 GE_CHECK_VAL(gitem, GE_DB_FAIL);
939 if (idx > ge_all_count)
941 ge_dbg("db_get_item_by_index(%d) is failed\n", idx);
946 *gitem = eina_list_nth(ge_db_item_list, idx -1);
947 return GE_DB_SUCCESS;
950 int ge_db_get_count_all(void)
955 int ge_db_get_selected_item_by_index(ge_item** gitem, int idx)
957 GE_CHECK_VAL(gitem, GE_DB_FAIL);
959 if (idx > ge_db_selected_list_count())
961 ge_dbg("db_get_item_by_index(%d) is failed\n", idx);
966 *gitem = eina_list_nth(ge_item_selected_list, idx -1);
967 return GE_DB_SUCCESS;
970 int ge_db_selected_list_count(void)
972 return eina_list_count(ge_item_selected_list);
975 Eina_List* ge_db_selected_list_get(void)
977 return ge_item_selected_list;
980 int ge_db_selected_list_append(ge_item* gitem)
982 GE_CHECK_VAL(gitem, GE_DB_FAIL);
984 ge_item_selected_list = eina_list_append(ge_item_selected_list, gitem);
985 return GE_DB_SUCCESS;
988 int ge_db_selected_list_remove(ge_item* gitem)
990 GE_CHECK_VAL(gitem, GE_DB_FAIL);
991 GE_CHECK_VAL(gitem->item, GE_DB_FAIL);
992 GE_CHECK_VAL(gitem->item->uuid, GE_DB_FAIL);
993 ge_item* current = NULL;
996 EINA_LIST_FOREACH(ge_item_selected_list, l, current)
998 if(current == NULL || current->item == NULL ||
999 current->item->uuid == NULL) {
1000 ge_dbgE("Invald gitem!");
1003 if(!g_strcmp0(current->item->uuid, gitem->item->uuid))
1005 ge_item_selected_list = eina_list_remove(ge_item_selected_list, current);
1009 return GE_DB_SUCCESS;
1012 int ge_db_selected_list_finalize(void)
1014 ge_item* gitem = NULL;
1016 EINA_LIST_FREE(ge_item_selected_list, gitem)
1020 gitem->checked = false;
1024 ge_item_selected_list = NULL;
1025 return GE_DB_SUCCESS;
1029 * get full path of cluster
1031 int ge_db_get_folder_fullpath(ge_ugdata* ugd, const char *id, char *path)
1033 GE_CHECK_VAL(ugd, GE_DB_FAIL);
1034 GE_CHECK_VAL(id, GE_DB_FAIL);
1035 GE_CHECK_VAL(path, GE_DB_FAIL);
1036 /*For safety, we should add one more parameter as a size of the output array. */
1037 return minfo_get_cluster_fullpath_by_id(ugd->db_handle,id, path,
1038 GE_DIR_PATH_LEN_MAX);
1042 * Check it's default album[Camera shot] or not
1044 bool ge_db_is_default_album(ge_ugdata* ugd, Mcluster* mcluster)
1046 GE_CHECK_VAL(ugd, GE_DB_FAIL);
1047 GE_CHECK_FALSE(mcluster);
1048 GE_CHECK_FALSE(mcluster->display_name);
1049 GE_CHECK_FALSE(mcluster->uuid);
1052 /* Name is 'Camera shot' and folder locates in Phone */
1053 ret = g_strcmp0(mcluster->display_name, GE_ALBUM_MY_NAME);
1054 if (ret == 0 && mcluster->type == MINFO_PHONE) {
1055 char dir_path[GE_DIR_PATH_LEN_MAX] = { 0, };
1056 int ret = minfo_get_cluster_fullpath_by_id(ugd->db_handle,
1059 GE_DIR_PATH_LEN_MAX);
1061 ge_dbgE("get_cluster_fullpath_by_id failed[%d]!", ret);
1064 ge_dbg("Full path: %s", dir_path);
1065 /* Get parent directory */
1066 char *parent_path = ecore_file_dir_get(dir_path);
1067 GE_CHECK_FALSE(parent_path);
1068 ge_dbg("Parent path: %s", parent_path);
1070 /* Parent directory is same as Phone root path, it's default folder */
1071 ret = g_strcmp0(parent_path, GE_ROOT_PATH_PHONE);
1072 GE_FREE_MEM(parent_path)
1075 ge_dbgW("Default folder!");
1083 bool ge_db_is_root_path(ge_ugdata* ugd, const char *cluster_id, const char *path)
1086 char dir_path[GE_DIR_PATH_LEN_MAX] = { 0, };
1089 g_strlcpy(dir_path, path, GE_DIR_PATH_LEN_MAX);
1091 GE_CHECK_FALSE(cluster_id);
1092 res = minfo_get_cluster_fullpath_by_id(ugd->db_handle,
1093 cluster_id, dir_path,
1094 GE_DIR_PATH_LEN_MAX);
1096 ge_dbgE("minfo_get_cluster_fullpath_by_id failed(%d)!", res);
1101 ge_dbg("Root path[/opt/media or /opt/storage/sdcard]: %s ?", dir_path);
1102 if(!g_strcmp0(GE_ROOT_PATH_PHONE, dir_path) ||
1103 !g_strcmp0(GE_ROOT_PATH_MMC, dir_path))
1109 int ge_db_init(ge_ugdata* ugd)
1111 ge_dbg("Connect to libmedia-info!");
1112 GE_CHECK_VAL(ugd, GE_DB_FAIL);
1113 MediaSvcHandle *_db_handle = NULL;
1115 int err = media_svc_connect(&_db_handle);
1117 ge_dbgE("Connect to DB failed!");
1121 ugd->db_handle = _db_handle;
1122 return GE_DB_SUCCESS;
1125 int ge_db_finalize(ge_ugdata* ugd)
1127 ge_dbg("Free memory and disconnect with libmedia-info!");
1128 GE_CHECK_VAL(ugd, GE_DB_FAIL);
1129 _ge_db_clear_clusters_list(ugd);
1130 _ge_db_clear_items_list();
1132 int err = media_svc_disconnect(ugd->db_handle);
1135 ge_dbgE("\n\nDisconnect with libmedia-info failed!!!\n");
1139 return GE_DB_SUCCESS;