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://floralicense.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.
19 #include "ivug-common.h"
20 #include "ivug-debug.h"
21 #include "ivug-parameter.h"
22 #include "ivug-file-info.h"
25 #include "ivug-util.h"
27 #include "ivug-filter.h"
30 #define IVUG_BUNDLE_KEY_VIEW_MODE "View Mode"
31 #define IVUG_BUNDLE_KEY_PATH "Path"
32 #define IVUG_BUNDLE_KEY_THUMBNAIL_PATH "Thumb Path"
33 #define IVUG_BUNDLE_KEY_ALBUM_IDX "Album index"
34 #define IVUG_BUNDLE_KEY_VIEW_BY "View By"
35 #define IVUG_BUNDLE_KEY_INDEX "Index"
36 #define IVUG_BUNDLE_KEY_SORT_BY "Sort By"
37 #define IVUG_BUNDLE_KEY_FOOTSTEPS "Footsteps"
39 #define IVUG_BUNDLE_KEY_MAX_LONGITUDE "LON_MAX"
40 #define IVUG_BUNDLE_KEY_MIN_LONGITUDE "LON_MIN"
41 #define IVUG_BUNDLE_KEY_MAX_LATITUDE "LAT_MAX"
42 #define IVUG_BUNDLE_KEY_MIN_LATITUDE "LAT_MIN"
44 #define IVUG_BUNDLE_KEY_SETAS_TYPE "Setas type"
45 #define IVUG_BUNDLE_KEY_TAG_NAME "Tag name"
47 #define IVUG_BUNDLE_KEY_RESOLUTION "Resolution"
48 #define IVUG_BUNDLE_KEY_FIXED_RATIO "Fixed ratio"
50 #define IVUG_BUNDLE_KEY_MEDIA_TYPE "Media type"
52 #define IVUG_BUNDLE_KEY_STANDALONE "Standalone"
54 #define IVUG_BUNDLE_KEY_CONTACT_ID "Contact id"
55 #define IVUG_BUNDLE_KEY_CLUSTER_ID "Cluster id"
56 #define IVUG_BUNDLE_KEY_GROUP_ID "Group id"
58 #define IVUG_BUNDLE_KEY_SELECTED_INDEX "Selected index"
61 #define IVUG_DEFAULT_MODE IVUG_MODE_SINGLE
62 #define IVUG_DEFAULT_INDEX (1) // First item
64 #define IVUG_FILE_PREFIX "file://"
67 void _ivug_free(char **val)
74 _get_view_mode(ivug_parameter* data, const char* val)
76 IV_ASSERT(val != NULL);
78 #define IVUG_BUNDLE_VALUE_VIEW_MODE_ALBUM "ALBUM"
79 #define IVUG_BUNDLE_VALUE_VIEW_MODE_NORMAL "NORMAL"
80 #define IVUG_BUNDLE_VALUE_VIEW_MODE_SINGLE "SINGLE"
81 #define IVUG_BUNDLE_VALUE_VIEW_MODE_GALLERY "GALLERY"
82 #define IVUG_BUNDLE_VALUE_VIEW_MODE_CAMERA "CAMERA"
83 #define IVUG_BUNDLE_VALUE_VIEW_MODE_DISPLAY "DISPLAY"
84 #define IVUG_BUNDLE_VALUE_VIEW_MODE_SETAS "SETAS"
85 #define IVUG_BUNDLE_VALUE_VIEW_MODE_SLIDESHOW "SLIDESHOW"
87 int len = strlen(val);
89 if (strncmp(val, IVUG_BUNDLE_VALUE_VIEW_MODE_NORMAL, len) == 0
90 || strncmp(val, IVUG_BUNDLE_VALUE_VIEW_MODE_GALLERY, len) == 0 )
92 return IVUG_MODE_NORMAL;
94 else if (strncmp(val, IVUG_BUNDLE_VALUE_VIEW_MODE_ALBUM, len) == 0)
97 MSG_IVUG_ERROR("ALBUM is deprecated!!!! plz check");
98 printf("bundle key ALBUM is deprecated!!!! plz check\n");
99 return IVUG_MODE_NORMAL;
101 else if ( strncmp(val, IVUG_BUNDLE_VALUE_VIEW_MODE_CAMERA, len) == 0)
103 data->start_index = 1; //apply window loading
104 data->view_by = IVUG_VIEW_BY_FOLDER; // In camera case, All images should be shown in camera folder.
105 return IVUG_MODE_CAMERA;
107 else if (strncmp(val, IVUG_BUNDLE_VALUE_VIEW_MODE_SINGLE, len) == 0)
109 if(data->view_by != IVUG_VIEW_BY_FOLDER)
110 data->view_by = IVUG_VIEW_BY_FILE;
111 return IVUG_MODE_SINGLE;
113 else if ( strncmp(val, IVUG_BUNDLE_VALUE_VIEW_MODE_DISPLAY, len) == 0)
115 data->view_by = IVUG_VIEW_BY_FILE;
116 return IVUG_MODE_DISPLAY;
118 else if(strncmp(val, IVUG_BUNDLE_VALUE_VIEW_MODE_SETAS, len) == 0)
120 data->view_by = IVUG_VIEW_BY_FILE;
121 return IVUG_MODE_SETAS;
123 else if(strncmp(val, IVUG_BUNDLE_VALUE_VIEW_MODE_SLIDESHOW, len) == 0)
125 if(data->view_by == IVUG_VIEW_BY_INVAILD)
127 data->view_by = IVUG_VIEW_BY_FOLDER;
129 return IVUG_MODE_SLIDESHOW;
132 MSG_IVUG_ERROR("Invalid mode : %s", val);
133 return IVUG_MODE_INVAILD;
138 _get_view_by(const char* val)
141 #define IVUG_BUNDLE_VALUE_VIEW_BY_ALL "All"
142 #define IVUG_BUNDLE_VALUE_VIEW_BY_FAVORITES "Favorites"
143 #define IVUG_BUNDLE_VALUE_VIEW_BY_TAGS "Tags"
144 #define IVUG_BUNDLE_VALUE_VIEW_BY_FLODER "By Folder"
145 #define IVUG_BUNDLE_VALUE_VIEW_BY_PLACES "Places"
147 IV_ASSERT(val != NULL);
149 int len = strlen(val);
151 if (strncmp(val, IVUG_BUNDLE_VALUE_VIEW_BY_FLODER, len) == 0 )
153 return IVUG_VIEW_BY_FOLDER;
155 else if (strncmp(val, IVUG_BUNDLE_VALUE_VIEW_BY_ALL, len) == 0 )
157 return IVUG_VIEW_BY_ALL;
159 else if (strncmp(val, IVUG_BUNDLE_VALUE_VIEW_BY_FAVORITES, len) == 0)
161 return IVUG_VIEW_BY_FAVORITES;
163 else if (strncmp(val, IVUG_BUNDLE_VALUE_VIEW_BY_TAGS, len) == 0)
165 return IVUG_VIEW_BY_TAG;
167 else if (strncmp(val, IVUG_BUNDLE_VALUE_VIEW_BY_PLACES, len) == 0)
169 return IVUG_VIEW_BY_PLACES;
172 MSG_IVUG_ERROR("Invalid view by : %s", val);
174 return IVUG_VIEW_BY_FILE;
179 static ivug_setas_type
180 _get_setas_type(const char* val)
182 IV_ASSERT(val != NULL);
184 #define IVUG_BUNDLE_VALUE_SETAS_UG_WALLPAPER "Wallpaper"
185 #define IVUG_BUNDLE_VALUE_SETAS_UG_LOCKSCREEN "Lockscreen"
186 #define IVUG_BUNDLE_VALUE_SETAS_UG_WALLPAPER_N_LOCKSCREEN "Wallpaper & Lockscreen"
187 #define IVUG_BUNDLE_VALUE_SETAS_UG_CALLERID "CallerID"
188 #define IVUG_BUNDLE_VALUE_SETAS_UG_VIDEO_CALLEID "VideoCallID"
189 #define IVUG_BUNDLE_VALUE_SETAS_UG_CROP "Crop"
190 #define IVUG_BUNDLE_VALUE_SETAS_UG_WALLPAPER_CROP "Wallpaper Crop"
192 int len = strlen(val);
194 if (strncmp(val, IVUG_BUNDLE_VALUE_SETAS_UG_WALLPAPER, len) == 0 )
196 return IVUG_SET_AS_UG_TYPE_WALLPAPER;
198 else if (strncmp(val, IVUG_BUNDLE_VALUE_SETAS_UG_WALLPAPER_CROP, len) == 0 )
200 return IVUG_SET_AS_UG_TYPE_WALLPAPER_CROP;
202 else if (strncmp(val, IVUG_BUNDLE_VALUE_SETAS_UG_LOCKSCREEN, len) == 0 )
204 return IVUG_SET_AS_UG_TYPE_LOCKSCREEN;
206 else if (strncmp(val, IVUG_BUNDLE_VALUE_SETAS_UG_WALLPAPER_N_LOCKSCREEN, len) == 0 )
208 return IVUG_SET_AS_UG_TYPE_WALLPAPER_N_LOCKSCREEN;
210 else if (strncmp(val, IVUG_BUNDLE_VALUE_SETAS_UG_CALLERID, len) == 0)
212 return IVUG_SET_AS_UG_TYPE_CALLER_ID;
214 else if (strncmp(val, IVUG_BUNDLE_VALUE_SETAS_UG_VIDEO_CALLEID, len) == 0)
216 return IVUG_SET_AS_UG_TYPE_VIDEO_CALL_ID;
218 else if (strncmp(val, IVUG_BUNDLE_VALUE_SETAS_UG_CROP, len) == 0)
220 return IVUG_SET_AS_UG_TYPE_CROP;
223 MSG_IVUG_ERROR("Invalid setas ug type : %s", val);
224 return IVUG_SET_AS_UG_TYPE_INVALID;
227 static ivug_media_type
228 _get_media_type(const char* val)
230 IV_ASSERT(val != NULL);
231 #define IVUG_BUNDLE_VALUE_MEDIA_TYPE_ALL "All"
232 #define IVUG_BUNDLE_VALUE_MEDIA_TYPE_IMAGE "Image"
233 #define IVUG_BUNDLE_VALUE_MEDIA_TYPE_VIDEO "Video"
235 int len = strlen(val);
237 if (strncmp(val, IVUG_BUNDLE_VALUE_MEDIA_TYPE_IMAGE, len) == 0 )
239 return IVUG_MEDIA_TYPE_IMAGE;
241 else if (strncmp(val, IVUG_BUNDLE_VALUE_MEDIA_TYPE_VIDEO, len) == 0)
243 return IVUG_MEDIA_TYPE_VIDEO;
245 else if(strncmp(val, IVUG_BUNDLE_VALUE_MEDIA_TYPE_ALL, len) == 0)
247 return IVUG_MEDIA_TYPE_ALL;
250 MSG_IVUG_ERROR("Invalid media type : %s", val);
251 return IVUG_MEDIA_TYPE_MAX;
254 static bool _data_print(service_h service, const char *key, void *user_data)
263 service_is_extra_data_array(service, key, &array);
266 service_get_extra_data(service, key, &value);
267 MSG_IVUG_HIGH(" %s : %s", key, value);
272 service_get_extra_data_array(service, key, &value_array, &array_len);
273 MSG_IVUG_HIGH(" %s :", key);
274 for(i=0; i<array_len; i++)
276 MSG_IVUG_HIGH(" %s", value_array[i]);
278 for(i=0; i<array_len; i++)
280 free(value_array[i]);
288 static void _print_service_data(service_h service)
290 int ret = service_foreach_extra_data(service, _data_print, NULL);
292 if(SERVICE_ERROR_NONE != ret)
294 MSG_IVUG_ERROR("service_foreach_extra_data ERROR");
302 ivug_param_create_from_bundle(service_h service)
306 MSG_IVUG_WARN("bundle value is NULL");
310 //print key and value.
311 MSG_IVUG_HIGH("**********************************");
312 _print_service_data(service);
313 MSG_IVUG_HIGH("**********************************");
316 ivug_parameter* data = (ivug_parameter*)calloc(1, sizeof(ivug_parameter));
320 MSG_IMAGEVIEW_FATAL("Cannot allocate memory");
325 char* standalone = NULL;
327 service_get_extra_data (service, IVUG_BUNDLE_KEY_STANDALONE, &standalone);
328 if (standalone != NULL)
330 data->bStandalone = true;
331 _ivug_free(&standalone);
335 data->bStandalone = false;
339 char* szFilePath = NULL;
341 service_get_extra_data (service, IVUG_BUNDLE_KEY_PATH, &szFilePath);
342 if(szFilePath == NULL)
344 MSG_IVUG_ERROR("File path is NULL");
345 service_get_uri(service, &szFilePath); // app gadget
348 MSG_IMAGEVIEW_ERROR("App gadget launched %s", szFilePath);
349 service_add_extra_data (service, "View Mode", "SINGLE");
352 if ( szFilePath != NULL )
354 if(strncmp(IVUG_FILE_PREFIX, szFilePath, strlen(IVUG_FILE_PREFIX)) == 0)
356 data->filepath = strdup(szFilePath + strlen(IVUG_FILE_PREFIX));
360 data->filepath = strdup(szFilePath);
362 MSG_IVUG_MED("Current File = %s", data->filepath);
363 _ivug_free(&szFilePath);
367 ivug_param_delete(data);
373 char* szViewBy = NULL;
375 service_get_extra_data (service, IVUG_BUNDLE_KEY_VIEW_BY, &szViewBy);
376 if (szViewBy != NULL)
378 MSG_IVUG_MED("View By = %s", szViewBy);
380 data->view_by = _get_view_by(szViewBy);
382 if (data->view_by == IVUG_VIEW_BY_TAG)
384 char* szTagName = NULL;
386 service_get_extra_data (service, IVUG_BUNDLE_KEY_TAG_NAME, &szTagName);
387 if ( szTagName != NULL )
389 tag_handle t_handle = ivug_db_get_tag_handle(szTagName);
392 MSG_IVUG_FATAL("View by Tag. but tag handle is NULL" );
393 ivug_param_delete(data);
397 data->tag_id = ivug_db_get_tag_id(t_handle);
399 ivug_db_destroy_tag(t_handle);
401 MSG_IVUG_HIGH("Tag name=%s", szTagName);
402 MSG_IVUG_HIGH("Tag id=%d", data->tag_id);
403 _ivug_free(&szTagName);
407 MSG_IVUG_FATAL("View by Tag. but Tagname is NULL" );
409 _ivug_free(&szViewBy);
410 ivug_param_delete(data);
414 _ivug_free(&szViewBy);
418 MSG_IVUG_ERROR("View By is NULL");
419 data->view_by = IVUG_VIEW_BY_INVAILD;
422 media_handle file_handle = ivug_db_get_file_handle(data->filepath);
423 if(file_handle == NULL)
425 MSG_IVUG_ERROR("Current File = %s is not in DB", data->filepath);
426 data->view_by = IVUG_VIEW_BY_FILE;
429 //parse image index at album
432 service_get_extra_data (service, IVUG_BUNDLE_KEY_INDEX, &val);
435 data->start_index = ivug_atoi(val);
436 MSG_IVUG_MED("Slide Index = %d", data->start_index);
441 if(data->view_by == IVUG_VIEW_BY_FOLDER)
443 MSG_IVUG_WARN("IVUG_VIEW_BY_FOLDER but index was not set");
444 data->start_index = IVUG_INVALID_INDEX;
448 data->start_index = IVUG_DEFAULT_INDEX;
450 MSG_IVUG_WARN("Slide Index is not set. Set as default : %d", data->start_index);
456 service_get_extra_data (service, IVUG_BUNDLE_KEY_VIEW_MODE, &szMode);
459 data->mode = _get_view_mode(data, szMode);
460 MSG_IVUG_MED("View mode is %s(%d)", szMode, data->mode);
465 data->mode = IVUG_DEFAULT_MODE;
466 MSG_IVUG_HIGH("View mode is NULL. Set Default(%d)", data->mode);
469 //parse album id -album id is cluster id of media service
470 service_get_extra_data (service, IVUG_BUNDLE_KEY_ALBUM_IDX, &val);
471 if(val && data->view_by != IVUG_VIEW_BY_ALL)
473 data->album_id = uuid_getuuid(val);
474 MSG_IVUG_MED("album_uuid is %s", uuid_getchar(data->album_id));
478 data->album_id = INVALID_UUID;
479 MSG_IVUG_WARN("Album index is NULL");
484 if (data->view_by == IVUG_VIEW_BY_FOLDER && data->album_id == INVALID_UUID)
488 **********************************
491 Path:/opt/usr/media/Camera shots/IMAGE0021.jpg
492 **********************************
494 // Get album id from file path.
495 char *dir = ivug_get_directory(data->filepath);
496 media_handle m_handle = ivug_db_get_folder_handle(dir);
499 if(data->album_id == INVALID_UUID)
503 MSG_IVUG_ERROR("View by Folder. but media handle is NULL" );
504 //ivug_param_delete(data);
506 data->view_by = IVUG_VIEW_BY_DIRECTORY; // check manually
510 data->album_id = ivug_db_get_folder_id(m_handle);
512 ivug_db_destroy_folder_handle(m_handle);
514 MSG_IVUG_HIGH("Get Album ID(%s) from file %s", uuid_getchar(data->album_id), data->filepath);
519 service_get_extra_data (service, IVUG_BUNDLE_KEY_MEDIA_TYPE, &val);
522 data->media_type = _get_media_type(val);
523 MSG_IVUG_MED("Media Type=%s(%d)", val, data->media_type);
528 MSG_IVUG_WARN("Media type is not specified.");
534 service_get_extra_data (service, IVUG_BUNDLE_KEY_MAX_LONGITUDE, &val);
537 eina_convert_atod(val, strlen(val), &m, &e);
538 data->max_longitude = ldexp((double)m, e);
539 MSG_IVUG_MED("Max Longitude =%f", data->max_longitude);
544 MSG_IVUG_MED("Max Longitude is not specified.");
547 service_get_extra_data (service, IVUG_BUNDLE_KEY_MIN_LONGITUDE, &val);
550 eina_convert_atod(val, strlen(val), &m, &e);
551 data->min_longitude = ldexp((double)m, e);
552 MSG_IVUG_MED("Min Longitude =%f", data->min_longitude);
557 MSG_IVUG_MED("Min Longitude is not specified.");
560 service_get_extra_data (service, IVUG_BUNDLE_KEY_MAX_LATITUDE, &val);
563 eina_convert_atod(val, strlen(val), &m, &e);
564 data->max_latitude = ldexp((double)m, e);
565 MSG_IVUG_MED("Max Latitude =%f", data->max_latitude);
570 MSG_IVUG_MED("Max Latitude is not specified.");
573 service_get_extra_data (service, IVUG_BUNDLE_KEY_MIN_LATITUDE, &val);
576 eina_convert_atod(val, strlen(val), &m, &e);
577 data->min_latitude = ldexp((double)m, e);
578 MSG_IVUG_MED("Min Latitude =%f", data->min_latitude);
583 MSG_IVUG_MED("Min Latitude is not specified.");
586 service_get_extra_data (service, IVUG_BUNDLE_KEY_SETAS_TYPE, &val);
589 MSG_IVUG_MED("SetAs UG Type=%s", val);
590 data->setas_type = _get_setas_type(val);
592 char* resolution = NULL;
594 service_get_extra_data (service, IVUG_BUNDLE_KEY_RESOLUTION, &resolution);
597 sscanf(resolution, "%5dx%5d", &(data->width), &(data->height));
598 MSG_IVUG_MED("Rectangle width = %d, height = %d", data->width, data->height);
599 if(data->width == 0 || data->height == 0)
601 MSG_IVUG_ERROR("Resolution is invalid");
602 _ivug_free(&resolution);
604 ivug_param_delete(data);
612 MSG_IVUG_HIGH("Rectangle ratio is not set. Set as default : %dx%d", data->width, data->height);
615 data->bRatioFix = false;
616 char* bRatioFix = NULL;
618 service_get_extra_data (service, IVUG_BUNDLE_KEY_FIXED_RATIO, &bRatioFix);
621 MSG_IVUG_MED("Fixed ratio=%s", bRatioFix);
622 if(strcmp(bRatioFix, "TRUE") == 0)
624 data->bRatioFix = true;
626 _ivug_free(&bRatioFix);
631 data->footsteps = false; /* default */
632 service_get_extra_data (service, IVUG_BUNDLE_KEY_FOOTSTEPS, &val);
635 MSG_IVUG_MED("Footsteps=%s", val);
636 if(strcmp(val, "TRUE") == 0)
638 data->footsteps = true;
646 char **index_list = NULL;
648 service_get_extra_data_array(service, IVUG_BUNDLE_KEY_SELECTED_INDEX, &index_list, &index_len);
649 if(index_list != NULL)
652 for(i=0; i<index_len; i++)
654 data->selected_list = eina_list_append(data->selected_list, (void *)ivug_atoi(index_list[i]));
656 for(i=0; i<index_len; i++)
667 ivug_param_delete(ivug_parameter* data)
669 IV_ASSERT(data != NULL);
672 free(data->filepath);
673 data->filepath = NULL;
677 uuid_free(data->album_id);
681 MSG_IVUG_HIGH("Parameter is freed.");
689 Filter_struct *ivug_param_create_filter(const ivug_parameter *param)
691 IV_ASSERT(param != NULL);
693 Filter_struct *filter_str = (Filter_struct *)calloc(1, sizeof(Filter_struct));
694 IV_ASSERT(filter_str != NULL);
696 media_handle handle = NULL;
699 if ( param->view_by == IVUG_VIEW_BY_DIRECTORY )
701 filter_str->type = FILTER_DIRECTORY;
702 filter_str->view_by = param->view_by;
704 Direcotry_Filter *filter = (Direcotry_Filter *)calloc(1, sizeof(Direcotry_Filter) );
706 IV_ASSERT(filter != NULL);
708 filter_str->dir_filter = filter;
709 filter_str->dir_filter->basedir = ivug_get_directory(param->filepath);
710 filter_str->dir_filter->current = strdup( param->filepath );
716 filter_str->type = FILTER_DB;
719 filter_str->view_by = param->view_by;
720 filter_str->media_type = param->media_type;
721 filter_str->sort_type = param->sort_type;
722 filter_str->index = param->start_index;
723 filter_str->selected_list = param->selected_list;
726 filter_str->filepath = strdup(param->filepath);
729 if(filter_str->type == FILTER_DB)
731 DB_Filter *filter = calloc(1, sizeof(DB_Filter));
733 IV_ASSERT(filter != NULL);
735 MSG_SDATA_HIGH("param->view_by is %d", param->view_by);
736 switch(filter_str->view_by)
738 case IVUG_VIEW_BY_PLACES:
739 filter->place.max_longitude = param->max_longitude;
740 filter->place.min_longitude = param->min_longitude;
741 filter->place.max_latitude = param->max_latitude;
742 filter->place.min_latitude = param->min_latitude;
745 case IVUG_VIEW_BY_TAG:
746 filter->tag_id = param->tag_id;
749 case IVUG_VIEW_BY_FAVORITES:
750 filter->album_id = INVALID_UUID;
752 case IVUG_VIEW_BY_FILE:
753 filter->file_path = strdup(param->filepath);
755 case IVUG_VIEW_BY_ALL:
756 filter->album_id = uuid_assign(param->album_id);
758 case IVUG_VIEW_BY_FOLDER:
759 if(param->album_id == NULL)
761 dir = ivug_get_directory(param->filepath);
762 handle = ivug_db_get_folder_handle(dir);
763 filter->album_id = ivug_db_get_folder_id(handle);
768 filter->album_id = uuid_assign(param->album_id);
771 case IVUG_VIEW_BY_DIRECTORY:
773 case IVUG_VIEW_BY_INVAILD:
775 MSG_SDATA_WARN("Invalid ViewBy : %d", param->view_by);
780 filter_str->db_filter = filter;