2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.tizenopensource.org/license
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "gl-albums.h"
19 #include "gl-gridview.h"
20 #include "gl-listview.h"
21 #include "gl-controlbar.h"
22 #include "gl-ui-util.h"
25 #include "gl-button.h"
28 #include "gl-progressbar.h"
30 #include "gl-strings.h"
31 #include "gl-nocontents.h"
32 #include "gl-notify.h"
34 #include "gl-rotate-bg.h"
38 void _gl_albums_realized(void *data, Evas_Object *obj, void *event_info)
40 gl_dbg_launch(" realized");
43 static void _gl_albums_comeback_from_view_cb(void *data,
44 Evas_Object *obj, void *event_info)
47 gl_appdata *ad = (gl_appdata *)data;
50 /* Delete callback when it is clicked to prevent it is called for many times */
51 evas_object_smart_callback_del(obj, "clicked",
52 _gl_albums_comeback_from_view_cb);
54 /* Reset aul launch flag if change to albums view */
55 ad->albuminfo.aul_launch_by_mime = false;
56 ad->albuminfo.aul_launch_type = GL_AUL_T_NONE;
58 if (_gl_data_check_update(ad, true))
59 gl_refresh_albums_list(ad);
61 gl_albums_comeback_from_view(ad);
63 _gl_ctrl_disable_toolbar_item(ad, false, GL_NAVI_ALBUMS, false);
67 * @Brif Update checkbox state and album cover and update selectioninfo.
69 * @Param data gl_appdata.
70 * @Param album_item album item.
71 * @Param check_obj object of checkbox.
72 * @Param b_ck_box true: Checkbox selection, false: album cover selection.
74 static int _gl_albums_update_check_state(void *data,
75 gl_cluster *album_item,
76 Evas_Object *check_obj, bool b_ck_box)
78 GL_CHECK_VAL(album_item, -1);
79 GL_CHECK_VAL(album_item->cluster, -1);
80 GL_CHECK_VAL(album_item->cluster->uuid, -1);
81 GL_CHECK_VAL(check_obj, -1);
82 GL_CHECK_VAL(data, -1);
83 gl_appdata *ad = (gl_appdata *)data;
84 gl_dbg("Select checkbox[1]/album_cover[0]: %d.", b_ck_box);
86 /* Update state of checkbox */
87 album_item->checked = !album_item->checked;
88 gl_dbg("album (%s) check state: %d", album_item->cluster->display_name,
92 * If album cover selected, update checkbox icon manually,
93 * If checkbox selected, its icon is updated by system automatically.
95 Evas_Object *ck = NULL;
96 if (b_ck_box == false)
97 ck = elm_object_item_part_content_get(album_item->item,
100 ck = elm_object_item_part_content_get(album_item->item,
101 GL_TILE_CHECKBOX_GRID);
102 elm_check_state_set(ck, album_item->checked);
104 if (album_item->checked) {
105 gl_dbg("Append:%s, id:%s", album_item->cluster->display_name,
106 album_item->cluster->uuid);
107 _gl_data_albums_selected_list_append(ad, album_item);
109 gl_dbg("Remove:%s, id:%s", album_item->cluster->display_name,
110 album_item->cluster->uuid);
111 _gl_data_albums_selected_list_remove(ad, album_item);
114 /* Display selectioninfo */
115 int cnt = _gl_data_get_albums_selected_cnt(ad);
116 _gl_notify_create_selinfo(ad, ad->albuminfo.edit_layout,
117 ad->albuminfo.nf_it_edit,
118 ad->albuminfo.albums_cnt, cnt, false);
122 static void _gl_albums_check_changed(void *data, Evas_Object *obj,
127 gl_cluster *album_item = (gl_cluster *)data;
128 GL_CHECK(album_item->ad);
129 gl_appdata *ad = (gl_appdata *)album_item->ad;
132 if (gl_get_view_mode(ad) != GL_VIEW_ALBUMS_EDIT) {
133 gl_dbgE("Wrong view mode!");
136 /* gl_dbg("EditMode"); */
139 /* Checkbox selected, b_ck_box=true */
140 _gl_albums_update_check_state(ad, album_item, obj, true);
143 static void _gl_albums_check_grid_changed(void *data, Evas_Object *obj,
148 gl_cluster *album_item = (gl_cluster *)data;
149 GL_CHECK(album_item->ad);
150 gl_appdata *ad = (gl_appdata *)album_item->ad;
153 if (gl_get_view_mode(ad) != GL_VIEW_ALBUMS_EDIT) {
154 gl_dbgE("Wrong view mode!");
158 /* Grid checkbox selected, b_ck_box=false */
159 _gl_albums_update_check_state(ad, album_item, obj, false);
162 /* Callback of album item selection */
163 static void __gl_albums_sel_cb(void *data, Evas_Object *obj, void *event_info)
165 GL_CHECK(event_info);
167 gl_cluster *album_item = (gl_cluster *)data;
168 GL_CHECK(album_item->cluster);
169 GL_CHECK(album_item->ad);
170 gl_appdata *ad = (gl_appdata *)album_item->ad;
171 Evas_Event_Mouse_Up *ev = (Evas_Event_Mouse_Up *)event_info;
173 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
176 int view_mode = gl_get_view_mode(ad);
177 gl_dbg("view mode: %d.", view_mode);
178 if (view_mode != GL_VIEW_ALBUMS_EDIT) {
179 if (album_item->cluster->count == 0) {
180 gl_dbgW("Empty album, return!");
183 gl_albums_sel_album(album_item);
187 static void __gl_albums_rename_job_cb(void *userdata)
190 gl_ui_rename_album(userdata);
194 static void _gl_albums_rename_btn_cb(void *data, Evas_Object *obj,
199 gl_cluster *album_item = (gl_cluster *)data;
200 gl_appdata *ad = (gl_appdata *)album_item->ad;
202 /* Return if album selected */
203 if (!album_item->checked) {
204 gl_dbgW("Album checked!");
208 /* Album cover selected, b_ck_box=false, deselect checkbox */
209 Evas_Object *ck = NULL;
210 ck = elm_object_item_part_content_get(album_item->item,
212 _gl_albums_update_check_state(ad, album_item, ck, false);
214 if(ad->maininfo.rename_album_job) {
215 ecore_job_del(ad->maininfo.rename_album_job);
216 ad->maininfo.rename_album_job = NULL;
218 ad->maininfo.rename_album_job = ecore_job_add(__gl_albums_rename_job_cb,
222 static char *__gl_albums_get_text(void *data, Evas_Object *obj, const char *part)
225 GL_CHECK_NULL(strlen(part));
227 gl_cluster *album_item = (gl_cluster *)data;
228 GL_CHECK_NULL(album_item->cluster);
229 GL_CHECK_NULL(album_item->cluster->display_name);
230 GL_CHECK_NULL(album_item->cluster->uuid);
231 GL_CHECK_NULL(album_item->ad);
232 gl_appdata *ad = (gl_appdata *)album_item->ad;
233 char buf[GL_ALBUM_NAME_LEN_MAX] = { 0, };
235 if (!g_strcmp0(part, "elm.text.name")) {
236 gl_dbg_launch(" text.name");
238 if (_gl_data_is_root_path(ad, album_item->cluster->path))
239 snprintf(buf, sizeof(buf), "%s",
240 GL_ALBUM_PHOME_ROOT_NAME);
241 else if (album_item->cluster->display_name &&
242 strlen(album_item->cluster->display_name))
243 snprintf(buf, sizeof(buf), "%s",
244 (char *)(album_item->cluster->display_name));
246 gl_dbgE("Album name[%s] is wrong!",
247 album_item->cluster->display_name);
248 } else if (!g_strcmp0(part, "elm.text.date")) {
250 int item_count = GL_ALBUM_COVER_THUMB_NUM;
251 gl_item **items1 = ad->albuminfo.cover_thumbs;
252 gl_albums_free_cover_thumbs(ad);
254 _gl_data_get_first_several_items(album_item, items1, &item_count,
255 MEDIA_CONTENT_ORDER_DESC);
258 if (item_count <= 0) {
259 gl_dbg("Empty album...");
260 ad->albuminfo.album_medias_cnt = 0;
264 ad->albuminfo.album_medias_cnt = item_count;
265 if (items1[0] == NULL || items1[0]->item == NULL) {
266 gl_dbgE("[Error] Invalid item!");
267 ad->albuminfo.album_medias_cnt = 0;
270 memcpy(&album_item->item_mtime,
271 &(items1[0]->item->mtime), sizeof(time_t));
275 int sort_t = MEDIA_CONTENT_ORDER_ASC;
276 memset(items2, 0x00, item_count * sizeof(int));
277 _gl_data_get_first_several_items(album_item,
281 if (item_count <= 0) {
282 gl_dbg("Empty album...");
286 if (items2[0] == NULL || items2[0]->item == NULL) {
287 gl_dbgE("Invalid items2[0]!");
288 ad->albuminfo.album_medias_cnt = 0;
291 _gl_tile_get_mtime((time_t *)&(album_item->item_mtime),
292 (time_t *)&(items2[0]->item->mtime),
293 buf, GL_ALBUM_NAME_LEN_MAX);
295 for (i = 0; i < item_count; i++) {
296 _gl_data_destroy_item(items2[i]);
300 } else if (!g_strcmp0(part, "elm.text.count")) {
301 _gl_data_update_item_cnt(album_item);
302 snprintf(buf, sizeof(buf), "%d",
303 (int)(album_item->cluster->count));
310 static gl_icon_type __gl_albums_set_bg_file(Evas_Object *bg, void *data)
312 gl_item *git = (gl_item *)data;
313 char *bg_path = GL_DEFAULT_THUMB_ICON;
314 gl_icon_type ret_val = GL_ICON_CORRUPTED_FILE;
316 if (git == NULL || git->item == NULL) {
317 gl_dbgE("Invalid item :%p", git);
318 goto GL_ALBUMS_FAILED;
321 /* Is it DRM file? Has a valid RO? */
322 char *path = git->item->file_url;
323 if(gl_drm_is_drm_file(path) &&
324 !gl_drm_check_valid_ro(path, gl_drm_get_permtype(git->item->type))) {
325 ret_val = GL_ICON_EXPIRED_DRM;
326 goto GL_ALBUMS_FAILED;
329 ret_val= GL_ICON_NORMAL;
330 bg_path = _GETICON(git->item->thumb_url);
334 #ifdef _USE_ROTATE_BG
335 _gl_rotate_bg_set_image_file(bg, bg_path);
337 elm_bg_file_set(bg, bg_path, NULL);
343 static Evas_Object *__gl_albums_get_content(void *data, Evas_Object *obj, const char *part)
346 GL_CHECK_NULL(strlen(part));
348 gl_cluster *album_item = (gl_cluster *)data;
349 GL_CHECK_NULL(album_item->cluster);
350 GL_CHECK_NULL(album_item->ad);
351 gl_appdata *ad = (gl_appdata *)album_item->ad;
352 GL_CHECK_NULL(album_item->cluster->uuid);
353 const char *al_id = album_item->cluster->uuid;
354 int view_mode = gl_get_view_mode(ad);
356 if (view_mode != GL_VIEW_ALBUMS &&
357 view_mode != GL_VIEW_ALBUMS_EDIT)
360 Evas_Object *_obj = NULL;
361 if ((!g_strcmp0(part, GT_TILE_FIRSTICON)) ||
362 (!g_strcmp0(part, GT_TILE_ONLYICON)) ||
363 (!g_strcmp0(part, GT_TILE_ICON))
364 #ifdef _USE_ROTATE_BG
365 || (!g_strcmp0(part, GT_TILE_3ICON1)) ||
366 (!g_strcmp0(part, GT_TILE_3ICON2)) ||
367 (!g_strcmp0(part, GT_TILE_4ICON3)) ||
368 (!g_strcmp0(part, GT_TILE_4ICON4)) ||
369 (!g_strcmp0(part, GT_TILE_5ICON1)) ||
370 (!g_strcmp0(part, GT_TILE_5ICON2)) ||
371 (!g_strcmp0(part, GT_TILE_6ICON4)) ||
372 (!g_strcmp0(part, GT_TILE_6ICON5))
375 _obj = _gl_tile_show_part_icon(obj, part,
376 ad->albuminfo.album_medias_cnt,
377 ad->maininfo.win_scale,
378 __gl_albums_set_bg_file,
379 (void **)ad->albuminfo.cover_thumbs);
380 } else if (!g_strcmp0(part, GT_TILE_LABEL)) {
382 * for "All albums" and "Camera shots", their colors should be
383 * 25:25:25 by new gui
385 bool b_default = false;
386 if (!g_strcmp0(al_id, GL_ALBUM_ALL_ID) ||
387 _gl_data_is_default_album(GL_ALBUM_DEFAULT_NAME, album_item->cluster))
389 _obj = _gl_tile_show_part_label(obj, album_item->index,
392 gl_dbg_launch(" content");
393 if (ad->albuminfo.album_medias_cnt <= 0)
394 gl_dbg("Empty album");
395 } else if (!g_strcmp0(part, GL_TILE_CHECKBOX_GRID) &&
396 view_mode == GL_VIEW_ALBUMS_EDIT) {
397 _obj = _gl_tile_show_part_checkbox_grid(obj, album_item->checked,
398 _gl_albums_check_grid_changed,
400 } else if (!g_strcmp0(part, GL_TILE_CHECKBOX) &&
401 view_mode == GL_VIEW_ALBUMS_EDIT) {
402 _obj = _gl_tile_show_part_checkbox(obj, album_item->checked,
403 _gl_albums_check_changed,
405 } else if (!g_strcmp0(part, GL_TILE_RENAME) &&
406 view_mode == GL_VIEW_ALBUMS_EDIT) {
407 if (!g_strcmp0(al_id, GL_ALBUM_ALL_ID) ||
408 _gl_data_is_default_album(GL_ALBUM_DEFAULT_NAME, album_item->cluster))
411 _obj = _gl_tile_show_part_rename(obj, _gl_albums_rename_btn_cb,
418 static int _gl_albums_create_items(void *data, Evas_Object *parent)
420 GL_CHECK_VAL(parent, -1);
421 GL_CHECK_VAL(data, -1);
422 gl_appdata *ad = (gl_appdata *)data;
424 gl_cluster *album_item = NULL;
426 int view_mode = gl_get_view_mode(ad);
429 /* Clear albums view */
430 elm_gengrid_clear(parent);
432 ad->albuminfo.albumgic.item_style = GL_GENGRID_STYLE_ALBUM_VIEW;
433 ad->albuminfo.albumgic.func.text_get = __gl_albums_get_text;
434 ad->albuminfo.albumgic.func.content_get = __gl_albums_get_content;
435 /* Show blue folder name */
436 ad->albuminfo.albumgic_blue.item_style = GL_GENGRID_STYLE_ALBUM_VIEW_BLUE;
437 ad->albuminfo.albumgic_blue.func.text_get = __gl_albums_get_text;
438 ad->albuminfo.albumgic_blue.func.content_get = __gl_albums_get_content;
440 GL_CHECK_VAL(ad->albuminfo.cluster_list, -1);
441 GL_CHECK_VAL(ad->albuminfo.cluster_list->clist, -1);
442 Eina_List *clist = ad->albuminfo.cluster_list->clist;
443 length = eina_list_count(clist);
444 gl_dbg("Albums length: %d", length);
445 const char *al_id = NULL;
446 Elm_Gengrid_Item_Class *pgic = &(ad->albuminfo.albumgic);
447 Elm_Gengrid_Item_Class *pgic_blue = &(ad->albuminfo.albumgic_blue);
450 gl_dbg_launch(" for:elm_gengrid_item_append:start");
451 for (i = 0; i < length; i++) {
452 album_item = eina_list_nth(clist, i);
453 GL_CHECK_VAL(album_item, -1);
454 GL_CHECK_VAL(album_item->cluster, -1);
455 GL_CHECK_VAL(album_item->cluster->display_name, -1);
456 GL_CHECK_VAL(album_item->cluster->uuid, -1);
457 al_id = album_item->cluster->uuid;
459 if (view_mode == GL_VIEW_ALBUMS_EDIT) {
460 if (!g_strcmp0(al_id, GL_ALBUM_ALL_ID))
464 /* Show blue folder name */
465 if (!g_strcmp0(album_item->cluster->uuid, GL_ALBUM_ALL_ID) ||
466 _gl_data_is_default_album(GL_ALBUM_DEFAULT_NAME, album_item->cluster))
467 album_item->item = elm_gengrid_item_append(parent,
473 album_item->item = elm_gengrid_item_append(parent, pgic,
477 album_item->index = item_cnt;
479 gl_dbg("Append[%s], id=%s.", album_item->cluster->display_name,
482 gl_dbg_launch(" for:elm_gengrid_item_append:end");
484 ad->albuminfo.albums_cnt = item_cnt;
488 static int __gl_albums_reset_view(void *data)
490 GL_CHECK_VAL(data, -1);
491 gl_appdata *ad = (gl_appdata *)data;
492 int view_mode = gl_get_view_mode(ad);
493 gl_dbg("view_mode: %d", view_mode);
495 if (view_mode != GL_VIEW_ALBUMS && view_mode != GL_VIEW_ALBUMS_EDIT &&
496 view_mode != GL_VIEW_ALBUMS_RENAME) {
497 gl_dbg("Change to albums view");
498 gl_destroy_thumbs_view(ad);
499 gl_refresh_albums_list(ad);
500 gl_albums_comeback_from_view(ad);
501 } else if (view_mode == GL_VIEW_ALBUMS_EDIT ||
502 view_mode == GL_VIEW_ALBUMS_RENAME) {
503 gl_del_invalid_widgets(ad, GL_INVALID_NONE);
504 gl_ui_edit_cancel(ad);
510 int gl_albums_sel_album(gl_cluster *album_item)
512 GL_CHECK_VAL(album_item, -1);
513 GL_CHECK_VAL(album_item->cluster, -1);
514 GL_CHECK_VAL(album_item->cluster->uuid, -1);
515 GL_CHECK_VAL(album_item->ad, -1);
516 gl_appdata *ad = (gl_appdata *)album_item->ad;
517 GL_CHECK_VAL(ad->albuminfo.cluster_list, -1);
518 GL_CHECK_VAL(ad->albuminfo.cluster_list->clist, -1);
519 int view_mode = gl_get_view_mode(ad);
521 if (view_mode == GL_VIEW_ALBUMS) {
522 gl_dbg("View mode!");
524 gl_dbgW("Wrong view mode");
528 Evas_Object *layout = NULL;
529 char *al_na = album_item->cluster->display_name;
530 Evas_Object *navi = ad->maininfo.naviframe;
531 gl_dbg("current %s album, id=%s", al_na, album_item->cluster->uuid);
533 ad->albuminfo.current_album = album_item;
535 _gl_data_get_item_list(ad, album_item, GL_FIRST_VIEW_START_POS,
536 GL_FIRST_VIEW_END_POS);
538 gl_set_view_mode(ad, GL_VIEW_THUMBS);
539 layout = _gl_ui_create_view_ly(navi);
540 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND,
542 evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
543 Evas_Object *gv = _gl_grid_create_view(ad, layout, GL_GRID_ALL, true);
544 elm_object_part_content_set(layout, "elm.swallow.view", gv);
545 ad->gridinfo.all_view = gv;
546 ad->gridinfo.layout = layout;
548 /* View mode reset, Update view mode */
549 view_mode = gl_get_view_mode(ad);
550 if (view_mode != GL_VIEW_THUMBS) {
551 gl_dbgE("View mode is wrong!");
555 if (_gl_data_is_root_path(ad, album_item->cluster->path)) {
556 /* check root case */
557 al_na = GL_ALBUM_PHOME_ROOT_NAME;
558 } else if (ad->albuminfo.aul_launch_type == GL_AUL_T_VIEW_ALBUM) {
559 /* launch by appsvc */
560 if (ad->albuminfo.aul_file_type == GL_AUL_FILE_T_IMAGE)
561 al_na = GL_ALBUM_IMAGES_NAME;
562 else if (ad->albuminfo.aul_file_type == GL_AUL_FILE_T_VIDEO)
563 al_na = GL_ALBUM_VIDEOS_NAME;
565 al_na = GL_ALBUM_ALL_NAME;
568 /* Checkme: clear albums view for animation effect pause issue */
569 elm_gengrid_clear(ad->albuminfo.view);
571 gl_ui_create_title_and_push(ad, navi, layout, GL_NAVI_THUMBS, al_na);
573 gl_dbg("albums_view 0x%x cleared", ad->albuminfo.view);
575 Evas_Object *bk_btn = NULL;
576 bk_btn = elm_object_item_part_content_get(ad->gridinfo.nf_it,
577 GL_NAVIFRAME_PREB_BTN);
578 elm_object_style_set(bk_btn, GL_BUTTON_STYLE_NAVI_PRE);
579 evas_object_smart_callback_add(bk_btn, "clicked",
580 _gl_albums_comeback_from_view_cb, ad);
582 edje_object_signal_emit(_EDJ(layout),
583 "elm,swallow_view,state,thumb_default", "elm");
584 gl_dbg("Done albums selected");
588 Evas_Object *_gl_albums_add_gengrid(void *data, Evas_Object *parent)
590 GL_CHECK_NULL(parent);
593 Evas_Object *grid = _gl_tile_add_gengrid(data, parent);
594 evas_object_smart_callback_add(grid, "realized", _gl_albums_realized,
596 evas_object_show(grid);
600 Evas_Object *gl_albums_create_view(void *data, Evas_Object *parent)
602 GL_CHECK_NULL(parent);
604 gl_appdata *ad = (gl_appdata *)data;
605 GL_CHECK_NULL(ad->albuminfo.cluster_list);
607 gl_dbg_launch(" gl_albums_create_view:start");
609 gl_albums_free_cover_thumbs(ad);
610 memset(ad->albuminfo.cover_thumbs, 0x00,
611 GL_ALBUM_COVER_THUMB_NUM * sizeof(int));
612 ad->albuminfo.album_medias_cnt = 0;
613 ad->albuminfo.albums_cnt = 0;
615 Evas_Object *grid = _gl_albums_add_gengrid(data, parent);
618 if (ad->maininfo.view_mode != GL_VIEW_THUMBS)
619 _gl_albums_create_items(ad, grid);
621 int view_mode = gl_get_view_mode(ad);
622 gl_dbg("view_mode: %d", view_mode);
624 /* show no contents none album exists */
625 if (gl_check_gallery_empty(ad)) {
626 evas_object_del(grid);
629 /* Set the grid view mode for creating nocontents view */
630 ad->gridinfo.grid_view_mode = GL_GRID_ALBUMS;
631 Evas_Object *noc = _gl_nocontents_create(ad);
632 evas_object_show(noc);
633 ad->albuminfo.nocontents = noc;
637 ad->albuminfo.nocontents = NULL;
640 gl_dbg("gl_albums_create_view:done");
641 gl_dbg_launch(" gl_albums_create_view:end");
646 /* From thumbnails view to albums view */
647 int gl_albums_comeback_from_view(void *data)
650 GL_CHECK_VAL(data, -1);
651 gl_appdata *ad = (gl_appdata *)data;
653 _gl_notify_destroy_notiinfo(ad);
655 gl_set_view_mode(ad, GL_VIEW_ALBUMS);
657 gl_grid_clear_view(ad);
658 gl_list_clear_view(ad);
660 ad->albuminfo.current_album = NULL;
661 gl_albums_update_items(ad);
663 ad->maininfo.seg_mode = GL_CTRL_SEG_ALL;
668 /* From albums edit view to albums view */
669 int gl_albums_change_to_view(void *data)
671 GL_CHECK_VAL(data, -1);
672 gl_appdata *ad = (gl_appdata *)data;
673 GL_CHECK_VAL(ad->albuminfo.cluster_list, -1);
676 ad->albuminfo.albums_cnt = 0;
677 GL_CHECK_VAL(ad->albuminfo.view, -1);
678 gl_set_view_mode(ad, GL_VIEW_ALBUMS);
679 /* changed to show no contents if needed */
680 if (gl_check_gallery_empty(ad)) {
681 if (ad->albuminfo.view)
682 evas_object_del(ad->albuminfo.view);
684 /* Set the grid view mode for creating nocontents view */
685 ad->gridinfo.grid_view_mode = GL_GRID_ALBUMS;
686 Evas_Object *noc = _gl_nocontents_create(ad);
687 ad->albuminfo.nocontents = noc;
688 ad->albuminfo.view = noc;
689 evas_object_show(noc);
691 Evas_Object *old_view = NULL;
692 old_view = elm_object_part_content_unset(ad->albuminfo.layout,
694 evas_object_del(old_view);
695 elm_object_part_content_set(ad->albuminfo.layout,
696 "elm.swallow.view", noc);
698 _gl_albums_create_items(ad, ad->albuminfo.view);
704 /* Update albums view */
705 int gl_albums_update_items(void *data)
707 GL_CHECK_VAL(data, -1);
708 gl_appdata *ad = (gl_appdata *)data;
709 GL_CHECK_VAL(ad->albuminfo.cluster_list, -1);
710 int view_mode = gl_get_view_mode(ad);
711 ad->albuminfo.albums_cnt = 0;
713 /* Changed to show no contents if needed */
714 if (gl_check_gallery_empty(ad)) {
715 /* Set the grid view mode for creating nocontents view */
716 ad->gridinfo.grid_view_mode = GL_GRID_ALBUMS;
717 evas_object_del(ad->albuminfo.view);
719 Evas_Object *noc = _gl_nocontents_create(ad);
720 ad->albuminfo.nocontents = noc;
721 ad->albuminfo.view = noc;
722 evas_object_show(noc);
724 Evas_Object *old_view = NULL;
725 old_view = elm_object_part_content_unset(ad->albuminfo.layout,
727 evas_object_del(old_view);
728 elm_object_part_content_set(ad->albuminfo.layout,
729 "elm.swallow.view", noc);
731 if (view_mode == GL_VIEW_ALBUMS_EDIT) {
732 _gl_albums_create_items(ad, ad->albuminfo.edit_view);
733 /* Display selectioninfo */
734 int cnt = _gl_data_get_albums_selected_cnt(ad);
735 _gl_notify_create_selinfo(ad,
736 ad->albuminfo.edit_layout,
737 ad->albuminfo.nf_it_edit,
738 ad->albuminfo.albums_cnt, cnt,
741 if (ad->albuminfo.nocontents) {
743 * current view is nocontents,
744 * unset it first then create albums view.
746 gl_albums_remove_nocontents(ad);
748 Evas_Object *al_view = NULL;
749 al_view = ad->albuminfo.view;
750 _gl_albums_create_items(ad, al_view);
758 /* Update albums list and refresh albums view, remove invalid widgets */
759 int gl_albums_update_view(void *data)
761 GL_CHECK_VAL(data, -1);
762 gl_appdata *ad = (gl_appdata *)data;
763 int view_mode = gl_get_view_mode(ad);
764 gl_dbg("view_mode: %d.", view_mode);
766 gl_albums_free_cover_thumbs(ad);
767 memset(ad->albuminfo.cover_thumbs, 0x00,
768 GL_ALBUM_COVER_THUMB_NUM * sizeof(int));
769 ad->albuminfo.albums_cnt = 0;
771 if (view_mode == GL_VIEW_ALBUMS) {
772 /* Update albums list*/
773 gl_refresh_albums_list(ad);
775 if (ad->albuminfo.nocontents) {
776 gl_albums_remove_nocontents(ad);
777 } else if (!gl_check_gallery_empty(ad)) {
778 _gl_albums_create_items(ad, ad->albuminfo.view);
779 if (ad->albuminfo.cluster_list->edit_cnt)
780 _gl_ctrl_disable_toolbar_item(ad, false,
784 _gl_ctrl_disable_toolbar_item(ad, true,
788 gl_dbg("View is empty.");
789 gl_albums_update_items(ad);
790 _gl_ctrl_disable_toolbar_item(ad, true, GL_NAVI_ALBUMS,
793 } else if (view_mode == GL_VIEW_ALBUMS_EDIT ||
794 view_mode == GL_VIEW_ALBUMS_RENAME) {
795 if (_gl_data_update_cluster_list(ad) != 0) {
796 gl_dbgE("_gl_data_update_cluster_list failed!");
800 if (gl_check_gallery_empty(ad) ||
801 ad->albuminfo.cluster_list->edit_cnt == 0) {
802 /* Remove invalid widgets */
803 gl_del_invalid_widgets(ad, GL_INVALID_NONE);
805 gl_dbg("Edit view is empty, back to albums view");
806 gl_ui_edit_cancel(ad);
808 _gl_ctrl_disable_toolbar_item(ad, true, GL_NAVI_ALBUMS,
811 int sel_cnt = _gl_data_get_albums_selected_cnt(ad);
812 int invalid_m = GL_INVALID_NONE;
813 /* Album selected for rename was deleted */
814 if (view_mode == GL_VIEW_ALBUMS_RENAME) {
815 if (ad->albuminfo.selected_album == NULL) {
816 gl_dbgW("Rename invalid album!");
817 invalid_m = GL_INVALID_RENAME_ALBUM;
818 /* Remove invalid widgets */
819 gl_del_invalid_widgets(ad, invalid_m);
820 /* Disable control bar buttons */
821 _gl_ctrl_disable_toolbar_items(ad,
822 ad->albuminfo.nf_it_edit,
826 /* Reset view mode */
828 GL_VIEW_ALBUMS_EDIT);
830 } else if (sel_cnt == 0) {
831 /* If none albums selected */
832 gl_dbgW("None albums selected!");
833 /* Disable control bar buttons */
834 _gl_ctrl_disable_toolbar_items(ad,
835 ad->albuminfo.nf_it_edit,
837 /* Remove invalid widgets */
838 gl_del_invalid_widgets(ad, invalid_m);
839 /* Reset view mode */
840 gl_set_view_mode(ad, GL_VIEW_ALBUMS_EDIT);
843 /* Update edit view, other update view in cancel callback */
844 Evas_Object *edit_view = ad->albuminfo.edit_view;
845 if (gl_get_view_mode(ad) == GL_VIEW_ALBUMS_EDIT) {
846 _gl_albums_create_items(ad, edit_view);
847 /* Display selectioninfo */
848 _gl_notify_create_selinfo(ad,
849 ad->albuminfo.edit_layout,
850 ad->albuminfo.nf_it_edit,
851 ad->albuminfo.albums_cnt,
854 /* Cluster list updated, clear view */
855 elm_gengrid_clear(edit_view);
863 * Remove nocontents view and show albums view.
864 * Case 1, gallery is empty->home key tapped
865 * ->take photos with camera->back to gallery;
867 int gl_albums_remove_nocontents(void *data)
869 GL_CHECK_VAL(data, -1);
870 gl_appdata *ad = (gl_appdata *)data;
871 Evas_Object *view = NULL;
874 if (ad->albuminfo.nocontents && !gl_check_gallery_empty(ad)) {
875 gl_dbg("Remove nocontents view then create albums view.");
876 evas_object_del(ad->albuminfo.nocontents);
877 ad->albuminfo.nocontents = NULL;
879 view = gl_albums_create_view(ad, ad->maininfo.naviframe);
880 elm_object_part_content_set(ad->albuminfo.layout,
881 "elm.swallow.view", view);
882 evas_object_show(view);
883 ad->albuminfo.view = view;
885 _gl_ctrl_disable_toolbar_item(ad, false, GL_NAVI_ALBUMS, false);
886 } else if (ad->albuminfo.nocontents) {
887 gl_dbg("Gallery is empty!");
888 bool b_update = false;
889 b_update = _gl_nocontents_update_label(ad->albuminfo.nocontents,
891 /* Update toolbar state */
893 _gl_ctrl_disable_toolbar_item(ad, false,
897 gl_dbg("Nocontents was removed!");
903 int gl_albums_free_cover_thumbs(void *data)
906 GL_CHECK_VAL(data, -1);
907 gl_appdata *ad = (gl_appdata *)data;
910 for (i = 0; i < GL_ALBUM_COVER_THUMB_NUM; i++) {
911 if (ad->albuminfo.cover_thumbs[i]) {
912 _gl_data_destroy_item(ad->albuminfo.cover_thumbs[i]);
913 ad->albuminfo.cover_thumbs[i] = NULL;
920 /* Free resources allocated for albums view */
921 int gl_albums_free_data(void *data)
924 GL_CHECK_VAL(data, -1);
925 gl_appdata *ad = (gl_appdata *)data;
927 gl_albums_free_cover_thumbs(data);
929 if (ad->albuminfo.path) {
930 free(ad->albuminfo.path);
931 ad->albuminfo.path = NULL;
936 int _gl_albums_reset_view(void *data, const char *uuid, const char *aul_type)
938 GL_CHECK_VAL(aul_type, -1);
939 GL_CHECK_VAL(uuid, -1);
940 GL_CHECK_VAL(data, -1);
941 gl_appdata *ad = (gl_appdata *)data;
942 int view_mode = gl_get_view_mode(ad);
944 gl_cluster *album = ad->albuminfo.current_album;
945 if (album && album->cluster && album->cluster->uuid) {
946 bool b_cur_album_exists = false;
947 if (!g_strcmp0(album->cluster->uuid, uuid)) {
950 ret = _gl_data_get_item_cnt(ad, uuid,
951 album->cluster->type,
953 if (ret != 0 || its_cnt == 0)
954 gl_dbgE("Empty current album!");
956 b_cur_album_exists = true;
959 /* Current album exists and it's not empty */
960 if (b_cur_album_exists) {
961 gl_dbg("Current album, update view");
962 if (view_mode == GL_VIEW_THUMBS_EDIT ||
963 view_mode == GL_VIEW_VIDEOLIST_EDIT) {
964 gl_del_invalid_widgets(ad, GL_INVALID_NONE);
965 /* Set flag to update albums list */
966 ad->albuminfo.update_albums_list = true;
967 gl_ui_edit_cancel(ad);
969 gl_update_view(ad, GL_UPDATE_VIEW_NORMAL);
976 __gl_albums_reset_view(ad);