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