initial upload for tizen 2.0 beta
[apps/home/gallery.git] / src / util / gl-ui-util.c
1 /*
2   * Copyright 2012  Samsung Electronics Co., Ltd
3   *
4   * Licensed under the Flora License, Version 1.0 (the "License");
5   * you may not use this file except in compliance with the License.
6   * You may obtain a copy of the License at
7   *
8   *     http://www.tizenopensource.org/license
9   *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16
17 #include <string.h>
18 #include <Ecore_X.h>
19 #include <glib.h>
20 #include "gl-ui-util.h"
21 #include "gl-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"
29 #include "gl-debug.h"
30 #include "gl-data.h"
31 #include "gl-thread-util.h"
32 #include "gl-popup.h"
33 #include "gl-progressbar.h"
34 #include "gl-strings.h"
35 #include "gl-drm.h"
36 #include "gl-nocontents.h"
37 #include "gl-notify.h"
38 #include "gl-editfield.h"
39
40 #define GL_TRANS_FINISHED "transition,finished"
41
42 #ifdef _USE_ROTATE_BG
43 static int __gl_ui_add_more_btn(void *data, Elm_Object_Item *nf_it,
44                                 Evas_Object *parent);
45 /*static int __gl_ui_remove_more_btn(Elm_Object_Item *nf_it);*/
46 #endif
47
48 /**
49 * Check album name is valid and remove unuseful characters
50 *       1) not only includes space;
51 *       2) contains invalid character;
52 *       3) it's empty.
53 *
54 * @param b_new
55 *       true: add a new album ; false: rename a album.
56 * @param b_enter
57 *       true: Enter key pressed ; false: Button Done clicked.
58 *
59 */
60 static int _gl_ui_get_valid_album_name(void *data, char* album_name,
61                                         bool b_new, bool b_enter)
62 {
63         GL_CHECK_VAL(album_name, -1);
64         GL_CHECK_VAL(data, -1);
65         gl_appdata* ad = (gl_appdata*)data;
66         int mode = 0;
67         gl_dbg("Input album name: %s", album_name);
68         char *popup_desc;
69         popup_desc = (char*)calloc(GL_POPUP_STRING_MAX, sizeof(char));
70         if (popup_desc == NULL) {
71                 gl_dbg("memory allocation fail");
72                 return -1;
73         }
74         /* Check album name length */
75         if (strlen(album_name) == 0) {
76                 gl_dbgW("Inserted text is empty!");
77                 if (b_enter) {
78                         gl_dbg("Enter key pressed.");
79                         goto INVALID_ALBUM_NAME;
80                 }
81
82                 if (b_new)
83                         mode = GL_POPUP_ALBUM_NEW_EMPTY;
84                 else
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;
91         }
92         gl_dbg("Inserted album name: %s, length: %d", album_name, strlen(album_name));
93
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!");
98                 if (b_enter) {
99                         gl_dbg("Enter key pressed.");
100                         goto INVALID_ALBUM_NAME;
101                 }
102
103                 if (b_new)
104                         mode = GL_POPUP_ALBUM_NEW_EMPTY;
105                 else
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;
112         }
113
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!");
117                 if (b_new)
118                         mode = GL_POPUP_ALBUM_NEW_INVALID;
119                 else
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;
126         }
127
128         free(popup_desc);
129
130         return 0;
131
132  INVALID_ALBUM_NAME:
133         free(popup_desc);
134         return -1;
135 }
136
137 #ifdef _RENAME_ALBUM_SENSITIVE
138 static bool __gl_ui_check_album_name_case(char *dir)
139 {
140         GL_CHECK_FALSE(dir);
141         gl_dbg("");
142
143         char dest_dir[GL_DIR_PATH_LEN_MAX] = {0};
144         char dest_filename[GL_FILE_NAME_LEN_MAX] = {0};
145         char *tmp = NULL;
146         tmp = strrchr(dir, '/');
147         if (tmp) {
148                 g_strlcpy(dest_filename, tmp + 1, GL_FILE_NAME_LEN_MAX);
149                 tmp[0] = '\0';
150                 g_strlcpy(dest_dir, dir, GL_DIR_PATH_LEN_MAX);
151                 tmp[0] = '/';
152         } else {
153                 return false;
154         }
155
156         bool ret = false;
157         Eina_List *name_list = NULL;
158         if((name_list = ecore_file_ls(dest_dir)) == NULL) {
159                 gl_dbgE("open dir failed!");
160                 return false;
161         } else {
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");
166                                 ret = true;
167                                 break;
168                         }
169                         free(dir_name);
170                 }
171         }
172         return ret;
173 }
174 #endif
175
176 static int _gl_ui_cancel_newalbum(void *data)
177 {
178         GL_CHECK_VAL(data, -1);
179         gl_appdata *ad = (gl_appdata *)data;
180         gl_dbg("");
181
182         elm_naviframe_item_pop(ad->maininfo.naviframe);
183         _gl_editfield_destroy_imf(ad);
184
185         gl_ui_update_select_widgets(ad);
186         return 0;
187 }
188
189 /*
190 * @param b_enter
191 *       True: Enter key on Keyboard pressed, False: Button Done clicked
192 */
193 int _gl_ui_newalbum_done(void *data, bool b_enter)
194 {
195         gl_dbg("b_enter: %d", b_enter);
196         GL_CHECK_VAL(data, -1);
197         gl_appdata *ad = (gl_appdata *)data;
198
199         if (ad->entryinfo.editfield == NULL) {
200                 gl_dbgE("Edit filed is NULL");
201                 goto NEW_ALBUM_FAILED;
202         }
203
204         if (ad->entryinfo.imf_context)
205                 ecore_imf_context_input_panel_hide(ad->entryinfo.imf_context);
206
207         Evas_Object *entry = ad->entryinfo.imf_entry;
208         char album_name[GL_ALBUM_NAME_LEN_MAX] = { 0, };
209
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;
214         }
215
216         /* Get valid name */
217         if (_gl_ui_get_valid_album_name(ad, album_name, true, b_enter) != 0) {
218                 if (b_enter)
219                         _gl_editfield_hide_imf(ad);
220                 return -1;
221         }
222         gl_dbg("Valid album name: %s", album_name);
223
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, };
227
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;
232         }
233
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);
241         if (res)
242 #else
243         int res = ecore_file_dir_is_empty(path);
244         /**
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.
248         */
249         gl_dbg("ecore_file_dir_is_empty return value: %d", res);
250         if (res == 0)
251 #endif
252         {
253                 char *popup_desc;
254                 popup_desc = (char*)calloc(GL_POPUP_STRING_MAX, sizeof(char));
255                 if (popup_desc == NULL) {
256                         gl_dbg("memory allocation fail");
257                         return -1;
258                 }
259
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,
264                                       popup_desc);
265                 free(popup_desc);
266                 gl_dbgW("New folder already exists and not NULL, return!");
267                 return -1;
268         }
269
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);
275
276         /* Move/Save files to dest album */
277         gl_move_to_album(ad);
278         return 0;
279
280  NEW_ALBUM_FAILED:
281         _gl_ui_cancel_newalbum(ad);
282         return -1;
283 }
284
285 static void _gl_ui_newalbum_done_cb(void *data, Evas_Object *obj, void *event_info)
286 {
287         gl_dbg("");
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);
290
291         _gl_ui_newalbum_done(data, false);
292 }
293
294 static void _gl_ui_newalbum_cancel_cb(void *data, Evas_Object *obj, void *event_info)
295 {
296         GL_CHECK(data);
297         gl_dbg("");
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);
301
302         _gl_ui_cancel_newalbum(data);
303 }
304
305 /**
306  * Launch camera
307  */
308 static void __gl_ui_camera_cb(void *data, Evas_Object *obj, void *event_info)
309 {
310         GL_CHECK(data);
311         gl_dbg("");
312         _gl_ext_load_camera();
313 }
314
315 static int __gl_ui_cancel_rename_album(void *data)
316 {
317         GL_CHECK_VAL(data, -1);
318         gl_appdata *ad = (gl_appdata *)data;
319         GL_CHECK_VAL(ad->maininfo.naviframe, -1);
320         gl_dbg("");
321
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);
327
328         /* Update edit view */
329         gl_albums_update_items(ad);
330         return 0;
331 }
332
333 static void __gl_ui_rename_album_cancel_cb(void *data, Evas_Object *obj, void *event_info)
334 {
335         GL_CHECK(data);
336
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);
340
341         __gl_ui_cancel_rename_album(data);
342 }
343
344 /*
345 * @param b_enter
346 *       True: Enter key on Keyboard pressed, False: Button Done clicked
347 */
348 int _gl_ui_rename_album_done(void *data, bool b_enter)
349 {
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;
355
356         if (gl_get_view_mode(ad) != GL_VIEW_ALBUMS_RENAME) {
357                 gl_dbgE("View mode is wrong!");
358                 goto RENAME_FAILED;
359         }
360
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!");
365                 goto RENAME_FAILED;
366         }
367
368         char etxt[GL_FILE_NAME_LEN_MAX] = { 0, };
369         /* Get utf8 format string */
370         int ret = -1;
371         ret = gl_get_entry_text(ad->entryinfo.imf_entry, etxt,
372                                 GL_FILE_NAME_LEN_MAX);
373         if (ret != 0) {
374                 gl_dbgE("Get entry text failed!");
375                 goto RENAME_FAILED;
376         }
377
378         /* Get valid name */
379         if (_gl_ui_get_valid_album_name(ad, etxt, false, b_enter) != 0) {
380                 if (b_enter)
381                         _gl_editfield_hide_imf(ad);
382                 return -1;
383         }
384
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)) {
393                         /**
394                         * Root path, couldn't rename root path,
395                         * make the new dest folder
396                         * and move all files for root path to it.
397                         */
398                         gl_dbg("Rename [No Name] album's name.");
399                         b_root_path = true;
400                 }
401         } else {
402                 gl_dbgE("gl_db_get_folder_fullpath failed(%d)!", ret);
403                 goto RENAME_FAILED;
404         }
405
406         /* Get dest folder path */
407         char dest_dir_path[GL_DIR_PATH_LEN_MAX] = { 0, };
408
409         if (b_root_path) {
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!");
414                         goto RENAME_FAILED;
415                 }
416
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';
420         } else {
421                 int length = 0;
422                 int i = 0;
423
424                 memcpy(dest_dir_path, src_dir_path, GL_DIR_PATH_LEN_MAX);
425                 length = strlen(src_dir_path);
426
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/" */
431                                 if (i == length - 1)
432                                         continue;
433                                 memcpy(&dest_dir_path[i + 1], etxt,
434                                        strlen(etxt));
435                                 dest_dir_path[i + 1+ strlen(etxt)] =  '\0';
436                                 break;
437                         }
438                 }
439         }
440
441         gl_dbg("Dest folder: %s", dest_dir_path);
442 #ifdef _RENAME_ALBUM_SENSITIVE
443         if (!strcasecmp(src_dir_path, dest_dir_path))
444 #else
445         if (!g_strcmp0(src_dir_path, dest_dir_path))
446 #endif
447         {
448                 gl_dbgW("Same as current name!");
449                 goto RENAME_FAILED;
450         }
451
452         /**
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.
456         */
457 #ifdef _RENAME_ALBUM_SENSITIVE
458         if (__gl_ui_check_album_name_case(dest_dir_path))
459 #else
460         if (ecore_file_dir_is_empty(dest_dir_path) == 0 ||
461             ecore_file_dir_is_empty(dest_dir_path) == 1)
462 #endif
463         {
464                 char *popup_desc;
465                 popup_desc = (char*)calloc(GL_POPUP_STRING_MAX, sizeof(char));
466                 if (popup_desc == NULL) {
467                         gl_dbg("memory allocation fail");
468                         return -1;
469                 }
470
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,
475                                       popup_desc);
476                 free(popup_desc);
477                 gl_dbgW("New folder already exists and not NULL, return!");
478                 return -1;
479         }
480
481         if (b_root_path) {
482                 /**
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.
487                 *
488                 * Create new folder under default images path,
489                 * Move all medias under root path to new folder.
490                 */
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!");
495                         goto RENAME_FAILED;
496                 }
497
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);
503                         goto RENAME_FAILED;
504                 } else {
505                         gl_dbg("New album added, update albums list.");
506                         ad->albuminfo.selected_album = NULL;
507                         _gl_data_update_cluster_list(ad);
508                 }
509         } else {
510                 /**
511                 * Case 2: Rename normal album.
512                 *
513                 *                 Update album record in DB.
514                 */
515                 media_folder_set_name(album_item->cluster->folder_h, etxt);
516                 ret = media_folder_update_to_db(album_item->cluster->folder_h);
517                 if (ret < 0) {
518                         gl_dbg("media_folder_set_name failed (%d)!", ret);
519                         goto RENAME_FAILED;
520                 }
521
522                 /**
523                 * Change folder name in file system
524                 * for some special name, DB update success, but file mv failed.
525                 * So, do this first.
526                 */
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!");
530                 } else {
531                         gl_dbgW("Source folder path doesn't exist!");
532                 }
533         }
534         /* Update memory */
535         if (!b_root_path) {
536                 FREE_DATA(album_item->cluster->display_name);
537                 album_item->cluster->display_name = strdup(etxt);
538         }
539         __gl_ui_cancel_rename_album(ad);
540         return 0;
541
542  RENAME_FAILED:
543         __gl_ui_cancel_rename_album(ad);
544         return -1;
545 }
546
547 static void __gl_ui_rename_album_done_cb(void *data, Evas_Object *obj, void *event_info)
548 {
549         gl_dbg("");
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);
554 }
555
556 /* Select-all checkbox selected/deselected */
557 static void _gl_ui_selall_check_changed(void *data, Evas_Object *obj,
558                                         void *event_info)
559 {
560         GL_CHECK(obj);
561         GL_CHECK(data);
562         gl_appdata *ad = (gl_appdata *)data;
563         int view_mode = gl_get_view_mode(ad);
564         gl_dbg("view_mode: %d.", view_mode);
565
566         gl_item *current = NULL;
567         int i = 0;
568         int item_cnt = 0;
569         int sel_all_cnt = 0;
570         Eina_Bool state = EINA_FALSE;
571         state = elm_check_state_get(obj);
572         gl_dbg("Checkbox state: %d.", state);
573
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);
581                 while(first_it) {
582                         /* Get data */
583                         item_cnt++;
584                         album = (gl_cluster *)elm_object_item_data_get(first_it);
585                         if (album == NULL) {
586                                 gl_dbgE("Invalid item data!");
587                                 continue;
588                         }
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);
594                         else
595                                 _gl_data_albums_selected_list_remove(ad, album);
596                         /* Update UI */
597                         elm_gengrid_item_update(first_it);
598                         /* Update selected album count */
599                         sel_all_cnt++;
600
601                         if (last_it == first_it) {
602                                 gl_dbg("Update done!");
603                                 break;
604                         } else {
605                                 next_it = elm_gengrid_item_next_get(first_it);
606                                 first_it = next_it;
607                         }
608                         album = NULL;
609                 }
610         } else {
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)
617                 {
618                         if (seg_mode == GL_CTRL_SEG_IMAGES)
619                         {
620                                 file_type = MEDIA_CONTENT_TYPE_IMAGE;
621                                 sel_all_cnt = 0;
622                         }
623                         else if (seg_mode == GL_CTRL_SEG_VIDEOS)
624                         {
625                                 file_type = MEDIA_CONTENT_TYPE_VIDEO;
626                                 sel_all_cnt = 0;
627                         }
628                 }
629                 else if (view_mode == GL_VIEW_VIDEOLIST_EDIT)
630                 {
631                         file_type = MEDIA_CONTENT_TYPE_VIDEO;
632                         sel_all_cnt = 0;
633                 }
634
635                 gl_dbg("seg_mode=%d", seg_mode);
636                 for (i = 0; i < item_cnt; i++)
637                 {
638                         _gl_data_get_item_by_index(ad, i + 1, false, &current);
639                         GL_CHECK(current);
640                         GL_CHECK(current->item);
641
642                         if (current->checked == state && seg_mode == GL_CTRL_SEG_ALL)
643                         {
644                                 continue;
645                         }
646
647                         if (view_mode == GL_VIEW_THUMBS_EDIT)
648                         {
649                                 if ((seg_mode == GL_CTRL_SEG_IMAGES) ||
650                                         (seg_mode == GL_CTRL_SEG_VIDEOS))
651                                 {
652                                         if (current->item->type != file_type)
653                                         {
654                                                 continue;
655                                         }
656
657                                         sel_all_cnt++;
658                                         if (current->checked == state)
659                                         {
660                                                 continue;
661                                         }
662                                 }
663                         }
664                         else if (view_mode == GL_VIEW_VIDEOLIST_EDIT)
665                         {
666                                 if (current->item->type != file_type)
667                                 {
668                                         continue;
669                                 }
670
671                                 sel_all_cnt++;
672                                 if (current->checked == state)
673                                 {
674                                         continue;
675                                 }
676                         }
677
678                         current->checked = state;
679
680                         if (view_mode == GL_VIEW_THUMBS_EDIT)
681                                 elm_gengrid_item_update(current->elm_item);
682
683                         if (state == EINA_TRUE)
684                                 _gl_data_selected_list_append(ad, current);
685                         else
686                                 _gl_data_selected_list_remove(ad, current);
687
688                 }
689         }
690
691         /* Update all realized items */
692         if (view_mode == GL_VIEW_VIDEOLIST_EDIT)
693                 elm_genlist_realized_items_update(ad->gridinfo.edit_view);
694
695         /* Recreate selection info for both cases */
696         if (state == EINA_FALSE)
697                 sel_all_cnt = 0;
698
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,
702                                           sel_all_cnt, false);
703         } else {
704                 _gl_notify_create_selinfo(ad, ad->gridinfo.edit_layout,
705                                           ad->gridinfo.nf_it_edit, item_cnt,
706                                           sel_all_cnt, false);
707         }
708 }
709
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,
713                                        const char *source)
714 {
715         GL_CHECK(data);
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);
720
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) {
725                 /* in Albums view */
726                 ly = ad->albuminfo.edit_layout;
727         } else {
728                gl_dbgE("Wrong view!");
729                return;
730         }
731
732         Evas_Object *check = elm_object_part_content_get(ly, "selectall_check");
733         if (check) {
734                 Eina_Bool new_state = EINA_FALSE;
735                 Eina_Bool ck_state = elm_check_state_get(check);
736                 /* uncheck->check */
737                 if (ck_state == EINA_FALSE)
738                         new_state = EINA_TRUE;
739
740                 elm_check_state_set(check, new_state);
741
742                 _gl_ui_selall_check_changed(ad, check, NULL);
743         } else {
744                 gl_dbgE("Get select all checkbox object failed!");
745         }
746 }
747
748 static int __gl_ui_cancel_edit(void *data)
749 {
750         GL_CHECK_VAL(data, -1);
751         gl_appdata *ad = (gl_appdata *)data;
752         int view_mode = gl_get_view_mode(ad);
753         gl_dbg("");
754
755         if (view_mode == GL_VIEW_ALBUMS_EDIT)
756         {
757                 _gl_destroy_albums_edit_view(ad);
758
759                 _gl_data_finalize_albums_selected_list(ad);
760                 /**
761                 *  after back to albums view from albums edit view,
762                 *  option header should be defaultly closed
763                 */
764
765                 _gl_data_get_cluster_list(ad);
766                 GL_CHECK_VAL(ad->albuminfo.cluster_list, -1);
767
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,
772                                                       false);
773                 } else {
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,
777                                                               GL_NAVI_ALBUMS,
778                                                               false);
779                         }
780                 }
781         }
782         else if (view_mode == GL_VIEW_THUMBS_EDIT)
783         {
784                 _gl_destroy_thumbs_edit_view(ad);
785                 _gl_data_selected_list_finalize(ad);
786
787                 gl_set_view_mode(ad, GL_VIEW_THUMBS);
788
789                 if (ad->albuminfo.update_albums_list)
790                 {
791                         /*
792                          * Update albums list if MMC added/removed,
793                          */
794                         ad->albuminfo.update_albums_list = false;
795                         gl_refresh_albums_list(ad);
796                 }
797
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);
804
805                 if (ad->albuminfo.update_albums_list)
806                 {
807                         /*
808                          * Update albums list if MMC added/removed
809                          */
810                         ad->albuminfo.update_albums_list = false;
811                         gl_refresh_albums_list(ad);
812                 }
813
814                 gl_list_change_to_view(ad);
815                 _gl_notify_destroy_selinfo(ad);
816         }
817         return 0;
818 }
819
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)
822 {
823         GL_CHECK(data);
824         GL_CHECK(obj);
825         gl_appdata *ad = (gl_appdata *)data;
826
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);
829
830         elm_naviframe_item_pop(ad->maininfo.naviframe);
831
832 #ifdef _USE_ROTATE_BG
833         ad->gridinfo.left_btn = NULL;
834         ad->gridinfo.right_btn = NULL;
835         ad->gridinfo.more_btn = NULL;
836 #endif
837         __gl_ui_cancel_edit(data);
838         return;
839 }
840
841 static void _gl_ui_edit_cb(void *data, Evas_Object *obj, void *event_info)
842 {
843         GL_CHECK(data);
844         gl_appdata *ad = (gl_appdata *)data;
845         if (ad->uginfo.ug_called_by_me || ad->gridinfo.grid_append_idler) {
846                 /**
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.
850                 */
851                 gl_dbgW("UG invoked or appending gridview!");
852                 return;
853         }
854
855         int view_mode = gl_get_view_mode(ad);
856         gl_dbg("mode: %d", view_mode);
857         if (view_mode == GL_VIEW_THUMBS_EDIT) {
858                 /**
859                 * Happen in quickly tap edit button,
860                 * it will invoke _gl_ui_edit_cb several time
861                 * and push some unuseful views.
862                 */
863                 gl_dbgW("Already in edit mode, return!");
864                 return;
865         }
866
867         _gl_notify_destroy_notiinfo(ad);
868
869         Evas_Object *layout = NULL;
870         Evas_Object *view = NULL;
871
872         if (view_mode == GL_VIEW_ALBUMS) {
873                 gl_set_view_mode(ad, GL_VIEW_ALBUMS_EDIT);
874
875                 layout = _gl_ui_create_view_ly(ad->maininfo.naviframe);
876                 GL_CHECK(layout);
877                 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND,
878                                                  EVAS_HINT_EXPAND);
879                 evas_object_size_hint_align_set(layout, EVAS_HINT_FILL,
880                                                 EVAS_HINT_FILL);
881                 ad->albuminfo.edit_layout = layout;
882
883                 view = gl_albums_create_view(ad, layout);
884                 ad->albuminfo.edit_view = view;
885
886                 edje_object_signal_emit(_EDJ(layout),
887                                         "elm,swallow_view,state,edit", "elm");
888
889                 gl_ui_create_title_and_push(ad, ad->maininfo.naviframe, layout,
890                                             GL_NAVI_ALBUMS_EDIT,
891                                             GL_STR_SELECT_ALBUM);
892
893                 elm_object_part_content_set(layout, "elm.swallow.view", view);
894                 /* Display 'Select all' widget */
895                 gl_ui_show_selall(ad);
896
897                 gl_dbg("Done");
898                 return;
899         }
900
901         layout = _gl_ui_create_view_ly(ad->maininfo.naviframe);
902         GL_CHECK(layout);
903         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND,
904                                          EVAS_HINT_EXPAND);
905         evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
906         ad->gridinfo.edit_layout = layout;
907
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,
912                                                     GL_GRID_ALL,
913                                                     false);
914                 else
915                         view = _gl_grid_create_view(ad, layout,
916                                                     GL_GRID_IMAGES,
917                                                     false);
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);
921         }
922
923         if (view == NULL) {
924                 gl_dbgE("View creation failed!");
925                 evas_object_del(layout);
926                 ad->gridinfo.edit_layout = NULL;
927                 return;
928         }
929
930         ad->gridinfo.edit_view = view;
931
932         elm_object_part_content_set(layout, "elm.swallow.view", view);
933
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",
937                                 "elm");
938         gl_ui_show_selall(ad);
939
940         gl_dbg("Done");
941 }
942
943 static void _gl_ui_share_cb(void *data, Evas_Object *obj, void *event_info)
944 {
945         GL_CHECK(data);
946         gl_appdata *ad = (gl_appdata *)data;
947         gl_dbg("");
948
949         if (ad->uginfo.ug_called_by_me || ad->uginfo.app_called_by_me)
950         {
951                 gl_dbg("UG or APP is already loaded, return.");
952                 return;
953         }
954
955         int view_mode = gl_get_view_mode(ad);
956         int cnt = 0;
957         if ((view_mode == GL_VIEW_THUMBS_EDIT) ||
958             (view_mode == GL_VIEW_VIDEOLIST_EDIT)) {
959                 cnt = _gl_data_selected_list_count(ad);
960                 if (cnt == 0) {
961                         gl_dbg("No thumbs selected, return!");
962                         gl_popup_create_popup(ad, GL_POPUP_NOBUT,
963                                               GL_STR_NO_FILES_SELECTED);
964                         return;
965                 }
966
967                 gl_popup_create_title_popup(ad, GL_POPUP_THUMB_SHARE,
968                                             GL_STR_SHARE, NULL);
969         } else if (view_mode == GL_VIEW_ALBUMS_EDIT) {
970                 cnt = _gl_data_get_albums_selected_cnt(ad);
971                 if (cnt == 0) {
972                         gl_dbg("No albums selected, return!");
973                         gl_popup_create_popup(ad, GL_POPUP_NOBUT,
974                                               GL_STR_NO_ALBUMS_SELECTED);
975                         return;
976                 }
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);
982                         return;
983                 }
984
985                 gl_popup_create_title_popup(ad, GL_POPUP_ALBUM_SHARE,
986                                             GL_STR_SHARE, NULL);
987         } else {
988                 gl_dbgE("Unknow mode!");
989         }
990 }
991
992 /* move media to album in edit view */
993 int gl_ui_move_media_to_album(gl_appdata *ad)
994 {
995         GL_CHECK_VAL(ad, -1);
996         int view_mode = gl_get_view_mode(ad);
997         gl_dbg("");
998
999         if (ad->uginfo.ug_called_by_me || ad->uginfo.app_called_by_me)
1000         {
1001                 gl_dbg("UG or APP is already loaded, return.");
1002                 return -1;
1003         }
1004
1005         if ((view_mode == GL_VIEW_THUMBS_EDIT) ||
1006                 (view_mode == GL_VIEW_VIDEOLIST_EDIT))
1007         {
1008
1009                 int cnt = _gl_data_selected_list_count(ad);
1010                 if (cnt == 0)
1011                 {
1012                         gl_dbg("No thumbs selected, return!");
1013                         gl_popup_create_popup(ad, GL_POPUP_NOBUT,
1014                                 GL_STR_NO_FILES_SELECTED);
1015                         return -1;
1016                 }
1017
1018                 gl_popup_create_title_popup(ad, GL_POPUP_THUMB_MOVE,
1019                                 GL_STR_MOVE, NULL);
1020                 return 0;
1021         }
1022         else
1023         {
1024                 gl_dbg("Unknow mode!");
1025                 return -1;
1026         }
1027 }
1028
1029 static void _gl_ui_medias_del_cb(void *data, Evas_Object *obj, void *event_info)
1030 {
1031         GL_CHECK(data);
1032         gl_appdata *ad = (gl_appdata *)data;
1033         gl_dbg("");
1034
1035         if (ad->uginfo.ug_called_by_me || ad->uginfo.app_called_by_me)
1036         {
1037                 gl_dbg("UG or APP is already loaded, return.");
1038                 return;
1039         }
1040
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);
1045                 if (cnt == 0)
1046                 {
1047                         gl_dbg("No thumbs selected, return!");
1048                         gl_popup_create_popup(ad, GL_POPUP_NOBUT, GL_STR_NO_FILES_SELECTED);
1049                         return;
1050                 }
1051
1052                 gl_del_medias(ad);
1053         } else {
1054                 gl_dbgW("Unknow mode!");
1055         }
1056 }
1057
1058 static void _gl_ui_albums_del_cb(void *data, Evas_Object *obj, void *event_info)
1059 {
1060         GL_CHECK(data);
1061         gl_appdata *ad = (gl_appdata *)data;
1062         gl_dbg("");
1063
1064         if ((gl_get_view_mode(ad) == GL_VIEW_ALBUMS_EDIT))
1065         {
1066                 int cnt = _gl_data_get_albums_selected_cnt(ad);
1067                 if (cnt == 0)
1068                 {
1069                         gl_dbg("No albums selected, return!");
1070                         gl_popup_create_popup(ad, GL_POPUP_NOBUT,
1071                                 GL_STR_NO_ALBUMS_SELECTED);
1072                         return;
1073                 }
1074                 gl_popup_create_albums_del_popup(ad);
1075         }
1076         else
1077         {
1078                 gl_dbg("Unknow mode!");
1079         }
1080 }
1081
1082 /**
1083 * Update checkbox state in select-all widget
1084 */
1085 int _gl_ui_update_selall(void *data, int all_cnt, int selected_cnt)
1086 {
1087         GL_CHECK_VAL(data, -1);
1088         gl_appdata *ad = (gl_appdata *)data;
1089         int i = 0;
1090         gl_item *gitem = NULL;
1091         int _all_cnt = 0;
1092         int db_all_cnt = 0;
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;
1097
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;
1105                 } else {
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;
1111
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))
1116                                         _all_cnt++;
1117                         }
1118                 }
1119
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;
1124         } else {
1125                 gl_dbg("Wrong view mode!");
1126                 return 0;
1127         }
1128
1129         /**
1130         * Set checkbox state
1131         * except in albums edit view and selectioninfo view
1132         */
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)
1138                 state = EINA_TRUE;
1139         else
1140                 state = EINA_FALSE;
1141
1142         check = elm_object_part_content_get(ly, "selectall_check");
1143         if (check)
1144                 elm_check_state_set(check, state);
1145         return 0;
1146 }
1147
1148 int _gl_ui_hide_back_button(Elm_Object_Item *nf_it)
1149 {
1150         GL_CHECK_VAL(nf_it, -1);
1151         elm_object_item_part_content_set(nf_it, GL_NAVIFRAME_PREB_BTN, NULL);
1152         return 0;
1153 }
1154
1155 static void __gl_ui_move_cb(void *data, Evas_Object *obj, void *event_info)
1156 {
1157         GL_CHECK(data);
1158         gl_ui_move_media_to_album(data);
1159         return;
1160 }
1161
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)
1164 {
1165         GL_CHECK(data);
1166         gl_appdata *ad = (gl_appdata *)data;
1167         GL_CHECK(ad->maininfo.win);
1168
1169         gl_dbg("Back button clicked, change view to background.");
1170         Evas_Object *win = (Evas_Object *) (ad->maininfo.win);
1171
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
1175         */
1176         ad->albuminfo.albumgic.func.text_get = NULL;
1177         ad->albuminfo.albumgic.func.content_get = NULL;
1178
1179         ad->albuminfo.albumgic_blue.func.text_get = NULL;
1180         ad->albuminfo.albumgic_blue.func.content_get = NULL;
1181
1182         elm_win_lower(win);
1183
1184         return;
1185 }
1186
1187 /**
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.
1190  */
1191 static int __gl_ui_add_toolbar_items_albums(void *data, Evas_Object *bot_bar)
1192 {
1193         gl_dbg("");
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;
1199
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;
1204
1205         _gl_ctrl_append_object_item(bot_bar, NULL);
1206         /* add edit item */
1207         edit_it = _gl_ui_append_edit(ad, bot_bar);
1208         _gl_ctrl_enable_item(edit_it);
1209
1210         ad->albuminfo.edit_it = edit_it;
1211
1212         _gl_ctrl_append_object_item(bot_bar, NULL);
1213
1214         _gl_ctrl_enable_item(edit_it);
1215
1216         return 0;
1217 }
1218
1219 #ifdef _USE_ROTATE_BG
1220 static void __gl_ui_rotate_left_cb(void *data, Evas_Object *obj, void *event_info)
1221 {
1222         GL_CHECK(data);
1223         _gl_rotate_images(data, true);
1224 }
1225
1226 static void __gl_ui_rotate_right_cb(void *data, Evas_Object *obj, void *event_info)
1227 {
1228         GL_CHECK(data);
1229         _gl_rotate_images(data, false);
1230 }
1231
1232 static Evas_Object *__gl_ui_add_optionheader(void *data, Evas_Object *parent)
1233 {
1234         GL_CHECK_NULL(data);
1235         gl_appdata *ad = (gl_appdata *)data;
1236         Evas_Object *oh = NULL;
1237         oh = _gl_ctrl_add_optionheader(parent);
1238
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,
1244                                        data);
1245         _gl_ctrl_append_object_item(oh, btn);
1246         ad->gridinfo.left_btn = btn;
1247
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,
1252                                        data);
1253         _gl_ctrl_append_object_item(oh, btn);
1254         ad->gridinfo.right_btn= btn;
1255
1256         return oh;
1257 }
1258 static void __gl_ui_more_btn_cb(void *data, Evas_Object *obj, void *event_info)
1259 {
1260         GL_CHECK(data);
1261         Elm_Object_Item *nf_it = (Elm_Object_Item *)data;
1262         _gl_ui_open_optionheader(data, !(int)elm_object_item_data_get(nf_it));
1263 }
1264
1265 static int __gl_ui_add_more_btn(void *data, Elm_Object_Item *nf_it, Evas_Object *parent)
1266 {
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;
1272
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,
1276                                        nf_it);
1277         elm_object_item_part_content_set(nf_it, GL_NAVIFRAME_TITLE_MORE_BTN,
1278                                          more_btn);
1279         ad->gridinfo.more_btn = more_btn;
1280         elm_object_disabled_set(more_btn, true);
1281
1282         Evas_Object *optionheader = __gl_ui_add_optionheader(data, parent);
1283         elm_object_item_part_content_set(nf_it, GL_NAVIFRAME_OPTIONHEAD,
1284                                          optionheader);
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);
1288         return 0;
1289 }
1290
1291 #endif
1292
1293 static void __gl_ui_trans_finished_cb(void *data, Evas_Object *obj, void *event_info)
1294 {
1295         GL_CHECK(data);
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);
1301
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)
1307                         return;
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)
1314                         return;
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);
1320         }
1321 }
1322 static void __gl_ui_slideshow_btn_cb(void *data, Evas_Object *obj, void *event_info)
1323 {
1324         GL_CHECK(data);
1325         gl_appdata *ad = (gl_appdata *)data;
1326         gl_item *cur_item = NULL;
1327
1328         media_content_type_e type = MEDIA_CONTENT_TYPE_IMAGE;
1329
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;
1334
1335         _gl_data_get_first_item(ad, type, &cur_item);
1336         GL_CHECK(cur_item);
1337         gl_ext_load_iv_ug(ad, cur_item, GL_UG_IV_SLIDESHOW_LOCAL);
1338 }
1339
1340 static int __gl_ui_add_slideshow_btn(void *data, Elm_Object_Item *nf_it, Evas_Object *parent)
1341 {
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;
1346
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,
1353                                          slideshow_btn);
1354         return 0;
1355 }
1356
1357 /**
1358  *  Use naviframe api to push albums view to stack.
1359  *  @param obj is the content to be pushed.
1360  */
1361 static int __gl_ui_push_view_albums(void *data, Evas_Object *parent,
1362                                     Evas_Object *obj, char *title)
1363 {
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;
1372
1373         /* create tool controlbar downside */
1374         bot_bar = _gl_ctrl_create_toolbar(obj);
1375         GL_CHECK_VAL(bot_bar, -1);
1376
1377         /* add items */
1378         __gl_ui_add_toolbar_items_albums(ad, bot_bar);
1379
1380         /**
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
1384         */
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,
1390                                        ad);
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,
1394                                         NULL);
1395         gl_dbg_launch("        elm_naviframe_item_push:end");
1396         ad->albuminfo.nf_it = nf_it;
1397
1398         /* Set tool controlbar to bottom */
1399         elm_object_item_part_content_set(ad->albuminfo.nf_it,
1400                                          GL_NAVIFRAME_CONTROLBAR, bot_bar);
1401         return 0;
1402 }
1403
1404 /**
1405  *  Use naviframe api to push albums edit view to stack.
1406  *  @param obj is the content to be pushed.
1407  */
1408 static int __gl_ui_push_view_albums_edit(void *data, Evas_Object *parent,
1409                                          Evas_Object *obj, char *title)
1410 {
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;
1421
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);
1429
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);
1439
1440         /* Add transition finished callback */
1441         evas_object_smart_callback_add(parent, GL_TRANS_FINISHED,
1442                                        __gl_ui_trans_finished_cb, ad);
1443         /* Push to stack */
1444         nf_it = elm_naviframe_item_push(parent, title, NULL, NULL, obj,
1445                                         NULL);
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);
1450         return 0;
1451 }
1452
1453 /**
1454  *  Use naviframe api to push thumbnails view to stack.
1455  *  @param obj is the content to be pushed.
1456  */
1457 static int __gl_ui_push_view_thumbs(void *data, Evas_Object *parent,
1458                                     Evas_Object *obj, char *title)
1459 {
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;
1469
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;
1478                 /* add segment */
1479                 segment = _gl_ctrl_create_segment(ad, bot_bar);
1480                 _gl_ctrl_append_object_item(bot_bar, segment);
1481         }
1482         /* Add transition finished callback */
1483         evas_object_smart_callback_add(parent, GL_TRANS_FINISHED,
1484                                        __gl_ui_trans_finished_cb, ad);
1485
1486         /* Push to stack with basic transition */
1487         nf_it = elm_naviframe_item_push(parent, title, NULL, NULL, obj,
1488                                         NULL);
1489
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);
1493
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);
1498         }
1499         return 0;
1500 }
1501
1502 /**
1503  *  Use naviframe api to push thumbnails eidt view to stack.
1504  *  @param obj is the content to be pushed.
1505  */
1506 static int __gl_ui_push_view_thumbs_edit(void *data, Evas_Object *parent,
1507                                          Evas_Object *obj, char *title)
1508 {
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;
1522 #endif
1523         /* create tool controlbar downside */
1524         bot_bar = _gl_ctrl_create_toolbar(obj);
1525         GL_CHECK_VAL(bot_bar, -1);
1526
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;
1531 #endif
1532         /* Add 'Delete' item */
1533         del_it = elm_toolbar_item_append(bot_bar,
1534                                          GL_CBAR_ICON_DELETE,
1535                                          NULL,
1536                                          _gl_ui_medias_del_cb,
1537                                          ad);
1538         _gl_ctrl_disable_item(del_it);
1539
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);
1544
1545         move_it = elm_toolbar_item_append(bot_bar,
1546                                           GL_CBAR_ICON_MOVE,
1547                                           NULL,
1548                                           __gl_ui_move_cb,
1549                                           ad);
1550         _gl_ctrl_disable_item(move_it);
1551
1552         /* Add 'Cancel' item */
1553         cancel_it = elm_toolbar_item_append(bot_bar, GL_CBAR_ICON_CANCEL,
1554                                             NULL,
1555                                             __gl_ui_click_cancel_edit_cb,
1556                                             ad);
1557
1558         /* Add transition finished callback */
1559         evas_object_smart_callback_add(parent, GL_TRANS_FINISHED,
1560                                        __gl_ui_trans_finished_cb, ad);
1561         /* Push to stack */
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);
1565
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);
1570         }
1571 #endif
1572
1573         /* Set tool bar to bottom */
1574         elm_object_item_part_content_set(nf_it, GL_NAVIFRAME_CONTROLBAR,
1575                                          bot_bar);
1576
1577         return 0;
1578 }
1579
1580 /**
1581  *  Use naviframe api to push albums rename view to stack.
1582  *  @param obj is the content to be pushed.
1583  */
1584 static int __gl_ui_push_view_albums_rename(void *data, Evas_Object *parent,
1585                                            Evas_Object *obj, char *title)
1586 {
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;
1595
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,
1608                                          cancel_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,
1617                                          done_btn);
1618         ad->entryinfo.done_btn = done_btn;
1619         ad->entryinfo.nf_it = nf_it;
1620         return 0;
1621 }
1622
1623 /**
1624  *  Use naviframe api to push new album view to stack.
1625  *  @param obj is the content to be pushed.
1626  */
1627 static int __gl_ui_push_view_albums_new(void *data, Evas_Object *parent,
1628                                         Evas_Object *obj, char *title)
1629 {
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;
1638
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,
1649                                          cancel_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,
1658                                          done_btn);
1659         ad->entryinfo.done_btn = done_btn;
1660         return 0;
1661 }
1662
1663 int _gl_ui_disable_slideshow_btn(void *data, bool b_disable)
1664 {
1665         GL_CHECK_VAL(data, -1);
1666         gl_appdata *ad = (gl_appdata *)data;
1667
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);
1672         if (slideshow_btn);
1673                 elm_object_disabled_set(slideshow_btn, b_disable);
1674         return 0;
1675 }
1676
1677 #ifdef _USE_ROTATE_BG
1678 int _gl_ui_open_optionheader(void *data, int open)
1679 {
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",
1684                                             "");
1685                 elm_object_item_data_set(nf_it, (void *)(GL_UI_MORE_STATE_OPEN));
1686         } else {
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));
1690         }
1691         return 0;
1692 }
1693
1694 int _gl_ui_disable_more_btn(void *data, bool b_disable)
1695 {
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);
1705         if (_more_btn)
1706                 elm_object_disabled_set(_more_btn, b_disable);
1707         /* Close optionheader manually */
1708         if (b_disable)
1709                 _gl_ui_open_optionheader(nf_it, GL_UI_MORE_STATE_CLOSE);
1710         return 0;
1711 }
1712 #endif
1713
1714 /* Append 'Edit' item to toolbar */
1715 Elm_Object_Item *_gl_ui_append_edit(void *data, Evas_Object *bot_bar)
1716 {
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);
1722         return edit_it;
1723 }
1724
1725 int gl_ui_cancel_rename_album(void *data)
1726 {
1727         GL_CHECK_VAL(data, -1);
1728         gl_dbg("");
1729         __gl_ui_cancel_rename_album(data);
1730
1731         return 0;
1732 }
1733
1734 int gl_ui_cancel_new_album(void *data)
1735 {
1736         GL_CHECK_VAL(data, -1);
1737         gl_dbg("");
1738         _gl_ui_cancel_newalbum(data);
1739
1740         return 0;
1741 }
1742
1743 int gl_ui_move_to_newalbum(void *data)
1744 {
1745         GL_CHECK_VAL(data, -1);
1746         gl_appdata *ad = (gl_appdata *)data;
1747         Evas_Object *editfield_ly = NULL;
1748         gl_dbg("");
1749
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);
1754
1755         gl_ui_create_title_and_push(ad, ad->maininfo.naviframe, editfield_ly,
1756                                     GL_NAVI_ALBUMS_NEW, GL_STR_CREATE_ALBUM);
1757
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);
1762
1763         return 0;
1764 }
1765
1766 int gl_ui_rename_album(gl_cluster *album_item)
1767 {
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;
1776         gl_dbg("");
1777
1778         if(ad->maininfo.rename_album_job) {
1779                 ecore_job_del(ad->maininfo.rename_album_job);
1780                 ad->maininfo.rename_album_job = NULL;
1781         }
1782         if (view_mode != GL_VIEW_ALBUMS_EDIT) {
1783                 gl_dbgE("Unexpected view mode(%d)!", view_mode);
1784                 return -1;
1785         }
1786
1787         /* save album selected for rename */
1788         ad->albuminfo.selected_album = album_item;
1789
1790         gl_set_view_mode(ad, GL_VIEW_ALBUMS_RENAME);
1791
1792         ad->entryinfo.entry_mode = GL_ENTRY_RENAME_ALBUM;
1793
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);
1798
1799         gl_ui_create_title_and_push(ad, ad->maininfo.naviframe, editfield_ly,
1800                                     GL_NAVI_ALBUMS_RENAME, GL_STR_CHNAGE_NAME);
1801
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);
1806         return 0;
1807 }
1808
1809 int gl_ui_create_title_and_push(void *data, Evas_Object *parent,
1810                                 Evas_Object *obj, gl_navi_mode mode, char *title)
1811 {
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);
1816
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);
1829         gl_dbg("Done");
1830         gl_dbg_launch("      gl_ui_create_title_and_push:end");
1831         return 0;
1832 }
1833
1834 Evas_Object *
1835 gl_ui_load_edj(Evas_Object * parent, const char *file, const char *group)
1836 {
1837         Evas_Object *eo = NULL;
1838         int r = 0;
1839
1840         eo = elm_layout_add(parent);
1841         if (eo)
1842         {
1843                 r = elm_layout_file_set(eo, file, group);
1844                 if (!r)
1845                 {
1846                         evas_object_del(eo);
1847                         return NULL;
1848                 }
1849
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);
1852         }
1853
1854         return eo;
1855 }
1856
1857 int gl_ui_edit_cancel(void *data)
1858 {
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;
1863
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);
1869                 }
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;
1874         }
1875         elm_naviframe_item_pop_to(nf_it);
1876         __gl_ui_cancel_edit(ad);
1877
1878         return 0;
1879 }
1880
1881 /* Remove selection and edit view then pop to normal thumbnail view */
1882 int _gl_ui_pop_to_thumb(void *data)
1883 {
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);
1890
1891         return 0;
1892 }
1893
1894 /**
1895 * Update checkbox state and add click signal to Select-all widget.
1896 * Show arrow button in thumbnails/list edit mode.
1897 */
1898 int gl_ui_show_selall(void *data)
1899 {
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";
1906
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;
1922         } else {
1923                 gl_dbgE("Wrong view!");
1924                 return -1;
1925         }
1926
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",
1931                                           GL_STR_SELECT_ALL);
1932
1933         Evas_Object *old_check = NULL;
1934         old_check = elm_object_part_content_unset(view_ly, "selectall_check");
1935         if (old_check)
1936                 evas_object_del(old_check);
1937
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);
1941
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");
1946
1947         /* Add signal to select-all bg */
1948         edje_object_signal_callback_del(_EDJ(view_ly), "elm,action,click",
1949                                         "selectall_bg",
1950                                         _gl_ui_selall_bg_click_cb);
1951         edje_object_signal_callback_add(_EDJ(view_ly), "elm,action,click",
1952                                         "selectall_bg",
1953                                         _gl_ui_selall_bg_click_cb, ad);
1954
1955         return 0;
1956 }
1957
1958 /* Update checkbox state of Select-all and selectioninfo */
1959 int gl_ui_update_select_widgets(void *data)
1960 {
1961         GL_CHECK_VAL(data, -1);
1962         gl_appdata *ad = (gl_appdata *)data;
1963
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);
1971         return 0;
1972 }
1973
1974 Evas_Object *gl_ui_create_main_ly(Evas_Object *parent)
1975 {
1976         gl_dbg_launch("    gl_ui_create_main_ly:start");
1977         GL_CHECK_NULL(parent);
1978         Evas_Object *layout = NULL;
1979
1980         layout = elm_layout_add(parent);
1981         GL_CHECK_NULL(layout);
1982
1983         /* Apply the layout style */
1984         gl_dbg_launch("      elm_layout_theme_set:start");
1985
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");
1991         }
1992
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");
1999
2000         return layout;
2001 }
2002
2003 Evas_Object *gl_ui_create_navi_ly(Evas_Object *parent)
2004 {
2005         GL_CHECK_NULL(parent);
2006         Evas_Object *navi_bar = NULL;
2007         gl_dbg_launch("    gl_ui_create_navi_ly:start");
2008
2009         navi_bar = elm_naviframe_add(parent);
2010         gl_dbg("elm_naviframe_add:done");
2011
2012         evas_object_show(navi_bar);
2013         gl_dbg("elm_object_style_set: done");
2014         gl_dbg_launch("    gl_ui_create_navi_ly:end");
2015
2016         return navi_bar;
2017 }
2018
2019 Evas_Object *_gl_ui_create_view_ly(Evas_Object *parent)
2020 {
2021         gl_dbg("");
2022         GL_CHECK_NULL(parent);
2023
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);
2028
2029         return layout;
2030 }
2031