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.
18 #include <vconf-keys.h>
19 #include <media-svc.h>
20 #include <appcore-efl.h>
21 #include "gl-db-handler.h"
22 #include "gl-controlbar.h"
26 #include "gl-strings.h"
29 _gl_db_get_file_dir_names(const char *file_path,
30 char *filename, char *dir_name, char *dir_path)
33 GL_CHECK_FALSE(file_path);
36 for (i = strlen(file_path); i >= 0; i--)
38 if (file_path[i] != '\0')
42 if (file_path[i] == '/')
46 memcpy(filename, &file_path[i + 1], --count);
47 *(filename + count) = '\0';
48 gl_dbg("File Name = %s", filename);
52 memcpy(dir_path, &file_path[0], i); // , i +1 changed to , i
53 *(dir_path + i) = '\0';
54 gl_dbg("Directory Name = %s", dir_path);
59 for (--i; i >= 0; i--)
62 if (file_path[i] == '/')
64 memcpy(dir_name, &file_path[i + 1], --count);
65 *(dir_name + count) = '\0';
66 gl_dbg("Directory Name = %s", dir_name);
79 static int _gl_db_elist_ite_fn(Mitem *item, void *user_data)
81 Eina_List **list = (Eina_List **)user_data;
82 *list = eina_list_append(*list, item);
87 static int _gl_db_cluster_elist_ite_fn(Mcluster *cluster, void *user_data)
89 Eina_List **list = (Eina_List **)user_data;
90 *list = eina_list_append(*list, cluster);
102 gl_item *gitem = (gl_item *) malloc(sizeof(gl_item));
103 GL_CHECK_NULL(gitem);
104 memset(gitem, 0x00, sizeof(gl_item));
108 gitem->checked = false;
109 gitem->check_obj = NULL;
110 gitem->elm_item = NULL;
112 gitem->_reserved = NULL;
121 _gl_db_destroy_item(gl_item * gitem)
123 GL_CHECK_VAL(gitem, GL_DB_FAIL);
126 minfo_destroy_mtype_item(gitem->item);
130 if (gitem->_reserved)
132 free(gitem->_reserved);
133 gitem->_reserved = NULL;
136 gitem->checked = false;
137 gitem->check_obj = NULL;
138 gitem->elm_item = NULL;
143 return GL_DB_SUCCESS;
146 /* Clear eina_list got from DB */
147 static int _gl_db_clear_mtype_items_list(Eina_List **elist)
149 void *current = NULL;
151 if (elist && *elist) {
152 gl_dbg("Clear Mtype items list.");
153 EINA_LIST_FREE(*elist, current) {
155 minfo_destroy_mtype_item(current);
163 return GL_DB_SUCCESS;
167 _gl_db_clear_item_list(void *data)
169 GL_CHECK_VAL(data, GL_DB_FAIL);
170 gl_appdata *ad = (gl_appdata *)data;
171 gl_item *current = NULL;
172 if (ad->maininfo.medias_elist)
174 Eina_List *item_list = ad->maininfo.medias_elist;
175 EINA_LIST_FREE(item_list, current)
177 _gl_db_destroy_item(current);
180 ad->maininfo.medias_elist = NULL;
183 return GL_DB_SUCCESS;
187 _gl_db_free_cluster_all(gl_cluster* gcluster)
189 GL_CHECK_VAL(gcluster, GL_DB_FAIL);
190 GL_CHECK_VAL(gcluster->cluster, GL_DB_FAIL);
192 if(gcluster->cluster->display_name)
194 free(gcluster->cluster->display_name);
195 gcluster->cluster->display_name = NULL;
198 if(gcluster->_reserved)
200 free(gcluster->_reserved);
201 gcluster->_reserved = NULL;
204 free(gcluster->cluster);
205 gcluster->cluster = NULL;
207 return GL_DB_SUCCESS;
211 _gl_db_free_cluster(gl_cluster * gcluster)
213 GL_CHECK_VAL(gcluster, GL_DB_FAIL);
214 if (gcluster->cluster)
216 minfo_destroy_mtype_item(gcluster->cluster);
217 gcluster->cluster = NULL;
219 if (gcluster->_reserved)
221 free(gcluster->_reserved);
222 gcluster->_reserved = NULL;
225 return GL_DB_SUCCESS;
229 _gl_db_clear_cluster_list(void *data, bool b_force)
231 GL_CHECK_VAL(data, GL_DB_FAIL);
232 gl_appdata *ad = (gl_appdata *)data;
233 gl_cluster *current = NULL;
234 Eina_List *tmp_list = NULL;
236 // To reset current album when clear cluster list.
237 ad->albuminfo.current_album = NULL;
239 if (ad->albuminfo.cluster_list)
241 if (ad->albuminfo.cluster_list->clist)
243 tmp_list = ad->albuminfo.cluster_list->clist;
245 EINA_LIST_FREE(tmp_list, current)
249 gl_db_free_cluster(current);
253 ad->albuminfo.cluster_list->clist = NULL;
257 free(ad->albuminfo.cluster_list);
258 ad->albuminfo.cluster_list = NULL;
262 return GL_DB_SUCCESS;
265 static gl_cluster *_gl_db_new_cluster_all(void *data, int all_item_cnt)
269 gl_cluster *gcluster = NULL;
270 Mcluster *mcluster = NULL;
272 gcluster = gl_db_new_cluster();
273 GL_CHECK_NULL(gcluster);
275 mcluster = gl_db_new_mcluster(data, GL_NEW_RECORD_ID);
276 if (mcluster == NULL) {
281 mcluster->uuid = strdup(GL_ALBUM_ALL_ID);
282 mcluster->count = all_item_cnt;
283 mcluster->display_name = strdup(GL_ALBUM_ALL_NAME);
285 gcluster->cluster = mcluster;
291 static gl_cluster_list *
292 _gl_db_new_cluster_list(void)
294 gl_cluster_list *clus_list = (gl_cluster_list *) malloc(sizeof(gl_cluster_list));
295 GL_CHECK_NULL(clus_list);
296 memset(clus_list, 0x00, sizeof(gl_cluster_list));
297 clus_list->clist = NULL;
298 clus_list->cur_pos = 0;
303 static int _gl_db_get_selected_cluster_id_list(void *data, Eina_List **sel_id_list)
305 GL_CHECK_VAL(sel_id_list, -1);
306 GL_CHECK_VAL(data, -1);
307 gl_appdata *ad = (gl_appdata *)data;
308 gl_cluster *gcluster = NULL;
309 char *item_id = NULL;
311 if (ad->albuminfo.selected_albums_elist == NULL)
314 /* Save ID of selected clusters */
315 EINA_LIST_FREE(ad->albuminfo.selected_albums_elist, gcluster) {
316 if (gcluster && gcluster->cluster && gcluster->cluster->uuid) {
317 item_id = strdup(gcluster->cluster->uuid);
318 *sel_id_list = eina_list_append(*sel_id_list,
322 gl_db_finalize_albums_selected_list(ad);
327 * Some issue about using ecore_file_exists(gitem->item->file_url),
328 * if user rename file in Myfile, file_url changed.
330 static int _gl_db_get_selected_item_id_list(void *data, Eina_List **sel_id_list)
332 GL_CHECK_VAL(sel_id_list, -1);
333 GL_CHECK_VAL(data, -1);
334 gl_appdata *ad = (gl_appdata *)data;
335 GL_CHECK_VAL(ad->selectedinfo.medias_elist, -1);
336 gl_item *gitem = NULL;
337 char *item_id = NULL;
339 /* Save ID of selected items */
340 EINA_LIST_FREE(ad->selectedinfo.medias_elist, gitem) {
341 if (gitem && gitem->item && gitem->item->uuid) {
342 item_id = strdup(gitem->item->uuid);
343 *sel_id_list = eina_list_append(*sel_id_list,
348 gl_db_selected_list_finalize(ad);
352 /* Check ID is in the list or not */
353 static bool _gl_db_check_selected_id(Eina_List **sel_id_list, const char *id)
355 GL_CHECK_FALSE(sel_id_list);
356 Eina_List *tmp_elist = NULL;
360 if (eina_list_count(*sel_id_list) == 0) {
361 gl_dbgE("sel_id_list is empty!");
365 EINA_LIST_FOREACH(*sel_id_list, tmp_elist, p_id) {
367 gl_dbgE("Invalid p_id!");
370 /* Get next one if they wasn't equal */
371 if (g_strcmp0(id, (char *)p_id)) {
375 *sel_id_list = eina_list_remove(*sel_id_list, p_id);
383 /* Free list of selected IDs */
384 static int __gl_db_free_selected_id_list(Eina_List **sel_id_list)
386 GL_CHECK_VAL(sel_id_list, -1);
387 if (*sel_id_list == NULL) {
388 gl_dbg("sel_id_list is empty!");
393 EINA_LIST_FREE(*sel_id_list, p_id) {
395 gl_dbgE("Invalid p_id!");
405 static int _gl_db_get_cluster_list(void *data, bool b_update)
407 GL_CHECK_VAL(data, -1);
408 gl_appdata *ad = (gl_appdata *)data;
410 int local_item_cnt = 0;
411 Eina_List *item_list = NULL;
412 Mcluster *f_data = NULL;
413 gl_cluster *default_cluster = NULL;
415 int edit_album_cnt = 0;
416 minfo_cluster_filter filter;
417 Mcluster *new_mc = NULL;
418 Eina_List *sel_id_list = NULL;
419 bool b_selected = false;
420 char new_mc_id[GL_MTYPE_ITEN_ID_LEN_MAX] = { 0, };
421 char sel_id[GL_MTYPE_ITEN_ID_LEN_MAX] = { 0, };
424 gl_dbg("Update mode.");
425 gl_cluster *album_item = ad->albuminfo.selected_album;
426 if (album_item && album_item->cluster &&
427 album_item->cluster->uuid) {
428 g_strlcpy(sel_id, album_item->cluster->uuid,
429 GL_MTYPE_ITEN_ID_LEN_MAX);
430 gl_dbg("Save selected album ID: %s.", sel_id);
432 ad->albuminfo.selected_album = NULL;
433 /* Get selected cluster IDs list */
434 _gl_db_get_selected_cluster_id_list(ad, &sel_id_list);
435 /* Clear cluster list */
436 _gl_db_clear_cluster_list(ad, false);
439 memset(&filter,0x00,sizeof(minfo_cluster_filter));
440 //ad->new_album_name is the cluster name of newly created album
441 //in moving medias to new album case.
442 if (strlen(ad->albuminfo.new_album_name))
444 memset(ad->albuminfo.new_album_name, 0x00, GL_ALBUM_NAME_LEN_MAX);
445 //get Mcluster from DB via folder full path(URL).
446 err = minfo_get_cluster(ad->maininfo.db_handle,
447 ad->albuminfo.dest_folder, NULL, &new_mc);
450 gl_dbgE("minfo_get_cluster fail: %d", err);
452 else if (new_mc->count == 0)
454 //media records of this cluster havn't been inserted to DB.
455 //save the cluster ID.
456 //update cluster item count while refresh albums view in _gl_albums_get_label().
457 gl_dbg("Get newly created Mcluster, url: %s.", ad->albuminfo.dest_folder);
458 g_strlcpy(new_mc_id, new_mc->uuid,
459 GL_MTYPE_ITEN_ID_LEN_MAX);
460 minfo_destroy_mtype_item(new_mc);
465 filter.cluster_type = MINFO_CLUSTER_TYPE_ALL;
466 filter.sort_type = MINFO_CLUSTER_SORT_BY_NAME_ASC;
467 filter.start_pos = GL_GET_ALL_RECORDS;
468 filter.end_pos = GL_GET_ALL_RECORDS;
470 err = minfo_get_cluster_list(ad->maininfo.db_handle, filter,
471 _gl_db_cluster_elist_ite_fn, &item_list);
472 if (err == MB_SVC_ERROR_DB_NO_RECORD)
474 gl_dbg("No record!");
475 ad->albuminfo.cluster_list->clist = NULL;
477 _gl_db_clear_mtype_items_list(&item_list);
478 /* Continue to add AllShare album */
482 gl_dbg("Failed to get cluster list!");
484 _gl_db_clear_mtype_items_list(&item_list);
485 /* Continue to add AllShare album */
488 gl_cluster *gcluster = NULL;
489 EINA_LIST_FREE(item_list, f_data) {
490 if (f_data == NULL || f_data->uuid == NULL) {
491 gl_dbgE("Invalid Mcluster!");
494 gl_dbg("folder id: %s.", f_data->uuid);
497 * There are Phone and other filters in libmedia-info,
498 * but they are seperated, if we want to get phone
499 * only we can use is MINFO_CLUSTER_TYPE_ALL,
500 * and add condition checking to skip MMC albums.
502 * To skip MMC albums if MMC already unmounted,
503 * in case of delay updating in DB.
505 if ((ad->maininfo.mmc_state == GL_MMC_STATE_REMOVED_MOVING ||
506 ad->maininfo.mmc_state == GL_MMC_STATE_REMOVED) &&
507 f_data->type == MINFO_MMC) {
508 gl_dbgW("MMC was unmounted, skip MMC album!");
509 minfo_destroy_mtype_item(f_data);
513 if (f_data->count == 0) {
514 /* append the newly created cluster to list */
515 if (!g_strcmp0(f_data->uuid, new_mc_id)) {
516 gl_dbg("empty local album, but it's newly created...");
518 gl_dbg("empty local album, skipping it...");
519 minfo_destroy_mtype_item(f_data);
523 local_item_cnt += f_data->count;
526 gcluster = gl_db_new_cluster();
527 if (gcluster == NULL) {
528 gl_dbgE("gl_db_new_cluster failed!");
529 minfo_destroy_mtype_item(f_data);
534 gcluster->cluster = f_data;
535 length += f_data->count;
537 if (gl_db_is_default_album(ad, f_data))
540 * Default album: Camera Shot
541 * Now Camera Shot is located in Phone.
542 * If user can determine the location of default album,
543 * here we should get the path and check it's in Phone or MMC.
545 default_cluster = gcluster;
546 ad->albuminfo.cluster_list->clist = eina_list_prepend(ad->albuminfo.cluster_list->clist,
551 ad->albuminfo.cluster_list->clist = eina_list_append(ad->albuminfo.cluster_list->clist,
554 /* Default album 'Camera shots' showed in edit view */
558 b_selected = _gl_db_check_selected_id(&sel_id_list,
562 /* Set checkbox state */
563 gcluster->checked = true;
564 /* Append gcluster to selected list */
565 gl_db_albums_selected_list_append(ad, gcluster);
568 if (strlen(sel_id) > 0 && !g_strcmp0(sel_id, f_data->uuid)) {
569 gl_dbgW("Found selected_album.");
570 ad->albuminfo.selected_album = gcluster;
574 /* Clear list of selected ID */
576 __gl_db_free_selected_id_list(&sel_id_list);
578 ad->albuminfo.cluster_list->edit_cnt = edit_album_cnt;
580 * add "all" album, only inclduing local albums temporarily,
582 if (local_item_cnt) {
583 /* Create "All albums" album if any local file exists */
584 gcluster = _gl_db_new_cluster_all(ad, local_item_cnt);
585 if (gcluster == NULL) {
586 gl_dbgE("_gl_db_new_cluster_all failed!");
587 _gl_db_clear_cluster_list(ad, false);
592 ad->albuminfo.cluster_list->clist = eina_list_append_relative(ad->albuminfo.cluster_list->clist,
593 gcluster, default_cluster);
595 ad->albuminfo.cluster_list->clist = eina_list_prepend(ad->albuminfo.cluster_list->clist,
598 default_cluster = gcluster;
601 gl_dbg("Cluster Done.");
606 * get a new item from media service by item id
608 Mitem *gl_db_new_mitem(void *data, const char *item_id)
612 gl_appdata *ad = (gl_appdata *)data;
613 /*new API, to use media id to get item. */
614 minfo_get_item_by_id(ad->maininfo.db_handle, item_id, &mitem);
620 gl_db_new_item_mitem(Mitem * mitem)
622 gl_item *gitem = _gl_db_new_item();
623 GL_CHECK_NULL(gitem);
630 * get a new cluster from media service by cluster id
632 Mcluster *gl_db_new_mcluster(void *data, const char *cluster_id)
634 gl_dbg("cluster_id=%s", cluster_id);
636 gl_appdata *ad = (gl_appdata *)data;
637 Mcluster *mcluster = NULL;
639 ret = minfo_get_cluster(ad->maininfo.db_handle, NULL, cluster_id, &mcluster);
642 gl_dbgE("minfo_get_cluster failed (ret=%d)", ret);
645 minfo_destroy_mtype_item(mcluster);
655 gl_db_new_cluster(void)
657 gl_cluster *gcluster = (gl_cluster *) malloc(sizeof(gl_cluster));
658 GL_CHECK_NULL(gcluster);
659 memset(gcluster, 0x00, sizeof(gl_cluster));
660 gcluster->cluster = NULL;
662 gcluster->item = NULL;
663 gcluster->checked = false;
665 gcluster->_reserved = NULL;
671 gl_db_clear_item_list(void *data)
673 GL_CHECK_VAL(data, GL_DB_FAIL);
674 _gl_db_clear_item_list(data);
676 return GL_DB_SUCCESS;
680 gl_db_free_cluster(gl_cluster * gcluster)
682 GL_CHECK_VAL(gcluster, GL_DB_FAIL);
684 if (gcluster->cluster && gcluster->cluster->uuid &&
685 !g_strcmp0(gcluster->cluster->uuid, GL_ALBUM_ALL_ID))
687 _gl_db_free_cluster_all(gcluster);
691 _gl_db_free_cluster(gcluster);
694 return GL_DB_SUCCESS;
698 gl_db_get_cluster_list(void *data)
700 GL_CHECK_FALSE(data);
701 gl_appdata *ad = (gl_appdata *)data;
702 int n_entire_items = 0;
704 _gl_db_clear_cluster_list(ad, true);
706 ad->albuminfo.cluster_list = _gl_db_new_cluster_list();
707 GL_CHECK_FALSE(ad->albuminfo.cluster_list);
708 n_entire_items = _gl_db_get_cluster_list(ad, false);
709 if (n_entire_items <= 0) //if error code is returned, negative value is possible
713 gl_dbg("cluster-length:%d", n_entire_items);
718 int gl_db_update_cluster_list(void *data)
720 GL_CHECK_VAL(data, -1);
721 gl_appdata *ad = (gl_appdata *)data;
724 len = _gl_db_get_cluster_list(ad, true);
725 gl_dbg("Cluster list length: %d.", len);
729 return GL_DB_SUCCESS;
733 gl_db_cluster_list_remove(void *data, gl_cluster * item)
735 GL_CHECK_VAL(item, GL_DB_FAIL);
736 GL_CHECK_VAL(item->cluster, GL_DB_FAIL);
737 GL_CHECK_VAL(item->cluster->uuid, GL_DB_FAIL);
738 GL_CHECK_VAL(data, GL_DB_FAIL);
739 gl_appdata *ad = (gl_appdata *)data;
740 gl_cluster *current = NULL;
743 GL_CHECK_VAL(ad->albuminfo.cluster_list, GL_DB_FAIL);
744 GL_CHECK_VAL(ad->albuminfo.cluster_list->clist, GL_DB_FAIL);
745 Eina_List *cluster_list = ad->albuminfo.cluster_list->clist;
746 EINA_LIST_FOREACH(cluster_list, l, current)
748 if (current == NULL || current->cluster == NULL ||
749 current->cluster->uuid == NULL) {
750 gl_dbgE("Invalid album item!");
754 if (!g_strcmp0(current->cluster->uuid, item->cluster->uuid))
756 ad->albuminfo.cluster_list->clist = eina_list_remove(ad->albuminfo.cluster_list->clist,
758 gl_db_free_cluster(current);
764 return GL_DB_SUCCESS;
767 int gl_db_get_cluster_by_id(void *data, const char *cluster_id, gl_cluster **cluster, int *pos)
769 GL_CHECK_VAL(data, -1);
770 GL_CHECK_VAL(pos, -1);
771 GL_CHECK_VAL(cluster, -1);
772 GL_CHECK_VAL(cluster_id, -1);
773 gl_appdata *ad = (gl_appdata *)data;
775 gl_cluster *current = NULL;
780 GL_CHECK_VAL(ad->albuminfo.cluster_list, -1);
781 int length = eina_list_count(ad->albuminfo.cluster_list->clist);
782 gl_dbg("album length: %d, current album id: %s", length, cluster_id);
784 for (i = 0; i < length; i++) {
785 current = eina_list_nth(ad->albuminfo.cluster_list->clist, i);
786 if (current && current->cluster && current->cluster->uuid) {
787 gl_dbg("cluster : %s", current->cluster->display_name);
789 gl_dbg("cluster is NULL");
793 if (!g_strcmp0(current->cluster->uuid, cluster_id)) {
796 gl_dbg("Find album: %s", current->cluster->display_name);
803 //add a new cluster whose url is 'cluster_url'.
805 gl_db_add_cluster(void *data, char *cluster_url)
807 GL_CHECK_VAL(cluster_url, GL_DB_FAIL);
808 GL_CHECK_VAL(data, GL_DB_FAIL);
809 gl_appdata *ad = (gl_appdata *)data;
812 char cluster_id[GL_MTYPE_ITEN_ID_LEN_MAX] = { 0, };
813 ret = minfo_add_cluster(ad->maininfo.db_handle, cluster_url, cluster_id,
814 GL_MTYPE_ITEN_ID_LEN_MAX);
817 gl_dbgE("minfo_add_cluster failed, ret: %d", ret);
819 return GL_DB_SUCCESS;
822 /* Get new record from DB to check mitem exists or was already removed */
823 bool gl_db_exists_item(void *data, const char *id)
827 gl_appdata *ad = (gl_appdata *)data;
828 Mitem *new_item = gl_db_new_mitem(ad, id);
829 if (new_item == NULL) {
830 gl_dbgW("Mitem doesn't exist!");
833 minfo_destroy_mtype_item(new_item);
840 * Get medias count of album.
842 int gl_db_get_item_cnt(void *data, const char *cluster_id, int *item_cnt)
844 GL_CHECK_VAL(item_cnt, GL_DB_FAIL);
845 GL_CHECK_VAL(cluster_id, GL_DB_FAIL);
846 GL_CHECK_VAL(data, GL_DB_FAIL);
847 gl_appdata *ad = (gl_appdata *)data;
849 gl_dbg("cluster_id: %s.", cluster_id);
851 if (g_strcmp0(cluster_id, GL_ALBUM_ALL_ID)) {
852 /* It's normal album */
853 minfo_item_filter filter;
854 memset(&filter, 0x00, sizeof(minfo_item_filter));
855 filter.file_type = MINFO_ITEM_IMAGE | MINFO_ITEM_VIDEO;
856 filter.sort_type = MINFO_MEDIA_SORT_BY_DATE_DESC;
857 filter.start_pos = GL_GET_ALL_RECORDS;
858 filter.end_pos = GL_GET_ALL_RECORDS;
859 filter.with_meta = false;
861 err = minfo_get_item_cnt(ad->maininfo.db_handle, cluster_id,
865 gl_dbg("All albums media count.");
866 gl_dbg("All albums media count.");
867 err = minfo_get_all_item_count(ad->maininfo.db_handle,
868 MINFO_CLUSTER_TYPE_LOCAL_ALL,
870 MINFO_MEDIA_FAV_ALL, item_cnt);
874 gl_dbg("Failed to get item count[err: %d]!", err);
878 gl_dbg("Item count: %d.", *item_cnt);
879 return GL_DB_SUCCESS;
882 int gl_db_update_item_cnt(gl_cluster * album)
884 GL_CHECK_VAL(album, GL_DB_FAIL);
885 GL_CHECK_VAL(album->cluster, GL_DB_FAIL);
887 int err = GL_DB_FAIL;
888 GL_CHECK_VAL(album->cluster->uuid, GL_DB_FAIL);
889 err = gl_db_get_item_cnt(album->ad, album->cluster->uuid, &item_count);
890 if (err != GL_DB_SUCCESS) {
891 gl_dbg("gl_db_get_item_cnt failed!");
892 album->cluster->count = 0;
896 gl_dbg("Media count: old=%d, new=%d", album->cluster->count,
898 album->cluster->count = item_count;
900 return GL_DB_SUCCESS;
904 gl_db_get_item_list(void *data,
909 GL_CHECK_VAL(data, -1);
910 gl_appdata *ad = (gl_appdata *)data;
911 Eina_List *itemlist = NULL;
912 minfo_item_filter filter;
914 minfo_file_type file_type;
916 file_type = MINFO_ITEM_IMAGE | MINFO_ITEM_VIDEO; /* default */
917 /* get file-type from bundle when launched by appsvc */
918 if (ad->albuminfo.aul_launch_type == GL_AUL_T_VIEW_ALBUM) {
919 if (ad->albuminfo.aul_file_type == GL_AUL_FILE_T_IMAGE) {
920 file_type = MINFO_ITEM_IMAGE;
921 } else if (ad->albuminfo.aul_file_type == GL_AUL_FILE_T_VIDEO) {
922 file_type = MINFO_ITEM_VIDEO;
926 memset(&filter,0x00,sizeof(minfo_item_filter));
927 GL_CHECK_VAL(album, GL_DB_FAIL);
928 GL_CHECK_VAL(album->cluster, GL_DB_FAIL);
929 gl_dbg("db_get_item_list--folder category; start_pos[%d], end_pos[%d]\n",
932 GL_CHECK_VAL(album->cluster->uuid, GL_DB_FAIL);
934 if (g_strcmp0(album->cluster->uuid, GL_ALBUM_ALL_ID))
936 filter.file_type = file_type;
937 filter.sort_type = MINFO_MEDIA_SORT_BY_DATE_DESC;
938 filter.start_pos = start_pos;
939 filter.end_pos = end_pos;
940 filter.with_meta = true;
942 ad->uginfo.sort_type = filter.sort_type;
944 if (start_pos == (GL_FIRST_VIEW_END_POS + 1) &&
945 end_pos == GL_GET_UNTIL_LAST_RECORD)
947 /* Keep medias_elist and medias_cnt unchanged */
948 gl_dbg("Gridview append idler; Keep medias_elist unchanged.");
952 /*Clear item list before new one got */
953 _gl_db_clear_item_list(ad);
956 err = minfo_get_item_list(ad->maininfo.db_handle,
957 album->cluster->uuid, filter,
958 _gl_db_elist_ite_fn, &itemlist);
960 else //add "All" album
962 gl_dbg("db_get_item_list--all media\n");
963 filter.file_type = file_type;
964 filter.sort_type = MINFO_MEDIA_SORT_BY_DATE_DESC;
965 filter.start_pos = start_pos;
966 filter.end_pos = end_pos;
967 filter.with_meta = true;
969 ad->uginfo.sort_type = filter.sort_type;
971 if (start_pos == (GL_FIRST_VIEW_END_POS + 1) &&
972 end_pos == GL_GET_UNTIL_LAST_RECORD)
974 /* Keep medias_elist and medias_cnt unchanged */
975 gl_dbg("Gridview append idler; Keep medias_elist unchanged.");
979 /* Clear item list before new one got */
980 _gl_db_clear_item_list(ad);
983 err = minfo_get_all_item_list(ad->maininfo.db_handle,
984 MINFO_CLUSTER_TYPE_LOCAL_ALL, filter,
989 gl_dbg("Error code: %d", err);
990 if ((err == 0) && (itemlist != NULL))
993 gl_item *gitem = NULL;
994 EINA_LIST_FREE(itemlist, item)
996 if (item == NULL || item->uuid == NULL) {
997 gl_dbgE("Invalid item!");
1001 gitem = _gl_db_new_item();
1002 if (gitem == NULL) {
1003 gl_dbgE("_gl_db_new_item failed!");
1004 minfo_destroy_mtype_item(gitem);
1010 ad->maininfo.medias_elist = eina_list_append(ad->maininfo.medias_elist, gitem);
1016 ad->maininfo.medias_cnt = eina_list_count(ad->maininfo.medias_elist);
1017 gl_dbg("medias_elist=%p", ad->maininfo.medias_elist);
1021 ad->maininfo.medias_cnt = 0;
1022 if (start_pos == (GL_FIRST_VIEW_END_POS + 1) &&
1023 end_pos == GL_GET_UNTIL_LAST_RECORD)
1025 /* Keep medias_elist and medias_cnt unchanged */
1026 ad->maininfo.medias_cnt = eina_list_count(ad->maininfo.medias_elist);
1027 gl_dbg("Gridview append idler; medias_elist=%p",
1028 ad->maininfo.medias_elist);
1032 ad->maininfo.medias_elist = NULL;
1036 _gl_db_clear_mtype_items_list(&itemlist);
1039 gl_dbg("DB all count : %d", ad->maininfo.medias_cnt);
1043 int gl_db_update_item_list(void *data)
1045 GL_CHECK_VAL(data, -1);
1046 gl_appdata *ad = (gl_appdata *)data;
1047 Eina_List *itemlist = NULL;
1048 minfo_item_filter filter;
1050 int view_mode = gl_get_view_mode(ad);
1051 Eina_List *sel_id_list = NULL;
1052 gl_item *gitem = NULL;
1054 memset(&filter, 0x00, sizeof(minfo_item_filter));
1056 if (view_mode == GL_VIEW_THUMBS_EDIT ||
1057 view_mode == GL_VIEW_VIDEOLIST_EDIT) {
1058 gl_dbg("Edit view.");
1059 /* Get ID list of selected items */
1060 _gl_db_get_selected_item_id_list(ad, &sel_id_list);
1063 gl_cluster *cur_album = ad->albuminfo.current_album;
1064 GL_CHECK_VAL(cur_album, -1);
1065 GL_CHECK_VAL(cur_album->cluster, -1);
1066 GL_CHECK_VAL(cur_album->cluster->uuid, -1);
1068 filter.file_type = MINFO_ITEM_IMAGE | MINFO_ITEM_VIDEO;
1069 filter.sort_type = MINFO_MEDIA_SORT_BY_DATE_DESC;
1070 filter.start_pos = GL_GET_ALL_RECORDS;
1071 filter.end_pos = GL_GET_ALL_RECORDS;
1072 filter.with_meta = true;
1074 ad->uginfo.sort_type = filter.sort_type;
1075 /* Clear item list before new one got */
1076 _gl_db_clear_item_list(ad);
1078 if (!g_strcmp0(cur_album->cluster->uuid, GL_ALBUM_ALL_ID)) {
1079 gl_dbg("All albums medias");
1080 int cluster_t = MINFO_CLUSTER_TYPE_LOCAL_ALL;
1081 err = minfo_get_all_item_list(ad->maininfo.db_handle,
1083 _gl_db_elist_ite_fn,
1086 gl_dbg("Normal album medias");
1087 err = minfo_get_item_list(ad->maininfo.db_handle,
1088 cur_album->cluster->uuid,
1089 filter, _gl_db_elist_ite_fn,
1093 gl_dbg("Error code: %d", err);
1094 if ((err != 0) || (itemlist == NULL)) {
1095 gl_dbgE("(err != 0) || (itemlist == NULL)");
1096 ad->maininfo.medias_cnt = 0;
1097 ad->maininfo.medias_elist = NULL;
1098 /* Clear list of selected ID */
1100 eina_list_free(sel_id_list);
1105 _gl_db_clear_mtype_items_list(&itemlist);
1110 bool b_selected = false;
1112 Eina_List *medias_elist = NULL;
1113 EINA_LIST_FREE(itemlist, item) {
1114 if (item == NULL || item->uuid == NULL) {
1115 gl_dbgE("Invalid item!");
1118 gitem = _gl_db_new_item();
1119 if (gitem == NULL) {
1120 gl_dbgE("_gl_db_new_item failed!");
1121 minfo_destroy_mtype_item(gitem);
1126 /* Append item to medias_elist */
1127 medias_elist = eina_list_append(ad->maininfo.medias_elist,
1129 ad->maininfo.medias_elist = medias_elist;
1132 b_selected = _gl_db_check_selected_id(&sel_id_list,
1136 /* Set checkbox state */
1137 gitem->checked = true;
1138 /* Append gitem to selected list */
1139 gl_db_selected_list_append(ad, gitem);
1144 /* Clear list of selected ID */
1146 __gl_db_free_selected_id_list(&sel_id_list);
1148 ad->maininfo.medias_cnt = eina_list_count(ad->maininfo.medias_elist);
1149 gl_dbg("All medias count:%d.", ad->maininfo.medias_cnt);
1154 gl_db_get_first_several_items(gl_cluster * album,
1155 gl_item * items[], int *item_count,
1156 minfo_media_sort_type sort_type)
1158 GL_CHECK_VAL(items, GL_DB_FAIL);
1159 GL_CHECK_VAL(item_count, GL_DB_FAIL);
1160 GL_CHECK_VAL(album, GL_DB_FAIL);
1161 GL_CHECK_VAL(album->cluster, GL_DB_FAIL);
1162 GL_CHECK_VAL(album->cluster->uuid, GL_DB_FAIL);
1163 GL_CHECK_VAL(album->ad, GL_DB_FAIL);
1164 gl_appdata *ad = (gl_appdata *)album->ad;
1165 minfo_item_filter filter;
1166 Eina_List *item_list = NULL;
1169 gl_item *gitem = NULL;
1172 if (*item_count <= 0)
1176 memset(&filter,0x00,sizeof(minfo_item_filter));
1177 if (g_strcmp0(album->cluster->uuid, GL_ALBUM_ALL_ID) ) //real album
1179 filter.file_type = MINFO_ITEM_IMAGE | MINFO_ITEM_VIDEO;
1180 filter.sort_type = sort_type;
1181 filter.start_pos = GL_FIRST_VIEW_START_POS;
1182 filter.end_pos = (*item_count == 1 ? 1 : (*item_count - 1));
1183 filter.with_meta = false;
1185 err = minfo_get_item_list(ad->maininfo.db_handle,
1186 album->cluster->uuid, filter,
1187 _gl_db_elist_ite_fn, &item_list);
1188 if (err != 0 || item_list == NULL) {
1189 gl_dbgE("minfo_get_item_list failed : err=%d", err);
1192 _gl_db_clear_mtype_items_list(&item_list);
1196 EINA_LIST_FREE(item_list, item) {
1198 gl_dbgE("Invalid Mitem!");
1202 if(result_cnt <= *item_count) {
1204 gitem = _gl_db_new_item();
1205 if (gitem == NULL) {
1206 gl_dbgE("_gl_db_new_item failed!");
1207 minfo_destroy_mtype_item(gitem);
1213 items[result_cnt-1] = gitem;
1215 minfo_destroy_mtype_item(item);
1220 if(*item_count > result_cnt)
1221 *item_count = result_cnt;
1223 else //add "All" album
1225 gl_dbg("db_get_item_list--all media\n");
1226 filter.file_type = MINFO_ITEM_IMAGE | MINFO_ITEM_VIDEO;
1227 filter.sort_type = sort_type;
1229 filter.start_pos = GL_FIRST_VIEW_START_POS;
1230 filter.end_pos = (*item_count == 1 ? 1 : (*item_count - 1));
1231 filter.with_meta = false;
1233 //use new api to get all local files, mmc status checking would be done in new apis
1234 err = minfo_get_all_item_list(ad->maininfo.db_handle,
1235 MINFO_CLUSTER_TYPE_LOCAL_ALL,
1236 filter, _gl_db_elist_ite_fn,
1238 if (err != 0 || item_list == NULL) {
1239 gl_dbgE("minfo_get_item_list fails : err=%d", err);
1242 _gl_db_clear_mtype_items_list(&item_list);
1247 EINA_LIST_FREE(item_list, item) {
1249 gl_dbgE("Invalid Mitem!");
1253 if(result_cnt <= *item_count) {
1255 gitem = _gl_db_new_item();
1256 if (gitem == NULL) {
1257 gl_dbgE("_gl_db_new_item failed!");
1258 minfo_destroy_mtype_item(gitem);
1264 items[result_cnt-1] = gitem;
1266 minfo_destroy_mtype_item(item);
1271 if(*item_count > result_cnt)
1272 *item_count = result_cnt;
1277 gl_dbg("first %d items for this album(%s)",
1278 *item_count, album->cluster->display_name);
1281 return GL_DB_SUCCESS;
1285 gl_db_is_item_cnt_zero(void *data, minfo_file_type type)
1287 GL_CHECK_VAL(data, GL_DB_FAIL);
1288 gl_appdata *ad = (gl_appdata *)data;
1290 gl_item *gitem = NULL;
1292 /* Get all medias count of current album */
1293 int all_cnt = ad->maininfo.medias_cnt;
1294 for (i = 1; i <= all_cnt; i++)
1296 gl_db_get_item_by_index(ad, i, false, &gitem);
1297 if (gitem && gitem->item)
1299 if (gitem->item->type == type)
1306 gl_dbg(" item_cnt = 0 ");
1311 gl_db_destroy_item(gl_item * gitem)
1313 GL_CHECK_VAL(gitem, GL_DB_FAIL);
1314 GL_CHECK_VAL(gitem->item, GL_DB_FAIL);
1315 _gl_db_destroy_item(gitem);
1316 return GL_DB_SUCCESS;
1320 * select_mode: true, get item from selected_media_elist; false, get item from media_elist.
1323 gl_db_get_item_by_index(void *data, int idx, bool select_mode, gl_item ** gitem)
1325 GL_CHECK_VAL(data, GL_DB_FAIL);
1326 gl_appdata *ad = (gl_appdata *)data;
1329 if (idx > ad->maininfo.medias_cnt) {
1330 gl_dbg("db_get_item_by_index(%d) is failed, ad->maininfo.medias_cnt=%d\n",
1331 idx, ad->maininfo.medias_cnt);
1336 *gitem = eina_list_nth(ad->maininfo.medias_elist, idx - 1);
1338 Eina_List *sel_list = ad->selectedinfo.medias_elist;
1339 *gitem = (gl_item *) eina_list_nth(sel_list, --idx);
1341 return GL_DB_SUCCESS;
1345 gl_db_item_list_remove(void *data, gl_item * gitem)
1347 GL_CHECK_VAL(gitem, GL_DB_FAIL);
1348 GL_CHECK_VAL(gitem->item, GL_DB_FAIL);
1349 GL_CHECK_VAL(gitem->item->uuid, GL_DB_FAIL);
1350 GL_CHECK_VAL(data, GL_DB_FAIL);
1351 gl_appdata *ad = (gl_appdata *)data;
1352 gl_item *current = NULL;
1353 Eina_List *l = NULL;
1355 Eina_List *media_elist = ad->maininfo.medias_elist;
1356 EINA_LIST_FOREACH(media_elist, l, current)
1358 if (current == NULL || current->item == NULL ||
1359 current->item->uuid == NULL) {
1360 gl_dbgE("Invalid gitem!");
1364 if (!g_strcmp0(current->item->uuid, gitem->item->uuid))
1366 ad->maininfo.medias_elist = eina_list_remove(ad->maininfo.medias_elist, current);
1368 ad->maininfo.medias_cnt--;
1369 gl_db_destroy_item(current);
1378 /* Remove file from DB and file system */
1379 int gl_db_remove_item(gl_item * gitem)
1381 GL_CHECK_VAL(gitem, GL_DB_FAIL);
1382 GL_CHECK_VAL(gitem->item, GL_DB_FAIL);
1383 GL_CHECK_VAL(gitem->item->uuid, GL_DB_FAIL);
1384 GL_CHECK_VAL(gitem->ad, GL_DB_FAIL);
1385 gl_appdata *ad = (gl_appdata *)gitem->ad;
1388 if (!gitem->item->file_url) {
1389 gl_dbgW("Invalid file_url!");
1390 ret = minfo_delete_media_id(ad->maininfo.db_handle, gitem->item->uuid);
1392 gl_dbgE("minfo_delete_media_id failed[%d]!", ret);
1395 return GL_DB_SUCCESS;
1398 gl_dbg("Remove file: %s.", gitem->item->file_url);
1399 /* Delete record from DB then delete media from file system */
1400 ret = minfo_delete_media(ad->maininfo.db_handle, gitem->item->file_url);
1402 gl_dbgE("minfo_delete_media failed[%d]!", ret);
1406 if (!ecore_file_unlink(gitem->item->file_url)) {
1407 gl_dbgE("ecore_file_unlink failed!");
1410 return GL_DB_SUCCESS;
1413 /* Append gl_item to medias_elist */
1415 gl_db_append_item(void *data, gl_item * gitem)
1417 GL_CHECK_VAL(gitem, GL_DB_FAIL);
1418 GL_CHECK_VAL(gitem->item, GL_DB_FAIL);
1419 GL_CHECK_VAL(data, GL_DB_FAIL);
1420 gl_appdata *ad = (gl_appdata *)data;
1423 ad->maininfo.medias_elist = eina_list_append(ad->maininfo.medias_elist, gitem);
1424 ad->maininfo.medias_cnt++;
1430 gl_db_selected_list_get_nth(void *data, int idx)
1432 GL_CHECK_NULL(data);
1433 gl_appdata *ad = (gl_appdata *)data;
1435 return eina_list_nth(ad->selectedinfo.medias_elist, idx);
1439 gl_db_selected_list_append(void *data, gl_item * gitem)
1441 GL_CHECK_VAL(gitem, GL_DB_FAIL);
1442 GL_CHECK_VAL(gitem->item, GL_DB_FAIL);
1443 GL_CHECK_VAL(data, GL_DB_FAIL);
1444 gl_appdata *ad = (gl_appdata *)data;
1446 /* Update selected images count */
1447 if (gitem->item->type == MINFO_ITEM_IMAGE)
1448 ad->selectedinfo.images_cnt++;
1450 Eina_List *sel_list = ad->selectedinfo.medias_elist;
1451 sel_list = eina_list_append(sel_list, gitem);
1452 ad->selectedinfo.medias_elist = sel_list;
1453 return GL_DB_SUCCESS;
1457 gl_db_selected_list_remove(void *data, gl_item * gitem)
1459 GL_CHECK_VAL(gitem, GL_DB_FAIL);
1460 GL_CHECK_VAL(gitem->item, GL_DB_FAIL);
1461 GL_CHECK_VAL(gitem->item->uuid, GL_DB_FAIL);
1462 GL_CHECK_VAL(data, GL_DB_FAIL);
1463 gl_appdata *ad = (gl_appdata *)data;
1464 gl_item *current = NULL;
1465 Eina_List *l = NULL;
1467 Eina_List *sel_list = ad->selectedinfo.medias_elist;
1468 EINA_LIST_FOREACH(sel_list, l, current) {
1469 if (current == NULL || current->item == NULL ||
1470 current->item->uuid == NULL) {
1471 gl_dbgE("Invalid gitem!");
1474 if (!g_strcmp0(current->item->uuid, gitem->item->uuid)) {
1475 /* Update selected images count */
1476 if (current->item->type == MINFO_ITEM_IMAGE &&
1477 ad->selectedinfo.images_cnt > 0)
1478 ad->selectedinfo.images_cnt--;
1480 sel_list = eina_list_remove(sel_list, current);
1481 ad->selectedinfo.medias_elist = sel_list;
1486 return GL_DB_SUCCESS;
1490 gl_db_selected_list_finalize(void *data)
1492 GL_CHECK_VAL(data, GL_DB_FAIL);
1493 gl_appdata *ad = (gl_appdata *)data;
1494 gl_item *gitem = NULL;
1496 Eina_List *sel_list = ad->selectedinfo.medias_elist;
1497 EINA_LIST_FREE(sel_list, gitem) {
1499 gitem->checked = false;
1502 ad->selectedinfo.medias_elist = NULL;
1503 ad->selectedinfo.images_cnt = 0;
1504 return GL_DB_SUCCESS;
1508 gl_db_selected_list_count(void *data)
1510 GL_CHECK_VAL(data, GL_DB_FAIL);
1511 gl_appdata *ad = (gl_appdata *)data;
1513 return eina_list_count(ad->selectedinfo.medias_elist);
1517 * get full path of cluster
1519 int gl_db_get_folder_fullpath(void *data, const char *cluster_id, char *path)
1521 GL_CHECK_VAL(path, GL_DB_FAIL);
1522 GL_CHECK_VAL(cluster_id, GL_DB_FAIL);
1523 GL_CHECK_VAL(data, GL_DB_FAIL);
1524 gl_appdata *ad = (gl_appdata *)data;
1525 /*For safety, add one more parameter as a size of the output array */
1526 return minfo_get_cluster_fullpath_by_id(ad->maininfo.db_handle,
1527 cluster_id, path, GL_DIR_PATH_LEN_MAX);
1531 * Check it's default album[Camera shot] or not
1534 gl_db_is_default_album(void *data, Mcluster* mcluster)
1536 GL_CHECK_FALSE(mcluster);
1537 GL_CHECK_FALSE(mcluster->display_name);
1538 GL_CHECK_FALSE(mcluster->uuid);
1540 /* Name is 'Camera shot and' folder locates in Phone */
1541 if (!strcmp(mcluster->display_name, GL_ALBUM_DEFAULT_NAME) &&
1542 mcluster->type == MINFO_PHONE)
1544 char dir_path[GL_DIR_PATH_LEN_MAX] = { 0, };
1545 char parent_path[GL_DIR_PATH_LEN_MAX] = { 0, };
1547 int ret = gl_db_get_folder_fullpath(data, mcluster->uuid, dir_path);
1550 gl_dbgE("gl_db_get_folder_fullpath failed[%d]!", ret);
1553 gl_dbg("Full path: %s", dir_path);
1555 _gl_db_get_file_dir_names(dir_path, NULL, NULL, parent_path);
1556 gl_dbg("Parent path: %s.", parent_path);
1558 /* And parent folder is Phone root path, it's default folder */
1559 return (strcmp(parent_path, GL_ROOT_PATH_PHONE) == 0);
1565 bool gl_db_is_root_path(void *data, const char *cluster_id, const char *path)
1568 char dir_path[GL_DIR_PATH_LEN_MAX] = { 0, };
1572 g_strlcpy(dir_path, path, GL_DIR_PATH_LEN_MAX);
1576 if (cluster_id == NULL || strlen(cluster_id) <= 0) {
1577 gl_dbgE("Invalid cluster_id!");
1580 res = gl_db_get_folder_fullpath(data, cluster_id, dir_path);
1583 gl_dbg("get folder fullpath failed(%d), return!", res);
1588 if (!g_strcmp0(GL_ROOT_PATH_PHONE, dir_path) ||
1589 !g_strcmp0(GL_ROOT_PATH_MMC, dir_path)) {
1590 gl_dbg("Root path: %s.", dir_path);
1598 gl_db_get_albums_selected_cnt(void *data)
1600 GL_CHECK_VAL(data, GL_DB_FAIL);
1601 gl_appdata *ad = (gl_appdata *)data;
1603 return eina_list_count(ad->albuminfo.selected_albums_elist);
1607 gl_db_albums_selected_list_append(void *data, gl_cluster * item)
1609 GL_CHECK_VAL(item, GL_DB_FAIL);
1610 GL_CHECK_VAL(item->cluster, GL_DB_FAIL);
1611 GL_CHECK_VAL(data, GL_DB_FAIL);
1612 gl_appdata *ad = (gl_appdata *)data;
1613 ad->albuminfo.selected_albums_elist = eina_list_append(ad->albuminfo.selected_albums_elist, item);
1615 return GL_DB_SUCCESS;
1619 gl_db_albums_selected_list_remove(void *data, gl_cluster * item)
1621 GL_CHECK_VAL(item, GL_DB_FAIL);
1622 GL_CHECK_VAL(item->cluster, GL_DB_FAIL);
1623 GL_CHECK_VAL(item->cluster->uuid, GL_DB_FAIL);
1624 GL_CHECK_VAL(data, GL_DB_FAIL);
1625 gl_appdata *ad = (gl_appdata *)data;
1626 gl_cluster *current = NULL;
1627 Eina_List *l = NULL;
1629 Eina_List *sel_list = ad->albuminfo.selected_albums_elist;
1630 EINA_LIST_FOREACH(sel_list, l, current)
1632 if (current == NULL || current->cluster == NULL ||
1633 current->cluster->uuid == NULL) {
1634 gl_dbgE("Invalid gcluster!");
1638 if (!g_strcmp0(current->cluster->uuid, item->cluster->uuid))
1640 ad->albuminfo.selected_albums_elist = eina_list_remove(ad->albuminfo.selected_albums_elist, current);
1646 return GL_DB_SUCCESS;
1650 gl_db_finalize_albums_selected_list(void *data)
1652 GL_CHECK_VAL(data, GL_DB_FAIL);
1653 gl_appdata *ad = (gl_appdata *)data;
1654 gl_cluster *item = NULL;
1656 Eina_List *sel_list = ad->albuminfo.selected_albums_elist;
1657 EINA_LIST_FREE(sel_list, item)
1660 item->checked = false;
1663 ad->albuminfo.selected_albums_elist = NULL;
1664 return GL_DB_SUCCESS;
1668 gl_db_is_albums_selected_list_empty(void *data)
1670 GL_CHECK_VAL(data, GL_DB_FAIL);
1671 gl_appdata *ad = (gl_appdata *)data;
1672 gl_cluster *current = NULL;
1673 Eina_List *l = NULL;
1675 Eina_List *sel_list = ad->albuminfo.selected_albums_elist;
1676 EINA_LIST_FOREACH(sel_list, l, current)
1678 if (current == NULL || current->cluster == NULL)
1684 if (current->cluster->count)
1695 gl_db_init(void *data)
1697 GL_CHECK_VAL(data, GL_DB_FAIL);
1698 gl_appdata *ad = (gl_appdata *)data;
1699 MediaSvcHandle *_db_handle = NULL;
1701 int err = media_svc_connect(&_db_handle);
1703 gl_dbgE("Connect to DB failed!");
1707 ad->maininfo.db_handle = _db_handle;
1708 return GL_DB_SUCCESS;
1712 gl_db_finalize(void *data)
1714 GL_CHECK_VAL(data, GL_DB_FAIL);
1715 gl_appdata *ad = (gl_appdata *)data;
1717 _gl_db_clear_cluster_list(ad, true);
1718 _gl_db_clear_item_list(ad);
1720 int err = media_svc_disconnect(ad->maininfo.db_handle);
1722 gl_dbgE("Disconnect with DB failed!");
1726 return GL_DB_SUCCESS;