dbf4e460c365dc11e01f5169e2be3b00876dbe97
[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 <vconf.h>
18 #include <vconf-keys.h>
19 #include <string.h>
20 #include <Ecore_X.h>
21 #include <glib.h>
22 #include "gl-ui-util.h"
23 #include "gl-util.h"
24 #include "gl-ext-ug-load.h"
25 #include "gl-ext-exec.h"
26 #include "gl-button.h"
27 #include "gl-gridview.h"
28 #include "gl-controlbar.h"
29 #include "gl-albums.h"
30 #include "gl-listview.h"
31 #include "gl-debug.h"
32 #include "gl-db-handler.h"
33 #include "gl-thread-util.h"
34 #include "gl-popup.h"
35 #include "gl-progressbar.h"
36 #include "gl-strings.h"
37
38 #define GL_CBAR_OCCUPIED_SEGMENT 4
39
40 #define GL_EDITFIELD_STYLE_DEFAULT GL_CHECKBOX_STYLE_DEFAULT
41 #define GL_ENTRY_STYLE_DEFAULT GL_CHECKBOX_STYLE_DEFAULT
42 #define GL_NAVIBAR_STYLE_DEFAULT GL_CHECKBOX_STYLE_DEFAULT
43 #define GL_TRANS_FINISHED "transition,finished"
44
45 static void _gl_ui_newalbum_cancel_cb(void *data, Evas_Object * obj,
46                                        void *event_info);
47 void __gl_ui_entry_space_check_cb(void *data, Evas_Object *obj, void *event_info);
48 void __gl_ui_entry_maxlen_reached_cb(void *data, Evas_Object *obj, void *event_info);
49 static void __gl_editfield_focused_cb(void *data, Evas_Object *obj, void *event_info);
50 static void __gl_editfield_unfocused_cb(void *data, Evas_Object *obj, void *event_info);
51 static void __gl_editfield_eraser_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source);
52
53 static Evas_Object *
54 _gl_ui_create_editfield(void *data, Evas_Object * parent, char *default_label)
55 {
56         GL_CHECK_NULL(data);
57         gl_appdata *ad = (gl_appdata *)data;
58         gl_dbg("");
59         Evas_Object *editfield_ly = NULL;
60         Evas_Object *lay = NULL;
61         Evas_Object *entry = NULL;
62         static Elm_Entry_Filter_Limit_Size limit_filter_data;
63
64         lay = elm_layout_add(parent);
65         GL_CHECK_NULL(lay);
66         evas_object_size_hint_weight_set(lay, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
67         elm_layout_file_set(lay, GL_EDJ_FILE, GL_GRP_ENTRY);
68
69         /* Single line with no title */
70         editfield_ly = elm_layout_add(lay);
71         if (editfield_ly == NULL) {
72                 gl_dbgE("elm_editfield_add failed!");
73                 evas_object_del(lay);
74                 return NULL;
75         }
76         elm_layout_theme_set(editfield_ly, "layout", "editfield", "gallery");
77         evas_object_size_hint_weight_set(editfield_ly, 1, 1);
78         evas_object_size_hint_align_set(editfield_ly, 1, 0.5);
79         /* Set editfield layout to view layout */
80         elm_object_part_content_set(lay, "entry_part", editfield_ly);
81
82         entry = elm_entry_add(editfield_ly);
83         if (entry == NULL) {
84                 gl_dbgE("elm_entry_add failed!");
85                 evas_object_del(lay);
86                 return NULL;
87         }
88         elm_object_style_set(entry, GL_ENTRY_STYLE_DEFAULT);
89         elm_entry_scrollable_set(entry, EINA_TRUE);
90         elm_entry_single_line_set(entry, EINA_TRUE);
91         /* Set entry to editfield layout */
92         elm_object_part_content_set(editfield_ly, "elm.swallow.content", entry);
93
94         /* Album name, the length is limited to 255 Chars*/
95         limit_filter_data.max_char_count = GL_ENTRY_STR_CHAR_MAX;
96         limit_filter_data.max_byte_count = 0;
97         elm_entry_markup_filter_append(entry, elm_entry_filter_limit_size,
98                                        &limit_filter_data);
99
100         if (gl_set_entry_text(entry, default_label) != 0) {
101                 gl_dbgE("gl_set_entry_text failed!");
102                 evas_object_del(lay);
103                 return NULL;
104         }
105
106         ad->entryinfo.imf_entry = entry;
107         ad->entryinfo.imf_context = elm_entry_imf_context_get(ad->entryinfo.imf_entry);
108
109         gl_dbg("view mode=%d", gl_get_view_mode(ad));
110         evas_object_smart_callback_add(entry, "maxlength,reached",
111                                        __gl_ui_entry_maxlen_reached_cb, ad);
112
113         /* Add space check callback */
114         evas_object_smart_callback_add(entry, "changed",
115                                        __gl_ui_entry_space_check_cb,
116                                        ad);
117         evas_object_smart_callback_add(entry, "focused",
118                                        __gl_editfield_focused_cb, editfield_ly);
119         evas_object_smart_callback_add(entry, "unfocused",
120                                        __gl_editfield_unfocused_cb,
121                                        editfield_ly);
122         elm_object_signal_callback_add(editfield_ly, "elm,eraser,clicked", "elm",
123                                        __gl_editfield_eraser_clicked_cb, entry);
124
125         ad->entryinfo.editfield = editfield_ly;
126
127         return lay;
128 }
129
130 static void
131 _gl_ui_selinfo_destroy_cb(void *data, Evas_Object * obj, void *event_info)
132 {
133         GL_CHECK(data);
134         gl_appdata *ad = (gl_appdata *)data;
135         int view_mode = gl_get_view_mode(ad);
136         gl_dbg("");
137         gl_ui_destroy_selinfo(ad);
138
139         if (view_mode == GL_VIEW_ALBUMS_EDIT)
140         {
141                 edje_object_signal_emit(_EDJ(ad->albuminfo.edit_layout),
142                                         "elm,swallow_view,state,default", "elm");
143         } else if (view_mode == GL_VIEW_THUMBS_EDIT ||
144                    view_mode == GL_VIEW_VIDEOLIST_EDIT) {
145                 edje_object_signal_emit(_EDJ(ad->gridinfo.edit_layout),
146                                         "elm,swallow_view,state,thumb_edit_default",
147                                         "elm");
148         } else {
149                 gl_dbgE("Wrong view mode!");
150         }
151 }
152
153 /* Hide input panel and entry cursor */
154 static int _gl_ui_hide_imf_input_panel(void *data)
155 {
156         GL_CHECK_VAL(data, -1);
157         gl_appdata* ad = (gl_appdata*)data;
158
159         if (ad->entryinfo.imf_context)
160                 ecore_imf_context_input_panel_hide(ad->entryinfo.imf_context);
161         /* Unfocus to hide cursor */
162         elm_object_focus_set(ad->entryinfo.imf_entry, FALSE);
163
164         return 0;
165 }
166
167 /**
168 * Check album name is valid and remove unuseful characters
169 *       1) not only includes space;
170 *       2) contains invalid character;
171 *       3) it's empty.
172 *
173 * @param b_new
174 *       true: add a new album ; false: rename a album.
175 * @param b_enter
176 *       true: Enter key pressed ; false: Button Done clicked.
177 *
178 */
179 static int _gl_ui_get_valid_album_name(void *data, char* album_name,
180                                         bool b_new, bool b_enter)
181 {
182         GL_CHECK_VAL(album_name, -1);
183         GL_CHECK_VAL(data, -1);
184         gl_appdata* ad = (gl_appdata*)data;
185         int mode = 0;
186         gl_dbg("Input album name: %s", album_name);
187         char *popup_desc;
188         popup_desc = (char*)calloc(GL_POPUP_STRING_MAX, sizeof(char));
189         if (popup_desc == NULL) {
190                 gl_dbg("memory allocation fail");
191                 return -1;
192         }
193         /* Check album name length */
194         if (strlen(album_name) == 0) {
195                 gl_dbgW("Inserted text is empty!");
196                 if (b_enter) {
197                         gl_dbg("Enter key pressed.");
198                         goto INVALID_ALBUM_NAME;
199                         return -1;
200                 }
201
202                 if (b_new)
203                         mode = GL_POPUP_ALBUM_NEW_EMPTY;
204                 else
205                         mode = GL_POPUP_ALBUM_RENAME_EMPTY;
206                 snprintf(popup_desc, GL_POPUP_STRING_MAX, "%s.<br>%s",
207                         GL_STR_ENTRY_IS_EMPTY, GL_STR_RETRY_Q);
208                 popup_desc[strlen(popup_desc)] = '\0';
209                 gl_popup_create_popup(ad, mode, popup_desc);
210                 goto INVALID_ALBUM_NAME;
211         }
212         gl_dbg("Inserted album name: %s, length: %d", album_name, strlen(album_name));
213
214         /* Removes leading and trailing whitespace */
215         g_strstrip((gchar*)album_name);
216         if (strlen(album_name) == 0) {
217                 gl_dbgW("Album name includes only space!");
218                 if (b_enter) {
219                         gl_dbg("Enter key pressed.");
220                         goto INVALID_ALBUM_NAME;
221                 }
222
223                 if (b_new)
224                         mode = GL_POPUP_ALBUM_NEW_EMPTY;
225                 else
226                         mode = GL_POPUP_ALBUM_RENAME_EMPTY;
227                 snprintf(popup_desc, GL_POPUP_STRING_MAX, "%s.<br>%s",
228                         GL_STR_INVALID_INPUT_PARAMETER, GL_STR_RETRY_Q);
229                 popup_desc[strlen(popup_desc)] = '\0';
230                 gl_popup_create_popup(ad, mode, popup_desc);
231                 goto INVALID_ALBUM_NAME;
232         }
233
234         /* Check if there is any invalid character in string */
235         if (gl_validate_album_name(album_name) == false) {
236                 gl_dbgW("Album name includes invalid character!");
237                 if (b_new)
238                         mode = GL_POPUP_ALBUM_NEW_INVALID;
239                 else
240                         mode = GL_POPUP_ALBUM_RENAME_INVALID;
241                 snprintf(popup_desc, GL_POPUP_STRING_MAX, "%s.<br>%s",
242                         GL_STR_INVALID_INPUT_PARAMETER, GL_STR_RETRY_Q);
243                 popup_desc[strlen(popup_desc)] = '\0';
244                 gl_popup_create_popup(ad, mode, popup_desc);
245                 goto INVALID_ALBUM_NAME;
246         }
247
248         free(popup_desc);
249
250         return 0;
251
252  INVALID_ALBUM_NAME:
253         free(popup_desc);
254         return -1;
255 }
256
257 /*
258 * @param b_enter
259 *       True: Enter key on Keyboard pressed, False: Button Done clicked
260 */
261 static int _gl_ui_newalbum_done(void *data, bool b_enter)
262 {
263         gl_dbg("b_enter: %d", b_enter);
264         GL_CHECK_VAL(data, -1);
265         gl_appdata *ad = (gl_appdata *)data;
266
267         if (ad->entryinfo.imf_entry == NULL) {
268                 gl_dbgE("Entry is NULL");
269                 goto NEW_ALBUM_FAILED;
270         }
271
272         if (ad->entryinfo.imf_context)
273                 ecore_imf_context_input_panel_hide(ad->entryinfo.imf_context);
274
275         Evas_Object *entry = ad->entryinfo.imf_entry;
276         char album_name[GL_ALBUM_NAME_LEN_MAX] = { 0, };
277
278         /* Get utf8 format string */
279         if (gl_get_entry_text(entry, album_name, GL_ALBUM_NAME_LEN_MAX) != 0) {
280                 gl_dbgE("Get entry text failed!");
281                 goto NEW_ALBUM_FAILED;
282         }
283
284         /* Get valid name */
285         if (_gl_ui_get_valid_album_name(ad, album_name, true, b_enter) != 0) {
286                 if (b_enter)
287                         _gl_ui_hide_imf_input_panel(ad);
288                 return -1;
289         }
290         gl_dbg("Valid album name: %s", album_name);
291
292         /* Check whether the new folder exist */
293         char path[GL_DIR_PATH_LEN_MAX] = { 0, };
294         char dir_path[GL_DIR_PATH_LEN_MAX] = { 0, };
295
296         /* Get default images path, make new album under it */
297         if (gl_get_default_images_path(dir_path) != 0) {
298                 gl_dbgE("Failed to get default image dir path!");
299                 goto NEW_ALBUM_FAILED;
300         }
301
302         /* Make dir full path of new album */
303         snprintf(path, GL_DIR_PATH_LEN_MAX, "%s/%s", dir_path, album_name);
304         path[strlen(path)] = '\0';
305         gl_dbg("New dir path: %s", path);
306
307         int res = ecore_file_dir_is_empty(path);
308         gl_dbg("ecore_file_dir_is_empty return value: %d", res);
309         /**
310         * If dir is empty, 1 is returned,
311         * if it contains at least 1 file, 0 is returned.
312         * On failure, -1 is returned.
313         */
314         if (res == 0) {
315                 char *popup_desc;
316                 popup_desc = (char*)calloc(GL_POPUP_STRING_MAX, sizeof(char));
317                 if (popup_desc == NULL) {
318                         gl_dbg("memory allocation fail");
319                         return -1;
320                 }
321
322                 snprintf(popup_desc, GL_POPUP_STRING_MAX, "%s.<br>%s",
323                         GL_STR_SAME_NAME_ALREADY_IN_USE, GL_STR_RETRY_Q);
324                 popup_desc[strlen(popup_desc)] = '\0';
325                 gl_popup_create_popup(ad, GL_POPUP_ALBUM_NEW_DUPLICATE,
326                                       popup_desc);
327                 free(popup_desc);
328                 gl_dbgW("New folder already exists and not NULL, return!");
329                 return -1;
330         }
331
332         /* Save new album name */
333         char* new_album = ad->albuminfo.new_album_name;
334         g_strlcpy(new_album, album_name, GL_ALBUM_NAME_LEN_MAX);
335         new_album[GL_ALBUM_NAME_LEN_MAX - 1] = '\0';
336         gl_ui_destroy_imf(ad);
337         /* Move files to dest album */
338         gl_move_to_album(ad);
339         return 0;
340
341  NEW_ALBUM_FAILED:
342         _gl_ui_newalbum_cancel_cb(ad, NULL, NULL);
343         return -1;
344 }
345
346 static void _gl_ui_newalbum_enter_cb(void *data, Evas_Object * obj, void *event_info)
347 {
348         gl_dbg("");
349         GL_CHECK(data);
350         gl_appdata *ad = (gl_appdata *)data;
351         /* Unfocus to hide cursor */
352         elm_object_focus_set(ad->entryinfo.imf_entry, FALSE);
353
354         _gl_ui_newalbum_done(data, true);
355 }
356
357 static void _gl_ui_newalbum_done_cb(void *data, Evas_Object * obj, void *event_info)
358 {
359         gl_dbg("");
360         _gl_ui_newalbum_done(data, false);
361 }
362
363 static void
364 _gl_ui_newalbum_cancel_cb(void *data, Evas_Object * obj, void *event_info)
365 {
366         GL_CHECK(data);
367         gl_appdata *ad = (gl_appdata *)data;
368         gl_dbg("");
369
370         elm_naviframe_item_pop(ad->maininfo.navi_bar);
371         gl_ui_destroy_imf(ad);
372         gl_ui_update_select_widgets(ad);
373 }
374
375 static void __gl_ui_rename_album_cancel_cb(void *data, Evas_Object * obj, void *event_info)
376 {
377         GL_CHECK(data);
378         gl_appdata *ad = (gl_appdata *)data;
379         GL_CHECK(ad->maininfo.navi_bar);
380         gl_dbg("");
381
382         ad->albuminfo.selected_album = NULL;
383         gl_set_view_mode(ad, GL_VIEW_ALBUMS_EDIT);
384         /* manually popup view after rename album */
385         elm_naviframe_item_pop(ad->maininfo.navi_bar);
386         /* Recover the previous UI */
387         gl_ui_destroy_imf(ad);
388         /* Update edit view */
389         gl_albums_update_items(ad);
390         return;
391 }
392
393 /*
394 * @param b_enter
395 *       True: Enter key on Keyboard pressed, False: Button Done clicked
396 */
397 static int __gl_ui_rename_album_done(void *data, bool b_enter)
398 {
399         gl_dbg("b_enter: %d", b_enter);
400         GL_CHECK_VAL(data, -1);
401         gl_appdata *ad = (gl_appdata *)data;
402         bool b_root_path = false;
403         gl_cluster *album_item = NULL;
404
405         if (gl_get_view_mode(ad) != GL_VIEW_ALBUMS_RENAME)      {
406                 gl_dbgE("View mode is wrong!");
407                 goto RENAME_FAILED;
408         }
409
410         album_item = ad->albuminfo.selected_album;
411         if (album_item == NULL || album_item->cluster == NULL ||
412             album_item->cluster->uuid == NULL) {
413                 gl_dbgE("selected_album is NULL!");
414                 goto RENAME_FAILED;
415         }
416
417         char etxt[GL_FILE_NAME_LEN_MAX] = { 0, };
418         /* Get utf8 format string */
419         int ret = -1;
420         ret = gl_get_entry_text(ad->entryinfo.imf_entry, etxt,
421                                 GL_FILE_NAME_LEN_MAX);
422         if (ret != 0) {
423                 gl_dbgE("Get entry text failed!");
424                 goto RENAME_FAILED;
425         }
426
427         /* Get valid name */
428         if (_gl_ui_get_valid_album_name(ad, etxt, false, b_enter) != 0) {
429                 if (b_enter)
430                         _gl_ui_hide_imf_input_panel(ad);
431                 return -1;
432         }
433
434         gl_dbg("Valid album name: %s", etxt);
435         /* Get src folder path */
436         char dir_path[GL_DIR_PATH_LEN_MAX] = { 0, };
437         ret = gl_db_get_folder_fullpath(ad, album_item->cluster->uuid, dir_path);
438         if (ret < 0) {
439                 gl_dbgE("gl_db_get_folder_fullpath failed(%d)!", ret);
440                 goto RENAME_FAILED;
441         } else {
442                 gl_dbg("Src folder: %s", dir_path);
443                 if (gl_db_is_root_path(ad, NULL, dir_path)) {
444                         /**
445                         * Root path, couldn't rename root path,
446                         * make the new dest folder
447                         * and move all files for root path to it.
448                         */
449                         gl_dbg("Rename [No Name] album's name.");
450                         b_root_path = true;
451                 }
452         }
453
454         /* Get dest folder path */
455         char temp_dir_path[GL_DIR_PATH_LEN_MAX] = { 0, };
456
457         if (b_root_path) {
458                 /* Get default images path, make dest foler under it */
459                 memset(dir_path, 0x00, GL_DIR_PATH_LEN_MAX);
460                 if (gl_get_default_images_path(dir_path) != 0) {
461                         gl_dbgW("Failed to get default images path!");
462                         goto RENAME_FAILED;
463                 }
464
465                 snprintf(temp_dir_path, GL_DIR_PATH_LEN_MAX,  "%s/%s", dir_path, etxt);
466                 temp_dir_path[strlen(temp_dir_path)] = '\0';
467         } else {
468                 int length = 0;
469                 int i = 0;
470
471                 memcpy(temp_dir_path, dir_path, GL_DIR_PATH_LEN_MAX);
472                 length = strlen(dir_path);
473
474                 for (i = length; i >= 0; i--) {
475                         if (temp_dir_path[i] == '/') {
476                                 gl_dbg("length=%d, i=%d", length, i);
477                                  /* Path like "/root/abc/" */
478                                 if (i == length - 1)
479                                         continue;
480                                 memcpy(&temp_dir_path[i + 1], etxt,
481                                        strlen(etxt));
482                                 temp_dir_path[i + 1+ strlen(etxt)] =  '\0';
483                                 break;
484                         }
485                 }
486         }
487         gl_dbg("Dest folder: %s", temp_dir_path);
488
489         /* Get selected folder path for rename */
490         char rename_dir_path[GL_DIR_PATH_LEN_MAX] = { 0, };
491         gl_db_get_folder_fullpath(ad, album_item->cluster->uuid, rename_dir_path);
492         if (!g_strcmp0(rename_dir_path, temp_dir_path)) {
493                 gl_dbgW("Same as current name!");
494                 goto RENAME_FAILED;
495         }
496
497         /**
498         * If dir is empty, 1 is returned,
499         * if it contains at least 1 file, 0 is returned.
500         * On failure, -1 is returned.
501         */
502         if (ecore_file_dir_is_empty(temp_dir_path) == 0) {
503                 char *popup_desc;
504                 popup_desc = (char*)calloc(GL_POPUP_STRING_MAX, sizeof(char));
505                 if (popup_desc == NULL) {
506                         gl_dbg("memory allocation fail");
507                         return -1;
508                 }
509
510                 snprintf(popup_desc, GL_POPUP_STRING_MAX, "%s.<br>%s",
511                         GL_STR_SAME_NAME_ALREADY_IN_USE, GL_STR_RETRY_Q);
512                 popup_desc[strlen(popup_desc)] = '\0';
513                 gl_popup_create_popup(ad, GL_POPUP_ALBUM_RENAME_DUPLICATE,
514                                       popup_desc);
515                 free(popup_desc);
516                 gl_dbgW("New folder already exists and not NULL, return!");
517                 return -1;
518         }
519
520         if (b_root_path) {
521                 /**
522                 * Case 1: Rename virtual album 'No Name'.
523                 * It couldn't be done by updating album record in DB directly.
524                 * Cuz it would change the folder path of all folder records,
525                 * to make them invalid.
526                 *
527                 * Create new folder under default images path,
528                 * Move all medias under root path to new folder.
529                 */
530                 if (gl_make_new_album(etxt) != 0) {
531                         gl_popup_create_popup(ad, GL_POPUP_NOBUT,
532                                               GL_STR_UNABLE_TO_RENAME);
533                         gl_dbgE("Failed to make a new directory!");
534                         goto RENAME_FAILED;
535                 }
536
537                 /* Move medias from 'No Name' album to new album */
538                 if (gl_move_root_album(ad, album_item, temp_dir_path) != 0) {
539                         gl_dbg("gl_move_root_album failed!");
540                         gl_popup_create_popup(ad, GL_POPUP_NOBUT,
541                                               GL_STR_UNABLE_TO_RENAME);
542                         goto RENAME_FAILED;
543                 } else {
544                         gl_dbg("New album added, update albums list.");
545                         ad->albuminfo.selected_album = NULL;
546                         gl_db_update_cluster_list(ad);
547                 }
548         } else {
549                 /**
550                 * Case 2: Rename normal album.
551                 *
552                 *                 Update album record in DB.
553                 */
554                 ret = minfo_update_cluster_name(ad->maininfo.db_handle,
555                                                 album_item->cluster->uuid, etxt);
556                 if (ret < 0) {
557                         gl_dbg("minfo_update_cluster_name failed (%d)!", ret);
558                         goto RENAME_FAILED;
559                 }
560
561                 /**
562                 * Change folder name in file system
563                 * for some special name, DB update success, but file mv failed.
564                 * So, do this first.
565                 */
566                 if (ecore_file_mv(dir_path, temp_dir_path) == EINA_FALSE) {
567                         gl_dbgE("ecore_file_mv failed!");
568                         gl_popup_create_popup(ad, GL_POPUP_NOBUT,
569                                               GL_STR_UNABLE_TO_RENAME);
570                 }
571         }
572         /* Update memory */
573         if (!b_root_path)
574                 g_strlcpy(album_item->cluster->display_name, etxt,
575                           GL_FILE_NAME_LEN_MAX);
576         __gl_ui_rename_album_cancel_cb(ad, NULL, NULL);
577         return 0;
578
579  RENAME_FAILED:
580         __gl_ui_rename_album_cancel_cb(ad, NULL, NULL);
581         return -1;
582 }
583
584 static void __gl_ui_rename_album_enter_cb(void *data, Evas_Object * obj, void *event_info)
585 {
586         gl_dbg("");
587         GL_CHECK(data);
588         gl_appdata *ad = (gl_appdata *)data;
589         /* Unfocus to hide cursor */
590         elm_object_focus_set(ad->entryinfo.imf_entry, FALSE);
591
592         __gl_ui_rename_album_done(data, true);
593 }
594
595 static void __gl_ui_rename_album_done_cb(void *data, Evas_Object * obj, void *event_info)
596 {
597         gl_dbg("");
598         __gl_ui_rename_album_done(data, false);
599 }
600
601 static bool
602 _gl_ui_display_nocontents(void *data)
603 {
604         GL_CHECK_FALSE(data);
605         gl_appdata *ad = (gl_appdata *)data;
606         bool is_video_file_existing = false;
607         bool is_image_file_existing = false;
608         int grid_view_mode = ad->gridinfo.grid_view_mode;
609         gl_item *gitem = NULL;
610         int i = 0;
611         bool ret = false;
612         int view_mode = gl_get_view_mode(ad);
613         /* Get all medias count of current album */
614         int cnt = ad->maininfo.medias_cnt;
615
616         if (grid_view_mode == GL_CTRL_SEG_VIDEOS ||
617                 grid_view_mode == GL_CTRL_SEG_IMAGES)   /*only check in video or image segment. */
618         {
619                 for (i = 1; i <= cnt; i++)
620                 {
621                         gl_db_get_item_by_index(ad, i, false, &gitem);
622                         if (gitem == NULL || gitem->item == NULL)
623                         {
624                                 gl_dbg("gitem == NULL || gitem->item == NULL");
625                                 continue;
626                         }
627
628                         if (grid_view_mode == GL_CTRL_SEG_VIDEOS &&
629                                 !is_video_file_existing &&
630                             gitem->item->type == MINFO_ITEM_VIDEO)
631                         {
632                                 is_video_file_existing = true;
633                                 break;
634                         }
635                         else if (grid_view_mode == GL_CTRL_SEG_IMAGES
636                                 && !is_image_file_existing &&
637                                 gitem->item->type == MINFO_ITEM_IMAGE)
638                         {
639                                 is_image_file_existing = true;
640                                 break;
641                         }
642
643                 }
644
645                 gl_dbg("video file exists->%d, image file exists->%d",
646                         is_video_file_existing, is_image_file_existing);
647                 if (grid_view_mode == GL_CTRL_SEG_VIDEOS && !is_video_file_existing)
648                 {
649                         if (view_mode == GL_VIEW_VIDEOLIST_EDIT)
650                         {
651                                 gl_dbg("In edit mode, back to normal view.");
652                                 gl_ui_edit_cancel(ad);
653                         }
654
655                         gl_dbg("None video files, show nocontents...");
656                         ret = true;
657                 }
658                 else if (grid_view_mode == GL_CTRL_SEG_IMAGES && !is_image_file_existing)
659                 {
660                         if (view_mode == GL_VIEW_THUMBS_EDIT)
661                         {
662                                 gl_dbg("In edit mode, back to normal view.");
663                                 gl_ui_edit_cancel(ad);
664                         }
665
666                         gl_dbg("None image files, show nocontents...");
667                         Evas_Object *noc = gl_ui_create_nocontents_full(ad);
668                         if (ad->gridinfo.image_view)
669                         {
670                                 evas_object_del(ad->gridinfo.image_view);
671                                 ad->gridinfo.image_view = NULL;
672                         }
673                         ad->gridinfo.image_view = noc;
674                         ad->gridinfo.image_nocontents = noc;
675                         elm_object_part_content_unset(ad->gridinfo.layout, "elm.swallow.view");
676                         evas_object_hide(ad->listinfo.video_view);
677                         evas_object_hide(ad->gridinfo.all_view);
678                         evas_object_show(ad->gridinfo.image_view);
679                         elm_object_part_content_set(ad->gridinfo.layout,
680                                 "elm.swallow.view", ad->gridinfo.image_view);
681                         gl_ui_disable_toolbar_item(ad, true, GL_NAVI_THUMBS, false);
682                         ret = true;
683                 }
684         }
685         return ret;
686 }
687
688
689 /* Select-all checkbox selected/deselected */
690 static void _gl_ui_selall_check_changed(void *data, Evas_Object *obj,
691                                         void *event_info)
692 {
693         GL_CHECK(obj);
694         GL_CHECK(data);
695         gl_appdata *ad = (gl_appdata *)data;
696         int view_mode = gl_get_view_mode(ad);
697         gl_dbg("view_mode: %d.", view_mode);
698
699         gl_item *current = NULL;
700         int i = 0;
701         int item_cnt = 0;
702         int sel_all_cnt = 0;
703         Eina_Bool state = EINA_FALSE;
704         state = elm_check_state_get(obj);
705         gl_dbg("Checkbox state: %d.", state);
706         /* Get all medias count of current album */
707         item_cnt = ad->maininfo.medias_cnt;
708         sel_all_cnt = item_cnt;
709         gl_ctrl_seg_mode seg_mode = ad->albuminfo.seg_mode;
710         minfo_file_type file_type = MINFO_ITEM_NONE;
711         if (view_mode == GL_VIEW_THUMBS_EDIT)
712         {
713                 if (seg_mode == GL_CTRL_SEG_IMAGES)
714                 {
715                         file_type = MINFO_ITEM_IMAGE;
716                         sel_all_cnt = 0;
717                 }
718                 else if (seg_mode == GL_CTRL_SEG_VIDEOS)
719                 {
720                         file_type = MINFO_ITEM_VIDEO;
721                         sel_all_cnt = 0;
722                 }
723         }
724         else if (view_mode == GL_VIEW_VIDEOLIST_EDIT)
725         {
726                 file_type = MINFO_ITEM_VIDEO;
727                 sel_all_cnt = 0;
728         }
729
730         gl_dbg("seg_mode=%d", seg_mode);
731         for (i = 0; i < item_cnt; i++)
732         {
733                 gl_db_get_item_by_index(ad, i + 1, false, &current);
734                 GL_CHECK(current);
735                 GL_CHECK(current->item);
736
737                 if (current->checked == state && seg_mode == GL_CTRL_SEG_ALL)
738                 {
739                         continue;
740                 }
741
742                 if (view_mode == GL_VIEW_THUMBS_EDIT)
743                 {
744                         if ((seg_mode == GL_CTRL_SEG_IMAGES) ||
745                                 (seg_mode == GL_CTRL_SEG_VIDEOS))
746                         {
747                                 if (current->item->type != file_type)
748                                 {
749                                         continue;
750                                 }
751
752                                 sel_all_cnt++;
753                                 if (current->checked == state)
754                                 {
755                                         continue;
756                                 }
757                         }
758                 }
759                 else if (view_mode == GL_VIEW_VIDEOLIST_EDIT)
760                 {
761                         if (current->item->type != file_type)
762                         {
763                                 continue;
764                         }
765
766                         sel_all_cnt++;
767                         if (current->checked == state)
768                         {
769                                 continue;
770                         }
771                 }
772
773                 current->checked = state;
774
775                 if (view_mode == GL_VIEW_THUMBS_EDIT)
776                         elm_gengrid_item_update(current->elm_item);
777
778                 if (state == EINA_TRUE)
779                         gl_db_selected_list_append(ad, current);
780                 else
781                         gl_db_selected_list_remove(ad, current);
782
783         }
784
785         /* Update all realized items */
786         if (view_mode == GL_VIEW_VIDEOLIST_EDIT)
787                 elm_genlist_realized_items_update(ad->gridinfo.edit_view);
788
789         /* Recreate selection info for both cases */
790         if (state == EINA_FALSE)
791                 sel_all_cnt = 0;
792         gl_ui_create_selinfo(ad, ad->gridinfo.edit_layout,
793                              ad->gridinfo.nf_it_edit, item_cnt,
794                              sel_all_cnt, false);
795 }
796
797 /* Select-all background click, selected/deselected checkbox */
798 static void _gl_ui_selall_bg_click_cb(void *data, Evas_Object *o,
799                                        const char *emission,
800                                        const char *source)
801 {
802         GL_CHECK(data);
803         gl_appdata *ad = (gl_appdata *)data;
804         int view_mode = gl_get_view_mode(ad);
805         Evas_Object *ly = NULL;
806         gl_dbg("view_mode: %d.", view_mode);
807
808         if (view_mode == GL_VIEW_THUMBS_EDIT ||
809             view_mode == GL_VIEW_VIDEOLIST_EDIT) {
810                 ly = ad->gridinfo.edit_layout;
811         } else {
812                gl_dbgE("Wrong view!");
813                return;
814         }
815
816         Evas_Object *check = elm_object_part_content_get(ly, "selectall_check");
817         if (check) {
818                 Eina_Bool new_state = EINA_FALSE;
819                 Eina_Bool ck_state = elm_check_state_get(check);
820                 /* uncheck->check */
821                 if (ck_state == EINA_FALSE)
822                         new_state = EINA_TRUE;
823
824                 elm_check_state_set(check, new_state);
825
826                 _gl_ui_selall_check_changed(ad, check, NULL);
827         } else {
828                 gl_dbgE("Get select all checkbox object failed!");
829         }
830 }
831
832
833 static void
834 _gl_ui_edit_cancel_cb(void *data, Evas_Object * obj, void *event_info)
835 {
836         GL_CHECK(data);
837         gl_appdata *ad = (gl_appdata *)data;
838         int view_mode = gl_get_view_mode(ad);
839         gl_dbg("");
840
841         if (view_mode == GL_VIEW_ALBUMS_EDIT)
842         {
843                 if (ad->albuminfo.edit_view)
844                 {
845                         evas_object_del(ad->albuminfo.edit_view);
846                         ad->albuminfo.edit_view = NULL;
847                         ad->albuminfo.edit_layout = NULL;
848                 }
849
850                 gl_db_finalize_albums_selected_list(ad);
851                 /**
852                 *  after back to albums view from albums edit view,
853                 *  option header should be defaultly closed
854                 */
855
856                 gl_db_get_cluster_list(ad);
857                 GL_CHECK(ad->albuminfo.cluster_list);
858
859                 gl_albums_change_to_view(ad);
860                 gl_ui_destroy_selinfo(ad);
861                 if (gl_check_gallery_empty(ad)) {
862                         gl_ui_disable_toolbar_item(ad, true, GL_NAVI_ALBUMS,
863                                                    false);
864                 } else {
865                         if (ad->albuminfo.cluster_list->edit_cnt == 0) {
866                                 gl_dbg("None editable albums, disable items.");
867                                 gl_ui_disable_toolbar_item(ad, true,
868                                                            GL_NAVI_ALBUMS,
869                                                            false);
870                         }
871                 }
872         }
873         else if (view_mode == GL_VIEW_THUMBS_EDIT)
874         {
875                 _gl_destroy_thumbs_edit_view(ad);
876                 gl_db_selected_list_finalize(ad);
877
878                 gl_set_view_mode(ad, GL_VIEW_THUMBS);
879                 if (ad->albuminfo.update_albums_list)
880                 {
881                         /*
882                          * Update albums list if MMC added/removed,
883                          */
884                         ad->albuminfo.update_albums_list = false;
885                         gl_refresh_albums_list(ad);
886                 }
887
888                 gl_grid_change_to_view(ad);
889                 gl_ui_destroy_selinfo(ad);
890         }
891         else if (view_mode == GL_VIEW_VIDEOLIST_EDIT)
892         {
893                 _gl_destroy_thumbs_edit_view(ad);
894                 gl_db_selected_list_finalize(ad);
895                 gl_set_view_mode(ad, GL_VIEW_VIDEOLIST);
896                 if (ad->albuminfo.update_albums_list)
897                 {
898                         /*
899                          * Update albums list if MMC added/removed
900                          */
901                         ad->albuminfo.update_albums_list = false;
902                         gl_refresh_albums_list(ad);
903                 }
904
905                 gl_list_change_to_view(ad);
906                 gl_ui_destroy_selinfo(ad);
907         }
908 }
909
910 /* callback after user tap Cancel button in option header in edit view */
911 static void __gl_ui_click_cancel_edit_cb(void *data, Evas_Object *obj, void *event_info)
912 {
913         GL_CHECK(data);
914         GL_CHECK(obj);
915         gl_appdata *ad = (gl_appdata *)data;
916         elm_naviframe_item_pop(ad->maininfo.navi_bar);
917         _gl_ui_edit_cancel_cb(data, obj, event_info);
918         return;
919 }
920
921 static void
922 _gl_ui_edit_cb(void *data, Evas_Object * obj, void *event_info)
923 {
924         GL_CHECK(data);
925         gl_appdata *ad = (gl_appdata *)data;
926
927         if (ad->uginfo.ug_called_by_me || ad->gridinfo.append_idler)
928         {
929                 /**
930                 * Prevent changed to edit view in wrong way.
931                 * 1. When invoke imageviewer UG;
932                 * 2. First show thumbnails view, use idler to append other medias.
933                 */
934                 gl_dbg("UG invoked or appending gridview.");
935                 return;
936         }
937
938         int view_mode = gl_get_view_mode(ad);
939         gl_dbg("mode: %d", view_mode);
940         if (view_mode == GL_VIEW_THUMBS_EDIT)
941         {
942                 /* Fixme: maybe we should disable edit button until grid append idler is done */
943                 /**
944                 * Happen in quickly tap edit button,
945                 * it will invoke _gl_ui_edit_cb several time
946                 * and push some unuseful views.
947                 */
948                 gl_dbg("Already in edit mode, return.");
949                 return;
950         }
951
952         gl_ui_destroy_notiinfo(ad);
953
954         if (view_mode == GL_VIEW_ALBUMS)
955         {
956                 gl_set_view_mode(ad, GL_VIEW_ALBUMS_EDIT);
957
958                 ad->albuminfo.edit_layout = gl_ui_create_view_ly(ad->maininfo.navi_bar);
959                 ad->albuminfo.edit_view = gl_albums_create_view(ad, ad->albuminfo.edit_layout);
960                 elm_object_part_content_set(ad->albuminfo.edit_layout,
961                                        "elm.swallow.view",
962                                        ad->albuminfo.edit_view);
963                 edje_object_signal_emit(_EDJ(ad->albuminfo.edit_layout),
964                                         "elm,swallow_view,state,default", "elm");
965                 gl_ui_create_title_and_push(ad, ad->maininfo.navi_bar,
966                                             ad->albuminfo.edit_layout,
967                                             GL_NAVI_ALBUMS_EDIT,
968                                             GL_STR_SELECT_ALBUM);
969                 return;
970         }
971         else if (view_mode == GL_VIEW_THUMBS)
972         {
973                 gl_set_view_mode(ad, GL_VIEW_THUMBS_EDIT);
974                 if (ad->gridinfo.grid_view_mode == GL_GRID_ALL)
975                         ad->gridinfo.edit_view = gl_grid_create_view(ad,
976                                                                      ad->maininfo.navi_bar,
977                                                                      GL_GRID_ALL);
978                 else
979                         ad->gridinfo.edit_view = gl_grid_create_view(ad,
980                                                                      ad->maininfo.navi_bar,
981                                                                      GL_GRID_IMAGES);
982         }
983         else if (view_mode == GL_VIEW_VIDEOLIST)
984         {
985                 gl_set_view_mode(ad, GL_VIEW_VIDEOLIST_EDIT);
986                 ad->gridinfo.edit_view = gl_list_create_view(ad, ad->maininfo.navi_bar);
987         }
988
989         ad->gridinfo.edit_layout = gl_ui_create_view_ly(ad->maininfo.navi_bar);
990         evas_object_size_hint_weight_set(ad->gridinfo.edit_layout,
991                 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
992         evas_object_size_hint_align_set(ad->gridinfo.edit_layout,
993                 EVAS_HINT_FILL, EVAS_HINT_FILL);
994
995         elm_object_part_content_set(ad->gridinfo.edit_layout,
996                         "elm.swallow.view", ad->gridinfo.edit_view);
997         gl_ui_create_title_and_push(ad, ad->maininfo.navi_bar,
998                                     ad->gridinfo.edit_layout,
999                                     GL_NAVI_THUMBS_EDIT, GL_STR_SELECT_ITEM);
1000         edje_object_signal_emit(_EDJ(ad->gridinfo.edit_layout),
1001                                 "elm,swallow_view,state,thumb_edit_default",
1002                                 "elm");
1003         gl_ui_show_selall(ad);
1004
1005         gl_dbg("Done");
1006 }
1007
1008 /* move media to album in edit view */
1009 int gl_ui_move_media_to_album(gl_appdata *ad)
1010 {
1011         GL_CHECK_VAL(ad, -1);
1012         int view_mode = gl_get_view_mode(ad);
1013         gl_dbg("");
1014
1015         if (ad->uginfo.ug_called_by_me || ad->uginfo.app_called_by_me)
1016         {
1017                 gl_dbg("UG or APP is already loaded, return.");
1018                 return -1;
1019         }
1020
1021         if ((view_mode == GL_VIEW_THUMBS_EDIT) ||
1022                 (view_mode == GL_VIEW_VIDEOLIST_EDIT))
1023         {
1024
1025                 int cnt = gl_db_selected_list_count(ad);
1026                 if (cnt == 0)
1027                 {
1028                         gl_dbg("No thumbs selected, return!");
1029                         gl_popup_create_popup(ad, GL_POPUP_NOBUT,
1030                                 GL_STR_NO_FILES_SELECTED);
1031                         return -1;
1032                 }
1033
1034                 gl_popup_create_title_popup(ad, GL_POPUP_THUMB_MOVE,
1035                                 GL_STR_MOVE, NULL);
1036                 return 0;
1037         }
1038         else
1039         {
1040                 gl_dbg("Unknow mode!");
1041                 return -1;
1042         }
1043 }
1044
1045 static void
1046 _gl_ui_medias_del_cb(void *data, Evas_Object * obj, void *event_info)
1047 {
1048         GL_CHECK(data);
1049         gl_appdata *ad = (gl_appdata *)data;
1050         gl_dbg("");
1051
1052         if (ad->uginfo.ug_called_by_me || ad->uginfo.app_called_by_me)
1053         {
1054                 gl_dbg("UG or APP is already loaded, return.");
1055                 return;
1056         }
1057
1058         int view_mode = gl_get_view_mode(ad);
1059         if ((view_mode == GL_VIEW_THUMBS_EDIT) ||
1060                 (view_mode == GL_VIEW_VIDEOLIST_EDIT))
1061         {
1062                 int cnt = gl_db_selected_list_count(ad);
1063                 if (cnt == 0)
1064                 {
1065                         gl_dbg("No thumbs selected, return!");
1066                         gl_popup_create_popup(ad, GL_POPUP_NOBUT, GL_STR_NO_FILES_SELECTED);
1067                         return;
1068                 }
1069
1070                 gl_del_medias(ad);
1071         }
1072         else
1073         {
1074                 gl_dbg("Unknow mode!");
1075         }
1076 }
1077
1078 static void
1079 _gl_ui_albums_del_cb(void *data, Evas_Object * obj, void *event_info)
1080 {
1081         GL_CHECK(data);
1082         gl_appdata *ad = (gl_appdata *)data;
1083         gl_dbg("");
1084
1085         if ((gl_get_view_mode(ad) == GL_VIEW_ALBUMS_EDIT))
1086         {
1087                 int cnt = gl_db_get_albums_selected_cnt(ad);
1088                 if (cnt == 0)
1089                 {
1090                         gl_dbg("No albums selected, return!");
1091                         gl_popup_create_popup(ad, GL_POPUP_NOBUT,
1092                                 GL_STR_NO_ALBUMS_SELECTED);
1093                         return;
1094                 }
1095                 gl_popup_create_albums_del_popup(ad);
1096         }
1097         else
1098         {
1099                 gl_dbg("Unknow mode!");
1100         }
1101 }
1102
1103 static void
1104 _gl_ui_notiinfo_destroy_cb(void *data, Evas_Object * obj, void *event_info)
1105 {
1106         GL_CHECK(data);
1107         gl_appdata *ad = (gl_appdata *)data;
1108         gl_dbg("");
1109
1110         gl_ui_destroy_notiinfo(ad);
1111 }
1112
1113 static int _gl_ui_enable_toolbar_items(gl_appdata *ad, Elm_Object_Item *nf_it)
1114 {
1115         GL_CHECK_VAL(ad, -1);
1116         GL_CHECK_VAL(nf_it, -1);
1117
1118         Elm_Object_Item *cbar_it = NULL;
1119         Evas_Object *ctlbar = _gl_ctrl_get_toolbar(nf_it);
1120         GL_CHECK_VAL(ctlbar, -1);
1121         cbar_it = elm_toolbar_first_item_get(ctlbar);
1122         while (cbar_it) {
1123                 gl_ui_enable_cbar_item(cbar_it);
1124                 cbar_it = elm_toolbar_item_next_get(cbar_it);
1125         }
1126
1127         return 0;
1128 }
1129
1130 static int _gl_ui_disable_toolbar_item(void *data, gl_navi_mode mode, bool edit)
1131 {
1132         GL_CHECK_VAL(data, -1);
1133         gl_appdata *ad = (gl_appdata *)data;
1134
1135         if (mode == GL_NAVI_ALBUMS) {
1136                 gl_dbg("GL_NAVI_ALBUMS");
1137                 /* disable 'edit' item */
1138                 gl_ui_disable_cbar_item(ad->albuminfo.edit_it);
1139         }else if (mode == GL_NAVI_THUMBS) {
1140                 gl_dbg("GL_NAVI_THUMBS");
1141                 /* disable 'edit' item */
1142                 gl_ui_disable_cbar_item(ad->gridinfo.edit_it);
1143         } else {
1144                 gl_dbgE("Unkonw mode");
1145                 return -1;
1146         }
1147         return 0;
1148 }
1149
1150 static int _gl_ui_enable_toolbar_item(void *data, gl_navi_mode mode)
1151 {
1152         GL_CHECK_VAL(data, -1);
1153         gl_appdata *ad = (gl_appdata *)data;
1154         gl_dbg("mode: %d", mode);
1155         if (mode == GL_NAVI_ALBUMS) {
1156                 gl_dbg("GL_NAVI_ALBUMS");
1157                 /* enable 'edit' item */
1158                 if (!gl_check_gallery_empty(ad) &&
1159                     ad->albuminfo.cluster_list->edit_cnt)
1160                         gl_ui_enable_cbar_item(ad->albuminfo.edit_it);
1161                 else
1162                         gl_ui_disable_cbar_item(ad->albuminfo.edit_it);
1163         } else if (mode == GL_NAVI_THUMBS) {
1164                 gl_dbg("GL_NAVI_THUMBS");
1165                 /* enable 'edit' item */
1166                 gl_ui_enable_cbar_item(ad->gridinfo.edit_it);
1167         } else {
1168                 gl_dbgE("Unkonw mode");
1169                 return -1;
1170         }
1171
1172         return 0;
1173 }
1174
1175 /**
1176 * Update checkbox state in select-all widget
1177 */
1178 static int _gl_ui_update_selall(void *data, int all_cnt, int selected_cnt)
1179 {
1180         GL_CHECK_VAL(data, -1);
1181         gl_appdata *ad = (gl_appdata *)data;
1182         int i = 0;
1183         gl_item *gitem = NULL;
1184         int _all_cnt = 0;
1185         int db_all_cnt = 0;
1186         gl_ctrl_seg_mode ctl_seg = GL_CTRL_SEG_ALL;
1187         minfo_file_type file_type = MINFO_ITEM_NONE;
1188         int view_mode = gl_get_view_mode(ad);
1189
1190         if (view_mode == GL_VIEW_THUMBS_EDIT ||
1191             view_mode == GL_VIEW_VIDEOLIST_EDIT) {
1192                 /* Get all medias count */
1193                 db_all_cnt = ad->maininfo.medias_cnt;
1194                 ctl_seg = ad->albuminfo.seg_mode;
1195                 if (ctl_seg == GL_CTRL_SEG_ALL) {
1196                         _all_cnt = db_all_cnt;
1197                 } else {
1198                         /* Get all count in diff segments */
1199                         if (ctl_seg == GL_CTRL_SEG_IMAGES)
1200                                 file_type = MINFO_ITEM_IMAGE;
1201                         else if (ctl_seg == GL_CTRL_SEG_VIDEOS)
1202                                 file_type = MINFO_ITEM_VIDEO;
1203
1204                         for (i = 1; i <= db_all_cnt; i++) {
1205                                 gl_db_get_item_by_index(ad, i, false,
1206                                                         &gitem);
1207                                 if (gitem && gitem->item &&
1208                                     (gitem->item->type == file_type))
1209                                         _all_cnt++;
1210                         }
1211                 }
1212         } else {
1213                 gl_dbg("Wrong view mode!");
1214                 return 0;
1215         }
1216
1217         /**
1218         * Set checkbox state
1219         * except in albums edit view and selectioninfo view
1220         */
1221         gl_dbg("selected_cnt/_all_cnt = %d/%d", selected_cnt, _all_cnt);
1222         Evas_Object *ly = NULL;
1223         Evas_Object *check = NULL;
1224         Eina_Bool state = EINA_FALSE;
1225
1226         if (selected_cnt == _all_cnt) {
1227                 /* Set checkbox checked */
1228                 state = EINA_TRUE;
1229         } else {
1230                 /* Set checkbox unchecked */
1231                 state = EINA_FALSE;
1232         }
1233
1234         ly = ad->gridinfo.edit_layout;
1235         check = elm_object_part_content_get(ly, "selectall_check");
1236         if (check)
1237                 elm_check_state_set(check, state);
1238         else
1239                 return -1;
1240
1241         return 0;
1242 }
1243
1244 /**
1245 * Update selectioinfo widget and view related to it
1246 */
1247 static int _gl_ui_update_view_selinfo(void *data, int selected_cnt)
1248 {
1249         GL_CHECK_VAL(data, -1);
1250         gl_appdata *ad = (gl_appdata *)data;
1251         Evas_Object *sel_edj = NULL;
1252         const char *emis = NULL;
1253         Evas_Object *v_edj = NULL;
1254         const char *v_emis = NULL;
1255         int view_mode = gl_get_view_mode(ad);
1256
1257         sel_edj = _EDJ(ad->popupinfo.selinfo_ly);
1258
1259         if (selected_cnt > 0) {
1260                 if (view_mode == GL_VIEW_THUMBS_EDIT ||
1261                         view_mode == GL_VIEW_VIDEOLIST_EDIT) {
1262                         v_edj = _EDJ(ad->gridinfo.edit_layout);
1263                         v_emis = "elm,swallow_view,state,moveup_view";
1264                 } else if (view_mode == GL_VIEW_ALBUMS_EDIT) {
1265                         emis = "elm,selectioninfo,portrait";
1266                         v_emis = "elm,swallow_view,state,moveup_albums_default";
1267                         v_edj = _EDJ(ad->albuminfo.edit_layout);
1268                 }
1269                 /* Set selectioninfo widget style */
1270                 edje_object_signal_emit(sel_edj, emis, "elm");
1271                 /* Move view up while selectioninfo shown. */
1272                 edje_object_signal_emit(v_edj, v_emis, "elm");
1273         } else {
1274                 if (view_mode == GL_VIEW_THUMBS_EDIT ||
1275                         view_mode == GL_VIEW_VIDEOLIST_EDIT) {
1276                         v_edj = _EDJ(ad->gridinfo.edit_layout);
1277                         v_emis = "elm,swallow_view,state,thumb_edit_default";
1278                 } else if (view_mode == GL_VIEW_ALBUMS_EDIT) {
1279                         v_edj = _EDJ(ad->albuminfo.edit_layout);
1280                         v_emis = "elm,swallow_view,state,default";
1281                 }
1282                 /* Restore view while selectioninfo vanished. */
1283                 edje_object_signal_emit(v_edj, v_emis, "elm");
1284         }
1285         return 0;
1286 }
1287
1288 /**
1289 * Create a new notify widget
1290 * b_selinfo, True: Create selectioninfo, False: Create notificationinfo.
1291 */
1292 static int _gl_ui_add_notify(void *data, Evas_Object *parent, bool b_selinfo)
1293 {
1294         gl_dbg("b_selinfo: %d.", b_selinfo);
1295         GL_CHECK_VAL(parent, -1);
1296         GL_CHECK_VAL(data, -1);
1297         gl_appdata *ad = (gl_appdata *)data;
1298
1299         if (b_selinfo)
1300                 gl_ui_destroy_selinfo(ad);
1301         else
1302                 gl_ui_destroy_notiinfo(ad);
1303
1304         ad->popupinfo.selinfo = elm_notify_add(parent);
1305         elm_notify_orient_set(ad->popupinfo.selinfo,
1306                               ELM_NOTIFY_ORIENT_BOTTOM);
1307         evas_object_size_hint_weight_set(ad->popupinfo.selinfo,
1308                                          EVAS_HINT_EXPAND,
1309                                          EVAS_HINT_EXPAND);
1310         evas_object_size_hint_align_set(ad->popupinfo.selinfo,
1311                                         EVAS_HINT_FILL,
1312                                         EVAS_HINT_FILL);
1313
1314         ad->popupinfo.selinfo_ly = elm_layout_add(parent);
1315         /* Set custom theme to notify layout */
1316         elm_layout_theme_set(ad->popupinfo.selinfo_ly, "standard",
1317                              "selectioninfo",
1318                              "selectioninfo_viewer");
1319
1320         evas_object_size_hint_weight_set(ad->popupinfo.selinfo_ly,
1321                                          EVAS_HINT_EXPAND,
1322                                          EVAS_HINT_EXPAND);
1323         evas_object_size_hint_align_set(ad->popupinfo.selinfo_ly,
1324                                         EVAS_HINT_FILL,
1325                                         EVAS_HINT_FILL);
1326         /* Set the content of the notify widget */
1327         elm_object_content_set(ad->popupinfo.selinfo,
1328                                ad->popupinfo.selinfo_ly);
1329
1330         if (!b_selinfo) {
1331                 /* Add callbacks for notificationinfo */
1332                 evas_object_smart_callback_add(ad->popupinfo.selinfo,
1333                                                "timeout",
1334                                                _gl_ui_notiinfo_destroy_cb,
1335                                                ad);
1336                 elm_notify_timeout_set(ad->popupinfo.selinfo, 2);
1337         } else {
1338                 /* Add callbacks for selectioninfo */
1339                 evas_object_smart_callback_add(ad->popupinfo.selinfo,
1340                                                "timeout",
1341                                                _gl_ui_selinfo_destroy_cb, ad);
1342                 elm_notify_timeout_set(ad->popupinfo.selinfo, 3);
1343         }
1344         return 0;
1345 }
1346
1347 static void __gl_ui_move_cb(void *data, Evas_Object *obj, void *event_info)
1348 {
1349         GL_CHECK(data);
1350         gl_ui_move_media_to_album(data);
1351         return;
1352 }
1353
1354 /* pause gallery and change view to background after tap Back button in albums view */
1355 static void __gl_ui_change_to_background_cb(void *data, Evas_Object * obj, void *event_info)
1356 {
1357         gl_dbg("Back button clicked, change view to background.");
1358         GL_CHECK(data);
1359         Evas_Object *win = (Evas_Object *) data;
1360         elm_win_lower(win);
1361         return;
1362 }
1363
1364 static int __gl_ui_append_object_item(Evas_Object *cbar, Evas_Object *object)
1365 {
1366         Elm_Object_Item *item = elm_toolbar_item_append(cbar, NULL, NULL, NULL,
1367                                                         NULL);
1368         if (object)
1369                 elm_object_item_part_content_set(item, "object", object);
1370         else
1371
1372                 elm_object_item_disabled_set(item, EINA_TRUE);
1373         return 0;
1374 }
1375
1376 static void __gl_ui_trans_finished_cb(void *data, Evas_Object *obj, void *event_info)
1377 {
1378         GL_CHECK(data);
1379         gl_appdata *ad = (gl_appdata *)data;
1380         int view_mode = gl_get_view_mode(ad);
1381         gl_dbgW("view_mode: %d", view_mode);
1382         evas_object_smart_callback_del(obj, GL_TRANS_FINISHED,
1383                                        __gl_ui_trans_finished_cb);
1384
1385         if (view_mode == GL_VIEW_ALBUMS_EDIT) {
1386                 elm_gengrid_clear(ad->albuminfo.view);
1387         } else if (view_mode == GL_VIEW_ALBUMS_RENAME) {
1388                 elm_gengrid_clear(ad->albuminfo.edit_view);
1389         } else if (view_mode == GL_VIEW_THUMBS_EDIT) {
1390                 if (ad->entryinfo.entry_mode != GL_ENTRY_NONE)
1391                         return;
1392                 if (ad->albuminfo.seg_mode == GL_CTRL_SEG_ALL)
1393                         elm_gengrid_clear(ad->gridinfo.all_view);
1394                 else if (ad->albuminfo.seg_mode == GL_CTRL_SEG_IMAGES)
1395                         elm_gengrid_clear(ad->gridinfo.image_view);
1396         } else if (view_mode == GL_VIEW_VIDEOLIST_EDIT) {
1397                 if (ad->entryinfo.entry_mode != GL_ENTRY_NONE)
1398                         return;
1399                 elm_genlist_clear(ad->listinfo.video_view);
1400         }
1401 }
1402
1403 /**
1404  *  Use naviframe api to push albums view to stack.
1405  *  @param obj is the content to be pushed.
1406  */
1407 static int __gl_ui_push_view_albums(void *data, Evas_Object *parent,
1408                                     Evas_Object *obj, char *title)
1409 {
1410         gl_dbg("GL_NAVI_ALBUMS");
1411         GL_CHECK_VAL(obj, -1);
1412         GL_CHECK_VAL(parent, -1);
1413         GL_CHECK_VAL(data, -1);
1414         gl_appdata *ad = (gl_appdata *)data;
1415         Elm_Object_Item *nf_it = NULL;
1416         Elm_Object_Item *edit_it = NULL;
1417         Elm_Object_Item *add_it = NULL;
1418         Evas_Object *end_btn = NULL;
1419         Evas_Object *bot_bar = NULL;
1420
1421         /* create tool controlbar downside */
1422         bot_bar = _gl_ctrl_create_toolbar(ad, obj);
1423         GL_CHECK_VAL(bot_bar, -1);
1424         /* add edit item */
1425         edit_it = elm_toolbar_item_append(bot_bar, GL_CBAR_ICON_EDIT, NULL,
1426                                           _gl_ui_edit_cb, ad);
1427         ad->albuminfo.edit_it = edit_it;
1428         gl_ui_enable_cbar_item(edit_it);
1429         __gl_ui_append_object_item(bot_bar, NULL);
1430         __gl_ui_append_object_item(bot_bar, NULL);
1431
1432         /**
1433         *  add End button in navigation var first view in galery
1434         *   with style "naviframe/back_btn/gallery"
1435         *  so after tap this button,gallery is paused
1436         *  but change view to background
1437         */
1438         GL_CHECK_VAL(ad->maininfo.win, -1);
1439         end_btn = _gl_but_create_but(obj, GL_BUT_NONE, GL_BUTTON_STYLE_NAVI_PRE);
1440         evas_object_smart_callback_add(end_btn, "clicked",
1441                                        __gl_ui_change_to_background_cb,
1442                                        ad->maininfo.win);
1443
1444         /* Disable items in exit mode */
1445         if (ad->maininfo.app_exit_mode) {
1446                 gl_ui_disable_cbar_item(edit_it);
1447                 gl_ui_disable_cbar_item(add_it);
1448         }
1449         /* Push view to stack */
1450         nf_it = elm_naviframe_item_push(parent, title, end_btn, NULL, obj, NULL);
1451         ad->albuminfo.nf_it = nf_it;
1452         /* Set tool controlbar to bottom */
1453         elm_object_item_part_content_set(nf_it, GE_NAVIFRAME_CONTROLBAR,
1454                                          bot_bar);
1455         return 0;
1456 }
1457
1458 /**
1459  *  Use naviframe api to push albums edit view to stack.
1460  *  @param obj is the content to be pushed.
1461  */
1462 static int __gl_ui_push_view_albums_edit(void *data, Evas_Object *parent,
1463                                          Evas_Object *obj, char *title)
1464 {
1465         gl_dbg("GL_NAVI_ALBUMS_EDIT");
1466         GL_CHECK_VAL(obj, -1);
1467         GL_CHECK_VAL(parent, -1);
1468         GL_CHECK_VAL(data, -1);
1469         gl_appdata *ad = (gl_appdata *)data;
1470         Elm_Object_Item *nf_it = NULL;
1471         Elm_Object_Item *cancel_it = NULL;
1472         Elm_Object_Item *del_it = NULL;
1473         Evas_Object *bot_bar = NULL;
1474
1475         /* create tool controlbar downside */
1476         bot_bar = _gl_ctrl_create_toolbar(ad, obj);
1477         GL_CHECK_VAL(bot_bar, -1);
1478
1479         /* Add delete item */
1480         del_it = elm_toolbar_item_append(bot_bar, GL_CBAR_ICON_DELETE, NULL,
1481                                          _gl_ui_albums_del_cb, ad);
1482         gl_ui_disable_cbar_item(del_it);
1483         __gl_ui_append_object_item(bot_bar, NULL);
1484         __gl_ui_append_object_item(bot_bar, NULL);
1485
1486         /* use Cancel button */
1487         cancel_it = elm_toolbar_item_append(bot_bar, GL_CBAR_ICON_CANCEL, NULL,
1488                                             __gl_ui_click_cancel_edit_cb, ad);
1489         /* Add transition finished callback */
1490         evas_object_smart_callback_add(parent, GL_TRANS_FINISHED,
1491                                        __gl_ui_trans_finished_cb, ad);
1492         /* Push to stack */
1493         nf_it = elm_naviframe_item_push(parent, title, NULL, NULL,
1494                                         obj, NULL);
1495         elm_object_item_part_content_set(nf_it, GE_NAVIFRAME_PREB_BTN, NULL);
1496
1497         ad->albuminfo.nf_it_edit = nf_it;
1498         /* Set tool bar to bottom */
1499         elm_object_item_part_content_set(nf_it, GE_NAVIFRAME_CONTROLBAR,
1500                                          bot_bar);
1501         return 0;
1502 }
1503
1504 /**
1505  *  Use naviframe api to push thumbnails view to stack.
1506  *  @param obj is the content to be pushed.
1507  */
1508 static int __gl_ui_push_view_thumbs(void *data, Evas_Object *parent,
1509                                     Evas_Object *obj, char *title)
1510 {
1511         gl_dbg("GL_NAVI_THUMBS");
1512         GL_CHECK_VAL(obj, -1);
1513         GL_CHECK_VAL(parent, -1);
1514         GL_CHECK_VAL(data, -1);
1515         gl_appdata *ad = (gl_appdata *)data;
1516         Elm_Object_Item *nf_it = NULL;
1517         Elm_Object_Item *edit_it = NULL;
1518         Evas_Object *bot_bar = NULL;
1519         Evas_Object *segment = NULL;
1520
1521         /* create tool controlbar downside */
1522         bot_bar = _gl_ctrl_create_toolbar(ad, obj);
1523         GL_CHECK_VAL(bot_bar, -1);
1524         /* add 'Back' item */
1525         if (ad->maininfo.medias_cnt) {
1526                 /* add 'Edit' item */
1527                 edit_it = elm_toolbar_item_append(bot_bar, GL_CBAR_ICON_EDIT,
1528                                                   NULL, _gl_ui_edit_cb, ad);
1529                 ad->gridinfo.edit_it = edit_it;
1530                 /* add segment */
1531                 segment = _gl_ctrl_create_segment(ad, bot_bar);
1532                 if(segment)
1533                         __gl_ui_append_object_item(bot_bar, segment);
1534         }
1535 #if 1
1536         nf_it = elm_naviframe_top_item_get(parent);
1537         /* For the instant transition, use the xxx_insert_after API */
1538         nf_it = elm_naviframe_item_insert_after(parent, nf_it, title,
1539                                                 NULL, NULL, obj, NULL);
1540 #else
1541         /* Push to stack */
1542         nf_it = elm_naviframe_item_push(parent, title, NULL, NULL, obj, NULL);
1543 #endif
1544         ad->gridinfo.nf_it = nf_it;
1545         /* Set tool bar to bottom */
1546         elm_object_item_part_content_set(nf_it, GE_NAVIFRAME_CONTROLBAR,
1547                                          bot_bar);
1548         return 0;
1549 }
1550
1551
1552 /**
1553  *  Use naviframe api to push thumbnails eidt view to stack.
1554  *  @param obj is the content to be pushed.
1555  */
1556 static int __gl_ui_push_view_thumbs_edit(void *data, Evas_Object *parent,
1557                                          Evas_Object *obj, char *title)
1558 {
1559         gl_dbg("GL_NAVI_THUMBS_EDIT");
1560         GL_CHECK_VAL(obj, -1);
1561         GL_CHECK_VAL(parent, -1);
1562         GL_CHECK_VAL(data, -1);
1563         gl_appdata *ad = (gl_appdata *)data;
1564         Elm_Object_Item *nf_it = NULL;
1565         Elm_Object_Item *del_it = NULL;
1566         Elm_Object_Item *move_it = NULL;
1567         Elm_Object_Item *cancel_it = NULL;
1568         Evas_Object *bot_bar = NULL;
1569
1570         /* create tool controlbar downside */
1571         bot_bar = _gl_ctrl_create_toolbar(ad, obj);
1572         GL_CHECK_VAL(bot_bar, -1);
1573         /* Add 'Delete' item */
1574         del_it = elm_toolbar_item_append(bot_bar, GL_CBAR_ICON_DELETE, NULL,
1575                                          _gl_ui_medias_del_cb, ad);
1576         gl_ui_disable_cbar_item(del_it);
1577         /* Add 'Move' item */
1578         move_it = elm_toolbar_item_append(bot_bar, GL_CBAR_ICON_MOVE, NULL,
1579                                           __gl_ui_move_cb, ad);
1580         gl_ui_disable_cbar_item(move_it);
1581         /* use Cancel button */
1582         cancel_it = elm_toolbar_item_append(bot_bar, GL_CBAR_ICON_CANCEL, NULL,
1583                                             __gl_ui_click_cancel_edit_cb, ad);
1584         /* Add transition finished callback */
1585         evas_object_smart_callback_add(parent, GL_TRANS_FINISHED,
1586                                        __gl_ui_trans_finished_cb, ad);
1587         /* Push to stack */
1588         nf_it = elm_naviframe_item_push(parent, title, NULL, NULL, obj,
1589                                         NULL);
1590         elm_object_item_part_content_set(nf_it, GE_NAVIFRAME_PREB_BTN, NULL);
1591
1592         ad->gridinfo.nf_it_edit = nf_it;
1593         /* Set tool bar to bottom */
1594         elm_object_item_part_content_set(nf_it, GE_NAVIFRAME_CONTROLBAR,
1595                                          bot_bar);
1596
1597         return 0;
1598 }
1599
1600 /**
1601  *  Use naviframe api to push albums rename view to stack.
1602  *  @param obj is the content to be pushed.
1603  */
1604 static int __gl_ui_push_view_albums_rename(void *data, Evas_Object *parent,
1605                                            Evas_Object *obj, char *title)
1606 {
1607         gl_dbg("GL_NAVI_ALBUMS_RENAME");
1608         GL_CHECK_VAL(obj, -1);
1609         GL_CHECK_VAL(parent, -1);
1610         GL_CHECK_VAL(data, -1);
1611         gl_appdata *ad = (gl_appdata *)data;
1612         Elm_Object_Item *nf_it = NULL;
1613         Evas_Object *done_btn = NULL;
1614         Evas_Object *cancel_btn = NULL;
1615
1616         /* Add transition finished callback */
1617         evas_object_smart_callback_add(parent, GL_TRANS_FINISHED,
1618                                        __gl_ui_trans_finished_cb, ad);
1619         nf_it = elm_naviframe_item_push(parent, title, NULL, NULL, obj, NULL);
1620         elm_object_item_part_content_set(nf_it, GE_NAVIFRAME_PREB_BTN, NULL);
1621         /* Add 'Cancel' button */
1622         cancel_btn = _gl_but_create_but(obj, GL_BUT_CANCEL,
1623                                         GL_BUTTON_STYLE_NAVI_TITLE);
1624         GL_CHECK_VAL(cancel_btn, -1);
1625         evas_object_smart_callback_add(cancel_btn, "clicked",
1626                                        __gl_ui_rename_album_cancel_cb, ad);
1627         elm_object_item_part_content_set(nf_it, GE_NAVIFRAME_TITLE_RIGHT_BTN,
1628                                          cancel_btn);
1629         /* Add 'Done' button */
1630         done_btn = _gl_but_create_but(obj, GL_BUT_DONE,
1631                                       GL_BUTTON_STYLE_NAVI_TITLE);
1632         GL_CHECK_VAL(done_btn, -1);
1633         evas_object_smart_callback_add(done_btn, "clicked",
1634                                        __gl_ui_rename_album_done_cb, ad);
1635         elm_object_item_part_content_set(nf_it, GE_NAVIFRAME_TITLE_LEFT_BTN,
1636                                          done_btn);
1637         ad->entryinfo.done_btn = done_btn;
1638         return 0;
1639 }
1640
1641 /**
1642  *  Use naviframe api to push new album view to stack.
1643  *  @param obj is the content to be pushed.
1644  */
1645 static int __gl_ui_push_view_albums_new(void *data, Evas_Object *parent,
1646                                         Evas_Object *obj, char *title)
1647 {
1648         gl_dbg("GL_NAVI_ALBUMS_NEW");
1649         GL_CHECK_VAL(obj, -1);
1650         GL_CHECK_VAL(parent, -1);
1651         GL_CHECK_VAL(data, -1);
1652         gl_appdata *ad = (gl_appdata *)data;
1653         Elm_Object_Item *nf_it = NULL;
1654         Evas_Object *done_btn = NULL;
1655         Evas_Object *cancel_btn = NULL;
1656
1657         nf_it = elm_naviframe_item_push(parent, title, NULL, NULL, obj, NULL);
1658         elm_object_item_part_content_set(nf_it, GE_NAVIFRAME_PREB_BTN, NULL);
1659         /* Add 'Cancel' button */
1660         cancel_btn = _gl_but_create_but(obj, GL_BUT_CANCEL,
1661                                         GL_BUTTON_STYLE_NAVI_TITLE);
1662         GL_CHECK_VAL(cancel_btn, -1);
1663         evas_object_smart_callback_add(cancel_btn, "clicked",
1664                                        _gl_ui_newalbum_cancel_cb, ad);
1665         elm_object_item_part_content_set(nf_it, GE_NAVIFRAME_TITLE_RIGHT_BTN,
1666                                          cancel_btn);
1667         /* Add 'Done' button */
1668         done_btn = _gl_but_create_but(obj, GL_BUT_DONE,
1669                                       GL_BUTTON_STYLE_NAVI_TITLE);
1670         GL_CHECK_VAL(done_btn, -1);
1671         evas_object_smart_callback_add(done_btn, "clicked",
1672                                        _gl_ui_newalbum_done_cb, ad);
1673         elm_object_item_part_content_set(nf_it, GE_NAVIFRAME_TITLE_LEFT_BTN,
1674                                          done_btn);
1675         ad->entryinfo.done_btn = done_btn;
1676         return 0;
1677 }
1678
1679 int gl_ui_reset_toolbar_item(void *data, gl_ctrl_seg_mode seg_mode, bool force)
1680 {
1681         GL_CHECK_VAL(data, -1);
1682         gl_appdata *ad = (gl_appdata *)data;
1683         bool is_zero = false;
1684
1685         gl_dbg("changed between tool tab(all/image/video)");
1686         if (seg_mode == GL_CTRL_SEG_VIDEOS)
1687                 is_zero = gl_db_is_item_cnt_zero(ad, MINFO_ITEM_VIDEO);
1688         else if (seg_mode == GL_CTRL_SEG_IMAGES)
1689                 is_zero = gl_db_is_item_cnt_zero(ad, MINFO_ITEM_IMAGE);
1690
1691         Elm_Object_Item *ctl_it = NULL;
1692         ctl_it = ad->gridinfo.edit_it;
1693
1694         /* none items, disable 'edit' item */
1695         if (is_zero) {
1696                 gl_ui_disable_cbar_item(ctl_it);
1697         } else {
1698                 gl_ui_enable_cbar_item(ctl_it);
1699         }
1700         return 0;
1701 }
1702
1703 int gl_ui_disable_toolbar_item(void *data, bool disabled, gl_navi_mode mode,
1704                                bool edit)
1705 {
1706         GL_CHECK_VAL(data, -1);
1707         gl_dbg("Title button disabled: %d.", disabled);
1708         if (disabled)
1709                 _gl_ui_disable_toolbar_item(data, mode, edit);
1710         else
1711                 _gl_ui_enable_toolbar_item(data, mode);
1712
1713         return 0;
1714 }
1715
1716 int gl_ui_disable_cbar_item(Elm_Object_Item *it)
1717 {
1718         if (it)
1719                 elm_object_item_disabled_set(it, EINA_TRUE);
1720         return 0;
1721 }
1722
1723 int gl_ui_enable_cbar_item(Elm_Object_Item *it)
1724 {
1725         if(it)
1726                 elm_object_item_disabled_set(it, EINA_FALSE);
1727         return 0;
1728 }
1729
1730 int gl_ui_disable_toolbar_items(void *data, Elm_Object_Item *nf_it)
1731 {
1732         GL_CHECK_VAL(data, -1);
1733         GL_CHECK_VAL(nf_it, -1);
1734
1735         Elm_Object_Item *cbar_it = NULL;
1736         Evas_Object *ctlbar = _gl_ctrl_get_toolbar(nf_it);
1737         cbar_it = elm_toolbar_last_item_get(ctlbar);
1738         GL_CHECK_VAL(cbar_it, -1);
1739         cbar_it = elm_toolbar_item_prev_get(cbar_it);
1740         while (cbar_it) {
1741                 gl_ui_disable_cbar_item(cbar_it);
1742                 cbar_it = elm_toolbar_item_prev_get(cbar_it);
1743         }
1744
1745         return 0;
1746 }
1747
1748 /* The maximun length reached callback */
1749 void __gl_ui_entry_maxlen_reached_cb(void *data, Evas_Object *obj, void *event_info)
1750 {
1751         gl_dbg("Entry maximum length reached, vibrate device.");
1752         GL_CHECK(data);
1753         /* Vibrate device if maximum length reached */
1754         gl_play_vibration(data);
1755 }
1756
1757 static void __gl_editfield_focused_cb(void *data, Evas_Object *obj, void *event_info)
1758 {
1759         GL_CHECK(obj);
1760         GL_CHECK(data);
1761         if (!elm_entry_is_empty(obj)) {
1762                 gl_dbg("Show eraser.");
1763                 elm_object_signal_emit(data, "elm,state,eraser,show", "elm");
1764         }
1765 }
1766
1767 static void __gl_editfield_unfocused_cb(void *data, Evas_Object *obj, void *event_info)
1768 {
1769         GL_CHECK(data);
1770         gl_dbg("Hide eraser.");
1771         elm_object_signal_emit(data, "elm,state,eraser,hide", "elm");
1772 }
1773
1774 static void __gl_editfield_eraser_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
1775 {
1776         GL_CHECK(data);
1777         gl_dbg("Clear emtry after eraser clicked.");
1778         elm_entry_entry_set(data, "");
1779 }
1780
1781 /*
1782 * Callback registered to signal 'changed' of entry.
1783 * It would get the entry string and check whether it's different
1784 * with original string or not, if so, enable 'Done' button, other disable it.
1785 */
1786 void __gl_ui_entry_space_check_cb(void *data, Evas_Object *obj, void *event_info)
1787 {
1788         gl_appdata *ad = (gl_appdata *)data;
1789         GL_CHECK(ad);
1790         GL_CHECK(ad->entryinfo.editfield);
1791         GL_CHECK(ad->entryinfo.done_btn);
1792         const char *entry_str = NULL;
1793
1794         /* Show/hide eraser */
1795         if (elm_object_focus_get(ad->entryinfo.editfield)) {
1796                 if (elm_entry_is_empty(obj)) {
1797                         gl_dbg("Show eraser.");
1798                         elm_object_signal_emit(ad->entryinfo.editfield,
1799                                                "elm,state,eraser,hide", "elm");
1800                 } else {
1801                         gl_dbg("Hide eraser.");
1802                         elm_object_signal_emit(ad->entryinfo.editfield,
1803                                                "elm,state,eraser,show", "elm");
1804                 }
1805         }
1806
1807         /* Get entry string. */
1808         GL_CHECK(ad->entryinfo.imf_entry);
1809         entry_str = elm_entry_entry_get(ad->entryinfo.imf_entry);
1810         GL_CHECK(entry_str);
1811         /**
1812         * Changes entry string to utf-8 encoding format,
1813         * other some special characters cannot be showed correctly.
1814         */
1815         char *entry_utf8 = elm_entry_markup_to_utf8(entry_str);
1816         GL_CHECK(entry_utf8);
1817         /**
1818         *  Removes leading and trailing whitespace
1819         *  to avoid showing popup when new name is only composed by space
1820         *  or avoid showing popup in the case when after trip leading and trailing space,
1821         *  new name is same as existing name
1822         */
1823         g_strstrip((gchar*)entry_utf8);
1824         GL_CHECK(entry_utf8);
1825         gl_dbg("New entry string without space: [%s]", entry_utf8);
1826
1827         bool b_disabled = false;
1828         /**
1829         * If entry string is empty, disable 'Done' button,
1830         * including create album and rename album.
1831         */
1832         if (!strlen(entry_utf8)) {
1833                 gl_dbg("Entry string is empty!");
1834                 b_disabled = true;
1835         }
1836
1837         gl_dbg("En/Disable Done button[%d]", b_disabled);
1838         elm_object_disabled_set(ad->entryinfo.done_btn, b_disabled);
1839
1840         /* Free string got from elm_entry_markup_to_utf8() */
1841         if (entry_utf8) {
1842                 free(entry_utf8);
1843                 entry_utf8 = NULL;
1844         }
1845 }
1846
1847 int gl_ui_cancel_rename_album(void *data)
1848 {
1849         GL_CHECK_VAL(data, -1);
1850         gl_dbg("");
1851         __gl_ui_rename_album_cancel_cb(data, NULL, NULL);
1852
1853         return 0;
1854 }
1855
1856 int
1857 gl_ui_cancel_new_album(void *data)
1858 {
1859         GL_CHECK_VAL(data, -1);
1860         gl_dbg("");
1861         _gl_ui_newalbum_cancel_cb(data, NULL, NULL);
1862
1863         return 0;
1864 }
1865
1866 int
1867 gl_ui_move_to_newalbum(void *data)
1868 {
1869         GL_CHECK_VAL(data, -1);
1870         gl_appdata *ad = (gl_appdata *)data;
1871         Evas_Object *editfield_ly = NULL;
1872         gl_dbg("");
1873
1874         ad->entryinfo.entry_mode = GL_ENTRY_NEW_ALBUM;
1875         editfield_ly = gl_ui_create_view_ly(ad->maininfo.navi_bar);
1876         Evas_Object *entry_ly = _gl_ui_create_editfield(ad, editfield_ly, NULL);
1877         evas_object_smart_callback_add(ad->entryinfo.imf_entry, "activated",
1878                                        _gl_ui_newalbum_enter_cb, ad);
1879         elm_object_part_content_set(editfield_ly, "elm.swallow.view", entry_ly);
1880         edje_object_signal_emit(_EDJ(editfield_ly),
1881                                 "elm,swallow_view,state,default", "elm");
1882         ad->entryinfo.imf_ly = NULL;
1883         gl_ui_create_title_and_push(ad, ad->maininfo.navi_bar, editfield_ly,
1884                                     GL_NAVI_ALBUMS_NEW, GL_STR_NEW_ALBUM);
1885         elm_entry_cursor_line_end_set(ad->entryinfo.imf_entry);
1886         elm_object_focus_set(ad->entryinfo.imf_entry, TRUE);
1887         ecore_imf_context_input_panel_show(ad->entryinfo.imf_context);
1888
1889         return 0;
1890 }
1891
1892 int gl_ui_rename_album(gl_cluster *album_item)
1893 {
1894         GL_CHECK_VAL(album_item, -1);
1895         GL_CHECK_VAL(album_item->cluster, -1);
1896         GL_CHECK_VAL(album_item->cluster->display_name, -1);
1897         GL_CHECK_VAL(album_item->ad, -1);
1898         gl_appdata *ad = (gl_appdata *)album_item->ad;
1899         int view_mode = gl_get_view_mode(ad);
1900         Evas_Object *editfield_ly = NULL;
1901         Evas_Object *entry_ly = NULL;
1902         gl_dbg("");
1903         if(ad->maininfo.rename_album_job) {
1904                 ecore_job_del(ad->maininfo.rename_album_job);
1905                 ad->maininfo.rename_album_job = NULL;
1906         }
1907         if (view_mode != GL_VIEW_ALBUMS_EDIT) {
1908                 gl_dbgE("Unexpected view mode(%d)!", view_mode);
1909                 return -1;
1910         }
1911
1912         /* save album selected for rename */
1913         ad->albuminfo.selected_album = album_item;
1914
1915         gl_set_view_mode(ad, GL_VIEW_ALBUMS_RENAME);
1916
1917         editfield_ly = gl_ui_create_view_ly(ad->maininfo.navi_bar);
1918         entry_ly = _gl_ui_create_editfield(ad, editfield_ly,
1919                                            album_item->cluster->display_name);
1920         evas_object_smart_callback_add(ad->entryinfo.imf_entry, "activated",
1921                                        __gl_ui_rename_album_enter_cb, ad);
1922         elm_object_part_content_set(editfield_ly, "elm.swallow.view", entry_ly);
1923         edje_object_signal_emit(_EDJ(editfield_ly),
1924                                 "elm,swallow_view,state,default", "elm");
1925         ad->entryinfo.imf_ly = NULL;
1926         gl_ui_create_title_and_push(ad, ad->maininfo.navi_bar, editfield_ly,
1927                                     GL_NAVI_ALBUMS_RENAME, GL_STR_CHNAGE_NAME);
1928         elm_entry_cursor_line_end_set(ad->entryinfo.imf_entry);
1929         elm_object_focus_set(ad->entryinfo.editfield, TRUE);
1930         ecore_imf_context_input_panel_show(ad->entryinfo.imf_context);
1931         return 0;
1932 }
1933
1934 int gl_ui_create_title_and_push(void *data, Evas_Object *parent,
1935                                 Evas_Object *obj, gl_navi_mode mode, char *title)
1936 {
1937         GL_CHECK_VAL(obj, -1);
1938         GL_CHECK_VAL(parent, -1);
1939         GL_CHECK_VAL(data, -1);
1940
1941         if (mode == GL_NAVI_ALBUMS)
1942                 __gl_ui_push_view_albums(data, parent, obj, title);
1943         else if (mode == GL_NAVI_ALBUMS_EDIT)
1944                 __gl_ui_push_view_albums_edit(data, parent, obj, title);
1945         else if (mode == GL_NAVI_THUMBS)
1946                 __gl_ui_push_view_thumbs(data, parent, obj, title);
1947         else if (mode == GL_NAVI_THUMBS_EDIT)
1948                 __gl_ui_push_view_thumbs_edit(data, parent, obj, title);
1949         else if (mode == GL_NAVI_ALBUMS_RENAME)
1950                 __gl_ui_push_view_albums_rename(data, parent, obj, title);
1951         else if (mode == GL_NAVI_ALBUMS_NEW)
1952                 __gl_ui_push_view_albums_new(data, parent, obj, title);
1953         gl_dbg("Done");
1954         return 0;
1955 }
1956
1957 bool
1958 gl_ui_display_nocontents(void *data)
1959 {
1960         GL_CHECK_VAL(data, -1);
1961         gl_appdata *ad = (gl_appdata *)data;
1962
1963         return _gl_ui_display_nocontents(ad);
1964 }
1965
1966 Evas_Object *
1967 gl_ui_load_edj(Evas_Object * parent, const char *file, const char *group)
1968 {
1969         Evas_Object *eo = NULL;
1970         int r = 0;
1971
1972         eo = elm_layout_add(parent);
1973         if (eo)
1974         {
1975                 r = elm_layout_file_set(eo, file, group);
1976                 if (!r)
1977                 {
1978                         evas_object_del(eo);
1979                         return NULL;
1980                 }
1981
1982                 evas_object_size_hint_weight_set(eo, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1983                 evas_object_size_hint_align_set(eo, EVAS_HINT_FILL, EVAS_HINT_FILL);
1984         }
1985
1986         return eo;
1987 }
1988
1989 int gl_ui_edit_cancel(void *data)
1990 {
1991         GL_CHECK_VAL(data, -1);
1992         gl_appdata *ad = (gl_appdata *)data;
1993         int view_mode = gl_get_view_mode(ad);
1994         Elm_Object_Item *nf_it = NULL;
1995
1996         if (view_mode == GL_VIEW_ALBUMS_EDIT ||
1997             view_mode == GL_VIEW_ALBUMS_RENAME) {
1998                 if (view_mode != GL_VIEW_ALBUMS_EDIT) {
1999                         gl_dbg("GL_VIEW_ALBUMS_xxx->Edit");
2000                         gl_set_view_mode(ad, GL_VIEW_ALBUMS_EDIT);
2001                 }
2002                 nf_it = ad->albuminfo.nf_it;
2003         } else if (view_mode == GL_VIEW_THUMBS_EDIT ||
2004                    view_mode == GL_VIEW_VIDEOLIST_EDIT) {
2005                 nf_it = ad->gridinfo.nf_it;
2006         }
2007         elm_naviframe_item_pop_to(nf_it);
2008         _gl_ui_edit_cancel_cb(ad, NULL, NULL);
2009
2010         return 0;
2011 }
2012
2013 /* Back to normal thumbnail view */
2014 int gl_ui_back_to_normal(void *data)
2015 {
2016         GL_CHECK_VAL(data, -1);
2017         gl_appdata *ad = (gl_appdata *)data;
2018         _gl_destroy_thumbs_edit_view(ad);
2019         elm_naviframe_item_pop_to(ad->gridinfo.nf_it);
2020         _gl_ui_edit_cancel_cb(ad, NULL, NULL);
2021
2022         return 0;
2023 }
2024
2025 Evas_Object *gl_ui_create_nocontents_full(void *data)
2026 {
2027         GL_CHECK_NULL(data);
2028         gl_appdata *ad = (gl_appdata *)data;
2029         Evas_Object *noc_lay = NULL;
2030         char label_str[GL_POPUP_DESC_LEN_MAX] = { 0, };
2031
2032         if (ad->maininfo.app_exit_mode == GL_APP_EXIT_NONE) {
2033                 int grid_mode = ad->gridinfo.grid_view_mode;
2034                 switch (grid_mode) {
2035                 case GL_GRID_ALL:
2036                         snprintf(label_str, sizeof(label_str), "%s",
2037                                  (char *)(GL_STR_NO_ITEMS));
2038                         break;
2039                 case GL_GRID_VIDEOS:
2040                         snprintf(label_str, sizeof(label_str), "%s",
2041                                  (char *)(GL_STR_NO_VIDEOS));
2042                         break;
2043                 case GL_GRID_IMAGES:
2044                         snprintf(label_str, sizeof(label_str), "%s",
2045                                  (char *)(GL_STR_NO_IMAGES));
2046                         break;
2047                 case GL_GRID_ALBUMS:
2048                         snprintf(label_str, sizeof(label_str), "%s",
2049                                  (char *)(GL_STR_NO_ALBUMS));
2050                         break;
2051                 default:
2052                         snprintf(label_str, sizeof(label_str), "%s",
2053                                  (char *)(GL_STR_NO_CONTENTS));
2054                         break;
2055                 }
2056         } else {
2057                 /* It's in Usb Mass Storage mode */
2058                 snprintf(label_str, sizeof(label_str), "%s<br>%s",
2059                          (char *)(GL_STR_NO_CONTENTS),
2060                          (char *)(GL_STR_UNABLE_USE_IN_UMS_MODE));
2061         }
2062
2063         gl_dbg("Nocontents label: %s", label_str);
2064         /* Full view nocontents */
2065         noc_lay = elm_layout_add(ad->maininfo.navi_bar);
2066         GL_CHECK_NULL(noc_lay);
2067         elm_object_part_text_set(noc_lay, "elm.text", label_str);
2068         elm_layout_theme_set(noc_lay, "layout", "nocontents", "gallery");
2069
2070         return noc_lay;
2071 }
2072
2073 /**
2074 * Add new notify widget, select-all widget and set view state.
2075 *
2076 * b_update, if true, update text only, other recreate notify widget
2077 */
2078 int gl_ui_create_selinfo(void *data, Evas_Object *parent, Elm_Object_Item *nf_it,
2079                           int all_cnt, int selected_cnt, bool b_update)
2080 {
2081         GL_CHECK_VAL(parent, -1);
2082         GL_CHECK_VAL(data, -1);
2083         GL_CHECK_VAL(nf_it, -1);
2084         gl_appdata *ad = (gl_appdata *)data;
2085         char text[GL_POPUP_DESC_LEN_MAX] = { 0, };
2086
2087         gl_dbg("selected_cnt/all_cnt = %d/%d", selected_cnt, all_cnt);
2088         if (selected_cnt > all_cnt) {
2089                 gl_ui_destroy_selinfo(ad);
2090                 gl_dbgE("selected_cnt > all_cnt!");
2091                 return -1;
2092         }
2093
2094         /* Create new notify widget */
2095         if (b_update == false)
2096                 _gl_ui_add_notify(ad, parent, true);
2097
2098         /* Reuse old notify widget in update case */
2099         GL_CHECK_VAL(ad->popupinfo.selinfo, -1);
2100         GL_CHECK_VAL(ad->popupinfo.selinfo_ly, -1);
2101
2102         /* Update state of checkbox in select-all widget */
2103         _gl_ui_update_selall(ad, all_cnt, selected_cnt);
2104
2105         /* Update notify widget and view related to it */
2106         _gl_ui_update_view_selinfo(ad, selected_cnt);
2107
2108         if (selected_cnt > 0) {
2109                 /* Enable/Disable control bar buttons */
2110                 _gl_ui_enable_toolbar_items(ad, nf_it);
2111                 snprintf(text, sizeof(text), "%s (%d)", GL_STR_SELECTED,
2112                          selected_cnt);
2113                 /* Set the text for notify */
2114                 edje_object_part_text_set(_EDJ(ad->popupinfo.selinfo_ly),
2115                                           "elm.text", text);
2116                 evas_object_show(ad->popupinfo.selinfo);
2117         } else {
2118                 /* Disable control bar buttons */
2119                 gl_ui_disable_toolbar_items(ad, nf_it);
2120                 gl_ui_destroy_selinfo(ad);
2121         }
2122
2123         return 0;
2124 }
2125
2126 int
2127 gl_ui_destroy_selinfo(void *data)
2128 {
2129         GL_CHECK_VAL(data, -1);
2130         gl_appdata *ad = (gl_appdata *)data;
2131         gl_dbg("");
2132         /* The selectioninfo_ly was filled in selectioninfo, so delete selectioninfo_ly first. */
2133         if (ad->popupinfo.selinfo_ly)
2134         {
2135                 evas_object_del(ad->popupinfo.selinfo_ly);
2136                 ad->popupinfo.selinfo_ly = NULL;
2137         }
2138
2139         if (ad->popupinfo.selinfo)
2140         {
2141                 evas_object_smart_callback_del(ad->popupinfo.selinfo,
2142                                 "timeout", _gl_ui_selinfo_destroy_cb);
2143                 evas_object_del(ad->popupinfo.selinfo);
2144                 ad->popupinfo.selinfo = NULL;
2145         }
2146
2147         return 0;
2148 }
2149
2150 /**
2151 * Update checkbox state and add click signal to Select-all widget.
2152 * Show arrow button in thumbnails/list edit mode.
2153 */
2154 int gl_ui_show_selall(void *data)
2155 {
2156         GL_CHECK_VAL(data, -1);
2157         gl_appdata *ad = (gl_appdata *)data;
2158         int view_mode = gl_get_view_mode(ad);
2159         Eina_Bool ck_state = EINA_FALSE;
2160         Evas_Object *view_ly = NULL;
2161         char *sig = "selectall_show";
2162
2163         gl_dbg("view_mode: %d.", view_mode);
2164         if (view_mode == GL_VIEW_THUMBS_EDIT ||
2165             view_mode == GL_VIEW_VIDEOLIST_EDIT) {
2166                 view_ly = ad->gridinfo.edit_layout;
2167                 if (ad->maininfo.medias_cnt == gl_db_selected_list_count(ad))
2168                         ck_state = EINA_TRUE;
2169                 if (view_mode == GL_VIEW_VIDEOLIST_EDIT)
2170                         sig = "selectall_show_video";
2171         } else {
2172                 gl_dbgE("Wrong view!");
2173                 return -1;
2174         }
2175
2176         const char *text = NULL;
2177         text = edje_object_part_text_get(_EDJ(view_ly), "selectall_text");
2178         if (text == NULL || g_strcmp0(text, GL_STR_SELECT_ALL))
2179                 edje_object_part_text_set(_EDJ(view_ly), "selectall_text",
2180                                           GL_STR_SELECT_ALL);
2181
2182         Evas_Object *old_check = NULL;
2183         old_check = elm_object_part_content_unset(view_ly, "selectall_check");
2184         if (old_check)
2185                 evas_object_del(old_check);
2186
2187         Evas_Object *check = elm_check_add(view_ly);
2188         elm_object_style_set(check, GL_CHECKBOX_STYLE_DEFAULT);
2189         evas_object_propagate_events_set(check, EINA_FALSE);
2190         elm_check_state_set(check, ck_state);
2191
2192         elm_object_part_content_set(view_ly, "selectall_check", check);
2193         evas_object_smart_callback_add(check, "changed",
2194                                        _gl_ui_selall_check_changed, ad);
2195         edje_object_signal_emit(_EDJ(view_ly), sig, "elm");
2196
2197         /* Add signal to select-all bg */
2198         edje_object_signal_callback_del(_EDJ(view_ly), "elm,action,click",
2199                                         "selectall_bg",
2200                                         _gl_ui_selall_bg_click_cb);
2201         edje_object_signal_callback_add(_EDJ(view_ly), "elm,action,click",
2202                                         "selectall_bg",
2203                                         _gl_ui_selall_bg_click_cb, ad);
2204
2205         return 0;
2206 }
2207
2208 /* Update checkbox state of Select-all and selectioninfo */
2209 int gl_ui_update_select_widgets(void *data)
2210 {
2211         GL_CHECK_VAL(data, -1);
2212         gl_appdata *ad = (gl_appdata *)data;
2213         /* Update checkbox state of Select-all */
2214         gl_ui_show_selall(ad);
2215         /* Update selectioninfo */
2216         int cnt = ad->maininfo.medias_cnt;
2217         int sel_cnt = gl_db_selected_list_count(ad);
2218         gl_ui_create_selinfo(ad, ad->gridinfo.edit_layout,
2219                              ad->gridinfo.nf_it_edit, cnt, sel_cnt, false);
2220         return 0;
2221 }
2222
2223 int gl_ui_create_notiinfo(void *data, Evas_Object *parent,
2224                            gl_ui_notify_mode n_mode)
2225 {
2226         GL_CHECK_VAL(parent, -1);
2227         GL_CHECK_VAL(data, -1);
2228         gl_appdata *ad = (gl_appdata *)data;
2229         const char *text = NULL;
2230         gl_dbg("");
2231
2232         _gl_ui_add_notify(ad, parent, false);
2233         GL_CHECK_VAL(ad->popupinfo.selinfo, -1);
2234         GL_CHECK_VAL(ad->popupinfo.selinfo_ly, -1);
2235
2236         edje_object_signal_emit(_EDJ(ad->popupinfo.selinfo_ly),
2237                                 "elm,selectioninfo,portrait", "elm");
2238
2239         switch (n_mode) {
2240         case GL_UI_NOTIFY_DELETED:
2241                 text = GL_STR_DELETED;
2242                 break;
2243         case GL_UI_NOTIFY_REMOVED:
2244                 text = GL_STR_REMOVED;
2245                 break;
2246         case GL_UI_NOTIFY_ADDED:
2247                 text = GL_STR_ADDED;
2248                 break;
2249         case GL_UI_NOTIFY_MOVED:
2250                 text = GL_STR_MOVED;
2251                 break;
2252         default:
2253                 gl_dbgE("GL_UI_NOTIFY_xxx, Error mode!");
2254                 break;
2255         }
2256
2257         edje_object_part_text_set(_EDJ(ad->popupinfo.selinfo_ly), "elm.text",
2258                                   text);
2259         evas_object_show(ad->popupinfo.selinfo);
2260
2261         return 0;
2262 }
2263
2264 int
2265 gl_ui_destroy_notiinfo(void *data)
2266 {
2267         GL_CHECK_VAL(data, -1);
2268         gl_appdata *ad = (gl_appdata *)data;
2269         gl_dbg("");
2270         /* The selectioninfo_ly was filled in selectioninfo, so delete selectioninfo_ly first. */
2271         if (ad->popupinfo.selinfo_ly)
2272         {
2273                 evas_object_del(ad->popupinfo.selinfo_ly);
2274                 ad->popupinfo.selinfo_ly = NULL;
2275         }
2276
2277         if (ad->popupinfo.selinfo)
2278         {
2279                 evas_object_smart_callback_del(ad->popupinfo.selinfo,
2280                                 "timeout", _gl_ui_notiinfo_destroy_cb);
2281                 evas_object_del(ad->popupinfo.selinfo);
2282                 ad->popupinfo.selinfo = NULL;
2283         }
2284
2285         return 0;
2286 }
2287
2288 int gl_ui_destroy_imf(void *data)
2289 {
2290         GL_CHECK_VAL(data, -1);
2291         gl_appdata *ad = (gl_appdata *)data;
2292         int view_mode = gl_get_view_mode(ad);
2293         gl_dbg("view_mode = %d", view_mode);
2294
2295         if (ad->entryinfo.imf_entry) {
2296                 evas_object_smart_callback_del(ad->entryinfo.imf_entry,
2297                                                "maxlength,reached",
2298                                                __gl_ui_entry_maxlen_reached_cb);
2299                 if (ad->entryinfo.entry_mode == GL_ENTRY_NEW_ALBUM)
2300                         evas_object_smart_callback_del(ad->entryinfo.imf_entry,
2301                                                        "activated",
2302                                                        _gl_ui_newalbum_enter_cb);
2303                 else
2304                         evas_object_smart_callback_del(ad->entryinfo.imf_entry,
2305                                                        "changed",
2306                                                        __gl_ui_entry_space_check_cb);
2307         }
2308         ad->entryinfo.entry_mode = GL_ENTRY_NONE;
2309
2310         if (ad->entryinfo.imf_context)
2311                 ecore_imf_context_input_panel_hide(ad->entryinfo.imf_context);
2312
2313         if (ad->entryinfo.editfield)
2314                 evas_object_hide(ad->entryinfo.editfield);
2315
2316         if (ad->entryinfo.imf_ly) {
2317                 evas_object_del(ad->entryinfo.imf_ly);
2318                 ad->entryinfo.imf_ly = NULL;
2319         }
2320
2321         ad->entryinfo.imf_entry = NULL;
2322         ad->entryinfo.imf_context = NULL;
2323         ad->entryinfo.editfield = NULL;
2324
2325         return 0;
2326 }
2327
2328 Evas_Object *gl_ui_create_main_ly(Evas_Object *parent)
2329 {
2330         GL_CHECK_NULL(parent);
2331         Evas_Object *layout = NULL;
2332
2333         layout = elm_layout_add(parent);
2334         GL_CHECK_NULL(layout);
2335
2336         elm_layout_theme_set(layout, "layout", "application", "default");
2337         evas_object_size_hint_weight_set(layout,
2338                         EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2339         elm_win_resize_object_add(parent, layout);
2340         evas_object_show(layout);
2341
2342         return layout;
2343 }
2344
2345 Evas_Object *gl_ui_create_naviframe(Evas_Object *parent)
2346 {
2347         GL_CHECK_NULL(parent);
2348         Evas_Object *navi_bar = NULL;
2349
2350         navi_bar = elm_naviframe_add(parent);
2351         gl_dbg("elm_naviframe_add:done");
2352         /* Use custom style to set bg color black(0 0 0 255). */
2353         elm_object_style_set(navi_bar, GL_NAVIBAR_STYLE_DEFAULT);
2354         evas_object_show(navi_bar);
2355         gl_dbg("elm_object_style_set: done");
2356
2357         return navi_bar;
2358 }
2359
2360 Evas_Object *gl_ui_create_view_ly(Evas_Object *parent)
2361 {
2362         gl_dbg("");
2363         GL_CHECK_NULL(parent);
2364
2365         Evas_Object *layout = NULL;
2366         layout = gl_ui_load_edj(parent, GL_EDJ_FILE, GL_GRP_VIEW_LAYOUT);
2367         GL_CHECK_NULL(layout);
2368         evas_object_show(layout);
2369
2370         return layout;
2371 }
2372
2373 int _gl_ui_elm_bg_file_set(Evas_Object *bg, gl_item *git)
2374 {
2375         if (git == NULL || git->item == NULL || git->ad == NULL) {
2376                 gl_dbgE("Invalid item :%p", git);
2377                 elm_bg_file_set(bg, GL_DEFAULT_THUMB_ICON, NULL);
2378                 return -1;
2379         }
2380
2381         char *path = NULL;
2382         path = _gl_get_thumb(git->ad, git->item->file_url,
2383                              &git->item->thumb_url);
2384         if (path) {
2385                 elm_bg_file_set(bg, path, NULL);
2386                 free(path);
2387                 path = NULL;
2388         } else {
2389                 elm_bg_file_set(bg, git->item->thumb_url, NULL);
2390         }
2391
2392         return 0;
2393 }