apply FSL(Flora Software License)
[apps/home/gallery.git] / libug / libug-gallery-efl / src / ge-gridview.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://www.tizenopensource.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 "ge-debug.h"
18 #include "ge-gridview.h"
19 #include "ge-ui-util.h"
20 #include "ge-util.h"
21 #include "ge-ext-ug-load.h"
22 #include "ge-db-handler.h"
23 #include "ge-strings.h"
24
25 /* Icon swallowed to part "elm.swallow.icon" */
26 #define GE_GRID_ICON_SIZE 156
27 #define GE_ITEM_MOUSE_UP_DISTANCE_X 20
28 #define GE_ITEM_MOUSE_UP_DISTANCE_Y 20
29 #define GE_GIRD_ICON_CLICK_TIME_DELAY 0.01f
30
31 static Elm_Gengrid_Item_Class gic;
32 static int ge_grid_item_cnt = 0;
33
34 typedef struct
35 {
36         Evas_Coord x;
37         Evas_Coord y;
38         bool b_pressed;
39 }ge_grid_touch_info;
40
41 static ge_grid_touch_info ge_touch_info;
42
43 static void _ge_grid_drag_up(void *data, Evas_Object *obj, void *event_info)
44 {
45         ge_dbg("");
46 }
47
48 static void _ge_grid_drag_right(void *data, Evas_Object *obj, void *event_info)
49 {
50         ge_dbg("");
51 }
52
53 static void _ge_grid_drag_down(void *data, Evas_Object *obj, void *event_info)
54 {
55         ge_dbg("");
56 }
57
58 static void _ge_grid_drag_left(void *data, Evas_Object *obj, void *event_info)
59 {
60         ge_dbg("");
61 }
62
63 static void _ge_grid_drag_stop(void *data, Evas_Object *obj, void *event_info)
64 {
65         ge_dbg("");
66 }
67
68 static void _ge_grid_selected(void *data, Evas_Object *obj, void *event_info)
69 {
70         ge_dbg("");
71 }
72
73 static void _ge_grid_unselected(void *data, Evas_Object *obj, void *event_info)
74 {
75         ge_dbg("");
76 }
77
78 static void _ge_grid_clicked(void *data, Evas_Object *obj, void *event_info)
79 {
80         ge_dbg("");
81 }
82
83 static void _ge_grid_longpress(void *data, Evas_Object *obj, void *event_info)
84 {
85         ge_dbg("");
86 }
87
88 static void _ge_grid_sel(void *data, Evas_Object *obj, void *event_info)
89 {
90         ge_dbg("");
91         GE_CHECK(data);
92         if(_ge_get_view_mode() != GE_ThumbnailView_Mode)
93         {
94                 //ge_dbgE("EditMode.. now return.");
95                 return;
96         }
97         else
98         {
99                 ge_dbg("ViewMode");
100         }
101
102         ge_item* gitem = (ge_item*)data;
103         GE_CHECK(gitem->item);
104         GE_CHECK(gitem->ugd);
105         ge_ugdata* ugd = gitem->ugd;
106
107         if(gitem->item->file_url == NULL || strlen(gitem->item->file_url) <= 0)
108         {
109                 ge_dbgE("file_url is invalid!");
110                 return;
111         }
112         else
113         {
114                 ge_dbg("file_url: %s.", gitem->item->file_url);
115         }
116
117         if(ugd->file_select_mode == GE_File_Select_Setas)//imageviewer only supprot image type while setting wallpaper
118         {
119                 if(gitem->item->type == MINFO_ITEM_IMAGE)
120                 {
121                         _ge_set_current_item(gitem);
122                         ge_dbg("Loading UG-IMAGE(VIDEO)-VIEWER");
123                         ge_ext_load_iv_ug(ugd);
124                 }
125                 else if(gitem->item->type == MINFO_ITEM_VIDEO && ugd->popup == NULL)
126                 {
127                         ge_ui_create_popup(ugd, GE_Popup_OneButton, GE_POPUP_ONLY_SUPPORT_IMAGE);
128                 }
129
130         }
131         else if(gitem->item->type == MINFO_ITEM_IMAGE || gitem->item->type == MINFO_ITEM_VIDEO)
132         {
133                 _ge_set_current_item(gitem);
134                 ge_dbg("Loading UG-IMAGE(VIDEO)-VIEWER");
135                 ge_ext_load_iv_ug(ugd);
136         }
137 }
138
139 static void _ge_grid_icon_clicked(void *data, Evas_Object *obj, void *event_info)
140 {
141         ge_dbg("");
142         GE_CHECK(data);
143         _ge_grid_sel(data, obj, event_info);
144 }
145
146 static void _ge_grid_item_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info)
147 {
148         Evas_Event_Mouse_Down *ev = (Evas_Event_Mouse_Down*)event_info;
149         if(ev)
150         {
151                 GE_CHECK(data);
152                 GE_CHECK(obj);
153                 ge_item *gitem = (ge_item *)data;
154                 GE_CHECK(gitem->ugd);
155                 ge_ugdata *ugd = gitem->ugd;
156
157                 ge_touch_info.x = ev->output.x;
158                 ge_touch_info.y = ev->output.y;
159
160                 if(ugd->ug_called_by_me == NULL)
161                 {
162                         edje_object_signal_emit(_EDJ(obj), "mouse,down,shrink", "bg");
163                         ge_touch_info.b_pressed = true;
164                 }
165         }
166 }
167
168 static void     _ge_grid_shrink_resp_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
169 {
170         ge_dbg("");
171         GE_CHECK(obj);
172         GE_CHECK(data);
173         ge_item *gitem = (ge_item *)data;
174         GE_CHECK(gitem->ugd);
175         _ge_grid_icon_clicked(data, obj, NULL);
176
177         edje_object_signal_callback_del(obj, "shrink,expand,done", "bg", _ge_grid_shrink_resp_cb);
178 }
179
180 static void _ge_grid_item_mouse_up(void *data, Evas *e, Evas_Object *obj, void *event_info)
181 {
182         GE_CHECK(obj);
183         Evas_Event_Mouse_Up *ev = event_info;
184
185         if(!ev)
186         {
187                 goto RET_WO_EXEC;
188         }
189
190         if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD || ev->event_flags & EVAS_EVENT_FLAG_ON_SCROLL)
191         {
192                 goto RET_WO_EXEC;
193         }
194         if((abs(ge_touch_info.x - ev->output.x) > GE_ITEM_MOUSE_UP_DISTANCE_X) || (abs(ge_touch_info.y - ev->output.y) > GE_ITEM_MOUSE_UP_DISTANCE_Y))
195         {
196                 goto RET_WO_EXEC;
197         }
198
199         ge_dbg("");
200
201         if(ge_touch_info.b_pressed)
202         {
203                 edje_object_signal_emit(_EDJ(obj), "mouse,up,expand", "bg");
204                 edje_object_signal_callback_add(_EDJ(obj), "shrink,expand,done", "bg", _ge_grid_shrink_resp_cb, data);
205                 ge_touch_info.b_pressed = false;
206         }
207         return;
208
209 RET_WO_EXEC:
210         if(ge_touch_info.b_pressed)
211         {
212                 edje_object_signal_emit(_EDJ(obj), "mouse,up,expand", "bg");
213                 ge_touch_info.b_pressed = false;
214         }
215 }
216
217 static void _ge_grid_check_changed(void *data, Evas_Object *obj, void *event_info)
218 {
219         ge_dbg("");
220         GE_CHECK(obj);
221         GE_CHECK(data);
222         ge_item *gitem = (ge_item *)data;
223         GE_CHECK(gitem->item);
224         GE_CHECK(gitem->item->file_url);
225         GE_CHECK(gitem->ugd);
226         ge_ugdata *ugd = gitem->ugd;
227
228         if(_ge_get_view_mode() != GE_ThumbnailEdit_Mode)
229                 return;
230
231         Eina_Bool checked = elm_check_state_get(obj);
232         if(checked)
233         {
234                 if(ugd->file_select_mode == GE_File_Select_One) // add for one file selection
235                 {
236                         ge_dbg("Bundle add:%s", gitem->item->file_url);
237                         /* Hide checked state in one file selection */
238                         elm_check_state_set(obj, false);
239
240                         bundle_del(ugd->bundle, GE_FILE_SELECT_RETURN_PATH);
241                         bundle_add(ugd->bundle, GE_FILE_SELECT_RETURN_PATH, gitem->item->file_url);
242                         ug_send_result(ugd->ug, ugd->bundle);
243                         ug_destroy_me(ugd->ug);
244                 }
245                 else
246                 {
247                         ge_dbg("Append:%s", gitem->item->file_url);
248                         ge_db_selected_list_append( gitem );
249                 }
250         }
251         else if(ugd->file_select_mode != GE_File_Select_One)
252         {
253                 ge_dbg("Remove:%s", gitem->item->file_url);
254                 ge_db_selected_list_remove( gitem );
255         }
256
257         if(ugd->file_select_mode != GE_File_Select_One)
258         {
259                 gitem->checked = checked;
260                 ge_ui_create_selinfo(ugd, ugd->thumbs_view_ly);
261         }
262 }
263
264 Evas_Object *_ge_grid_get_content(void *data, Evas_Object *obj, const char *part)
265 {
266         GE_CHECK_NULL(data);
267         GE_CHECK_NULL(part);
268         GE_CHECK_NULL(obj);
269         ge_item *gitem = NULL;
270
271         if(strlen(part) <= 0)
272         {
273                 ge_dbgE("part length <= 0");
274                 return NULL;
275         }
276
277         gitem = (ge_item*)data;
278         GE_CHECK_NULL(gitem->item);
279         GE_CHECK_NULL(gitem->ugd);
280         ge_ugdata *ugd = gitem->ugd;
281
282         if (!strcmp(part, "elm.swallow.icon"))
283         {
284                 Evas_Object *layout = elm_layout_add(obj);
285                 GE_CHECK_NULL(layout);
286                 Evas_Object *bg = elm_bg_add(obj);
287                 GE_CHECK_NULL(bg);
288                 elm_bg_load_size_set(bg, ugd->icon_size, ugd->icon_size);
289
290                 elm_bg_file_set(bg, _GETICON(gitem->item->thumb_url), NULL);
291                 evas_object_size_hint_max_set(bg, ugd->icon_size,
292                                               ugd->icon_size);
293                 evas_object_size_hint_aspect_set(bg, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
294                 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
295                 evas_object_size_hint_align_set(bg, EVAS_HINT_FILL, EVAS_HINT_FILL);
296
297                 if(gitem->item->type == MINFO_ITEM_VIDEO)
298                 {
299                         int bk_len = 0;
300
301                         if(ugd->th)
302                         {
303                                 elm_object_theme_set(layout, ugd->th);
304                         }
305                         elm_layout_theme_set(layout, "gengrid", "photoframe", "default_layout_video");
306                         elm_object_part_content_set(layout, "elm.swallow.icon", bg);
307
308                         // Set bookmark icon.
309                         if(gitem->item->meta_info == NULL || gitem->item->meta_info->video_info == NULL)
310                         {
311                                 bk_len = 0;
312                         }
313                         else
314                         {
315                                 bk_len = g_list_length(gitem->item->meta_info->video_info->bookmarks);
316                         }
317
318                         if(bk_len)
319                         {
320                                 elm_layout_theme_set(layout, "gengrid", "photoframe", "default_layout_video_bookmark");
321                         }
322                         else
323                         {
324                                 elm_layout_theme_set(layout, "gengrid", "photoframe", "default_layout_video");
325                         }
326                         elm_object_part_content_set(layout, "elm.swallow.icon", bg);
327
328                         /* Set bookmark icon */
329                         if(bk_len)
330                         {
331                                 Evas_Object *icon = elm_icon_add(obj);
332                                 GE_CHECK_NULL(icon);
333                                 elm_icon_file_set(icon, GE_THUMB_BOOKMARK, NULL);
334                                 evas_object_show(icon);
335                                 elm_object_part_content_set(layout, "elm.swallow.bookmarkicon", icon);
336                         }
337
338                         /* Running time of the video */
339                         if(gitem->item->meta_info && gitem->item->meta_info->video_info)
340                         {
341                                 char ret_str[GE_VIDEO_DURATION_MAX]={0,};
342                                 /* Convert time unit form millisecond to second */
343                                 int duration = floor((gitem->item->meta_info->video_info->duration) / GE_TIME_SECOND_MILLISECOND);
344                                 int dur_hr = 0;
345                                 int dur_min = 0;
346                                 int dur_sec = 0;
347                                 int tmp = 0;
348
349                                 if(duration >= GE_TIME_HOUR_SECOND)
350                                 {
351                                         /* It's equal or greater than 1 hour */
352                                         dur_sec = duration % GE_TIME_MINUTE_SECOND;
353                                         tmp = floor(duration / GE_TIME_MINUTE_SECOND);
354                                         dur_min = tmp % GE_TIME_HOUR_MINUTE;
355                                         dur_hr = floor(tmp / GE_TIME_HOUR_MINUTE);
356                                 }
357                                 else if(duration >= GE_TIME_MINUTE_SECOND)
358                                 {
359                                         /* It's equal or greater than 1 minute */
360                                         dur_hr = 0;
361                                         dur_min = floor(duration / GE_TIME_MINUTE_SECOND);
362                                         dur_sec = duration % GE_TIME_MINUTE_SECOND;
363                                 }
364                                 else
365                                 {
366                                         dur_hr = 0;
367                                         dur_min = 0;
368                                         dur_sec = duration % GE_TIME_MINUTE_SECOND;
369                                 }
370
371                                 snprintf(ret_str, sizeof(ret_str), "%02d:%02d:%02d", dur_hr, dur_min, dur_sec);
372                                 ret_str[strlen(ret_str)] = '\0';
373                                 elm_object_part_text_set(layout, "elm.text", ret_str);
374                         }
375                 }
376                 else
377                 {
378                         if(ugd->th)
379                         {
380                                 elm_object_theme_set(layout, ugd->th);
381                         }
382
383                         elm_layout_theme_set(layout, "gengrid", "photoframe", "default_layout");
384                         elm_object_part_content_set(layout, "elm.swallow.icon", bg);
385                 }
386
387                 evas_object_event_callback_add(layout, EVAS_CALLBACK_MOUSE_DOWN, _ge_grid_item_mouse_down, gitem);
388                 evas_object_event_callback_add(layout, EVAS_CALLBACK_MOUSE_UP, _ge_grid_item_mouse_up, gitem);
389                 evas_object_show(layout);
390
391                 return layout;
392         }
393         else if (!strcmp(part, "elm.swallow.end") && (_ge_get_view_mode() == GE_ThumbnailEdit_Mode))
394         {
395                 Evas_Object* ck = NULL;
396
397                 ck = elm_check_add(obj);
398                 GE_CHECK_NULL(ck);
399                 elm_object_style_set(ck, GE_CHECKBOX_STYLE_GRID);
400                 evas_object_propagate_events_set(ck, EINA_FALSE);
401
402                 gitem->check_obj = ck;
403                 elm_check_state_set(ck, gitem->checked);
404
405                 evas_object_smart_callback_add(ck, "changed", _ge_grid_check_changed, data);
406                 evas_object_show(ck);
407
408                 return ck;
409         }
410
411         return NULL;
412 }
413
414 static bool _ge_grid_create_thumb(ge_ugdata* ugd, Evas_Object* parent)
415 {
416         ge_dbg("");
417         GE_CHECK_FALSE(parent);
418         GE_CHECK_FALSE(ugd);
419         int i = 0;
420         ge_item* gitem = NULL;
421         int cnt = ge_db_get_count_all();
422         int item_cnt = 0;
423         ge_dbg("List count : %d", cnt);
424
425         gic.item_style = "thumbnail_view";
426         gic.func.text_get = NULL;
427         gic.func.content_get = _ge_grid_get_content;
428
429         elm_gengrid_clear(parent);
430         if(ugd->th)
431         {
432                 elm_object_theme_set(parent, ugd->th);
433         }
434         elm_object_style_set(parent, "gallery_efl/default");
435
436         for(i = 1; i <= cnt; i++)
437         {
438                 ge_db_get_item_by_index(&gitem, i);
439                 if(gitem == NULL || gitem->item == NULL ||
440                    gitem->item->uuid == NULL) {
441                         ge_dbgE("Invalid gitem, continue...");
442                         continue;
443                 }
444
445                 if(!gitem->item->file_url)
446                 {
447                         ge_db_del_media_id(ugd, gitem->item->uuid);
448                         ge_db_item_list_remove(gitem);
449                         --i;
450                         --cnt;
451                         continue;
452                 }
453
454                 if(_ge_get_view_mode() == GE_ThumbnailEdit_Mode)
455                 {
456                         Mitem* new_item = ge_db_new_mitem(ugd, gitem->item->uuid);
457                         if(!new_item || !ecore_file_exists(gitem->item->file_url))
458                         {
459                                 ge_dbg("item or file doesn't exist, remove it...");
460                                 ge_db_selected_list_remove(gitem);
461                                 ge_db_item_list_remove(gitem);
462
463                                 if(new_item)
464                                 {
465                                         ge_db_destroy_mtype_item(new_item);
466                                         new_item = NULL;
467                                 }
468                                 --i;
469                                 --cnt;
470                                 continue;
471                         }
472
473                         if(new_item)
474                         {
475                                 ge_db_destroy_mtype_item(new_item);
476                                 new_item = NULL;
477                         }
478                 }
479
480                 gitem->elm_item = elm_gengrid_item_append(parent, &gic, gitem, _ge_grid_sel, gitem);
481                 gitem->check_obj = NULL;
482                 item_cnt++;
483
484         }
485
486         elm_gengrid_select_mode_set(parent, ELM_OBJECT_SELECT_MODE_NONE);
487         ge_grid_item_cnt = item_cnt;
488         if(item_cnt == 0)
489         {
490                 return EINA_FALSE;
491         }
492         else
493         {
494                 return EINA_TRUE;
495         }
496 }
497
498 Evas_Object* ge_grid_create_ly(Evas_Object* parent)
499 {
500         ge_dbg("");
501         GE_CHECK_NULL(parent);
502         Evas_Object* layout = NULL;
503
504         layout = ge_ui_load_edj(parent, GE_EDJ_FILE, GE_GRP_GRIDVIEW);
505         GE_CHECK_NULL(layout);
506         evas_object_show (layout);
507
508         return layout;
509 }
510
511 int ge_grid_del_callbacks(ge_ugdata *ugd)
512 {
513         GE_CHECK_VAL(ugd, -1);
514         if(ugd->thumbs_view)
515         {
516                 ge_dbg("Delete thumbnails callbacks!");
517                 evas_object_smart_callback_del(ugd->thumbs_view, "selected", _ge_grid_selected);
518                 evas_object_smart_callback_del(ugd->thumbs_view, "unselected", _ge_grid_unselected);
519                 evas_object_smart_callback_del(ugd->thumbs_view, "clicked", _ge_grid_clicked);
520                 evas_object_smart_callback_del(ugd->thumbs_view, "longpressed", _ge_grid_longpress);
521                 evas_object_smart_callback_del(ugd->thumbs_view, "drag,start,up", _ge_grid_drag_up);
522                 evas_object_smart_callback_del(ugd->thumbs_view, "drag,start,right", _ge_grid_drag_right);
523                 evas_object_smart_callback_del(ugd->thumbs_view, "drag,start,down", _ge_grid_drag_down);
524                 evas_object_smart_callback_del(ugd->thumbs_view, "drag,start,left", _ge_grid_drag_left);
525                 evas_object_smart_callback_del(ugd->thumbs_view, "drag,stop", _ge_grid_drag_stop);
526         }
527         return 0;
528 }
529
530 /*
531 * When select album, show first (GE_FIRST_VIEW_END_POS+1) medias.
532 * Then use idler to get other medias from DB and appened
533 * them to gridview.
534 * In order to reduce transit time of first show of thumbnails view.
535 * Cause most of time is spent for getting records from DB,
536 * so we get first (GE_FIRST_VIEW_END_POS+1) items and show thumbnails view,
537 * it will accelerate view show.
538 */
539 int ge_grid_idler_append_thumbs(void* data)
540 {
541         GE_CHECK_VAL(data, -1);
542         ge_ugdata *ugd = (ge_ugdata *)data;
543         GE_CHECK_VAL(ugd->thumbs_view, -1);
544         int i = 0;
545         int item_cnt = 0;
546         ge_item* gitem = NULL;
547         /* Get all medias count of current album */
548         int cnt = ge_db_get_count_all();
549         int ret = -1;
550         ge_cluster* cur_album = _ge_get_current_album();
551         GE_CHECK_VAL(cur_album, -1);
552         GE_CHECK_VAL(cur_album->cluster, -1);
553         ge_dbg("First view medias count: %d;", cnt);
554
555         if(cnt != (GE_FIRST_VIEW_END_POS+1))
556         {
557                 ge_dbg("No any more items, return!");
558                 return -1;
559         }
560         /* Get other items from DB */
561         ret = ge_db_get_items_list(ugd, cur_album, (GE_FIRST_VIEW_END_POS+1), GE_GET_UNTIL_LAST_RECORD);
562         ge_dbg("\n\n############ge_db_get_items_list Error code: %d#################\n", ret);
563         if(ret < 0)
564         {
565                 ge_dbg("ge_db_get_items_list ERROR, return!");
566                 return ret;
567         }
568
569         cnt = ge_db_get_count_all();
570         ge_dbg("Grid view all medias count: %d", cnt);
571
572
573         /* From (GL_FIRST_VIEW_END_POS + 2)th item to last one */
574         i = GE_FIRST_VIEW_END_POS + 2;
575
576         for(; i <= cnt; i++)
577         {
578                 ge_db_get_item_by_index(&gitem, i);
579                 if(gitem == NULL || gitem->item == NULL ||
580                    gitem->item->uuid == NULL) {
581                         ge_dbgE("Invalid gitem, continue...");
582                         continue;
583                 }
584
585                 if(!gitem->item->file_url)
586                 {
587                         ge_dbg("file_url is invalid.");
588                         ge_db_del_media_id(ugd, gitem->item->uuid);
589                         ge_db_selected_list_remove(gitem);
590                         ge_db_item_list_remove(gitem);
591                         cnt--;
592                         i--;
593                         gitem = NULL;
594                         continue;
595                 }
596
597                 gitem->elm_item = elm_gengrid_item_append(ugd->thumbs_view, &gic, gitem, _ge_grid_sel, gitem);
598                 item_cnt++;
599         }
600
601         ge_dbg("\n\n<<<<<<<<Use idler to append other medias--Done<<<<<<<<<\n");
602         if(item_cnt == 0)
603         {
604                 return -1;
605         }
606         else
607         {
608                 ge_grid_item_cnt = item_cnt + GE_FIRST_VIEW_END_POS + 1;
609                 ge_dbg("All count appended: %d", ge_grid_item_cnt);
610                 return 0;
611         }
612 }
613
614 Evas_Object* ge_grid_create_view(ge_ugdata* ugd, Evas_Object *parent)
615 {
616         ge_dbg("");
617         GE_CHECK_NULL(parent);
618         GE_CHECK_NULL(ugd);
619         int item_w = 0;
620         int item_h = 0;
621         int icon_size = 0;
622         Evas_Object *grid = elm_gengrid_add(parent);
623         GE_CHECK_NULL(grid);
624         double scale_factor = ugd->win_scale;
625         item_w = (int)(GE_GRID_ITEM_SIZE_W * scale_factor);
626         item_h = (int)(GE_GRID_ITEM_SIZE_H * scale_factor);
627         icon_size = (int)(GE_GRID_ICON_SIZE * scale_factor);
628         ge_dbg("Own scale: %f, elm_config_scale_get =%f", scale_factor, elm_config_scale_get());
629
630         if(!_ge_grid_create_thumb(ugd, grid)) {
631                 evas_object_del(grid);
632                 grid = NULL;
633
634                 ugd->nocontents = ge_ui_create_nocontents(ugd);
635                 evas_object_show (ugd->nocontents);
636
637                 return ugd->nocontents;
638         } else {
639                 ge_dbg("ge_grid_item_cnt : %d", ge_grid_item_cnt);
640                 if(ge_grid_item_cnt == GE_GRID_ITEM_ZOOM_LEVEL_01_CNT) {
641                         item_w *= GE_GRID_ITEM_ZOOM_LEVEL_01;
642                         item_h *= GE_GRID_ITEM_ZOOM_LEVEL_01;
643                         icon_size *= GE_GRID_ITEM_ZOOM_LEVEL_01;
644                 } else if(ge_grid_item_cnt <= GE_GRID_ITEM_ZOOM_LEVEL_02_CNT) {
645                         item_w *= GE_GRID_ITEM_ZOOM_LEVEL_02;
646                         item_h *= GE_GRID_ITEM_ZOOM_LEVEL_02;
647                         icon_size *= GE_GRID_ITEM_ZOOM_LEVEL_02;
648                 }
649
650                 ugd->icon_size = icon_size;
651                 evas_object_show (grid);
652         }
653
654
655         elm_gengrid_item_size_set(grid, item_w, item_h);
656         ge_dbg("Gengrid item w: %d, h: %d.", item_w, item_h);
657         elm_gengrid_align_set(grid, 0.5, 0.0);
658         elm_gengrid_horizontal_set(grid, EINA_FALSE);
659         elm_gengrid_bounce_set(grid, EINA_FALSE, EINA_TRUE);
660         elm_gengrid_multi_select_set(grid, EINA_TRUE);
661
662         evas_object_smart_callback_add(grid, "selected", _ge_grid_selected, NULL);
663         evas_object_smart_callback_add(grid, "unselected", _ge_grid_unselected, NULL);
664         evas_object_smart_callback_add(grid, "clicked", _ge_grid_clicked, NULL);
665         evas_object_smart_callback_add(grid, "longpressed", _ge_grid_longpress, NULL);
666         evas_object_smart_callback_add(grid, "drag,start,up", _ge_grid_drag_up, NULL);
667         evas_object_smart_callback_add(grid, "drag,start,right", _ge_grid_drag_right, NULL);
668         evas_object_smart_callback_add(grid, "drag,start,down", _ge_grid_drag_down, NULL);
669         evas_object_smart_callback_add(grid, "drag,start,left", _ge_grid_drag_left, NULL);
670         evas_object_smart_callback_add(grid, "drag,stop", _ge_grid_drag_stop, NULL);
671         evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
672
673         return grid;
674 }
675
676 int ge_grid_clear_view(ge_ugdata *ugd)
677 {
678         GE_CHECK_VAL(ugd, -1);
679         if(ugd->file_select_mode == GE_File_Select_One)
680         {
681                 bundle_del(ugd->bundle, GE_FILE_SELECT_RETURN_PATH);
682         }
683
684         if(ugd->thumbs_view)
685         {
686                 if(ugd->thumbs_nocontents != ugd->thumbs_view)
687                         ge_grid_del_callbacks(ugd);
688
689                 evas_object_del(ugd->thumbs_view);
690                 ugd->thumbs_view = NULL;
691                 ugd->thumbs_nocontents = NULL;
692                 ugd->thumbs_nf_it = NULL;
693         }
694
695         return 0;
696 }
697 int ge_grid_update_view(ge_ugdata *ugd)
698 {
699         ge_dbg("");
700         GE_CHECK_VAL(ugd, -1);
701         if(_ge_grid_create_thumb(ugd, ugd->thumbs_view) == EINA_FALSE) {
702                 ge_grid_del_callbacks(ugd);
703         } else {
704                 double scale_factor = ugd->win_scale;
705                 int item_w = (int)(GE_GRID_ITEM_SIZE_W * scale_factor);
706                 int item_h = (int)(GE_GRID_ITEM_SIZE_H * scale_factor);
707                 int icon_size = (int)(GE_GRID_ICON_SIZE * scale_factor);
708
709                 ge_dbg("ge_grid_item_cnt : %d", ge_grid_item_cnt);
710                 if(ge_grid_item_cnt == GE_GRID_ITEM_ZOOM_LEVEL_01_CNT) {
711                         item_w *= GE_GRID_ITEM_ZOOM_LEVEL_01;
712                         item_h *= GE_GRID_ITEM_ZOOM_LEVEL_01;
713                         icon_size *= GE_GRID_ITEM_ZOOM_LEVEL_01;
714                 } else if(ge_grid_item_cnt <= GE_GRID_ITEM_ZOOM_LEVEL_02_CNT) {
715                         item_w *= GE_GRID_ITEM_ZOOM_LEVEL_02;
716                         item_h *= GE_GRID_ITEM_ZOOM_LEVEL_02;
717                         icon_size *= GE_GRID_ITEM_ZOOM_LEVEL_02;
718                 }
719
720                 ugd->icon_size = icon_size;
721                 elm_gengrid_item_size_set(ugd->thumbs_view, item_w, item_h);
722         }
723
724         return 0;
725 }
726