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.
20 #include "gl-ui-util.h"
22 #include "gl-ext-ug-load.h"
23 #include "gl-ext-exec.h"
24 #include "gl-button.h"
25 #include "gl-gridview.h"
26 #include "gl-controlbar.h"
27 #include "gl-albums.h"
28 #include "gl-listview.h"
31 #include "gl-thread-util.h"
33 #include "gl-progressbar.h"
34 #include "gl-strings.h"
36 #include "gl-nocontents.h"
37 #include "gl-notify.h"
38 #include "gl-editfield.h"
40 #define GL_TRANS_FINISHED "transition,finished"
43 static int __gl_ui_add_more_btn(void *data, Elm_Object_Item *nf_it,
45 /*static int __gl_ui_remove_more_btn(Elm_Object_Item *nf_it);*/
49 * Check album name is valid and remove unuseful characters
50 * 1) not only includes space;
51 * 2) contains invalid character;
55 * true: add a new album ; false: rename a album.
57 * true: Enter key pressed ; false: Button Done clicked.
60 static int _gl_ui_get_valid_album_name(void *data, char* album_name,
61 bool b_new, bool b_enter)
63 GL_CHECK_VAL(album_name, -1);
64 GL_CHECK_VAL(data, -1);
65 gl_appdata* ad = (gl_appdata*)data;
67 gl_dbg("Input album name: %s", album_name);
69 popup_desc = (char*)calloc(GL_POPUP_STRING_MAX, sizeof(char));
70 if (popup_desc == NULL) {
71 gl_dbg("memory allocation fail");
74 /* Check album name length */
75 if (strlen(album_name) == 0) {
76 gl_dbgW("Inserted text is empty!");
78 gl_dbg("Enter key pressed.");
79 goto INVALID_ALBUM_NAME;
83 mode = GL_POPUP_ALBUM_NEW_EMPTY;
85 mode = GL_POPUP_ALBUM_RENAME_EMPTY;
86 snprintf(popup_desc, GL_POPUP_STRING_MAX, "%s.<br>%s",
87 GL_STR_ENTRY_IS_EMPTY, GL_STR_RETRY_Q);
88 popup_desc[strlen(popup_desc)] = '\0';
89 gl_popup_create_popup(ad, mode, popup_desc);
90 goto INVALID_ALBUM_NAME;
92 gl_dbg("Inserted album name: %s, length: %d", album_name, strlen(album_name));
94 /* Removes leading and trailing whitespace */
95 g_strstrip((gchar*)album_name);
96 if (strlen(album_name) == 0) {
97 gl_dbgW("Album name includes only space!");
99 gl_dbg("Enter key pressed.");
100 goto INVALID_ALBUM_NAME;
104 mode = GL_POPUP_ALBUM_NEW_EMPTY;
106 mode = GL_POPUP_ALBUM_RENAME_EMPTY;
107 snprintf(popup_desc, GL_POPUP_STRING_MAX, "%s.<br>%s",
108 GL_STR_INVALID_INPUT_PARAMETER, GL_STR_RETRY_Q);
109 popup_desc[strlen(popup_desc)] = '\0';
110 gl_popup_create_popup(ad, mode, popup_desc);
111 goto INVALID_ALBUM_NAME;
114 /* Check if there is any invalid character in string */
115 if (gl_validate_album_name(album_name) == false) {
116 gl_dbgW("Album name includes invalid character!");
118 mode = GL_POPUP_ALBUM_NEW_INVALID;
120 mode = GL_POPUP_ALBUM_RENAME_INVALID;
121 snprintf(popup_desc, GL_POPUP_STRING_MAX, "%s.<br>%s",
122 GL_STR_INVALID_INPUT_PARAMETER, GL_STR_RETRY_Q);
123 popup_desc[strlen(popup_desc)] = '\0';
124 gl_popup_create_popup(ad, mode, popup_desc);
125 goto INVALID_ALBUM_NAME;
137 #ifdef _RENAME_ALBUM_SENSITIVE
138 static bool __gl_ui_check_album_name_case(char *dir)
143 char dest_dir[GL_DIR_PATH_LEN_MAX] = {0};
144 char dest_filename[GL_FILE_NAME_LEN_MAX] = {0};
146 tmp = strrchr(dir, '/');
148 g_strlcpy(dest_filename, tmp + 1, GL_FILE_NAME_LEN_MAX);
150 g_strlcpy(dest_dir, dir, GL_DIR_PATH_LEN_MAX);
157 Eina_List *name_list = NULL;
158 if((name_list = ecore_file_ls(dest_dir)) == NULL) {
159 gl_dbgE("open dir failed!");
162 char *dir_name = NULL;
163 EINA_LIST_FREE(name_list, dir_name) {
164 if (strcasecmp(dir_name, dest_filename) == 0) {
165 gl_dbg("Have same name directory");
176 static int _gl_ui_cancel_newalbum(void *data)
178 GL_CHECK_VAL(data, -1);
179 gl_appdata *ad = (gl_appdata *)data;
182 elm_naviframe_item_pop(ad->maininfo.naviframe);
183 _gl_editfield_destroy_imf(ad);
185 gl_ui_update_select_widgets(ad);
191 * True: Enter key on Keyboard pressed, False: Button Done clicked
193 int _gl_ui_newalbum_done(void *data, bool b_enter)
195 gl_dbg("b_enter: %d", b_enter);
196 GL_CHECK_VAL(data, -1);
197 gl_appdata *ad = (gl_appdata *)data;
199 if (ad->entryinfo.editfield == NULL) {
200 gl_dbgE("Edit filed is NULL");
201 goto NEW_ALBUM_FAILED;
204 if (ad->entryinfo.imf_context)
205 ecore_imf_context_input_panel_hide(ad->entryinfo.imf_context);
207 Evas_Object *entry = ad->entryinfo.imf_entry;
208 char album_name[GL_ALBUM_NAME_LEN_MAX] = { 0, };
210 /* Get utf8 format string */
211 if (gl_get_entry_text(entry, album_name, GL_ALBUM_NAME_LEN_MAX) != 0) {
212 gl_dbgE("Get entry text failed!");
213 goto NEW_ALBUM_FAILED;
217 if (_gl_ui_get_valid_album_name(ad, album_name, true, b_enter) != 0) {
219 _gl_editfield_hide_imf(ad);
222 gl_dbg("Valid album name: %s", album_name);
224 /* Check whether the new folder exist */
225 char path[GL_DIR_PATH_LEN_MAX] = { 0, };
226 char dir_path[GL_DIR_PATH_LEN_MAX] = { 0, };
228 /* Get default images path, make new album under it */
229 if (gl_get_default_images_path(dir_path) != 0) {
230 gl_dbgE("Failed to get default image dir path!");
231 goto NEW_ALBUM_FAILED;
234 /* Make dir full path of new album */
235 snprintf(path, GL_DIR_PATH_LEN_MAX, "%s/%s", dir_path, album_name);
236 path[strlen(path)] = '\0';
237 gl_dbg("New dir path: %s", path);
238 #ifdef _RENAME_ALBUM_SENSITIVE
239 bool res = __gl_ui_check_album_name_case(path);
240 gl_dbg("__gl_ui_check_album_name_case : %d", res);
243 int res = ecore_file_dir_is_empty(path);
245 * If dir is empty, 1 is returned,
246 * if it contains at least 1 file, 0 is returned.
247 * On failure, -1 is returned.
249 gl_dbg("ecore_file_dir_is_empty return value: %d", res);
254 popup_desc = (char*)calloc(GL_POPUP_STRING_MAX, sizeof(char));
255 if (popup_desc == NULL) {
256 gl_dbg("memory allocation fail");
260 snprintf(popup_desc, GL_POPUP_STRING_MAX, "%s.<br>%s",
261 GL_STR_SAME_NAME_ALREADY_IN_USE, GL_STR_RETRY_Q);
262 popup_desc[strlen(popup_desc)] = '\0';
263 gl_popup_create_popup(ad, GL_POPUP_ALBUM_NEW_DUPLICATE,
266 gl_dbgW("New folder already exists and not NULL, return!");
270 /* Save new album name */
271 char* new_album = ad->albuminfo.new_album_name;
272 g_strlcpy(new_album, album_name, GL_ALBUM_NAME_LEN_MAX);
273 new_album[GL_ALBUM_NAME_LEN_MAX - 1] = '\0';
274 _gl_editfield_destroy_imf(ad);
276 /* Move/Save files to dest album */
277 gl_move_to_album(ad);
281 _gl_ui_cancel_newalbum(ad);
285 static void _gl_ui_newalbum_done_cb(void *data, Evas_Object *obj, void *event_info)
288 /* Delete callback when it is clicked to prevent it is called for many times */
289 evas_object_smart_callback_del(obj, "clicked", _gl_ui_newalbum_done_cb);
291 _gl_ui_newalbum_done(data, false);
294 static void _gl_ui_newalbum_cancel_cb(void *data, Evas_Object *obj, void *event_info)
298 /* Delete callback when it is clicked to prevent it is called for many times */
299 evas_object_smart_callback_del(obj, "clicked",
300 _gl_ui_newalbum_cancel_cb);
302 _gl_ui_cancel_newalbum(data);
308 static void __gl_ui_camera_cb(void *data, Evas_Object *obj, void *event_info)
312 _gl_ext_load_camera();
315 static int __gl_ui_cancel_rename_album(void *data)
317 GL_CHECK_VAL(data, -1);
318 gl_appdata *ad = (gl_appdata *)data;
319 GL_CHECK_VAL(ad->maininfo.naviframe, -1);
322 ad->albuminfo.selected_album = NULL;
323 gl_set_view_mode(ad, GL_VIEW_ALBUMS_EDIT);
324 /* manually popup view after rename album */
325 elm_naviframe_item_pop(ad->maininfo.naviframe);
326 _gl_editfield_destroy_imf(ad);
328 /* Update edit view */
329 gl_albums_update_items(ad);
333 static void __gl_ui_rename_album_cancel_cb(void *data, Evas_Object *obj, void *event_info)
337 /* Delete callback when it is clicked to prevent it is called for many times */
338 evas_object_smart_callback_del(obj, "clicked",
339 __gl_ui_rename_album_cancel_cb);
341 __gl_ui_cancel_rename_album(data);
346 * True: Enter key on Keyboard pressed, False: Button Done clicked
348 int _gl_ui_rename_album_done(void *data, bool b_enter)
350 gl_dbg("b_enter: %d", b_enter);
351 GL_CHECK_VAL(data, -1);
352 gl_appdata *ad = (gl_appdata *)data;
353 bool b_root_path = false;
354 gl_cluster *album_item = NULL;
356 if (gl_get_view_mode(ad) != GL_VIEW_ALBUMS_RENAME) {
357 gl_dbgE("View mode is wrong!");
361 album_item = ad->albuminfo.selected_album;
362 if (album_item == NULL || album_item->cluster == NULL ||
363 album_item->cluster->uuid == NULL) {
364 gl_dbgE("selected_album is NULL!");
368 char etxt[GL_FILE_NAME_LEN_MAX] = { 0, };
369 /* Get utf8 format string */
371 ret = gl_get_entry_text(ad->entryinfo.imf_entry, etxt,
372 GL_FILE_NAME_LEN_MAX);
374 gl_dbgE("Get entry text failed!");
379 if (_gl_ui_get_valid_album_name(ad, etxt, false, b_enter) != 0) {
381 _gl_editfield_hide_imf(ad);
385 gl_dbg("Valid album name: %s", etxt);
386 /* Get src folder path */
387 char src_dir_path[GL_DIR_PATH_LEN_MAX] = { 0, };
388 if (album_item->cluster->path) {
389 g_strlcpy(src_dir_path, album_item->cluster->path,
390 GL_DIR_PATH_LEN_MAX);
391 gl_dbg("Src folder: %s", src_dir_path);
392 if (_gl_data_is_root_path(ad, src_dir_path)) {
394 * Root path, couldn't rename root path,
395 * make the new dest folder
396 * and move all files for root path to it.
398 gl_dbg("Rename [No Name] album's name.");
402 gl_dbgE("gl_db_get_folder_fullpath failed(%d)!", ret);
406 /* Get dest folder path */
407 char dest_dir_path[GL_DIR_PATH_LEN_MAX] = { 0, };
410 /* Get default images path, make dest foler under it */
411 char default_dir_path[GL_DIR_PATH_LEN_MAX] = { 0, };
412 if (gl_get_default_images_path(default_dir_path) != 0) {
413 gl_dbgW("Failed to get default images path!");
417 snprintf(dest_dir_path, GL_DIR_PATH_LEN_MAX, "%s/%s",
418 default_dir_path, etxt);
419 dest_dir_path[strlen(dest_dir_path)] = '\0';
424 memcpy(dest_dir_path, src_dir_path, GL_DIR_PATH_LEN_MAX);
425 length = strlen(src_dir_path);
427 for (i = length; i >= 0; i--) {
428 if (dest_dir_path[i] == '/') {
429 gl_dbg("length=%d, i=%d", length, i);
430 /* Path like "/root/abc/" */
433 memcpy(&dest_dir_path[i + 1], etxt,
435 dest_dir_path[i + 1+ strlen(etxt)] = '\0';
441 gl_dbg("Dest folder: %s", dest_dir_path);
442 #ifdef _RENAME_ALBUM_SENSITIVE
443 if (!strcasecmp(src_dir_path, dest_dir_path))
445 if (!g_strcmp0(src_dir_path, dest_dir_path))
448 gl_dbgW("Same as current name!");
453 * If dir is empty, 1 is returned,
454 * if it contains at least 1 file, 0 is returned.
455 * On failure, -1 is returned.
457 #ifdef _RENAME_ALBUM_SENSITIVE
458 if (__gl_ui_check_album_name_case(dest_dir_path))
460 if (ecore_file_dir_is_empty(dest_dir_path) == 0 ||
461 ecore_file_dir_is_empty(dest_dir_path) == 1)
465 popup_desc = (char*)calloc(GL_POPUP_STRING_MAX, sizeof(char));
466 if (popup_desc == NULL) {
467 gl_dbg("memory allocation fail");
471 snprintf(popup_desc, GL_POPUP_STRING_MAX, "%s.<br>%s",
472 GL_STR_SAME_NAME_ALREADY_IN_USE, GL_STR_RETRY_Q);
473 popup_desc[strlen(popup_desc)] = '\0';
474 gl_popup_create_popup(ad, GL_POPUP_ALBUM_RENAME_DUPLICATE,
477 gl_dbgW("New folder already exists and not NULL, return!");
483 * Case 1: Rename virtual album 'No Name'.
484 * It couldn't be done by updating album record in DB directly.
485 * Cuz it would change the folder path of all folder records,
486 * to make them invalid.
488 * Create new folder under default images path,
489 * Move all medias under root path to new folder.
491 if (gl_make_new_album(etxt) != 0) {
492 gl_popup_create_popup(ad, GL_POPUP_NOBUT,
493 GL_STR_UNABLE_tO_RENAME);
494 gl_dbgE("Failed to make a new directory!");
498 /* Move medias from 'No Name' album to new album */
499 if (gl_move_root_album(ad, album_item, dest_dir_path) != 0) {
500 gl_dbg("gl_move_root_album failed!");
501 gl_popup_create_popup(ad, GL_POPUP_NOBUT,
502 GL_STR_UNABLE_tO_RENAME);
505 gl_dbg("New album added, update albums list.");
506 ad->albuminfo.selected_album = NULL;
507 _gl_data_update_cluster_list(ad);
511 * Case 2: Rename normal album.
513 * Update album record in DB.
515 media_folder_set_name(album_item->cluster->folder_h, etxt);
516 ret = media_folder_update_to_db(album_item->cluster->folder_h);
518 gl_dbg("media_folder_set_name failed (%d)!", ret);
523 * Change folder name in file system
524 * for some special name, DB update success, but file mv failed.
527 if (ecore_file_exists(src_dir_path)) {
528 if (!ecore_file_mv(src_dir_path, dest_dir_path))
529 gl_dbg("ecore_file_mv failed!");
531 gl_dbgW("Source folder path doesn't exist!");
536 FREE_DATA(album_item->cluster->display_name);
537 album_item->cluster->display_name = strdup(etxt);
539 __gl_ui_cancel_rename_album(ad);
543 __gl_ui_cancel_rename_album(ad);
547 static void __gl_ui_rename_album_done_cb(void *data, Evas_Object *obj, void *event_info)
550 /* Delete callback when it is clicked to prevent it is called for many times */
551 evas_object_smart_callback_del(obj, "clicked",
552 __gl_ui_rename_album_done_cb);
553 _gl_ui_rename_album_done(data, false);
556 /* Select-all checkbox selected/deselected */
557 static void _gl_ui_selall_check_changed(void *data, Evas_Object *obj,
562 gl_appdata *ad = (gl_appdata *)data;
563 int view_mode = gl_get_view_mode(ad);
564 gl_dbg("view_mode: %d.", view_mode);
566 gl_item *current = NULL;
570 Eina_Bool state = EINA_FALSE;
571 state = elm_check_state_get(obj);
572 gl_dbg("Checkbox state: %d.", state);
574 if (view_mode == GL_VIEW_ALBUMS_EDIT) {
575 gl_cluster *album = NULL;
576 Elm_Object_Item *first_it = NULL;
577 Elm_Object_Item *next_it = NULL;
578 Elm_Object_Item *last_it = NULL;
579 first_it = elm_gengrid_first_item_get(ad->albuminfo.edit_view);
580 last_it = elm_gengrid_last_item_get(ad->albuminfo.edit_view);
584 album = (gl_cluster *)elm_object_item_data_get(first_it);
586 gl_dbgE("Invalid item data!");
589 /* Update checkbox state */
590 album->checked = state;
591 /* Update selected list */
592 if (state == EINA_TRUE)
593 _gl_data_albums_selected_list_append(ad, album);
595 _gl_data_albums_selected_list_remove(ad, album);
597 elm_gengrid_item_update(first_it);
598 /* Update selected album count */
601 if (last_it == first_it) {
602 gl_dbg("Update done!");
605 next_it = elm_gengrid_item_next_get(first_it);
611 /* Get all medias count of current album */
612 item_cnt = ad->maininfo.medias_cnt;
613 sel_all_cnt = item_cnt;
614 gl_ctrl_seg_mode seg_mode = ad->maininfo.seg_mode;
615 media_content_type_e file_type = MEDIA_CONTENT_TYPE_IMAGE;
616 if (view_mode == GL_VIEW_THUMBS_EDIT)
618 if (seg_mode == GL_CTRL_SEG_IMAGES)
620 file_type = MEDIA_CONTENT_TYPE_IMAGE;
623 else if (seg_mode == GL_CTRL_SEG_VIDEOS)
625 file_type = MEDIA_CONTENT_TYPE_VIDEO;
629 else if (view_mode == GL_VIEW_VIDEOLIST_EDIT)
631 file_type = MEDIA_CONTENT_TYPE_VIDEO;
635 gl_dbg("seg_mode=%d", seg_mode);
636 for (i = 0; i < item_cnt; i++)
638 _gl_data_get_item_by_index(ad, i + 1, false, ¤t);
640 GL_CHECK(current->item);
642 if (current->checked == state && seg_mode == GL_CTRL_SEG_ALL)
647 if (view_mode == GL_VIEW_THUMBS_EDIT)
649 if ((seg_mode == GL_CTRL_SEG_IMAGES) ||
650 (seg_mode == GL_CTRL_SEG_VIDEOS))
652 if (current->item->type != file_type)
658 if (current->checked == state)
664 else if (view_mode == GL_VIEW_VIDEOLIST_EDIT)
666 if (current->item->type != file_type)
672 if (current->checked == state)
678 current->checked = state;
680 if (view_mode == GL_VIEW_THUMBS_EDIT)
681 elm_gengrid_item_update(current->elm_item);
683 if (state == EINA_TRUE)
684 _gl_data_selected_list_append(ad, current);
686 _gl_data_selected_list_remove(ad, current);
691 /* Update all realized items */
692 if (view_mode == GL_VIEW_VIDEOLIST_EDIT)
693 elm_genlist_realized_items_update(ad->gridinfo.edit_view);
695 /* Recreate selection info for both cases */
696 if (state == EINA_FALSE)
699 if (view_mode == GL_VIEW_ALBUMS_EDIT) {
700 _gl_notify_create_selinfo(ad, ad->albuminfo.edit_layout,
701 ad->albuminfo.nf_it_edit, item_cnt,
704 _gl_notify_create_selinfo(ad, ad->gridinfo.edit_layout,
705 ad->gridinfo.nf_it_edit, item_cnt,
710 /* Select-all background click, selected/deselected checkbox */
711 static void _gl_ui_selall_bg_click_cb(void *data, Evas_Object *o,
712 const char *emission,
716 gl_appdata *ad = (gl_appdata *)data;
717 int view_mode = gl_get_view_mode(ad);
718 Evas_Object *ly = NULL;
719 gl_dbg("view_mode: %d.", view_mode);
721 if (view_mode == GL_VIEW_THUMBS_EDIT ||
722 view_mode == GL_VIEW_VIDEOLIST_EDIT) {
723 ly = ad->gridinfo.edit_layout;
724 } else if (view_mode == GL_VIEW_ALBUMS_EDIT) {
726 ly = ad->albuminfo.edit_layout;
728 gl_dbgE("Wrong view!");
732 Evas_Object *check = elm_object_part_content_get(ly, "selectall_check");
734 Eina_Bool new_state = EINA_FALSE;
735 Eina_Bool ck_state = elm_check_state_get(check);
737 if (ck_state == EINA_FALSE)
738 new_state = EINA_TRUE;
740 elm_check_state_set(check, new_state);
742 _gl_ui_selall_check_changed(ad, check, NULL);
744 gl_dbgE("Get select all checkbox object failed!");
748 static int __gl_ui_cancel_edit(void *data)
750 GL_CHECK_VAL(data, -1);
751 gl_appdata *ad = (gl_appdata *)data;
752 int view_mode = gl_get_view_mode(ad);
755 if (view_mode == GL_VIEW_ALBUMS_EDIT)
757 _gl_destroy_albums_edit_view(ad);
759 _gl_data_finalize_albums_selected_list(ad);
761 * after back to albums view from albums edit view,
762 * option header should be defaultly closed
765 _gl_data_get_cluster_list(ad);
766 GL_CHECK_VAL(ad->albuminfo.cluster_list, -1);
768 gl_albums_change_to_view(ad);
769 _gl_notify_destroy_selinfo(ad);
770 if (gl_check_gallery_empty(ad)) {
771 _gl_ctrl_disable_toolbar_item(ad, true, GL_NAVI_ALBUMS,
774 if (ad->albuminfo.cluster_list->edit_cnt == 0) {
775 gl_dbg("None editable albums, disable items.");
776 _gl_ctrl_disable_toolbar_item(ad, true,
782 else if (view_mode == GL_VIEW_THUMBS_EDIT)
784 _gl_destroy_thumbs_edit_view(ad);
785 _gl_data_selected_list_finalize(ad);
787 gl_set_view_mode(ad, GL_VIEW_THUMBS);
789 if (ad->albuminfo.update_albums_list)
792 * Update albums list if MMC added/removed,
794 ad->albuminfo.update_albums_list = false;
795 gl_refresh_albums_list(ad);
798 gl_grid_change_to_view(ad);
799 _gl_notify_destroy_selinfo(ad);
800 } else if (view_mode == GL_VIEW_VIDEOLIST_EDIT) {
801 _gl_destroy_thumbs_edit_view(ad);
802 _gl_data_selected_list_finalize(ad);
803 gl_set_view_mode(ad, GL_VIEW_VIDEOLIST);
805 if (ad->albuminfo.update_albums_list)
808 * Update albums list if MMC added/removed
810 ad->albuminfo.update_albums_list = false;
811 gl_refresh_albums_list(ad);
814 gl_list_change_to_view(ad);
815 _gl_notify_destroy_selinfo(ad);
820 /* callback after user tap Cancel button in option header in edit view */
821 static void __gl_ui_click_cancel_edit_cb(void *data, Evas_Object *obj, void *event_info)
825 gl_appdata *ad = (gl_appdata *)data;
827 /* Disable item when it is clicked to prevent it is called for many times */
828 _gl_ctrl_disable_item((Elm_Object_Item *)event_info);
830 elm_naviframe_item_pop(ad->maininfo.naviframe);
832 #ifdef _USE_ROTATE_BG
833 ad->gridinfo.left_btn = NULL;
834 ad->gridinfo.right_btn = NULL;
835 ad->gridinfo.more_btn = NULL;
837 __gl_ui_cancel_edit(data);
841 static void _gl_ui_edit_cb(void *data, Evas_Object *obj, void *event_info)
844 gl_appdata *ad = (gl_appdata *)data;
845 if (ad->uginfo.ug_called_by_me || ad->gridinfo.grid_append_idler) {
847 * Prevent changed to edit view in wrong way.
848 * 1. When invoke imageviewer UG;
849 * 2. First show thumbnails view, use idler to append other medias.
851 gl_dbgW("UG invoked or appending gridview!");
855 int view_mode = gl_get_view_mode(ad);
856 gl_dbg("mode: %d", view_mode);
857 if (view_mode == GL_VIEW_THUMBS_EDIT) {
859 * Happen in quickly tap edit button,
860 * it will invoke _gl_ui_edit_cb several time
861 * and push some unuseful views.
863 gl_dbgW("Already in edit mode, return!");
867 _gl_notify_destroy_notiinfo(ad);
869 Evas_Object *layout = NULL;
870 Evas_Object *view = NULL;
872 if (view_mode == GL_VIEW_ALBUMS) {
873 gl_set_view_mode(ad, GL_VIEW_ALBUMS_EDIT);
875 layout = _gl_ui_create_view_ly(ad->maininfo.naviframe);
877 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND,
879 evas_object_size_hint_align_set(layout, EVAS_HINT_FILL,
881 ad->albuminfo.edit_layout = layout;
883 view = gl_albums_create_view(ad, layout);
884 ad->albuminfo.edit_view = view;
886 edje_object_signal_emit(_EDJ(layout),
887 "elm,swallow_view,state,edit", "elm");
889 gl_ui_create_title_and_push(ad, ad->maininfo.naviframe, layout,
891 GL_STR_SELECT_ALBUM);
893 elm_object_part_content_set(layout, "elm.swallow.view", view);
894 /* Display 'Select all' widget */
895 gl_ui_show_selall(ad);
901 layout = _gl_ui_create_view_ly(ad->maininfo.naviframe);
903 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND,
905 evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
906 ad->gridinfo.edit_layout = layout;
908 if (view_mode == GL_VIEW_THUMBS) {
909 gl_set_view_mode(ad, GL_VIEW_THUMBS_EDIT);
910 if (ad->gridinfo.grid_view_mode == GL_GRID_ALL)
911 view = _gl_grid_create_view(ad, layout,
915 view = _gl_grid_create_view(ad, layout,
918 } else if (view_mode == GL_VIEW_VIDEOLIST) {
919 gl_set_view_mode(ad, GL_VIEW_VIDEOLIST_EDIT);
920 view = gl_list_create_view(ad, layout);
924 gl_dbgE("View creation failed!");
925 evas_object_del(layout);
926 ad->gridinfo.edit_layout = NULL;
930 ad->gridinfo.edit_view = view;
932 elm_object_part_content_set(layout, "elm.swallow.view", view);
934 gl_ui_create_title_and_push(ad, ad->maininfo.naviframe, layout,
935 GL_NAVI_THUMBS_EDIT, GL_STR_SELECT_ITEM);
936 edje_object_signal_emit(_EDJ(layout), "elm,swallow_view,state,edit",
938 gl_ui_show_selall(ad);
943 static void _gl_ui_share_cb(void *data, Evas_Object *obj, void *event_info)
946 gl_appdata *ad = (gl_appdata *)data;
949 if (ad->uginfo.ug_called_by_me || ad->uginfo.app_called_by_me)
951 gl_dbg("UG or APP is already loaded, return.");
955 int view_mode = gl_get_view_mode(ad);
957 if ((view_mode == GL_VIEW_THUMBS_EDIT) ||
958 (view_mode == GL_VIEW_VIDEOLIST_EDIT)) {
959 cnt = _gl_data_selected_list_count(ad);
961 gl_dbg("No thumbs selected, return!");
962 gl_popup_create_popup(ad, GL_POPUP_NOBUT,
963 GL_STR_NO_FILES_SELECTED);
967 gl_popup_create_title_popup(ad, GL_POPUP_THUMB_SHARE,
969 } else if (view_mode == GL_VIEW_ALBUMS_EDIT) {
970 cnt = _gl_data_get_albums_selected_cnt(ad);
972 gl_dbg("No albums selected, return!");
973 gl_popup_create_popup(ad, GL_POPUP_NOBUT,
974 GL_STR_NO_ALBUMS_SELECTED);
977 /* Check albums are empty */
978 if (_gl_data_is_albums_selected_empty(ad)) {
979 gl_dbg("No thumbs selected, return!");
980 gl_popup_create_popup(ad, GL_POPUP_NOBUT,
981 GL_STR_NO_FILES_SELECTED);
985 gl_popup_create_title_popup(ad, GL_POPUP_ALBUM_SHARE,
988 gl_dbgE("Unknow mode!");
992 /* move media to album in edit view */
993 int gl_ui_move_media_to_album(gl_appdata *ad)
995 GL_CHECK_VAL(ad, -1);
996 int view_mode = gl_get_view_mode(ad);
999 if (ad->uginfo.ug_called_by_me || ad->uginfo.app_called_by_me)
1001 gl_dbg("UG or APP is already loaded, return.");
1005 if ((view_mode == GL_VIEW_THUMBS_EDIT) ||
1006 (view_mode == GL_VIEW_VIDEOLIST_EDIT))
1009 int cnt = _gl_data_selected_list_count(ad);
1012 gl_dbg("No thumbs selected, return!");
1013 gl_popup_create_popup(ad, GL_POPUP_NOBUT,
1014 GL_STR_NO_FILES_SELECTED);
1018 gl_popup_create_title_popup(ad, GL_POPUP_THUMB_MOVE,
1024 gl_dbg("Unknow mode!");
1029 static void _gl_ui_medias_del_cb(void *data, Evas_Object *obj, void *event_info)
1032 gl_appdata *ad = (gl_appdata *)data;
1035 if (ad->uginfo.ug_called_by_me || ad->uginfo.app_called_by_me)
1037 gl_dbg("UG or APP is already loaded, return.");
1041 int view_mode = gl_get_view_mode(ad);
1042 if ((view_mode == GL_VIEW_THUMBS_EDIT) ||
1043 (view_mode == GL_VIEW_VIDEOLIST_EDIT)) {
1044 int cnt = _gl_data_selected_list_count(ad);
1047 gl_dbg("No thumbs selected, return!");
1048 gl_popup_create_popup(ad, GL_POPUP_NOBUT, GL_STR_NO_FILES_SELECTED);
1054 gl_dbgW("Unknow mode!");
1058 static void _gl_ui_albums_del_cb(void *data, Evas_Object *obj, void *event_info)
1061 gl_appdata *ad = (gl_appdata *)data;
1064 if ((gl_get_view_mode(ad) == GL_VIEW_ALBUMS_EDIT))
1066 int cnt = _gl_data_get_albums_selected_cnt(ad);
1069 gl_dbg("No albums selected, return!");
1070 gl_popup_create_popup(ad, GL_POPUP_NOBUT,
1071 GL_STR_NO_ALBUMS_SELECTED);
1074 gl_popup_create_albums_del_popup(ad);
1078 gl_dbg("Unknow mode!");
1083 * Update checkbox state in select-all widget
1085 int _gl_ui_update_selall(void *data, int all_cnt, int selected_cnt)
1087 GL_CHECK_VAL(data, -1);
1088 gl_appdata *ad = (gl_appdata *)data;
1090 gl_item *gitem = NULL;
1093 gl_ctrl_seg_mode ctl_seg = GL_CTRL_SEG_ALL;
1094 media_content_type_e file_type = MEDIA_CONTENT_TYPE_IMAGE;
1095 int view_mode = gl_get_view_mode(ad);
1096 Evas_Object *ly = NULL;
1098 if (view_mode == GL_VIEW_THUMBS_EDIT ||
1099 view_mode == GL_VIEW_VIDEOLIST_EDIT) {
1100 /* Get all medias count */
1101 db_all_cnt = ad->maininfo.medias_cnt;
1102 ctl_seg = ad->maininfo.seg_mode;
1103 if (ctl_seg == GL_CTRL_SEG_ALL) {
1104 _all_cnt = db_all_cnt;
1106 /* Get all count in diff segments */
1107 if (ctl_seg == GL_CTRL_SEG_IMAGES)
1108 file_type = MEDIA_CONTENT_TYPE_IMAGE;
1109 else if (ctl_seg == GL_CTRL_SEG_VIDEOS)
1110 file_type = MEDIA_CONTENT_TYPE_VIDEO;
1112 for (i = 1; i <= db_all_cnt; i++) {
1113 _gl_data_get_item_by_index(ad, i, false, &gitem);
1114 if (gitem && gitem->item &&
1115 (gitem->item->type == file_type))
1120 ly = ad->gridinfo.edit_layout;
1121 } else if (view_mode == GL_VIEW_ALBUMS_EDIT) {
1122 _all_cnt = ad->albuminfo.albums_cnt;
1123 ly = ad->albuminfo.edit_layout;
1125 gl_dbg("Wrong view mode!");
1130 * Set checkbox state
1131 * except in albums edit view and selectioninfo view
1133 gl_dbg("selected_cnt/_all_cnt = %d/%d", selected_cnt, _all_cnt);
1134 Evas_Object *check = NULL;
1135 Eina_Bool state = EINA_FALSE;
1136 /* Set checkbox checked/unchecked */
1137 if (selected_cnt == _all_cnt)
1142 check = elm_object_part_content_get(ly, "selectall_check");
1144 elm_check_state_set(check, state);
1148 int _gl_ui_hide_back_button(Elm_Object_Item *nf_it)
1150 GL_CHECK_VAL(nf_it, -1);
1151 elm_object_item_part_content_set(nf_it, GL_NAVIFRAME_PREB_BTN, NULL);
1155 static void __gl_ui_move_cb(void *data, Evas_Object *obj, void *event_info)
1158 gl_ui_move_media_to_album(data);
1162 /* pause gallery and change view to background after tap Back button in albums view */
1163 static void __gl_ui_change_to_background_cb(void *data, Evas_Object * obj, void *event_info)
1166 gl_appdata *ad = (gl_appdata *)data;
1167 GL_CHECK(ad->maininfo.win);
1169 gl_dbg("Back button clicked, change view to background.");
1170 Evas_Object *win = (Evas_Object *) (ad->maininfo.win);
1172 /*Fix core dump. When gallery is launching , quick click back button before
1173 *album items show, occur core dump. So before pause gallery, set text_get
1174 *and content_get to NULL to stop show album items
1176 ad->albuminfo.albumgic.func.text_get = NULL;
1177 ad->albuminfo.albumgic.func.content_get = NULL;
1179 ad->albuminfo.albumgic_blue.func.text_get = NULL;
1180 ad->albuminfo.albumgic_blue.func.content_get = NULL;
1188 * When push albums view for the first time, albums list is empty.
1189 * After albums list got from DB then update edit item state.
1191 static int __gl_ui_add_toolbar_items_albums(void *data, Evas_Object *bot_bar)
1194 GL_CHECK_VAL(bot_bar, -1);
1195 GL_CHECK_VAL(data, -1);
1196 gl_appdata *ad = (gl_appdata *)data;
1197 Elm_Object_Item *edit_it = NULL;
1198 Elm_Object_Item *camera_it = NULL;
1200 /* add 'Camera' item */
1201 camera_it = elm_toolbar_item_append(bot_bar, GL_CBAR_ICON_CAMERA,
1202 NULL, __gl_ui_camera_cb, ad);
1203 ad->albuminfo.camera_it = camera_it;
1205 _gl_ctrl_append_object_item(bot_bar, NULL);
1207 edit_it = _gl_ui_append_edit(ad, bot_bar);
1208 _gl_ctrl_enable_item(edit_it);
1210 ad->albuminfo.edit_it = edit_it;
1212 _gl_ctrl_append_object_item(bot_bar, NULL);
1214 _gl_ctrl_enable_item(edit_it);
1219 #ifdef _USE_ROTATE_BG
1220 static void __gl_ui_rotate_left_cb(void *data, Evas_Object *obj, void *event_info)
1223 _gl_rotate_images(data, true);
1226 static void __gl_ui_rotate_right_cb(void *data, Evas_Object *obj, void *event_info)
1229 _gl_rotate_images(data, false);
1232 static Evas_Object *__gl_ui_add_optionheader(void *data, Evas_Object *parent)
1234 GL_CHECK_NULL(data);
1235 gl_appdata *ad = (gl_appdata *)data;
1236 Evas_Object *oh = NULL;
1237 oh = _gl_ctrl_add_optionheader(parent);
1239 /* OptionHeader Button left */
1240 Evas_Object *btn = NULL;
1241 btn = _gl_but_create_but(oh, GL_BUT_ROTATE_LEFT,
1242 GL_BUTTON_STYLE_NAVI_CTRL);
1243 evas_object_smart_callback_add(btn, "clicked", __gl_ui_rotate_left_cb,
1245 _gl_ctrl_append_object_item(oh, btn);
1246 ad->gridinfo.left_btn = btn;
1248 /* OptionHeader Button right */
1249 btn = _gl_but_create_but(oh, GL_BUT_ROTATE_RIGHT,
1250 GL_BUTTON_STYLE_NAVI_CTRL);
1251 evas_object_smart_callback_add(btn, "clicked", __gl_ui_rotate_right_cb,
1253 _gl_ctrl_append_object_item(oh, btn);
1254 ad->gridinfo.right_btn= btn;
1258 static void __gl_ui_more_btn_cb(void *data, Evas_Object *obj, void *event_info)
1261 Elm_Object_Item *nf_it = (Elm_Object_Item *)data;
1262 _gl_ui_open_optionheader(data, !(int)elm_object_item_data_get(nf_it));
1265 static int __gl_ui_add_more_btn(void *data, Elm_Object_Item *nf_it, Evas_Object *parent)
1267 GL_CHECK_VAL(parent, -1);
1268 GL_CHECK_VAL(nf_it, -1);
1269 GL_CHECK_VAL(data, -1);
1270 gl_appdata *ad = (gl_appdata *)data;
1271 Evas_Object *more_btn = NULL;
1273 more_btn = _gl_but_create_but(parent, GL_BUT_NONE,
1274 GL_BUTTON_STYLE_NAVI_MORE);
1275 evas_object_smart_callback_add(more_btn, "clicked", __gl_ui_more_btn_cb,
1277 elm_object_item_part_content_set(nf_it, GL_NAVIFRAME_TITLE_MORE_BTN,
1279 ad->gridinfo.more_btn = more_btn;
1280 elm_object_disabled_set(more_btn, true);
1282 Evas_Object *optionheader = __gl_ui_add_optionheader(data, parent);
1283 elm_object_item_part_content_set(nf_it, GL_NAVIFRAME_OPTIONHEAD,
1285 elm_object_item_signal_emit(nf_it,
1286 "elm,state,optionheader,instant_close", "");
1287 elm_object_item_data_set(nf_it, (void *)GL_UI_MORE_STATE_CLOSE);
1293 static void __gl_ui_trans_finished_cb(void *data, Evas_Object *obj, void *event_info)
1296 gl_appdata *ad = (gl_appdata *)data;
1297 int view_mode = gl_get_view_mode(ad);
1298 gl_dbgW("view_mode: %d", view_mode);
1299 evas_object_smart_callback_del(obj, GL_TRANS_FINISHED,
1300 __gl_ui_trans_finished_cb);
1302 /* Clear previous view after animation finished */
1303 if (view_mode == GL_VIEW_THUMBS) {
1304 elm_gengrid_clear(ad->albuminfo.view);
1305 } else if (view_mode == GL_VIEW_THUMBS_EDIT) {
1306 if (ad->entryinfo.entry_mode != GL_ENTRY_NONE)
1308 if (ad->maininfo.seg_mode == GL_CTRL_SEG_ALL)
1309 elm_gengrid_clear(ad->gridinfo.all_view);
1310 else if (ad->maininfo.seg_mode == GL_CTRL_SEG_IMAGES)
1311 elm_gengrid_clear(ad->gridinfo.images_view);
1312 } else if (view_mode == GL_VIEW_VIDEOLIST_EDIT) {
1313 if (ad->entryinfo.entry_mode != GL_ENTRY_NONE)
1315 elm_genlist_clear(ad->listinfo.videos_view);
1316 } else if (view_mode == GL_VIEW_ALBUMS_EDIT) {
1317 elm_gengrid_clear(ad->albuminfo.view);
1318 } else if (view_mode == GL_VIEW_ALBUMS_RENAME) {
1319 elm_gengrid_clear(ad->albuminfo.edit_view);
1322 static void __gl_ui_slideshow_btn_cb(void *data, Evas_Object *obj, void *event_info)
1325 gl_appdata *ad = (gl_appdata *)data;
1326 gl_item *cur_item = NULL;
1328 media_content_type_e type = MEDIA_CONTENT_TYPE_IMAGE;
1330 if (ad->maininfo.seg_mode == GL_CTRL_SEG_VIDEOS)
1331 type = MEDIA_CONTENT_TYPE_VIDEO;
1332 else if (ad->maininfo.seg_mode == GL_CTRL_SEG_IMAGES)
1333 type = MEDIA_CONTENT_TYPE_IMAGE;
1335 _gl_data_get_first_item(ad, type, &cur_item);
1337 gl_ext_load_iv_ug(ad, cur_item, GL_UG_IV_SLIDESHOW_LOCAL);
1340 static int __gl_ui_add_slideshow_btn(void *data, Elm_Object_Item *nf_it, Evas_Object *parent)
1342 GL_CHECK_VAL(parent, -1);
1343 GL_CHECK_VAL(nf_it, -1);
1344 GL_CHECK_VAL(data, -1);
1345 Evas_Object *slideshow_btn = NULL;
1347 slideshow_btn = _gl_but_create_but(parent, GL_BUT_NONE,
1348 GL_BUTTON_STYLE_NAVI_SLIDESHOW);
1349 GL_CHECK_VAL(slideshow_btn, -1);
1350 evas_object_smart_callback_add(slideshow_btn, "clicked",
1351 __gl_ui_slideshow_btn_cb, data);
1352 elm_object_item_part_content_set(nf_it, GL_NAVIFRAME_TITLE_RIGHT_BTN,
1358 * Use naviframe api to push albums view to stack.
1359 * @param obj is the content to be pushed.
1361 static int __gl_ui_push_view_albums(void *data, Evas_Object *parent,
1362 Evas_Object *obj, char *title)
1364 gl_dbg("GL_NAVI_ALBUMS");
1365 GL_CHECK_VAL(obj, -1);
1366 GL_CHECK_VAL(parent, -1);
1367 GL_CHECK_VAL(data, -1);
1368 gl_appdata *ad = (gl_appdata *)data;
1369 Elm_Object_Item *nf_it = NULL;
1370 Evas_Object *end_btn = NULL;
1371 Evas_Object *bot_bar = NULL;
1373 /* create tool controlbar downside */
1374 bot_bar = _gl_ctrl_create_toolbar(obj);
1375 GL_CHECK_VAL(bot_bar, -1);
1378 __gl_ui_add_toolbar_items_albums(ad, bot_bar);
1381 * add End button in navigation var first view in galery
1382 * so after tap this button,gallery is paused
1383 * but change view to background
1385 GL_CHECK_VAL(ad->maininfo.win, -1);
1386 end_btn = _gl_but_create_but(parent, GL_BUT_NONE,
1387 GL_BUTTON_STYLE_NAVI_PRE);
1388 evas_object_smart_callback_add(end_btn, "clicked",
1389 __gl_ui_change_to_background_cb,
1391 /* Push view to stack */
1392 gl_dbg_launch(" elm_naviframe_item_push:start");
1393 nf_it = elm_naviframe_item_push(parent, title, end_btn, NULL, obj,
1395 gl_dbg_launch(" elm_naviframe_item_push:end");
1396 ad->albuminfo.nf_it = nf_it;
1398 /* Set tool controlbar to bottom */
1399 elm_object_item_part_content_set(ad->albuminfo.nf_it,
1400 GL_NAVIFRAME_CONTROLBAR, bot_bar);
1405 * Use naviframe api to push albums edit view to stack.
1406 * @param obj is the content to be pushed.
1408 static int __gl_ui_push_view_albums_edit(void *data, Evas_Object *parent,
1409 Evas_Object *obj, char *title)
1411 gl_dbg("GL_NAVI_ALBUMS_EDIT");
1412 GL_CHECK_VAL(obj, -1);
1413 GL_CHECK_VAL(parent, -1);
1414 GL_CHECK_VAL(data, -1);
1415 gl_appdata *ad = (gl_appdata *)data;
1416 Elm_Object_Item *nf_it = NULL;
1417 Elm_Object_Item *share_it = NULL;
1418 Elm_Object_Item *del_it = NULL;
1419 Elm_Object_Item *cancel_it = NULL;
1420 Evas_Object *bot_bar = NULL;
1422 /* create tool controlbar downside */
1423 bot_bar = _gl_ctrl_create_toolbar(obj);
1424 GL_CHECK_VAL(bot_bar, -1);
1425 /* Add delete item */
1426 del_it = elm_toolbar_item_append(bot_bar, GL_CBAR_ICON_DELETE, NULL,
1427 _gl_ui_albums_del_cb, ad);
1428 _gl_ctrl_append_object_item(bot_bar, NULL);
1430 /* Add 'Share' item */
1431 share_it = elm_toolbar_item_append(bot_bar, GL_CBAR_ICON_SHARE, NULL,
1432 _gl_ui_share_cb, ad);
1433 _gl_ctrl_append_object_item(bot_bar, NULL);
1434 _gl_ctrl_disable_item(share_it);
1435 /* Add 'Cancel' item */
1436 cancel_it = elm_toolbar_item_append(bot_bar, GL_CBAR_ICON_CANCEL, NULL,
1437 __gl_ui_click_cancel_edit_cb, ad);
1438 _gl_ctrl_disable_item(del_it);
1440 /* Add transition finished callback */
1441 evas_object_smart_callback_add(parent, GL_TRANS_FINISHED,
1442 __gl_ui_trans_finished_cb, ad);
1444 nf_it = elm_naviframe_item_push(parent, title, NULL, NULL, obj,
1446 ad->albuminfo.nf_it_edit = nf_it;
1447 _gl_ui_hide_back_button(nf_it);
1448 /* Set tool bar to bottom */
1449 elm_object_item_part_content_set(nf_it, GL_NAVIFRAME_CONTROLBAR, bot_bar);
1454 * Use naviframe api to push thumbnails view to stack.
1455 * @param obj is the content to be pushed.
1457 static int __gl_ui_push_view_thumbs(void *data, Evas_Object *parent,
1458 Evas_Object *obj, char *title)
1460 gl_dbg("GL_NAVI_THUMBS");
1461 GL_CHECK_VAL(obj, -1);
1462 GL_CHECK_VAL(parent, -1);
1463 GL_CHECK_VAL(data, -1);
1464 gl_appdata *ad = (gl_appdata *)data;
1465 Elm_Object_Item *nf_it = NULL;
1466 Elm_Object_Item *edit_it = NULL;
1467 Evas_Object *bot_bar = NULL;
1468 Evas_Object *segment = NULL;
1470 /* create tool controlbar downside */
1471 bot_bar = _gl_ctrl_create_toolbar(obj);
1472 GL_CHECK_VAL(bot_bar, -1);
1473 /* add 'Back' item */
1474 if (ad->maininfo.medias_cnt) {
1475 /* add 'Edit' item */
1476 edit_it = _gl_ui_append_edit(ad, bot_bar);
1477 ad->gridinfo.edit_it = edit_it;
1479 segment = _gl_ctrl_create_segment(ad, bot_bar);
1480 _gl_ctrl_append_object_item(bot_bar, segment);
1482 /* Add transition finished callback */
1483 evas_object_smart_callback_add(parent, GL_TRANS_FINISHED,
1484 __gl_ui_trans_finished_cb, ad);
1486 /* Push to stack with basic transition */
1487 nf_it = elm_naviframe_item_push(parent, title, NULL, NULL, obj,
1490 ad->gridinfo.nf_it = nf_it;
1491 /* Set tool bar to bottom */
1492 elm_object_item_part_content_set(nf_it, GL_NAVIFRAME_CONTROLBAR, bot_bar);
1494 if (ad->maininfo.medias_cnt) {
1495 /* Add slide show button */
1496 gl_dbg("Add slideshow button");
1497 __gl_ui_add_slideshow_btn(ad, nf_it, parent);
1503 * Use naviframe api to push thumbnails eidt view to stack.
1504 * @param obj is the content to be pushed.
1506 static int __gl_ui_push_view_thumbs_edit(void *data, Evas_Object *parent,
1507 Evas_Object *obj, char *title)
1509 gl_dbg("GL_NAVI_THUMBS_EDIT");
1510 GL_CHECK_VAL(obj, -1);
1511 GL_CHECK_VAL(parent, -1);
1512 GL_CHECK_VAL(data, -1);
1513 gl_appdata *ad = (gl_appdata *)data;
1514 Elm_Object_Item *nf_it = NULL;
1515 Elm_Object_Item *del_it = NULL;
1516 Elm_Object_Item *share_it = NULL;
1517 Elm_Object_Item *move_it = NULL;
1518 Elm_Object_Item *cancel_it = NULL;
1519 Evas_Object *bot_bar = NULL;
1520 #ifdef _USE_ROTATE_BG
1521 bool b_add_more_btn = false;
1523 /* create tool controlbar downside */
1524 bot_bar = _gl_ctrl_create_toolbar(obj);
1525 GL_CHECK_VAL(bot_bar, -1);
1527 #ifdef _USE_ROTATE_BG
1528 /* Add button is available in all/images segment */
1529 if (ad->maininfo.seg_mode != GL_CTRL_SEG_VIDEOS)
1530 b_add_more_btn = true;
1532 /* Add 'Delete' item */
1533 del_it = elm_toolbar_item_append(bot_bar,
1534 GL_CBAR_ICON_DELETE,
1536 _gl_ui_medias_del_cb,
1538 _gl_ctrl_disable_item(del_it);
1540 /* Add 'Share' item */
1541 share_it = elm_toolbar_item_append(bot_bar, GL_CBAR_ICON_SHARE,
1542 NULL, _gl_ui_share_cb, ad);
1543 _gl_ctrl_disable_item(share_it);
1545 move_it = elm_toolbar_item_append(bot_bar,
1550 _gl_ctrl_disable_item(move_it);
1552 /* Add 'Cancel' item */
1553 cancel_it = elm_toolbar_item_append(bot_bar, GL_CBAR_ICON_CANCEL,
1555 __gl_ui_click_cancel_edit_cb,
1558 /* Add transition finished callback */
1559 evas_object_smart_callback_add(parent, GL_TRANS_FINISHED,
1560 __gl_ui_trans_finished_cb, ad);
1562 nf_it = elm_naviframe_item_push(parent, title, NULL, NULL, obj, NULL);
1563 ad->gridinfo.nf_it_edit = nf_it;
1564 _gl_ui_hide_back_button(nf_it);
1566 #ifdef _USE_ROTATE_BG
1567 if (b_add_more_btn) {
1568 gl_dbg("Add more button");
1569 __gl_ui_add_more_btn(ad, nf_it, parent);
1573 /* Set tool bar to bottom */
1574 elm_object_item_part_content_set(nf_it, GL_NAVIFRAME_CONTROLBAR,
1581 * Use naviframe api to push albums rename view to stack.
1582 * @param obj is the content to be pushed.
1584 static int __gl_ui_push_view_albums_rename(void *data, Evas_Object *parent,
1585 Evas_Object *obj, char *title)
1587 gl_dbg("GL_NAVI_ALBUMS_RENAME");
1588 GL_CHECK_VAL(obj, -1);
1589 GL_CHECK_VAL(parent, -1);
1590 GL_CHECK_VAL(data, -1);
1591 gl_appdata *ad = (gl_appdata *)data;
1592 Elm_Object_Item *nf_it = NULL;
1593 Evas_Object *done_btn = NULL;
1594 Evas_Object *cancel_btn = NULL;
1596 /* Add transition finished callback */
1597 evas_object_smart_callback_add(parent, GL_TRANS_FINISHED,
1598 __gl_ui_trans_finished_cb, ad);
1599 nf_it = elm_naviframe_item_push(parent, title, NULL, NULL, obj, NULL);
1600 _gl_ui_hide_back_button(nf_it);
1601 /* Add 'Cancel' button */
1602 cancel_btn = _gl_but_create_but(parent, GL_BUT_NONE,
1603 GL_BUTTON_STYLE_NAVI_CANCEL);
1604 GL_CHECK_VAL(cancel_btn, -1);
1605 evas_object_smart_callback_add(cancel_btn, "clicked",
1606 __gl_ui_rename_album_cancel_cb, ad);
1607 elm_object_item_part_content_set(nf_it, GL_NAVIFRAME_TITLE_RIGHT_BTN,
1609 ad->entryinfo.cancel_btn = cancel_btn;
1610 /* Add 'Done' button */
1611 done_btn = _gl_but_create_but(parent, GL_BUT_NONE,
1612 GL_BUTTON_STYLE_NAVI_DONE);
1613 GL_CHECK_VAL(done_btn, -1);
1614 evas_object_smart_callback_add(done_btn, "clicked",
1615 __gl_ui_rename_album_done_cb, ad);
1616 elm_object_item_part_content_set(nf_it, GL_NAVIFRAME_TITLE_LEFT_BTN,
1618 ad->entryinfo.done_btn = done_btn;
1619 ad->entryinfo.nf_it = nf_it;
1624 * Use naviframe api to push new album view to stack.
1625 * @param obj is the content to be pushed.
1627 static int __gl_ui_push_view_albums_new(void *data, Evas_Object *parent,
1628 Evas_Object *obj, char *title)
1630 gl_dbg("GL_NAVI_ALBUMS_NEW");
1631 GL_CHECK_VAL(obj, -1);
1632 GL_CHECK_VAL(parent, -1);
1633 GL_CHECK_VAL(data, -1);
1634 gl_appdata *ad = (gl_appdata *)data;
1635 Elm_Object_Item *nf_it = NULL;
1636 Evas_Object *done_btn = NULL;
1637 Evas_Object *cancel_btn = NULL;
1639 nf_it = elm_naviframe_item_push(parent, title, NULL, NULL, obj, NULL);
1640 ad->entryinfo.nf_it = nf_it;
1641 _gl_ui_hide_back_button(nf_it);
1642 /* Add 'Cancel' button */
1643 cancel_btn = _gl_but_create_but(parent, GL_BUT_NONE,
1644 GL_BUTTON_STYLE_NAVI_CANCEL);
1645 GL_CHECK_VAL(cancel_btn, -1);
1646 evas_object_smart_callback_add(cancel_btn, "clicked",
1647 _gl_ui_newalbum_cancel_cb, ad);
1648 elm_object_item_part_content_set(nf_it, GL_NAVIFRAME_TITLE_RIGHT_BTN,
1650 ad->entryinfo.cancel_btn = cancel_btn;
1651 /* Add 'Done' button */
1652 done_btn = _gl_but_create_but(parent, GL_BUT_NONE,
1653 GL_BUTTON_STYLE_NAVI_DONE);
1654 GL_CHECK_VAL(done_btn, -1);
1655 evas_object_smart_callback_add(done_btn, "clicked",
1656 _gl_ui_newalbum_done_cb, ad);
1657 elm_object_item_part_content_set(nf_it, GL_NAVIFRAME_TITLE_LEFT_BTN,
1659 ad->entryinfo.done_btn = done_btn;
1663 int _gl_ui_disable_slideshow_btn(void *data, bool b_disable)
1665 GL_CHECK_VAL(data, -1);
1666 gl_appdata *ad = (gl_appdata *)data;
1668 GL_CHECK_VAL(ad->gridinfo.nf_it, -1);
1669 Evas_Object *slideshow_btn = NULL;
1670 slideshow_btn = elm_object_item_part_content_get(ad->gridinfo.nf_it,
1671 GL_NAVIFRAME_TITLE_RIGHT_BTN);
1673 elm_object_disabled_set(slideshow_btn, b_disable);
1677 #ifdef _USE_ROTATE_BG
1678 int _gl_ui_open_optionheader(void *data, int open)
1680 GL_CHECK_VAL(data, -1);
1681 Elm_Object_Item *nf_it = (Elm_Object_Item *)data;
1682 if (open == GL_UI_MORE_STATE_OPEN) {
1683 elm_object_item_signal_emit(nf_it, "elm,state,optionheader,open",
1685 elm_object_item_data_set(nf_it, (void *)(GL_UI_MORE_STATE_OPEN));
1687 elm_object_item_signal_emit(nf_it,
1688 "elm,state,optionheader,close", "");
1689 elm_object_item_data_set(nf_it, (void *)(GL_UI_MORE_STATE_CLOSE));
1694 int _gl_ui_disable_more_btn(void *data, bool b_disable)
1696 gl_dbg("b_disable: %d", b_disable);
1697 GL_CHECK_VAL(data, -1);
1698 gl_appdata *ad = (gl_appdata *)data;
1699 GL_CHECK_VAL(ad->maininfo.naviframe, -1);
1700 Evas_Object *_more_btn = NULL;
1701 Elm_Object_Item *nf_it = NULL;
1702 nf_it = elm_naviframe_top_item_get(ad->maininfo.naviframe);
1703 _more_btn = elm_object_item_part_content_get(nf_it,
1704 GL_NAVIFRAME_TITLE_MORE_BTN);
1706 elm_object_disabled_set(_more_btn, b_disable);
1707 /* Close optionheader manually */
1709 _gl_ui_open_optionheader(nf_it, GL_UI_MORE_STATE_CLOSE);
1714 /* Append 'Edit' item to toolbar */
1715 Elm_Object_Item *_gl_ui_append_edit(void *data, Evas_Object *bot_bar)
1717 GL_CHECK_NULL(bot_bar);
1718 GL_CHECK_NULL(data);
1719 Elm_Object_Item *edit_it = NULL;
1720 edit_it = elm_toolbar_item_append(bot_bar, GL_CBAR_ICON_EDIT,
1721 NULL, _gl_ui_edit_cb, data);
1725 int gl_ui_cancel_rename_album(void *data)
1727 GL_CHECK_VAL(data, -1);
1729 __gl_ui_cancel_rename_album(data);
1734 int gl_ui_cancel_new_album(void *data)
1736 GL_CHECK_VAL(data, -1);
1738 _gl_ui_cancel_newalbum(data);
1743 int gl_ui_move_to_newalbum(void *data)
1745 GL_CHECK_VAL(data, -1);
1746 gl_appdata *ad = (gl_appdata *)data;
1747 Evas_Object *editfield_ly = NULL;
1750 ad->entryinfo.entry_mode = GL_ENTRY_NEW_ALBUM;
1751 editfield_ly = _gl_ui_create_view_ly(ad->maininfo.naviframe);
1752 Evas_Object *entry_ly = _gl_editfield_create(ad, editfield_ly, NULL);
1753 elm_object_part_content_set(editfield_ly, "elm.swallow.view", entry_ly);
1755 gl_ui_create_title_and_push(ad, ad->maininfo.naviframe, editfield_ly,
1756 GL_NAVI_ALBUMS_NEW, GL_STR_CREATE_ALBUM);
1758 elm_entry_cursor_end_set(ad->entryinfo.imf_entry);
1759 evas_object_show(ad->entryinfo.imf_entry);
1760 elm_object_focus_set(ad->entryinfo.imf_entry, EINA_TRUE);
1761 ecore_imf_context_input_panel_show(ad->entryinfo.imf_context);
1766 int gl_ui_rename_album(gl_cluster *album_item)
1768 GL_CHECK_VAL(album_item, -1);
1769 GL_CHECK_VAL(album_item->cluster, -1);
1770 GL_CHECK_VAL(album_item->cluster->display_name, -1);
1771 GL_CHECK_VAL(album_item->ad, -1);
1772 gl_appdata *ad = (gl_appdata *)album_item->ad;
1773 int view_mode = gl_get_view_mode(ad);
1774 Evas_Object *editfield_ly = NULL;
1775 Evas_Object *entry_ly = NULL;
1778 if(ad->maininfo.rename_album_job) {
1779 ecore_job_del(ad->maininfo.rename_album_job);
1780 ad->maininfo.rename_album_job = NULL;
1782 if (view_mode != GL_VIEW_ALBUMS_EDIT) {
1783 gl_dbgE("Unexpected view mode(%d)!", view_mode);
1787 /* save album selected for rename */
1788 ad->albuminfo.selected_album = album_item;
1790 gl_set_view_mode(ad, GL_VIEW_ALBUMS_RENAME);
1792 ad->entryinfo.entry_mode = GL_ENTRY_RENAME_ALBUM;
1794 editfield_ly = _gl_ui_create_view_ly(ad->maininfo.naviframe);
1795 entry_ly = _gl_editfield_create(ad, editfield_ly,
1796 album_item->cluster->display_name);
1797 elm_object_part_content_set(editfield_ly, "elm.swallow.view", entry_ly);
1799 gl_ui_create_title_and_push(ad, ad->maininfo.naviframe, editfield_ly,
1800 GL_NAVI_ALBUMS_RENAME, GL_STR_CHNAGE_NAME);
1802 elm_entry_cursor_end_set(ad->entryinfo.imf_entry);
1803 evas_object_show(ad->entryinfo.imf_entry);
1804 elm_object_focus_set(ad->entryinfo.imf_entry, EINA_TRUE);
1805 ecore_imf_context_input_panel_show(ad->entryinfo.imf_context);
1809 int gl_ui_create_title_and_push(void *data, Evas_Object *parent,
1810 Evas_Object *obj, gl_navi_mode mode, char *title)
1812 gl_dbg_launch(" gl_ui_create_title_and_push:start");
1813 GL_CHECK_VAL(obj, -1);
1814 GL_CHECK_VAL(parent, -1);
1815 GL_CHECK_VAL(data, -1);
1817 if (mode == GL_NAVI_ALBUMS)
1818 __gl_ui_push_view_albums(data, parent, obj, title);
1819 else if (mode == GL_NAVI_ALBUMS_EDIT)
1820 __gl_ui_push_view_albums_edit(data, parent, obj, title);
1821 else if (mode == GL_NAVI_THUMBS)
1822 __gl_ui_push_view_thumbs(data, parent, obj, title);
1823 else if (mode == GL_NAVI_THUMBS_EDIT)
1824 __gl_ui_push_view_thumbs_edit(data, parent, obj, title);
1825 else if (mode == GL_NAVI_ALBUMS_RENAME)
1826 __gl_ui_push_view_albums_rename(data, parent, obj, title);
1827 else if (mode == GL_NAVI_ALBUMS_NEW)
1828 __gl_ui_push_view_albums_new(data, parent, obj, title);
1830 gl_dbg_launch(" gl_ui_create_title_and_push:end");
1835 gl_ui_load_edj(Evas_Object * parent, const char *file, const char *group)
1837 Evas_Object *eo = NULL;
1840 eo = elm_layout_add(parent);
1843 r = elm_layout_file_set(eo, file, group);
1846 evas_object_del(eo);
1850 evas_object_size_hint_weight_set(eo, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1851 evas_object_size_hint_align_set(eo, EVAS_HINT_FILL, EVAS_HINT_FILL);
1857 int gl_ui_edit_cancel(void *data)
1859 GL_CHECK_VAL(data, -1);
1860 gl_appdata *ad = (gl_appdata *)data;
1861 int view_mode = gl_get_view_mode(ad);
1862 Elm_Object_Item *nf_it = NULL;
1864 if (view_mode == GL_VIEW_ALBUMS_EDIT ||
1865 view_mode == GL_VIEW_ALBUMS_RENAME) {
1866 if (view_mode != GL_VIEW_ALBUMS_EDIT) {
1867 gl_dbg("GL_VIEW_ALBUMS_xxx->Edit");
1868 gl_set_view_mode(ad, GL_VIEW_ALBUMS_EDIT);
1870 nf_it = ad->albuminfo.nf_it;
1871 } else if (view_mode == GL_VIEW_THUMBS_EDIT ||
1872 view_mode == GL_VIEW_VIDEOLIST_EDIT) {
1873 nf_it = ad->gridinfo.nf_it;
1875 elm_naviframe_item_pop_to(nf_it);
1876 __gl_ui_cancel_edit(ad);
1881 /* Remove selection and edit view then pop to normal thumbnail view */
1882 int _gl_ui_pop_to_thumb(void *data)
1884 GL_CHECK_VAL(data, -1);
1885 gl_appdata *ad = (gl_appdata *)data;
1886 /* Delete edit view and update thumbnail view */
1887 __gl_ui_cancel_edit(ad);
1888 /* Delete invlid naviframe items */
1889 elm_naviframe_item_pop_to(ad->gridinfo.nf_it);
1895 * Update checkbox state and add click signal to Select-all widget.
1896 * Show arrow button in thumbnails/list edit mode.
1898 int gl_ui_show_selall(void *data)
1900 GL_CHECK_VAL(data, -1);
1901 gl_appdata *ad = (gl_appdata *)data;
1902 int view_mode = gl_get_view_mode(ad);
1903 Eina_Bool ck_state = EINA_FALSE;
1904 Evas_Object *view_ly = NULL;
1905 char *sig = "selectall_show";
1907 gl_dbg("view_mode: %d.", view_mode);
1908 if (view_mode == GL_VIEW_THUMBS_EDIT ||
1909 view_mode == GL_VIEW_VIDEOLIST_EDIT) {
1910 view_ly = ad->gridinfo.edit_layout;
1911 if (ad->maininfo.medias_cnt == _gl_data_selected_list_count(ad))
1912 ck_state = EINA_TRUE;
1913 if (view_mode == GL_VIEW_VIDEOLIST_EDIT)
1914 sig = "selectall_show_video";
1915 } else if (view_mode == GL_VIEW_ALBUMS_EDIT) {
1916 /* in Albums view */
1917 view_ly = ad->albuminfo.edit_layout;
1918 int sel_all = _gl_data_get_albums_selected_cnt(ad);
1919 int cnt_all = ad->albuminfo.albums_cnt;
1920 if (cnt_all == sel_all)
1921 ck_state = EINA_TRUE;
1923 gl_dbgE("Wrong view!");
1927 const char *text = NULL;
1928 text = edje_object_part_text_get(_EDJ(view_ly), "selectall_text");
1929 if (text == NULL || g_strcmp0(text, GL_STR_SELECT_ALL))
1930 edje_object_part_text_set(_EDJ(view_ly), "selectall_text",
1933 Evas_Object *old_check = NULL;
1934 old_check = elm_object_part_content_unset(view_ly, "selectall_check");
1936 evas_object_del(old_check);
1938 Evas_Object *check = elm_check_add(view_ly);
1939 evas_object_propagate_events_set(check, EINA_FALSE);
1940 elm_check_state_set(check, ck_state);
1942 elm_object_part_content_set(view_ly, "selectall_check", check);
1943 evas_object_smart_callback_add(check, "changed",
1944 _gl_ui_selall_check_changed, ad);
1945 edje_object_signal_emit(_EDJ(view_ly), sig, "elm");
1947 /* Add signal to select-all bg */
1948 edje_object_signal_callback_del(_EDJ(view_ly), "elm,action,click",
1950 _gl_ui_selall_bg_click_cb);
1951 edje_object_signal_callback_add(_EDJ(view_ly), "elm,action,click",
1953 _gl_ui_selall_bg_click_cb, ad);
1958 /* Update checkbox state of Select-all and selectioninfo */
1959 int gl_ui_update_select_widgets(void *data)
1961 GL_CHECK_VAL(data, -1);
1962 gl_appdata *ad = (gl_appdata *)data;
1964 /* Update checkbox state of Select-all */
1965 gl_ui_show_selall(ad);
1966 /* Update selectioninfo */
1967 int cnt = ad->maininfo.medias_cnt;
1968 int sel_cnt = _gl_data_selected_list_count(ad);
1969 _gl_notify_create_selinfo(ad, ad->gridinfo.edit_layout,
1970 ad->gridinfo.nf_it_edit, cnt, sel_cnt, false);
1974 Evas_Object *gl_ui_create_main_ly(Evas_Object *parent)
1976 gl_dbg_launch(" gl_ui_create_main_ly:start");
1977 GL_CHECK_NULL(parent);
1978 Evas_Object *layout = NULL;
1980 layout = elm_layout_add(parent);
1981 GL_CHECK_NULL(layout);
1983 /* Apply the layout style */
1984 gl_dbg_launch(" elm_layout_theme_set:start");
1986 const char *profile = elm_config_profile_get();
1987 if (!g_strcmp0(profile, "mobile")) {
1988 elm_layout_theme_set(layout, "layout", "application", "default");
1989 } else if (!g_strcmp0(profile,"extension")) {
1990 elm_layout_theme_set(layout, "layout", "application", "noindicator");
1993 gl_dbg_launch(" elm_layout_theme_set:end");
1994 evas_object_size_hint_weight_set(layout,
1995 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1996 elm_win_resize_object_add(parent, layout);
1997 evas_object_show(layout);
1998 gl_dbg_launch(" gl_ui_create_main_ly:end");
2003 Evas_Object *gl_ui_create_navi_ly(Evas_Object *parent)
2005 GL_CHECK_NULL(parent);
2006 Evas_Object *navi_bar = NULL;
2007 gl_dbg_launch(" gl_ui_create_navi_ly:start");
2009 navi_bar = elm_naviframe_add(parent);
2010 gl_dbg("elm_naviframe_add:done");
2012 evas_object_show(navi_bar);
2013 gl_dbg("elm_object_style_set: done");
2014 gl_dbg_launch(" gl_ui_create_navi_ly:end");
2019 Evas_Object *_gl_ui_create_view_ly(Evas_Object *parent)
2022 GL_CHECK_NULL(parent);
2024 Evas_Object *layout = NULL;
2025 layout = gl_ui_load_edj(parent, GL_EDJ_FILE, GL_GRP_VIEW_LAYOUT);
2026 GL_CHECK_NULL(layout);
2027 evas_object_show(layout);