4ad4150cfd0d26ff91216fd727817900874fdc48
[apps/core/preloaded/gallery.git] / src / features / gl-thumbs.c
1 /*
2   * Copyright (c) 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 "gl-debug.h"
18 #include "gl-thumbs.h"
19 #include "gl-ui-util.h"
20 #include "gl-util.h"
21 #include "gl-drm.h"
22 #include "gl-albums.h"
23 #include "gl-data.h"
24 #include "gl-ext-ug-load.h"
25 #include "gl-ext-exec.h"
26 #include "gl-controlbar.h"
27 #include "gl-nocontents.h"
28 #include "gl-notify.h"
29 #include "gl-strings.h"
30 #include "gl-icons.h"
31 #include "gl-thumb.h"
32 #ifdef _USE_ROTATE_BG
33 #include "gl-exif.h"
34 #endif
35
36 /* Icon swallowed to part "elm.swallow.icon" */
37 #define GL_GRID_TOUCH_RANGE 20
38 typedef struct _gl_thumb_data_t gl_thumb_data_s;
39
40 struct _gl_thumb_data_t{
41         void *ad;
42         gl_item *item;
43 };
44
45 static void __gl_thumbs_open_file(void *data)
46 {
47         gl_dbg("");
48         GL_CHECK(data);
49         gl_item *gitem = (gl_item *)data;
50         GL_CHECK(gitem->item);
51         GL_CHECK(gitem->item->file_url);
52         GL_CHECK(strlen(gitem->item->file_url));
53         GL_CHECK(gitem->ad);
54         gl_appdata *ad = (gl_appdata *)gitem->ad;
55         int view_mode = gl_get_view_mode(ad);
56         if (view_mode != GL_VIEW_THUMBS) {
57                 gl_dbgE("Error view mode!");
58                 return;
59         }
60
61         if (ad->gridinfo.view_mode == GL_THUMB_VIDEOS) {
62                 gl_dbg("Loading VIDEO-PLAYER");
63                 gl_ext_exec(gitem, GL_APP_VIDEOPLAYER);
64         } else {
65                 gl_dbg("Loading UG-IMAGE(VIDEO)-VIEWER");
66                 gl_ext_load_iv_ug(ad, gitem, GL_UG_IV);
67         }
68 }
69
70 static void __gl_thumbs_sel_cb(void *data, Evas_Object *obj, void *event_info)
71 {
72         _gl_ui_save_scroller_pos(obj);
73         __gl_thumbs_open_file(data);
74 }
75
76 static void __gl_thumbs_longpressed(void *data, Evas_Object *obj,
77                                     void *event_info)
78 {
79         GL_CHECK(event_info);
80         void *it_data = elm_object_item_data_get(event_info);
81         GL_CHECK(it_data);
82         gl_dbg("");
83         if (gl_get_view_mode(data) == GL_VIEW_THUMBS)
84                 __gl_thumbs_open_file(it_data);
85 }
86
87 static void __gl_thumbs_check_changed(void *data, Evas_Object *obj,
88                                       void *event_info)
89 {
90         GL_CHECK(obj);
91         GL_CHECK(data);
92         gl_item *gitem = (gl_item *) data;
93         GL_CHECK(gitem->ad);
94         gl_appdata *ad = (gl_appdata *)gitem->ad;
95         int view_mode = gl_get_view_mode(ad);
96         Evas_Object *view_ly = NULL;
97         Elm_Object_Item *nf_it = NULL;
98         gl_dbg("");
99
100         if (view_mode == GL_VIEW_THUMBS_EDIT) {
101                 view_ly = ad->gridinfo.navi_content_edit_ly;
102                 nf_it = ad->gridinfo.nf_it_edit;
103         } else if (view_mode == GL_VIEW_THUMBS_SELECT) {
104                 view_ly = ad->gridinfo.select_view_ly;
105                 nf_it = ad->gridinfo.nf_it_select;
106         } else {
107                 return;
108         }
109
110
111         Eina_Bool checked = elm_check_state_get(obj);
112         gitem->checked = checked;
113         if (checked) {
114                 gl_dbg("Append:%s", gitem->item->file_url);
115                 _gl_data_selected_list_append(ad, gitem);
116         } else {
117                 gl_dbg("Remove:%s", gitem->item->file_url);
118                 _gl_data_selected_list_remove(ad, gitem);
119         }
120
121         /* Display selectioninfo */
122         int sel_cnt = _gl_data_selected_list_count(ad);
123         _gl_notify_create_selinfo(ad, view_ly, nf_it, ad->gridinfo.thumbs_cnt,
124                                   sel_cnt, false);
125 }
126
127 /* Only for local medias */
128 static void __gl_thumbs_create_thumb_cb(media_content_error_e error,
129                                         const char *path, void *user_data)
130 {
131         GL_CHECK(user_data);
132         gl_thumb_data_s *thumb_data = (gl_thumb_data_s *)user_data;
133         GL_CHECK(thumb_data->ad);
134         gl_appdata *ad = (gl_appdata *)thumb_data->ad;
135         gl_item *gitem = thumb_data->item;
136         GL_FREE(thumb_data);
137
138         if (gl_get_view_mode(ad) != GL_VIEW_THUMBS &&
139             gl_get_view_mode(ad) != GL_VIEW_THUMBS_EDIT)
140                 return;
141
142         GL_CHECK(gitem);
143         GL_CHECK(gitem->item);
144         if (GL_FILE_EXISTS(path)) {
145                 gl_dbg("Update item with new thumb path[%s]", path);
146                 /* Update thumb path */
147                 GL_FREEIF(gitem->item->thumb_url);
148                 gitem->item->thumb_url = strdup(path);
149                 elm_gengrid_item_update(gitem->elm_item);
150         } else {
151                 gl_dbgE("Invalid thumb path!");
152         }
153 }
154
155 /* Use file to create new thumb if possible */
156 static int __gl_thumbs_create_thumb(gl_item *gitem)
157 {
158         GL_CHECK_VAL(gitem, -1);
159         GL_CHECK_VAL(gitem->item, -1);
160         GL_CHECK_VAL(gitem->item->file_url, -1);
161
162         if (GL_FILE_EXISTS(gitem->item->file_url)) {
163                 gl_thumb_data_s *thumb_data = NULL;
164                 thumb_data = (gl_thumb_data_s *)calloc(1, sizeof(gl_thumb_data_s));
165                 GL_CHECK_VAL(thumb_data, -1);
166                 thumb_data->ad = gitem->ad;
167                 thumb_data->item = gitem;
168                 _gl_data_create_thumb(gitem, __gl_thumbs_create_thumb_cb,
169                                       thumb_data);
170                 return 0;
171         }
172         return -1;
173 }
174
175 static Evas_Object *__gl_thumbs_get_content(void *data, Evas_Object *obj,
176                                             const char *part)
177 {
178         GL_CHECK_NULL(part);
179         GL_CHECK_NULL(strlen(part));
180         GL_CHECK_NULL(data);
181         gl_item *gitem = (gl_item *)data;
182         GL_CHECK_NULL(gitem->item);
183         GL_CHECK_NULL(gitem->ad);
184         gl_appdata *ad = (gl_appdata *)gitem->ad;
185         int view_mode = gl_get_view_mode(ad);
186         int item_size = ad->gridinfo.icon_size;
187         bool is_expired_drm = false;
188
189         if (!g_strcmp0(part, GL_THUMB_ICON)) {
190                 Evas_Object *layout = NULL;
191                 char *path = NULL;
192                 char *drm_path = NULL;
193                 unsigned int orient = 0;
194
195                 /* Is it DRM file? Has a valid RO? */
196                 if(_gl_get_icon_type(gitem) == GL_ICON_EXPIRED_DRM) {
197                         path =  GL_DEFAULT_THUMB_ICON;
198                         is_expired_drm = true;
199                 /* Only one photo in a (normal, not web) album */
200                 } else if (ad->maininfo.medias_cnt < 2 &&
201                            gitem->item->type == MEDIA_CONTENT_TYPE_IMAGE) {
202                         if (!g_strcmp0(GL_DB_DEFAULT_THUMB, gitem->item->thumb_url)) {
203                                 path = GL_DEFAULT_THUMB_ICON;
204                         } else {
205                                 drm_path = gl_drm_get_file_path(gitem);
206                                 path = _GET_ICON(drm_path);
207                                 if (gl_is_image_valid(ad, path) == false)
208                                         path = _GET_ICON(gitem->item->thumb_url);
209 #ifdef _USE_ROTATE_BG
210                                 /* Rotate bg if it's created from original file */
211                                 if (!g_strcmp0(path, gitem->item->file_url))
212                                         _gl_exif_get_orientation(path, &orient);
213 #endif
214                         }
215                 } else {
216                         /* Use default image */
217                         if (GL_FILE_EXISTS(gitem->item->thumb_url)) {
218                                 path = gitem->item->thumb_url;
219                         } else {
220                                 path = GL_DEFAULT_THUMB_ICON;
221                                 __gl_thumbs_create_thumb(gitem);
222                         }
223                 }
224
225                 if (gitem->item->type == MEDIA_CONTENT_TYPE_VIDEO) {
226                         unsigned int v_dur = 0;
227                         if (gitem->item->video_info) {
228                                 v_dur = gitem->item->video_info->duration;
229                         }
230                         int bk_len = 0;
231                         if (gitem->item->video_info == NULL)
232                                 bk_len = 0;
233                         else
234                                 bk_len = gitem->item->video_info->bookmarks;
235                         layout = _gl_thumb_show_part_icon_video(obj, path,
236                                                                 v_dur, bk_len,
237                                                                 gitem->item->favorite,
238                                                                 is_expired_drm,
239                                                                 item_size);
240                 } else {
241                         layout = _gl_thumb_show_part_icon_image(obj, path,
242                                                                 orient,
243                                                                 gitem->item->favorite,
244                                                                 is_expired_drm,
245                                                                 item_size);
246                 }
247
248                 GL_FREEIF(drm_path);
249                 return layout;
250         } else if (!g_strcmp0(part, GL_THUMB_CHECKBOX) &&
251                    (view_mode == GL_VIEW_THUMBS_EDIT ||
252                     view_mode == GL_VIEW_THUMBS_SELECT)) {
253                 Evas_Object *ck = NULL;
254                 ck = _gl_thumb_show_part_checkbox(obj, gitem->checked,
255                                                   __gl_thumbs_check_changed,
256                                                   data);
257                 GL_CHECK_NULL(ck);
258
259                 gitem->check_obj = ck;
260                 return ck;
261         }
262
263         return NULL;
264 }
265
266 static int __gl_thumbs_set_type(void *data)
267 {
268         GL_CHECK_VAL(data, -1);
269         gl_appdata *ad = (gl_appdata *)data;
270
271         ad->gridinfo.grid_type = GL_GRID_T_NONE;;
272         if (ad->ctrlinfo.tab_mode == GL_CTRL_TAB_TAGS) {
273                 ad->gridinfo.grid_type = GL_GRID_T_TAGS;
274         } else {
275                 gl_cluster *cur_album = ad->albuminfo.current_album;
276                 GL_CHECK_VAL(cur_album, -1);
277                 GL_CHECK_VAL(cur_album->cluster, -1);
278
279                 if (cur_album->cluster->type == GL_STORE_T_PHONE ||
280                     cur_album->cluster->type == GL_STORE_T_MMC)
281                         ad->gridinfo.grid_type = GL_GRID_T_LOCAL;
282                 else if (cur_album->cluster->type == GL_STORE_T_ALL)
283                         ad->gridinfo.grid_type = GL_GRID_T_ALLALBUMS;
284                 else
285                         gl_dbgE("Wrong cluster storage type!");
286         }
287         gl_dbg("Gridview type: %d", ad->gridinfo.grid_type);
288         return 0;
289 }
290
291 static bool __gl_thumbs_create_items(void *data, Evas_Object *parent)
292 {
293         GL_CHECK_FALSE(data);
294         GL_CHECK_FALSE(parent);
295         gl_appdata *ad = (gl_appdata *)data;
296         int i = 0;
297         int item_cnt = 0;
298         gl_item *gitem = NULL;
299         int ret = -1;
300         /* Get all medias count of current album */
301         int cnt = ad->maininfo.medias_cnt;
302         gl_dbg("List count : %d gv_mode : %d", cnt, ad->gridinfo.view_mode);
303
304         ad->gridinfo.thumbgic.item_style = GL_GENGRID_ITEM_STYLE_THUMBNAIL;
305         ad->gridinfo.thumbgic.func.text_get = NULL;
306         ad->gridinfo.thumbgic.func.content_get = __gl_thumbs_get_content;
307
308         if (elm_gengrid_items_count(parent) > 0) {
309                 /* Save scroller position before clearing gengrid */
310                 _gl_ui_save_scroller_pos(parent);
311                 elm_gengrid_clear(parent);
312         }
313
314         for (i = 1; i <= cnt; i++) {
315                 _gl_data_get_item_by_index(ad, i, false, &gitem);
316                 if (gitem == NULL || gitem->item == NULL ||
317                     gitem->item->uuid == NULL) {
318                         gl_dbgE("Invalid gitem. continue...");
319                         continue;
320                 }
321
322                 /* For PTP Album, file_url is NULL untill the file is saved from camera */
323                 if (!gitem->item->file_url) {
324                         gl_dbg("file_url is invalid.");
325                         ret = _gl_data_delete_media(ad, gitem->item);
326                         if (ret != 0)
327                                 continue;
328                         _gl_data_selected_list_remove(ad, gitem);
329                         _gl_data_item_list_remove(ad, gitem);
330                         cnt--;
331                         i--;
332                         gitem = NULL;
333                         continue;
334                 }
335
336                 if (ad->gridinfo.back_to_normal) {
337                         gitem->checked = false;
338                         //gitem->check_obj = NULL;
339                 }
340
341                 if (ad->gridinfo.view_mode == GL_THUMB_IMAGES &&
342                     gitem->item->type != MEDIA_CONTENT_TYPE_IMAGE)
343                     continue;
344                 if (ad->gridinfo.view_mode == GL_THUMB_VIDEOS &&
345                     gitem->item->type != MEDIA_CONTENT_TYPE_VIDEO)
346                     continue;
347                 gitem->elm_item = elm_gengrid_item_append(parent,
348                                                           &(ad->gridinfo.thumbgic),
349                                                           gitem,
350                                                           __gl_thumbs_sel_cb,
351                                                           gitem);
352                 item_cnt++;
353                 gitem->sequence = item_cnt;
354
355         }
356
357         _gl_ui_restore_scroller_pos(parent);
358         ad->gridinfo.thumbs_cnt = item_cnt;
359         ad->gridinfo.back_to_normal = false;
360
361         if (item_cnt == 0)
362                 return EINA_FALSE;
363         else
364                 return EINA_TRUE;
365 }
366
367 /*
368 * Set new view to all/image_grid_view.
369 *
370 * b_noc, true: it's nocontents view, false: normal view.
371 */
372 static int __gl_thumbs_set_view(void *data, Evas_Object *view, bool b_noc)
373 {
374         GL_CHECK_VAL(data, -1);
375         gl_appdata *ad = (gl_appdata *)data;
376         ad->gridinfo.all_grid_view = view;
377         if (b_noc)
378                 _gl_thumbs_set_nocontents(ad, view);
379         else
380                 _gl_thumbs_set_nocontents(ad, NULL);
381
382         return 0;
383 }
384
385 /*
386 * When select album, show first (GL_FIRST_VIEW_END_POS+1) medias.
387 * Then use idler to get other medias from DB and appened
388 * them to gridview.
389 * In order to reduce transit time of first show of thumbnails view.
390 * Cause most of time is spent for getting records from DB,
391 * so we get first (GL_FIRST_VIEW_END_POS+1) items and show thumbnails view,
392 * it will accelerate view show.
393 */
394 static int __gl_thumbs_idler_append_items(void *data)
395 {
396         GL_CHECK_VAL(data, -1);
397         gl_appdata *ad = (gl_appdata *)data;
398         GL_CHECK_VAL(ad->albuminfo.current_album, -1);
399         GL_CHECK_VAL(ad->gridinfo.all_grid_view, -1);
400         int i = 0;
401         int item_cnt = 0;
402         gl_item *gitem = NULL;
403         /* Get all medias count of current album */
404         int cnt = ad->maininfo.medias_cnt;
405         int ret = -1;
406
407         gl_dbg("First view medias count: %d; girdview mode: %d",
408                 cnt, ad->gridinfo.view_mode);
409         if (ad->maininfo.medias_cnt != (GL_FIRST_VIEW_END_POS + 1)) {
410                 gl_dbg("No any more items, return!");
411                 return -1;
412         }
413         /* Get other items from DB */
414         ret = _gl_data_get_item_list(ad, GL_CATEGORY_FOLDER,
415                                      ad->albuminfo.current_album,
416                                      (GL_FIRST_VIEW_END_POS + 1),
417                                      GL_GET_UNTIL_LAST_RECORD);
418         if (ret < 0) {
419                 gl_dbgE("Get items list failed[%d]!", ret);
420                 return ret;
421         }
422
423         cnt = ad->maininfo.medias_cnt;
424         gl_dbg("Grid view all medias count: %d", cnt);
425
426         if (ad->gridinfo.view_mode != GL_THUMB_ALL) {
427                 /* Event gridview mode is wrong, we still need to get other records */
428                 gl_dbg("Gridview mode is wrong, return!");
429                 return -1;
430         }
431
432         /* From (GL_FIRST_VIEW_END_POS + 2)th item to last one */
433         i = GL_FIRST_VIEW_END_POS + 2;
434
435         for (; i <= cnt; i++) {
436                 _gl_data_get_item_by_index(ad, i, false, &gitem);
437                 if (gitem == NULL || gitem->item == NULL ||
438                     gitem->item->uuid == NULL ) {
439                         gl_dbgE("Invalid gitem, continue...");
440                         continue;
441                 }
442
443                 if (!gitem->item->file_url) {
444                         gl_dbg("file_url is invalid.");
445                         _gl_data_delete_media(ad, gitem->item);
446                         _gl_data_selected_list_remove(ad, gitem);
447                         _gl_data_item_list_remove(ad, gitem);
448                         cnt--;
449                         i--;
450                         gitem = NULL;
451                         continue;
452                 }
453
454                 if (ad->gridinfo.view_mode == GL_THUMB_IMAGES &&
455                     gitem->item->type != MEDIA_CONTENT_TYPE_IMAGE)
456                     continue;
457                 if (ad->gridinfo.view_mode == GL_THUMB_VIDEOS &&
458                     gitem->item->type != MEDIA_CONTENT_TYPE_VIDEO)
459                     continue;
460                 gitem->elm_item = elm_gengrid_item_append(ad->gridinfo.all_grid_view,
461                                                                 &(ad->gridinfo.thumbgic),
462                                                                 gitem,
463                                                                 __gl_thumbs_sel_cb,
464                                                                 gitem);
465                 item_cnt++;
466                 gitem->sequence = item_cnt + GL_FIRST_VIEW_END_POS + 1;
467         }
468
469         gl_dbgW("\tUse idler to append other medias--Done!");
470         if (item_cnt == 0) {
471                 return -1;
472         } else {
473                 ad->gridinfo.thumbs_cnt = item_cnt + GL_FIRST_VIEW_END_POS + 1;
474                 gl_dbg("All count appended: %d", ad->gridinfo.thumbs_cnt);
475                 return 0;
476         }
477 }
478
479 static Eina_Bool __gl_thumbs_append_items_idler_cb(void *data)
480 {
481         GL_CHECK_CANCEL(data);
482
483         /* Try to get other medias from DB and append them to gridview */
484         if (__gl_thumbs_idler_append_items(data) < 0) {
485                 gl_dbgE("Failed to append grid items!");
486         } else {
487                 gl_dbg("Successful to append grid items!");
488         }
489
490         /* Remove idler after all items appended */
491         _gl_thumbs_del_append_idler(data);
492
493         return ECORE_CALLBACK_CANCEL;
494 }
495
496 void _gl_thumbs_mouse_down(void *data, Evas *e, Evas_Object *obj,
497                            void *event_info)
498 {
499         GL_CHECK(obj);
500         GL_CHECK(event_info);
501         GL_CHECK(data);
502         gl_item *gitem = (gl_item *) data;
503         GL_CHECK(gitem->ad);
504         gl_appdata *ad = (gl_appdata *)gitem->ad;
505         Evas_Event_Mouse_Down *ev = (Evas_Event_Mouse_Down *) event_info;
506
507         ad->gridinfo.grid_touch_info.x = ev->output.x;
508         ad->gridinfo.grid_touch_info.y = ev->output.y;
509 }
510
511 void _gl_thumbs_mouse_up(void *data, Evas *e, Evas_Object *obj, void *event_info)
512 {
513         GL_CHECK(data);
514         gl_item *gitem = (gl_item *) data;
515         GL_CHECK(gitem->ad);
516         gl_appdata *ad = (gl_appdata *)gitem->ad;
517
518         if (!event_info || !obj)
519                 goto RET_WO_EXEC;
520
521         Evas_Event_Mouse_Up *ev = event_info;
522         if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD ||
523             ev->event_flags & EVAS_EVENT_FLAG_ON_SCROLL)
524                 goto RET_WO_EXEC;
525
526         if ((abs(ad->gridinfo.grid_touch_info.x - ev->output.x) > GL_GRID_TOUCH_RANGE) ||
527             (abs(ad->gridinfo.grid_touch_info.y - ev->output.y) > GL_GRID_TOUCH_RANGE))
528                 goto RET_WO_EXEC;
529
530         gl_dbg("");
531         __gl_thumbs_open_file(data);
532         return;
533
534  RET_WO_EXEC:
535         return;
536 }
537
538 Evas_Object *_gl_thumbs_add_grid(void *data, Evas_Object *parent,
539                                  gl_thumb_mode mode, bool b_use_idler)
540 {
541         GL_CHECK_NULL(parent);
542         GL_CHECK_NULL(data);
543         gl_appdata *ad = (gl_appdata *)data;
544         Evas_Object *grid = NULL;
545         ad->gridinfo.view_mode = mode;
546         grid = _gl_thumb_add_gengrid(parent);
547         evas_object_smart_callback_add(grid, "realized", NULL, data);
548         evas_object_smart_callback_add(grid, "unrealized", NULL, data);
549         evas_object_smart_callback_add(grid, "longpressed",
550                                        __gl_thumbs_longpressed, data);
551
552         /* Set grid view type */
553         __gl_thumbs_set_type(ad);
554         _gl_ui_reset_scroller_pos(grid);
555
556         int view_mode = gl_get_view_mode(ad);
557
558         if (!__gl_thumbs_create_items(ad, grid)) {
559                 _gl_ui_del_scroller_pos(grid);
560                 evas_object_del(grid);
561                 grid = NULL;
562                 Evas_Object *noc = _gl_nocontents_create(ad);
563                 _gl_thumbs_set_nocontents(ad, noc);
564                 evas_object_show(noc);
565                 return noc;
566         }
567
568         gl_dbg("thumbs_cnt : %d", ad->gridinfo.thumbs_cnt);
569         _gl_thumbs_set_size(ad, grid);
570         if (view_mode != GL_VIEW_THUMBS_SELECT)
571                 _gl_thumbs_set_nocontents(ad, NULL);
572         evas_object_show(grid);
573
574         if (b_use_idler &&
575             ad->maininfo.medias_cnt == (GL_FIRST_VIEW_END_POS + 1)) {
576                 gl_dbgW("\tUse idler to append other medias--Start");
577                 /* Remove idler */
578                 _gl_thumbs_del_append_idler(ad);
579                 /* Add idler */
580                 ad->gridinfo.grid_append_idler = ecore_idler_add(__gl_thumbs_append_items_idler_cb,
581                                                                  ad);
582         }
583
584         return grid;
585 }
586
587 int _gl_thumbs_show_edit_view(void *data)
588 {
589         GL_CHECK_VAL(data, -1);
590         gl_appdata *ad = (gl_appdata *)data;
591         int view_mode = gl_get_view_mode(ad);
592         bool b_ret = false;
593         Evas_Object *view = NULL;
594         gl_dbg("view_mode: %d", view_mode);
595
596         if (view_mode == GL_VIEW_THUMBS_EDIT) {
597                 view = ad->gridinfo.navi_content_edit_view;
598         } else if (view_mode == GL_VIEW_THUMBS_SELECT) {
599                 view = ad->gridinfo.select_view;
600         } else {
601                 gl_dbgE("Wrong view mode!");
602                 return -1;
603         }
604         GL_CHECK_VAL(view, -1);
605         b_ret = __gl_thumbs_create_items(ad, view);
606         _gl_thumbs_set_size(ad, NULL);
607
608         if (!b_ret) {
609                 gl_dbgE("Create items failed!");
610                 return -1;
611         } else {
612                 return 0;
613         }
614 }
615
616 int _gl_thumbs_show_view(void *data)
617 {
618         GL_CHECK_VAL(data, -1);
619         gl_appdata *ad = (gl_appdata *)data;
620         int gridview_mode = ad->gridinfo.view_mode;
621         bool b_ret = false;
622         gl_dbg("gridview_mode: %d", gridview_mode);
623
624         if (ad->gridinfo.all_grid_view == NULL) {
625                 gl_dbg("Error : Any gridview doesn't exist");
626                 return -1;
627         }
628
629         /* Come back from edit mode, save state */
630         ad->gridinfo.back_to_normal = true;
631         b_ret = __gl_thumbs_create_items(ad,
632                                          ad->gridinfo.all_grid_view);
633         _gl_thumbs_set_size(ad, NULL);
634
635         if (!b_ret) {
636                 gl_dbgE("Create items failed!");
637                 return -1;
638         } else {
639                 return 0;
640         }
641 }
642
643 Eina_Bool _gl_thumbs_update_view(void *data)
644 {
645         GL_CHECK_FALSE(data);
646         gl_appdata *ad = (gl_appdata *)data;
647         Eina_Bool res = EINA_FALSE;
648         Evas_Object *gv = NULL;
649         int view_mode = gl_get_view_mode(ad);
650         bool b_view = false;
651         gl_dbg("");
652
653         if (view_mode == GL_VIEW_THUMBS_EDIT) {
654                 gl_dbg("\n\nEdit_Mode\n");
655                 gv = ad->gridinfo.navi_content_edit_view;
656         } else {
657                 b_view = _gl_thumbs_get_view(ad, &gv);
658                 GL_CHECK_FALSE(gv);
659         }
660         if (b_view) {
661                 res = __gl_thumbs_create_items(ad, gv);
662                 if (!res) {
663                         gl_dbg("__gl_thumbs_create_items() return false...");
664                         evas_object_hide(gv);
665                         _gl_ui_del_scroller_pos(gv);
666                         evas_object_del(gv);
667                         __gl_thumbs_set_view(ad, NULL, false);
668                         Evas_Object *noc = _gl_nocontents_create(ad);
669                         evas_object_show(noc);
670                         __gl_thumbs_set_view(ad, noc, true);
671
672                         elm_object_part_content_unset(ad->gridinfo.navi_content_ly,
673                                                       "elm.swallow.view");
674                         elm_object_part_content_set(ad->gridinfo.navi_content_ly,
675                                                     "elm.swallow.view", noc);
676                 } else {
677                         _gl_thumbs_set_size(ad, gv);
678                 }
679         } else {
680                 gl_dbg("Remove nocontents view.");
681                 evas_object_hide(gv);
682                 _gl_ui_del_scroller_pos(gv);
683                 evas_object_del(gv);
684                 __gl_thumbs_set_view(ad, NULL, false);
685                 bool b_noc = false;
686                 int view_m = ad->gridinfo.view_mode;
687
688                 Evas_Object *view = NULL;
689                 view = _gl_thumbs_add_grid(ad, ad->gridinfo.navi_content_ly,
690                                            view_m, false);
691                 if (ad->gridinfo.all_grid_nocontents)
692                         b_noc = true;
693
694                 /* No nocotents removed, gridview created, enable edit button */
695                 if (!b_noc) {
696                         /* When nocontents removed from webalbum,
697                          * it means this empty album was just refreshed
698                          * to download photo from web, progressbr showed.
699                          */
700                         _gl_ctrl_disable_btn(ad, false, GL_NAVI_THUMBS);
701                 }
702                 __gl_thumbs_set_view(ad, view, b_noc);
703
704                 elm_object_part_content_unset(ad->gridinfo.navi_content_ly,
705                                               "elm.swallow.view");
706                 elm_object_part_content_set(ad->gridinfo.navi_content_ly,
707                                             "elm.swallow.view", view);
708         }
709
710         return res;
711 }
712
713 int _gl_thumbs_create_view(void *data, int nf_mode, char *title, bool b_idler,
714                            Evas_Smart_Cb func)
715 {
716         GL_CHECK_VAL(data, -1);
717         gl_appdata *ad = (gl_appdata *)data;
718         GL_CHECK_VAL(ad->maininfo.naviframe, -1);
719         Evas_Object *layout = NULL;
720         Evas_Object *view = NULL;
721
722         gl_set_view_mode(data, GL_VIEW_THUMBS);
723         layout = gl_ctrl_create_ctrlbar_view(ad->maininfo.naviframe);
724         GL_CHECK_VAL(layout, -1);
725         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND,
726                                          EVAS_HINT_EXPAND);
727         evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
728         view = _gl_thumbs_add_grid(ad, layout, GL_THUMB_ALL, b_idler);
729         if (view == NULL) {
730                 evas_object_del(layout);
731                 gl_dbgE("Failed to add gridview!");
732                 return -1;
733         }
734
735         elm_object_part_content_set(layout, "elm.swallow.view", view);
736         ad->gridinfo.all_grid_view = view;
737         ad->gridinfo.navi_content_ly = layout;
738
739         gl_ui_create_title_and_push(ad, ad->maininfo.naviframe, layout, nf_mode,
740                                     title);
741
742         Evas_Object *bk_btn = NULL;
743         bk_btn = elm_object_item_part_content_get(ad->gridinfo.nf_it,
744                                                   GL_NAVIFRAME_PREV_BTN);
745         elm_object_style_set(bk_btn, GL_BUTTON_STYLE_NAVI_PRE);
746         evas_object_smart_callback_add(bk_btn, "clicked", func, ad);
747
748         edje_object_signal_emit(_EDJ(layout), GL_SIGNAL_VIEW_DEFAULT, "elm");
749         gl_dbg("Done");
750         return 0;
751 }
752
753 int _gl_thumbs_update_count(void *data, int new_cnt)
754 {
755         GL_CHECK_VAL(data, -1);
756         gl_appdata *ad = (gl_appdata *)data;
757
758         gl_dbg("gridview display item count=%d", new_cnt);
759         ad->gridinfo.updated_thumbs_cnt = new_cnt;
760
761         return 0;
762 }
763
764 /**
765 * Get all/image_grid_view.
766 *
767 * True returned if it's normal view, if it's nocontents view return false.
768 */
769 bool _gl_thumbs_get_view(void *data, Evas_Object **view)
770 {
771         GL_CHECK_FALSE(data);
772         gl_appdata *ad = (gl_appdata *)data;
773         Evas_Object *gv = NULL;
774         bool b_view = false;
775
776         gv = ad->gridinfo.all_grid_view;
777         if (gv && ad->gridinfo.all_grid_nocontents == NULL)
778                 b_view = true;
779
780         /* Nocontents */
781         if (!b_view)
782                 gl_dbg("Previous view is Nocontents...");
783
784         /* Return view */
785         if (view)
786                 *view = gv;
787
788         return b_view;
789 }
790
791 /* Assign new value to all/image_grid_nocontents */
792 int _gl_thumbs_set_nocontents(void *data, Evas_Object *noc)
793 {
794         GL_CHECK_VAL(data, -1);
795         gl_appdata *ad = (gl_appdata *)data;
796
797         ad->gridinfo.all_grid_nocontents = noc;
798
799         return 0;
800 }
801
802 int _gl_thumbs_set_size(void *data, Evas_Object *gridview)
803 {
804         GL_CHECK_VAL(data, -1);
805         gl_appdata *ad = (gl_appdata *)data;
806         int cnt = 0;
807         Evas_Object *gv = NULL;
808         int view_mode = gl_get_view_mode(ad);
809
810         if (gridview) {
811                 gv = gridview;
812         } else {
813                 bool b_view = false;
814                 if (view_mode == GL_VIEW_THUMBS_EDIT) {
815                         b_view = true;
816                         gv = ad->gridinfo.navi_content_edit_view;
817                 } else if (view_mode == GL_VIEW_THUMBS_SELECT) {
818                         b_view = true;
819                         gv = ad->gridinfo.select_view;
820                 } else {
821                         b_view = _gl_thumbs_get_view(ad, &gv);
822                 }
823
824                 if (!b_view || !gv) {
825                         gl_dbgE("gridview is invalid!");
826                         return -1;
827                 }
828         }
829
830         if (ad->gridinfo.updated_thumbs_cnt <= 0) {
831                 cnt = ad->gridinfo.thumbs_cnt;
832         } else {
833                 cnt = ad->gridinfo.updated_thumbs_cnt;
834                 ad->gridinfo.updated_thumbs_cnt = 0;
835         }
836
837         return _gl_thumb_set_size(ad, gv, cnt, &(ad->gridinfo.icon_size));
838 }
839
840 int _gl_thumbs_clear_cbs(Evas_Object *grid)
841 {
842         GL_CHECK_VAL(grid, -1);
843         evas_object_smart_callback_del(grid, "longpressed",
844                                        __gl_thumbs_longpressed);
845         return 0;
846 }
847
848 int _gl_thumbs_delete_view(void *data)
849 {
850         GL_CHECK_VAL(data, -1);
851         gl_appdata *ad = (gl_appdata *)data;
852
853         /* Destroy idler */
854         _gl_thumbs_del_append_idler(data);
855
856         if (ad->gridinfo.all_grid_view != NULL) {
857                 _gl_ui_del_scroller_pos(ad->gridinfo.all_grid_view);
858                 _gl_thumbs_clear_cbs(ad->gridinfo.all_grid_view);
859                 evas_object_del(ad->gridinfo.all_grid_view);
860                 ad->gridinfo.all_grid_view = NULL;
861         }
862         ad->gridinfo.grid_type = GL_GRID_T_NONE;
863         ad->gridinfo.all_grid_nocontents = NULL;
864         ad->gridinfo.edit_btn = NULL;
865         return 0;
866 }
867
868 /* Update griditem size */
869 int _gl_thumbs_update_size(void *data, Evas_Object *view)
870 {
871         GL_CHECK_VAL(data, -1);
872         gl_appdata *ad = (gl_appdata *)data;
873         Evas_Object *_view = NULL;
874         int view_mode = gl_get_view_mode(ad);
875         gl_dbg("");
876
877         if (ad->gridinfo.thumbs_cnt <= GL_GRID_ITEM_ZOOM_LEVEL_02_CNT) {
878                 gl_dbgW("Thumbs count is less than 7!");
879                 return -1;
880         }
881
882         if (view) {
883                 _view = view;
884         } else {
885                 bool b_view = false;
886                 if (view_mode == GL_VIEW_THUMBS_EDIT) {
887                         b_view = true;
888                         _view = ad->gridinfo.navi_content_edit_view;
889                 } else if (view_mode == GL_VIEW_THUMBS_SELECT) {
890                         b_view = true;
891                         _view = ad->gridinfo.select_view;
892                 } else {
893                         b_view = _gl_thumbs_get_view(ad, &_view);
894                 }
895
896                 if (!b_view || !_view) {
897                         gl_dbgE("gridview is invalid!");
898                         return -1;
899                 }
900         }
901
902         _gl_thumbs_set_size(data, _view);
903
904         _gl_thumb_update_gengrid(_view);
905
906         return 0;
907 }
908
909 int _gl_thumbs_del_append_idler(void *data)
910 {
911         GL_CHECK_VAL(data, -1);
912         gl_appdata *ad = (gl_appdata *)data;
913
914         if (ad->gridinfo.grid_append_idler) {
915                 ecore_idler_del(ad->gridinfo.grid_append_idler);
916                 ad->gridinfo.grid_append_idler = NULL;
917         }
918
919         return 0;
920 }
921