add public result at crop
[apps/core/preloaded/ug-image-viewer-efl.git] / main / src / control / ivug-parameter.c
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
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
7  *
8  *        http://floralicense.org/license/
9  *
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.
15  */
16
17 #include <string.h>
18
19 #include "ivug-common.h"
20 #include "ivug-debug.h"
21 #include "ivug-parameter.h"
22 #include "ivug-file-info.h"
23
24 #include "ivug-db.h"
25 #include "ivug-util.h"
26
27 #include "ivug-filter.h"
28
29 //bundle key
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"
38
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"
43
44 #define IVUG_BUNDLE_KEY_SETAS_TYPE              "Setas type"
45 #define IVUG_BUNDLE_KEY_TAG_NAME                "Tag name"
46
47 #define IVUG_BUNDLE_KEY_RESOLUTION              "Resolution"
48 #define IVUG_BUNDLE_KEY_FIXED_RATIO             "Fixed ratio"
49
50 #define IVUG_BUNDLE_KEY_CROP_MODE               "http://tizen.org/appcontrol/data/image/crop_mode"
51 #define IVUG_BUNDLE_VALUE_CROP_MODE_AUTO                "auto"
52 #define IVUG_BUNDLE_VALUE_CROP_MODE_FIT_TO_SCREEN       "fit_to_screen"
53
54 #define IVUG_BUNDLE_KEY_MEDIA_TYPE              "Media type"
55
56 #define IVUG_BUNDLE_KEY_STANDALONE              "Standalone"
57
58 #define IVUG_BUNDLE_KEY_CONTACT_ID              "Contact id"
59 #define IVUG_BUNDLE_KEY_CLUSTER_ID              "Cluster id"
60 #define IVUG_BUNDLE_KEY_GROUP_ID                "Group id"
61
62 #define IVUG_BUNDLE_KEY_SELECTED_INDEX  "Selected index"
63
64 //default values
65 #define IVUG_DEFAULT_MODE IVUG_MODE_SINGLE
66 #define IVUG_DEFAULT_INDEX (1)                          // First item
67
68 #define IVUG_FILE_PREFIX                "file://"
69
70 static inline
71 void _ivug_free(char **val)
72 {
73         free(*val);
74         *val = NULL;
75 }
76
77 static ivug_mode
78 _get_view_mode(ivug_parameter* data, const char* val)
79 {
80         IV_ASSERT(val != NULL);
81
82 #define IVUG_BUNDLE_VALUE_VIEW_MODE_ALBUM       "ALBUM"
83 #define IVUG_BUNDLE_VALUE_VIEW_MODE_NORMAL      "NORMAL"
84 #define IVUG_BUNDLE_VALUE_VIEW_MODE_SINGLE      "SINGLE"
85 #define IVUG_BUNDLE_VALUE_VIEW_MODE_GALLERY     "GALLERY"
86 #define IVUG_BUNDLE_VALUE_VIEW_MODE_CAMERA      "CAMERA"
87 #define IVUG_BUNDLE_VALUE_VIEW_MODE_DISPLAY     "DISPLAY"
88 #define IVUG_BUNDLE_VALUE_VIEW_MODE_SETAS               "SETAS"
89 #define IVUG_BUNDLE_VALUE_VIEW_MODE_SLIDESHOW   "SLIDESHOW"
90
91         int len = strlen(val);
92
93         if (strncmp(val, IVUG_BUNDLE_VALUE_VIEW_MODE_NORMAL, len) == 0
94                 || strncmp(val, IVUG_BUNDLE_VALUE_VIEW_MODE_GALLERY, len) == 0 )
95         {
96                 return IVUG_MODE_NORMAL;
97         }
98         else if (strncmp(val, IVUG_BUNDLE_VALUE_VIEW_MODE_ALBUM, len) == 0)
99         {
100                 // Probably, UnUsed.
101                 MSG_IVUG_ERROR("ALBUM is deprecated!!!! plz check");
102                 printf("bundle key ALBUM is deprecated!!!! plz check\n");
103                 return IVUG_MODE_NORMAL;
104         }
105         else if ( strncmp(val, IVUG_BUNDLE_VALUE_VIEW_MODE_CAMERA, len) == 0)
106         {
107                 data->start_index = 1;                                          //apply window loading
108                 data->view_by = IVUG_VIEW_BY_FOLDER;            // In camera case, All images should be shown in camera folder.
109                 return IVUG_MODE_CAMERA;
110         }
111         else if (strncmp(val, IVUG_BUNDLE_VALUE_VIEW_MODE_SINGLE, len) == 0)
112         {
113                 if(data->view_by != IVUG_VIEW_BY_FOLDER)
114                         data->view_by = IVUG_VIEW_BY_FILE;
115                 return IVUG_MODE_SINGLE;
116         }
117         else if ( strncmp(val, IVUG_BUNDLE_VALUE_VIEW_MODE_DISPLAY, len) == 0)
118         {
119                 data->view_by = IVUG_VIEW_BY_FILE;
120                 return IVUG_MODE_DISPLAY;
121         }
122         else if(strncmp(val, IVUG_BUNDLE_VALUE_VIEW_MODE_SETAS, len) == 0)
123         {
124                 data->view_by = IVUG_VIEW_BY_FILE;
125                 return IVUG_MODE_SETAS;
126         }
127         else if(strncmp(val, IVUG_BUNDLE_VALUE_VIEW_MODE_SLIDESHOW, len) == 0)
128         {
129                 if(data->view_by == IVUG_VIEW_BY_INVAILD)
130                 {
131                         data->view_by = IVUG_VIEW_BY_FOLDER;
132                 }
133                 return IVUG_MODE_SLIDESHOW;
134         }
135
136         MSG_IVUG_ERROR("Invalid mode : %s", val);
137         return IVUG_MODE_INVAILD;
138 }
139
140
141 static ivug_view_by
142 _get_view_by(const char* val)
143 {
144         //bundle value
145 #define IVUG_BUNDLE_VALUE_VIEW_BY_ALL                   "All"
146 #define IVUG_BUNDLE_VALUE_VIEW_BY_FAVORITES             "Favorites"
147 #define IVUG_BUNDLE_VALUE_VIEW_BY_TAGS                  "Tags"
148 #define IVUG_BUNDLE_VALUE_VIEW_BY_FLODER                "By Folder"
149 #define IVUG_BUNDLE_VALUE_VIEW_BY_PLACES                "Places"
150
151         IV_ASSERT(val != NULL);
152
153         int len = strlen(val);
154
155         if (strncmp(val, IVUG_BUNDLE_VALUE_VIEW_BY_FLODER, len) == 0 )
156         {
157                 return IVUG_VIEW_BY_FOLDER;
158         }
159         else if (strncmp(val, IVUG_BUNDLE_VALUE_VIEW_BY_ALL, len) == 0 )
160         {
161                 return IVUG_VIEW_BY_ALL;
162         }
163         else if (strncmp(val, IVUG_BUNDLE_VALUE_VIEW_BY_FAVORITES, len) == 0)
164         {
165                 return IVUG_VIEW_BY_FAVORITES;
166         }
167         else if (strncmp(val, IVUG_BUNDLE_VALUE_VIEW_BY_TAGS, len) == 0)
168         {
169                 return IVUG_VIEW_BY_TAG;
170         }
171         else if (strncmp(val, IVUG_BUNDLE_VALUE_VIEW_BY_PLACES, len) == 0)
172         {
173                 return IVUG_VIEW_BY_PLACES;
174         }
175
176         MSG_IVUG_ERROR("Invalid view by : %s", val);
177
178         return IVUG_VIEW_BY_FILE;
179
180 }
181
182
183 static ivug_setas_type
184 _get_setas_type(const char* val)
185 {
186         IV_ASSERT(val != NULL);
187
188 #define IVUG_BUNDLE_VALUE_SETAS_UG_WALLPAPER    "Wallpaper"
189 #define IVUG_BUNDLE_VALUE_SETAS_UG_LOCKSCREEN   "Lockscreen"
190 #define IVUG_BUNDLE_VALUE_SETAS_UG_WALLPAPER_N_LOCKSCREEN       "Wallpaper & Lockscreen"
191 #define IVUG_BUNDLE_VALUE_SETAS_UG_CALLERID             "CallerID"
192 #define IVUG_BUNDLE_VALUE_SETAS_UG_VIDEO_CALLEID        "VideoCallID"
193 #define IVUG_BUNDLE_VALUE_SETAS_UG_CROP                 "Crop"
194 #define IVUG_BUNDLE_VALUE_SETAS_UG_WALLPAPER_CROP       "Wallpaper Crop"
195
196         int len = strlen(val);
197
198         if (strncmp(val, IVUG_BUNDLE_VALUE_SETAS_UG_WALLPAPER, len) == 0 )
199         {
200                 return IVUG_SET_AS_UG_TYPE_WALLPAPER;
201         }
202         else if (strncmp(val, IVUG_BUNDLE_VALUE_SETAS_UG_WALLPAPER_CROP, len) == 0 )
203         {
204                 return IVUG_SET_AS_UG_TYPE_WALLPAPER_CROP;
205         }
206         else if (strncmp(val, IVUG_BUNDLE_VALUE_SETAS_UG_LOCKSCREEN, len) == 0 )
207         {
208                 return IVUG_SET_AS_UG_TYPE_LOCKSCREEN;
209         }
210         else if (strncmp(val, IVUG_BUNDLE_VALUE_SETAS_UG_WALLPAPER_N_LOCKSCREEN, len) == 0 )
211         {
212                 return IVUG_SET_AS_UG_TYPE_WALLPAPER_N_LOCKSCREEN;
213         }
214         else if (strncmp(val, IVUG_BUNDLE_VALUE_SETAS_UG_CALLERID, len) == 0)
215         {
216                 return IVUG_SET_AS_UG_TYPE_CALLER_ID;
217         }
218         else if (strncmp(val, IVUG_BUNDLE_VALUE_SETAS_UG_VIDEO_CALLEID, len) == 0)
219         {
220                 return IVUG_SET_AS_UG_TYPE_VIDEO_CALL_ID;
221         }
222         else if (strncmp(val, IVUG_BUNDLE_VALUE_SETAS_UG_CROP, len) == 0)
223         {
224                 return IVUG_SET_AS_UG_TYPE_CROP;
225         }
226
227         MSG_IVUG_ERROR("Invalid setas ug type : %s", val);
228         return IVUG_SET_AS_UG_TYPE_INVALID;
229 }
230
231 static ivug_media_type
232 _get_media_type(const char* val)
233 {
234         IV_ASSERT(val != NULL);
235 #define IVUG_BUNDLE_VALUE_MEDIA_TYPE_ALL        "All"
236 #define IVUG_BUNDLE_VALUE_MEDIA_TYPE_IMAGE      "Image"
237 #define IVUG_BUNDLE_VALUE_MEDIA_TYPE_VIDEO      "Video"
238
239         int len = strlen(val);
240
241         if (strncmp(val, IVUG_BUNDLE_VALUE_MEDIA_TYPE_IMAGE, len) == 0 )
242         {
243                 return IVUG_MEDIA_TYPE_IMAGE;
244         }
245         else if (strncmp(val, IVUG_BUNDLE_VALUE_MEDIA_TYPE_VIDEO, len) == 0)
246         {
247                 return IVUG_MEDIA_TYPE_VIDEO;
248         }
249         else if(strncmp(val, IVUG_BUNDLE_VALUE_MEDIA_TYPE_ALL, len) == 0)
250         {
251                 return IVUG_MEDIA_TYPE_ALL;
252         }
253
254         MSG_IVUG_ERROR("Invalid media type : %s", val);
255         return IVUG_MEDIA_TYPE_MAX;
256 }
257
258 static bool _data_print(service_h service, const char *key, void *user_data)
259 {
260         char *value;
261
262         char **value_array;
263         int array_len = 1;
264         int i;
265         bool array = false;
266
267         service_is_extra_data_array(service, key, &array);
268         if(array == false)
269         {
270                 service_get_extra_data(service, key, &value);
271                 MSG_IVUG_HIGH("  %s : %s", key, value);
272                 free(value);
273         }
274         else
275         {
276                 service_get_extra_data_array(service, key, &value_array, &array_len);
277                 MSG_IVUG_HIGH("  %s :", key);
278                 for(i=0; i<array_len; i++)
279                 {
280                         MSG_IVUG_HIGH(" %s", value_array[i]);
281                 }
282                 for(i=0; i<array_len; i++)
283                 {
284                         free(value_array[i]);
285                 }
286                 free(value_array);
287         }
288
289         return true;
290 }
291
292 static void _print_service_data(service_h service)
293 {
294         int ret = service_foreach_extra_data(service, _data_print, NULL);
295
296         if(SERVICE_ERROR_NONE != ret)
297         {
298                 MSG_IVUG_ERROR("service_foreach_extra_data ERROR");
299         }
300 }
301
302
303
304 //parsing bundle
305 ivug_parameter*
306 ivug_param_create_from_bundle(service_h service)
307 {
308         if (service == NULL)
309         {
310                 MSG_IVUG_WARN("bundle value is NULL");
311                 return NULL;
312         }
313
314         //print key and value.
315         MSG_IVUG_HIGH("**********************************");
316         _print_service_data(service);
317         MSG_IVUG_HIGH("**********************************");
318
319         //parsing param
320         ivug_parameter* data = (ivug_parameter*)calloc(1, sizeof(ivug_parameter));
321
322         if (data == NULL)
323         {
324                 MSG_IMAGEVIEW_FATAL("Cannot allocate memory");
325                 return NULL;
326         }
327
328 // appsvc
329         char* standalone = NULL;
330
331         service_get_extra_data (service, IVUG_BUNDLE_KEY_STANDALONE, &standalone);
332         if (standalone != NULL)
333         {
334                 data->bStandalone = true;
335                 _ivug_free(&standalone);
336         }
337         else
338         {
339                 data->bStandalone = false;
340         }
341
342         //parse path
343         char* szFilePath = NULL;
344         {
345                 service_get_extra_data (service, IVUG_BUNDLE_KEY_PATH, &szFilePath);
346                 if(szFilePath == NULL)
347                 {
348                         MSG_IVUG_ERROR("File path is NULL");
349                         service_get_uri(service, &szFilePath);  // app gadget
350                         if(szFilePath)
351                         {
352                                 MSG_IMAGEVIEW_ERROR("App gadget launched %s", szFilePath);
353                                 service_add_extra_data (service, "View Mode", "SINGLE");
354                         }
355                 }
356                 if ( szFilePath != NULL )
357                 {
358                         if(strncmp(IVUG_FILE_PREFIX, szFilePath, strlen(IVUG_FILE_PREFIX)) == 0)
359                         {
360                                 data->filepath = strdup(szFilePath + strlen(IVUG_FILE_PREFIX));
361                         }
362                         else
363                         {
364                                 data->filepath = strdup(szFilePath);
365                         }
366                         MSG_IVUG_MED("Current File = %s", data->filepath);
367                         _ivug_free(&szFilePath);
368                 }
369                 else
370                 {
371                         ivug_param_delete(data);
372                         return NULL;
373                 }
374         }
375
376 // View By
377         char* szViewBy = NULL;
378
379         service_get_extra_data (service, IVUG_BUNDLE_KEY_VIEW_BY, &szViewBy);
380         if (szViewBy != NULL)
381         {
382                 MSG_IVUG_MED("View By = %s", szViewBy);
383
384                 data->view_by = _get_view_by(szViewBy);
385
386                 if (data->view_by == IVUG_VIEW_BY_TAG)
387                 {
388                         char* szTagName = NULL;
389
390                         service_get_extra_data (service, IVUG_BUNDLE_KEY_TAG_NAME, &szTagName);
391                         if ( szTagName != NULL )
392                         {
393                                 tag_handle t_handle = ivug_db_get_tag_handle(szTagName);
394                                 if(t_handle == NULL)
395                                 {
396                                         MSG_IVUG_FATAL("View by Tag. but tag handle is NULL" );
397                                         ivug_param_delete(data);
398                                         return NULL;
399                                 }
400
401                                 data->tag_id = ivug_db_get_tag_id(t_handle);
402
403                                 ivug_db_destroy_tag(t_handle);
404
405                                 MSG_IVUG_HIGH("Tag name=%s", szTagName);
406                                 MSG_IVUG_HIGH("Tag id=%d", data->tag_id);
407                                 _ivug_free(&szTagName);
408                         }
409                         else
410                         {
411                                 MSG_IVUG_FATAL("View by Tag. but Tagname is NULL" );
412
413                                 _ivug_free(&szViewBy);
414                                 ivug_param_delete(data);
415                                 return NULL;
416                         }
417                 }
418                 _ivug_free(&szViewBy);
419         }
420         else
421         {
422                 MSG_IVUG_ERROR("View By is NULL");
423                 data->view_by = IVUG_VIEW_BY_INVAILD;
424         }
425
426         media_handle file_handle = ivug_db_get_file_handle(data->filepath);
427         if(file_handle == NULL)
428         {
429                 MSG_IVUG_ERROR("Current File = %s is not in DB", data->filepath);
430                 data->view_by = IVUG_VIEW_BY_FILE;
431         }
432
433 //parse image index at album
434         char* val = NULL;
435
436         service_get_extra_data (service, IVUG_BUNDLE_KEY_INDEX, &val);
437         if(val)
438         {
439                 data->start_index = ivug_atoi(val);
440                 MSG_IVUG_MED("Slide Index = %d", data->start_index);
441                 _ivug_free(&val);
442         }
443         else
444         {
445                 if(data->view_by == IVUG_VIEW_BY_FOLDER)
446                 {
447                         MSG_IVUG_WARN("IVUG_VIEW_BY_FOLDER but index was not set");
448                         data->start_index = IVUG_INVALID_INDEX;
449                 }
450                 else
451                 {
452                 data->start_index = IVUG_DEFAULT_INDEX;
453                 }
454                 MSG_IVUG_WARN("Slide Index is not set. Set as default : %d", data->start_index);
455         }
456
457 //parse mode
458         char* szMode = NULL;
459
460         service_get_extra_data (service, IVUG_BUNDLE_KEY_VIEW_MODE, &szMode);
461         if (szMode != NULL)
462         {
463                 data->mode = _get_view_mode(data, szMode);
464                 MSG_IVUG_MED("View mode is %s(%d)", szMode, data->mode);
465                 _ivug_free(&szMode);
466         }
467         else
468         {
469                 data->mode = IVUG_DEFAULT_MODE;
470                 MSG_IVUG_HIGH("View mode is NULL. Set Default(%d)", data->mode);
471         }
472
473         //parse album id -album id is cluster id of media service
474         service_get_extra_data (service, IVUG_BUNDLE_KEY_ALBUM_IDX, &val);
475         if(val && data->view_by != IVUG_VIEW_BY_ALL)
476         {
477                 data->album_id = uuid_getuuid(val);
478                 MSG_IVUG_MED("album_uuid is %s", uuid_getchar(data->album_id));
479         }
480         else
481         {
482                 data->album_id = INVALID_UUID;
483                 MSG_IVUG_WARN("Album index is NULL");
484         }
485         if(val)
486                 _ivug_free(&val);
487
488         if (data->view_by == IVUG_VIEW_BY_FOLDER && data->album_id == INVALID_UUID)
489         {
490 /*
491                 example:
492                 **********************************
493                   Bundle Count = 2
494                    View Mode:CAMERA
495                    Path:/opt/usr/media/Camera shots/IMAGE0021.jpg
496                 **********************************
497 */
498                 // Get album id from file path.
499                 char *dir = ivug_get_directory(data->filepath);
500                 media_handle m_handle = ivug_db_get_folder_handle(dir);
501                 free(dir);
502
503                 if(data->album_id == INVALID_UUID)
504                 {
505                         if(m_handle == NULL)
506                         {
507                                 MSG_IVUG_ERROR("View by Folder. but media handle is NULL" );
508                                 //ivug_param_delete(data);
509                                 //return NULL;
510                                 data->view_by = IVUG_VIEW_BY_DIRECTORY; // check manually
511                         }
512                         else
513                         {
514                                 data->album_id = ivug_db_get_folder_id(m_handle);
515
516                                 ivug_db_destroy_folder_handle(m_handle);
517
518                                 MSG_IVUG_HIGH("Get Album ID(%s) from file %s", uuid_getchar(data->album_id), data->filepath);
519                         }
520                 }
521         }
522
523         service_get_extra_data (service, IVUG_BUNDLE_KEY_MEDIA_TYPE, &val);
524         if(val != NULL)
525         {
526                 data->media_type = _get_media_type(val);
527                 MSG_IVUG_MED("Media Type=%s(%d)", val, data->media_type);
528                 _ivug_free(&val);
529         }
530         else
531         {
532                 MSG_IVUG_WARN("Media type is not specified.");
533         }
534
535         long long int m = 0;
536         long int e = 0;
537
538         service_get_extra_data (service, IVUG_BUNDLE_KEY_MAX_LONGITUDE, &val);
539         if(val != NULL)
540         {
541                 eina_convert_atod(val, strlen(val), &m, &e);
542                 data->max_longitude = ldexp((double)m, e);
543                 MSG_IVUG_MED("Max Longitude =%f", data->max_longitude);
544                 _ivug_free(&val);
545         }
546         else
547         {
548                 MSG_IVUG_MED("Max Longitude is not specified.");
549         }
550
551         service_get_extra_data (service, IVUG_BUNDLE_KEY_MIN_LONGITUDE, &val);
552         if(val != NULL)
553         {
554                 eina_convert_atod(val, strlen(val), &m, &e);
555                 data->min_longitude = ldexp((double)m, e);
556                 MSG_IVUG_MED("Min Longitude =%f", data->min_longitude);
557                 _ivug_free(&val);
558         }
559         else
560         {
561                 MSG_IVUG_MED("Min Longitude is not specified.");
562         }
563
564         service_get_extra_data (service, IVUG_BUNDLE_KEY_MAX_LATITUDE, &val);
565         if(val != NULL)
566         {
567                 eina_convert_atod(val, strlen(val), &m, &e);
568                 data->max_latitude = ldexp((double)m, e);
569                 MSG_IVUG_MED("Max Latitude =%f", data->max_latitude);
570                 _ivug_free(&val);
571         }
572         else
573         {
574                 MSG_IVUG_MED("Max Latitude is not specified.");
575         }
576
577         service_get_extra_data (service, IVUG_BUNDLE_KEY_MIN_LATITUDE, &val);
578         if(val != NULL)
579         {
580                 eina_convert_atod(val, strlen(val), &m, &e);
581                 data->min_latitude = ldexp((double)m, e);
582                 MSG_IVUG_MED("Min Latitude =%f", data->min_latitude);
583                 _ivug_free(&val);
584         }
585         else
586         {
587                 MSG_IVUG_MED("Min Latitude is not specified.");
588         }
589
590         service_get_extra_data (service, IVUG_BUNDLE_KEY_SETAS_TYPE, &val);
591         if (val)
592         {
593                 MSG_IVUG_MED("SetAs UG Type=%s", val);
594                 data->setas_type = _get_setas_type(val);
595
596                 char* resolution = NULL;
597
598                 service_get_extra_data (service, IVUG_BUNDLE_KEY_RESOLUTION, &resolution);
599                 if(resolution)
600                 {
601                         sscanf(resolution, "%5dx%5d", &(data->width), &(data->height));
602                         MSG_IVUG_MED("Rectangle width = %d, height = %d", data->width, data->height);
603                         if(data->width == 0 || data->height == 0)
604                         {
605                                 MSG_IVUG_ERROR("Resolution is invalid");
606                                 _ivug_free(&resolution);
607                                 _ivug_free(&val);
608                                 ivug_param_delete(data);
609                                 return NULL;
610                         }
611                 }
612                 else
613                 {
614                         data->width = 100;
615                         data->height = 100;
616                         MSG_IVUG_HIGH("Rectangle ratio is not set. Set as default : %dx%d", data->width, data->height);
617                 }
618
619                 data->bRatioFix = false;
620                 char* bRatioFix = NULL;
621
622                 service_get_extra_data (service, IVUG_BUNDLE_KEY_FIXED_RATIO, &bRatioFix);
623                 if(bRatioFix)
624                 {
625                         MSG_IVUG_MED("Fixed ratio=%s", bRatioFix);
626                         if(strcmp(bRatioFix, "TRUE") == 0)
627                         {
628                                 data->bRatioFix = true;
629                         }
630                         _ivug_free(&bRatioFix);
631                 }
632
633                 char* crop_mode = NULL;
634                 service_get_extra_data (service, IVUG_BUNDLE_KEY_CROP_MODE, &crop_mode);
635                 if(crop_mode)
636                 {
637                         MSG_IVUG_MED("Crop mode=%s", crop_mode);
638                         if(strcmp(crop_mode, IVUG_BUNDLE_VALUE_CROP_MODE_FIT_TO_SCREEN) == 0)
639                         {
640                                 int lcd_x = 0;
641                                 int lcd_y = 0;
642                                 int lcd_w = 0;
643                                 int lcd_h = 0;
644                                 int rot = 0;
645                                 evas_object_geometry_get((Evas_Object *)ug_get_window(), &lcd_x, &lcd_y, &lcd_w, &lcd_h);
646                                 rot = gGetRotationDegree();
647                                 if(rot == 90 || rot == 270)
648                                 {
649                                         int temp = lcd_w;
650                                         lcd_w = lcd_h;
651                                         lcd_h = temp;
652                                 }
653                                 data->width = lcd_w;
654                                 data->height = lcd_h;
655                                 data->bRatioFix = true;
656                         }
657                         _ivug_free(&crop_mode);
658                 }
659
660                 _ivug_free(&val);
661         }
662
663         data->footsteps = false;        /* default */
664         service_get_extra_data (service, IVUG_BUNDLE_KEY_FOOTSTEPS, &val);
665         if (val)
666         {
667                 MSG_IVUG_MED("Footsteps=%s", val);
668                 if(strcmp(val, "TRUE") == 0)
669                 {
670                         data->footsteps = true;
671                 }
672                 _ivug_free(&val);
673         }
674
675
676
677
678         char **index_list = NULL;
679         int index_len = 0;
680         service_get_extra_data_array(service, IVUG_BUNDLE_KEY_SELECTED_INDEX, &index_list, &index_len);
681         if(index_list != NULL)
682         {
683                 int i;
684                 for(i=0; i<index_len; i++)
685                 {
686                         data->selected_list = eina_list_append(data->selected_list, (void *)ivug_atoi(index_list[i]));
687                 }
688                 for(i=0; i<index_len; i++)
689                 {
690                         free(index_list[i]);
691                 }
692                 free(index_list);
693         }
694
695         return data;
696 }
697
698 void
699 ivug_param_delete(ivug_parameter* data)
700 {
701         IV_ASSERT(data != NULL);
702         if (data->filepath)
703         {
704                 free(data->filepath);
705                 data->filepath = NULL;
706         }
707
708
709         uuid_free(data->album_id);
710
711         free(data);
712
713         MSG_IVUG_HIGH("Parameter is freed.");
714
715 }
716
717
718
719
720
721 Filter_struct *ivug_param_create_filter(const ivug_parameter *param)
722 {
723         IV_ASSERT(param != NULL);
724
725         Filter_struct *filter_str = (Filter_struct *)calloc(1, sizeof(Filter_struct));
726         IV_ASSERT(filter_str != NULL);
727
728         media_handle handle = NULL;
729         char *dir = NULL;
730
731         if ( param->view_by == IVUG_VIEW_BY_DIRECTORY )
732         {
733                 filter_str->type = FILTER_DIRECTORY;
734                 filter_str->view_by = param->view_by;
735
736                 Direcotry_Filter *filter = (Direcotry_Filter *)calloc(1, sizeof(Direcotry_Filter) );
737
738                 IV_ASSERT(filter != NULL);
739
740                 filter_str->dir_filter = filter;
741                 filter_str->dir_filter->basedir = ivug_get_directory(param->filepath);
742                 filter_str->dir_filter->current = strdup( param->filepath );
743
744                 return filter_str;
745         }
746         else
747         {
748                 filter_str->type = FILTER_DB;
749         }
750
751         filter_str->view_by = param->view_by;
752         filter_str->media_type = param->media_type;
753         filter_str->sort_type = param->sort_type;
754         filter_str->index = param->start_index;
755         filter_str->selected_list = param->selected_list;
756         if(param->filepath)
757         {
758                 filter_str->filepath = strdup(param->filepath);
759         }
760
761         if(filter_str->type == FILTER_DB)
762         {
763                 DB_Filter *filter = calloc(1, sizeof(DB_Filter));
764
765                 IV_ASSERT(filter != NULL);
766
767                 MSG_SDATA_HIGH("param->view_by is %d", param->view_by);
768                 switch(filter_str->view_by)
769                 {
770                 case IVUG_VIEW_BY_PLACES:
771                         filter->place.max_longitude = param->max_longitude;
772                         filter->place.min_longitude = param->min_longitude;
773                         filter->place.max_latitude = param->max_latitude;
774                         filter->place.min_latitude = param->min_latitude;
775                         break;
776
777                 case IVUG_VIEW_BY_TAG:
778                         filter->tag_id = param->tag_id;
779                         break;
780
781                 case IVUG_VIEW_BY_FAVORITES:
782                         filter->album_id = INVALID_UUID;
783                         break;
784                 case IVUG_VIEW_BY_FILE:
785                         filter->file_path = strdup(param->filepath);
786                         break;
787                 case IVUG_VIEW_BY_ALL:
788                         filter->album_id = uuid_assign(param->album_id);
789                         break;
790                 case IVUG_VIEW_BY_FOLDER:
791                         if(param->album_id == NULL)
792                         {
793                                 dir = ivug_get_directory(param->filepath);
794                                 handle = ivug_db_get_folder_handle(dir);
795                                 filter->album_id = ivug_db_get_folder_id(handle);
796                                 free(dir);
797                         }
798                         else
799                         {
800                                 filter->album_id = uuid_assign(param->album_id);
801                         }
802                         break;
803                 case IVUG_VIEW_BY_DIRECTORY:
804                         break;
805                 case IVUG_VIEW_BY_INVAILD:
806                 default:
807                         MSG_SDATA_WARN("Invalid ViewBy : %d", param->view_by);
808                         break;
809
810                 }
811
812                 filter_str->db_filter = filter;
813         }
814
815         return filter_str;
816
817 }
818
819