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 <media_info.h>
20 #include "gl-data-util.h"
21 #include "gl-controlbar.h"
26 #include "gl-strings.h"
27 #include "gl-data-type.h"
29 bool _gl_data_util_get_file_dir_name(const char *file_path, char *filename,
30 char *dir_name, char *dir_path)
32 GL_CHECK_FALSE(file_path);
35 for (i = strlen(file_path); i >= 0; i--) {
36 if (file_path[i] != '\0') {
39 if (file_path[i] == '/') {
40 if (filename != NULL) {
41 memcpy(filename, &file_path[i + 1], --count);
42 *(filename + count) = '\0';
43 gl_dbg("File Name = %s", filename);
45 if (dir_path != NULL) {
46 memcpy(dir_path, &file_path[0], i);
47 *(dir_path + i) = '\0';
48 gl_dbg("Directory Name = %s", dir_path);
50 if (dir_name != NULL) {
52 for (--i; i >= 0; i--) {
54 if (file_path[i] == '/') {
55 memcpy(dir_name, &file_path[i + 1], --count);
56 *(dir_name + count) = '\0';
57 gl_dbg("Directory Name = %s", dir_name);
73 gl_item *_gl_data_util_calloc_gitem(void)
75 gl_item *gitem = (gl_item *)calloc(1, sizeof(gl_item));
80 int _gl_data_util_free_gitem(gl_item *gitem)
82 GL_CHECK_VAL(gitem, -1);
84 _gl_data_type_free_glitem((void **)&(gitem->item));
88 if (gitem->_reserved) {
89 free(gitem->_reserved);
90 gitem->_reserved = NULL;
99 gl_cluster *_gl_data_util_calloc_gcluster(void)
101 gl_cluster *gcluster = (gl_cluster *)calloc(1, sizeof(gl_cluster));
102 GL_CHECK_NULL(gcluster);
106 int _gl_data_util_free_gcluster(gl_cluster *gcluster)
108 GL_CHECK_VAL(gcluster, -1);
109 if (gcluster->cluster) {
110 _gl_data_type_free_glitem((void **)&(gcluster->cluster));
111 gcluster->cluster = NULL;
114 if (gcluster->_reserved) {
115 free(gcluster->_reserved);
116 gcluster->_reserved = NULL;
123 gl_cluster *_gl_data_util_new_gcluster_all(void *data, int count)
127 gl_cluster *gcluster = NULL;
128 gl_album_s *mcluster = NULL;
130 gcluster = _gl_data_util_calloc_gcluster();
131 GL_CHECK_NULL(gcluster);
133 _gl_data_type_new_album(&mcluster);
134 if (mcluster == NULL) {
140 mcluster->uuid = strdup(GL_ALBUM_ALL_ID);
141 mcluster->count = count;
142 mcluster->display_name = strdup(GL_ALBUM_ALL_NAME);
144 gcluster->cluster = mcluster;
148 gl_cluster_list *_gl_data_util_calloc_cluster_list(void)
150 gl_cluster_list *clus_list = (gl_cluster_list *)calloc(1,
151 sizeof(gl_cluster_list));
152 GL_CHECK_NULL(clus_list);
156 /* Clear eina_list got from DB */
157 int _gl_data_util_clear_gtype_item_list(Eina_List **elist)
159 void *current = NULL;
161 if (elist && *elist) {
162 gl_dbg("Clear gtype items list");
163 EINA_LIST_FREE(*elist, current) {
165 _gl_data_type_free_glitem((void **)¤t);
175 int _gl_data_util_clear_item_list(Eina_List **elist)
177 GL_CHECK_VAL(elist, -1);
178 gl_item *current = NULL;
180 gl_dbg("Clear elist");
181 EINA_LIST_FREE(*elist, current) {
182 _gl_data_util_free_gitem(current);
192 int _gl_data_util_get_selected_cluster_id_list(void *data,
193 Eina_List **sel_id_list)
195 GL_CHECK_VAL(sel_id_list, -1);
196 GL_CHECK_VAL(data, -1);
197 gl_appdata *ad = (gl_appdata *)data;
198 GL_CHECK_VAL(ad->albuminfo.selected_albums_elist, -1);
199 gl_cluster *gcluster = NULL;
200 char *item_id = NULL;
202 /* Save ID of selected clusters */
203 EINA_LIST_FREE(ad->albuminfo.selected_albums_elist, gcluster) {
204 if (gcluster && gcluster->cluster && gcluster->cluster->uuid) {
205 item_id = strdup(gcluster->cluster->uuid);
206 *sel_id_list = eina_list_append(*sel_id_list,
213 int _gl_data_util_get_selected_item_id_list(void *data,
214 Eina_List **sel_id_list)
216 GL_CHECK_VAL(sel_id_list, -1);
217 GL_CHECK_VAL(data, -1);
218 gl_appdata *ad = (gl_appdata *)data;
219 GL_CHECK_VAL(ad->selectedinfo.medias_elist, -1);
220 gl_item *gitem = NULL;
221 char *item_id = NULL;
223 /* Save ID of selected items */
224 EINA_LIST_FREE(ad->selectedinfo.medias_elist, gitem) {
225 if (gitem && gitem->item && gitem->item->uuid) {
226 item_id = strdup(gitem->item->uuid);
227 *sel_id_list = eina_list_append(*sel_id_list,
234 /* Check ID is in the list or not */
235 bool _gl_data_util_check_selected_id(Eina_List **sel_id_list, const char *id)
237 GL_CHECK_FALSE(sel_id_list);
238 Eina_List *tmp_elist = NULL;
242 if (eina_list_count(*sel_id_list) == 0) {
243 gl_dbgE("sel_id_list is empty!");
247 EINA_LIST_FOREACH(*sel_id_list, tmp_elist, p_id) {
249 gl_dbgE("Invalid p_id!");
252 /* Get next one if they wasn't equal */
253 if (g_strcmp0(id, (char *)p_id)) {
257 *sel_id_list = eina_list_remove(*sel_id_list, p_id);
265 /* Free list of selected IDs */
266 int _gl_data_util_free_selected_id_list(Eina_List **sel_id_list)
268 GL_CHECK_VAL(sel_id_list, -1);
269 if (*sel_id_list == NULL) {
270 gl_dbg("sel_id_list is empty!");
275 EINA_LIST_FREE(*sel_id_list, p_id) {
277 gl_dbgE("Invalid p_id!");
287 int _gl_data_util_check_album_selected_files(gl_cluster *album, int *drm_cnt,
288 int *img_cnt, int *sel_cnt)
290 GL_CHECK_VAL(album, -1);
291 GL_CHECK_VAL(album->cluster, -1);
292 GL_CHECK_VAL(album->cluster->uuid, -1);
293 GL_CHECK_VAL(album->ad, -1);
298 Eina_List *itemlist = NULL;
301 memset(&filter, 0x00, sizeof(gl_filter_s));
302 g_strlcpy(filter.cond, GL_CONDITION_IMAGE_VIDEO, CONDITION_LENGTH);
303 filter.sort_type = MEDIA_CONTENT_ORDER_DESC;
304 filter.collate_type = MEDIA_CONTENT_COLLATE_DEFAULT;
305 g_strlcpy(filter.sort_keyword, MEDIA_MODIFIED_TIME, KEYWORD_LENGTH);
306 filter.offset = GL_GET_ALL_RECORDS;
307 filter.count = GL_GET_ALL_RECORDS;
308 filter.with_meta = false;
310 if (!g_strcmp0(album->cluster->uuid, GL_ALBUM_ALL_ID)) {
311 gl_dbg("All albums.");
312 err = _gl_local_data_get_all_albums_media_list(&filter,
315 err = _gl_local_data_get_album_media_list(&filter,
316 album->cluster->uuid,
320 if ((err == 0) && (itemlist != NULL)) {
321 gl_media_s *item = NULL;
322 EINA_LIST_FREE(itemlist, item) {
323 if (item == NULL || item->uuid == NULL) {
324 gl_dbgE("Invalid item!");
329 if (album->cluster->type == GL_PHONE ||
330 album->cluster->type == GL_MMC) {
331 if (item->type == MEDIA_CONTENT_TYPE_IMAGE)
333 /* Update selected DRM files count */
334 if (gl_drm_is_drm_file(item->file_url))
338 /* Checkme: now only image supported */
344 gl_dbg("Selected items count: %d, image count: %d, drm count: %d.",
345 _sel_cnt, _img_cnt, _drm_cnt);