Modify flora license version(LICENSE.Flora)
[apps/core/preloaded/gallery.git] / src / widget / gl-controlbar.c
1 /*
2   * Copyright (c) 2012  Samsung Electronics Co., Ltd
3   *
4   * Licensed under the Flora License, Version 1.1 (the "License");
5   * you may not use this file except in compliance with the License.
6   * You may obtain a copy of the License at
7   *
8   *     http://floralicense.org/license/
9   *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16
17 #include "gl-debug.h"
18 #include "gl-ui-util.h"
19 #include "gl-util.h"
20 #include "gl-controlbar.h"
21 #include "gl-albums.h"
22 #include "gl-thumbs.h"
23 #include "gl-data.h"
24 #include "gl-tags.h"
25 #include "gl-strings.h"
26 #include "gl-icons.h"
27 #include "gl-notify.h"
28 #include "gl-progressbar.h"
29 #include "gl-ctxpopup.h"
30
31 #define GL_CTRL_STYLE_TABBAR "tabbar"
32 #define GL_CTRL_STYLE_TABBAR_LAND "tabbar/item_horizontal"
33
34 #define GL_CTRL_SEG_STYLE "gallery/default"
35 /* (144x3) */
36 #define GL_SEGMENT_WIDTH_MIN_INC (396*elm_config_scale_get())
37
38 static int __gl_ctrl_reset_btn(void *data, int grid_mode)
39 {
40         GL_CHECK_VAL(data, -1);
41         gl_appdata *ad = (gl_appdata *)data;
42
43         bool is_zero = false;
44         gl_dbg("changed between tool tab(all/image/video)");
45         if (grid_mode == GL_THUMB_VIDEOS)
46                 is_zero = _gl_data_is_item_cnt_zero(ad, MEDIA_CONTENT_TYPE_VIDEO);
47         else if (grid_mode == GL_THUMB_IMAGES)
48                 is_zero = _gl_data_is_item_cnt_zero(ad, MEDIA_CONTENT_TYPE_IMAGE);
49
50         /* none items, disable 'edit' button */
51         if (is_zero) {
52                 _gl_ui_disable_btn(ad->gridinfo.edit_btn);
53                 _gl_ui_disable_slideshow(ad, true);
54         } else {
55                 _gl_ui_enable_btn(ad->gridinfo.edit_btn);
56                 _gl_ui_disable_slideshow(ad, false);
57         }
58         return 0;
59 }
60
61 void _gl_ctrl_segment_change_cb(void *data, Evas_Object *obj, void *event_info)
62 {
63         GL_CHECK(data);
64         gl_appdata *ad = (gl_appdata *)data;
65         gl_dbg("");
66
67         if (ad->uginfo.ug_called_by_me || ad->gridinfo.grid_append_idler) {
68                 gl_dbgW("UG invoked or appending gridview!");
69                 return;
70         }
71
72         const char *label = NULL;
73         label = elm_object_item_text_get((Elm_Object_Item *)event_info);
74         GL_CHECK(label);
75         gl_dbg("label: %s", label);
76         _gl_ctxpopup_del(data);
77
78         int old_m = ad->gridinfo.view_mode;
79
80         if (!g_strcmp0(label, GL_STR_ALL)) {
81                 gl_dbg("Creating all-media view");
82                 ad->gridinfo.view_mode = GL_THUMB_ALL;
83         } else if (!g_strcmp0(label, GL_STR_IMAGES)) {
84                 gl_dbg("Creating image view");
85                 ad->gridinfo.view_mode = GL_THUMB_IMAGES;
86         } else if (!g_strcmp0(label, GL_STR_VIDEOS)) {
87                 gl_dbg("Creating video view");
88                 ad->gridinfo.view_mode = GL_THUMB_VIDEOS;
89         } else {
90                 gl_dbgE("Wrong label!");
91                 return;
92         }
93
94         if (ad->gridinfo.view_mode == old_m) {
95                 gl_dbgW("Already showed!");
96                 return;
97         }
98
99         if (ad->gridinfo.all_grid_view == NULL)
100                 ad->gridinfo.all_grid_view = _gl_thumbs_add_grid(ad,
101                                                                  ad->gridinfo.navi_content_ly,
102                                                                  ad->gridinfo.view_mode,
103                                                                  false);
104         else
105                 _gl_thumbs_update_view(ad);
106
107         elm_object_part_content_unset(ad->gridinfo.navi_content_ly,
108                                       "elm.swallow.view");
109         evas_object_show(ad->gridinfo.all_grid_view);
110         elm_object_part_content_set(ad->gridinfo.navi_content_ly,
111                                     "elm.swallow.view",
112                                     ad->gridinfo.all_grid_view);
113
114         __gl_ctrl_reset_btn(ad, ad->gridinfo.view_mode);
115         gl_set_view_mode(ad, GL_VIEW_THUMBS);
116 }
117
118 /* Pop naviframe item when show albums/tags edit view */
119 static int _gl_ctrl_popup_edit_view(void *data)
120 {
121         GL_CHECK_VAL(data, -1);
122         gl_appdata *ad = (gl_appdata *)data;
123         GL_CHECK_VAL(ad->ctrlinfo.nf_it, -1);
124
125         elm_naviframe_item_pop_to(ad->ctrlinfo.nf_it);
126         ad->ctrlinfo.nf_it_edit = NULL;
127         return 0;
128 }
129
130 static int __gl_ctrl_reset_albums(void *data)
131 {
132         GL_CHECK_VAL(data, -1);
133         gl_appdata *ad = (gl_appdata *)data;
134         int view_mode = gl_get_view_mode(ad);
135
136         if (view_mode == GL_VIEW_ALBUMS_EDIT) {
137                 /* Destroy data */
138                 _gl_data_finalize_albums_selected_list(ad);
139                 /* Refresh albums list */
140                 _gl_data_get_cluster_list(ad);
141         }
142
143         return 0;
144 }
145
146 static int __gl_ctrl_reset_tags(void *data)
147 {
148         GL_CHECK_VAL(data, -1);
149         gl_appdata *ad = (gl_appdata *)data;
150         int view_mode = gl_get_view_mode(ad);
151
152         /* Destroy data */
153         if (view_mode == GL_VIEW_TAGS_EDIT)
154                 _gl_data_finalize_tags_selected_list(ad);
155
156         if (ad->taginfo.tags_view)
157                 gl_tag_unset_rename(ad);
158         ad->taginfo.current_tag = NULL;
159
160         return 0;
161 }
162
163 static int __gl_ctrl_reset_previous_tab(void *data)
164 {
165         GL_CHECK_VAL(data, -1);
166         gl_appdata *ad = (gl_appdata *)data;
167
168         switch (ad->ctrlinfo.tab_mode) {
169         case GL_CTRL_TAB_ALBUMS:
170                 __gl_ctrl_reset_albums(ad);
171                 break;
172         case GL_CTRL_TAB_TAGS:
173                 __gl_ctrl_reset_tags(ad);
174                 break;
175         default:
176                 gl_dbgE("Wrong tabbar mode!");
177                 return -1;
178         }
179
180         /* Delete layout and edit view */
181         _gl_destroy_ctrl_edit_view(ad);
182         /* Delete naviframe item */
183         _gl_ctrl_popup_edit_view(ad);
184
185         /* Hide previous view */
186         Evas_Object *pre_view = NULL;
187         pre_view = elm_object_part_content_unset(ad->ctrlinfo.ctrlbar_view_ly,
188                                                  "contents");
189         evas_object_hide(pre_view);
190
191         return 0;
192 }
193
194 static int __gl_ctrl_remake_btns(void *data, gl_ctrl_tab_mode mode)
195 {
196         GL_CHECK_VAL(data, -1);
197         gl_appdata *ad = (gl_appdata *)data;
198
199         /* Reset some flags */
200         ad->albuminfo.b_edit_disable = false;
201         ad->taginfo.b_edit_disable = false;
202
203         switch (mode) {
204         case GL_CTRL_TAB_ALBUMS:
205                 gl_dbg("GL_CTRL_TAB_ALBUMS");
206                 /* add items */
207                 _gl_ui_add_btns_albums(ad, GL_UI_ALBUMS_REMAKE);
208                 break;
209         case GL_CTRL_TAB_TAGS:
210                 gl_dbg("GL_CTRL_TAB_TAGS");
211                 _gl_tags_add_btns(ad);
212                 break;
213         default:
214                 gl_dbgE("Error mode!");
215                 return -1;
216         }
217         gl_dbg("Done");
218
219         return 0;
220 }
221
222 static void _gl_ctrl_view_change_cb(void *data, Evas_Object *obj, void *event_info)
223 {
224         GL_CHECK(obj);
225         GL_CHECK(data);
226         gl_appdata *ad = (gl_appdata *)data;
227         int view_mode = gl_get_view_mode(ad);
228         gl_dbg("view_mode: %d, tab_mode: %d", view_mode, ad->ctrlinfo.tab_mode);
229         Elm_Object_Item *it = elm_toolbar_selected_item_get(obj);
230         GL_CHECK(it);
231         const char *selected_label = elm_object_item_text_get(it);
232         GL_CHECK(selected_label);
233         gl_dbg("Tab %s selected.", selected_label);
234         _gl_ctxpopup_del(data);
235
236         if (!g_strcmp0(selected_label, GL_STR_CTRL_ITEM_ALBUMS)) {
237                 gl_dbg("Albums");
238                 if (ad->ctrlinfo.tab_mode == GL_CTRL_TAB_ALBUMS) {
239                         gl_dbg("Already in Albums Tab.");
240                         return;
241                 }
242                 __gl_ctrl_reset_previous_tab(ad);
243                 gl_set_view_mode(ad, GL_VIEW_ALBUMS);
244
245                 _gl_data_get_cluster_list(ad);
246                 gl_albums_update_items(ad);
247
248                 if (ad->albuminfo.albums_nocontents) {
249                         gl_ctrl_disable_ctrlbar(ad, true);
250                 } else {
251                         evas_object_show(ad->albuminfo.albums_view);
252                         elm_object_part_content_set(ad->ctrlinfo.ctrlbar_view_ly,
253                                                     "contents",
254                                                     ad->albuminfo.albums_view);
255                 }
256
257                 ad->ctrlinfo.tab_mode = GL_CTRL_TAB_ALBUMS;
258
259                 __gl_ctrl_remake_btns(ad, GL_CTRL_TAB_ALBUMS);
260         } else if (!g_strcmp0(selected_label, GL_STR_CTRL_ITEM_TAGS)) {
261                 gl_dbg("Tags");
262                 if (ad->ctrlinfo.tab_mode == GL_CTRL_TAB_TAGS) {
263                         gl_dbg("Already in Tags Tab.");
264                         return;
265                 }
266
267                 __gl_ctrl_reset_previous_tab(ad);
268                 gl_set_view_mode(ad, GL_VIEW_TAGS);
269
270                 if (ad->taginfo.tags_view)
271                         gl_tag_update_view(ad);
272                 else
273                         ad->taginfo.tags_view = gl_tag_create_view(ad,
274                                                                    ad->ctrlinfo.ctrlbar_view_ly);
275                 evas_object_show(ad->taginfo.tags_view);
276                 elm_object_part_content_set(ad->ctrlinfo.ctrlbar_view_ly,
277                                             "contents", ad->taginfo.tags_view);
278
279                 ad->taginfo.current_tag = NULL;
280                 ad->ctrlinfo.tab_mode = GL_CTRL_TAB_TAGS;
281
282                 __gl_ctrl_remake_btns(ad, GL_CTRL_TAB_TAGS);
283         }
284 }
285
286 static int __gl_ctrl_disable_btn(void *data, int mode)
287 {
288         GL_CHECK_VAL(data, -1);
289         gl_appdata *ad = (gl_appdata *)data;
290
291         if (mode == GL_NAVI_ALBUMS) {
292                 gl_dbg("GL_NAVI_ALBUMS");
293                 /* disable 'edit' button */
294                 ad->albuminfo.b_edit_disable = true;
295         } else if (mode == GL_NAVI_TAGS) {
296                 gl_dbg("GL_NAVI_TAGS");
297                 /* disable 'edit' button */
298                 ad->taginfo.b_edit_disable = true;
299         }else if (mode == GL_NAVI_THUMBS) {
300                 gl_dbg("GL_NAVI_THUMBS");
301                 /* disable 'edit' button */
302                 _gl_ui_disable_btn(ad->gridinfo.edit_btn);
303                 _gl_ui_disable_btn(ad->gridinfo.slideshow_btn);
304                 /* Check title button */
305                 if (ad->ctrlinfo.tab_mode == GL_CTRL_TAB_TAGS)
306                         _gl_ui_show_add_btn(ad);
307         } else {
308                 gl_dbgE("Unkonw mode");
309                 return -1;
310         }
311         return 0;
312 }
313
314 static int __gl_ctrl_enable_btn(void *data, int mode)
315 {
316         GL_CHECK_VAL(data, -1);
317         gl_appdata *ad = (gl_appdata *)data;
318         gl_dbg("mode: %d", mode);
319
320         if (mode == GL_NAVI_ALBUMS) {
321                 gl_dbg("GL_NAVI_ALBUMS");
322                 /* enable 'edit' item */
323                 if (!gl_check_gallery_empty(ad) &&
324                     ad->albuminfo.cluster_list->edit_cnt) {
325                         ad->albuminfo.b_edit_disable = false;
326                 } else {
327                         ad->albuminfo.b_edit_disable = true;
328                 }
329         } else if (mode == GL_NAVI_THUMBS) {
330                 gl_dbg("GL_NAVI_THUMBS");
331                 /* enable 'Edit' button */
332                 _gl_ui_enable_btn(ad->gridinfo.edit_btn);
333                 /* Check more button */
334                 if (ad->ctrlinfo.tab_mode == GL_CTRL_TAB_TAGS) {
335                         Evas_Object *more_btn = NULL;
336                         more_btn = _gl_ui_get_btn(ad, NULL, GL_NAVIFRAME_MORE);
337                         if (ad->maininfo.medias_cnt)
338                                 _gl_ui_enable_btn(more_btn);
339                         else
340                                 _gl_ui_disable_btn(more_btn);
341                         /* Check "+" button */
342                         _gl_ui_show_add_btn(ad);
343                 }
344
345                 if (ad->maininfo.medias_cnt)
346                         _gl_ui_disable_slideshow(ad, false);
347                 else
348                         _gl_ui_disable_slideshow(ad, true);
349         } else if (mode == GL_NAVI_TAGS) {
350                 gl_dbg("GL_NAVI_TAGS");
351                 /* enable 'edit' button not only favorites tag */
352                 if (_gl_data_get_tag_count_all(ad) > 1)
353                         ad->taginfo.b_edit_disable = false;
354                 else
355                         ad->taginfo.b_edit_disable = true;
356         } else {
357                 gl_dbgE("Unkonw mode");
358                 return -1;
359         }
360
361         return 0;
362 }
363
364 /* Enable all buttons except for some special cases */
365 static int __gl_ctrl_enable_btns(gl_appdata *ad, Elm_Object_Item *nf_it)
366 {
367         gl_dbg("");
368         GL_CHECK_VAL(ad, -1);
369         GL_CHECK_VAL(nf_it, -1);
370         bool b_disable_del = false;
371         bool b_disable_share = false;
372
373         int view_mode = gl_get_view_mode(ad);
374         if (view_mode == GL_VIEW_ALBUMS_EDIT) {
375                 GL_CHECK_VAL(ad->albuminfo.selected_albums_elist, -1);
376                 int sel_cnt = 0;
377                 sel_cnt = _gl_data_get_albums_selected_cnt(ad);
378
379                 gl_cluster *album_item = NULL;
380                 int i = 0;
381                 for (i = 0; i < sel_cnt; i++) {
382                         if (b_disable_del && b_disable_share)
383                                 break;
384                         album_item = eina_list_nth(ad->albuminfo.selected_albums_elist,
385                                                    i);
386                         if (album_item == NULL || album_item->cluster == NULL ||
387                             album_item->cluster->uuid == NULL) {
388                                 gl_dbgE("Invlaid album item!");
389                                 continue;
390                         }
391                         /* All albums couldn't be deleted, so disable Delete item */
392                         if (album_item->cluster->type == GL_STORE_T_ALL) {
393                                 gl_dbg("All albums, disable Delete item.");
394                                 b_disable_del = true;
395                                 /* Disable share*/
396                                 if (sel_cnt > 1)
397                                         b_disable_share = true;
398                         }
399                         album_item = NULL;
400                 }
401         }
402         int share_m = gl_get_share_mode(ad);
403         if ((view_mode == GL_VIEW_THUMBS_EDIT ||
404              view_mode == GL_VIEW_ALBUMS_EDIT ||
405              view_mode == GL_VIEW_TAGS_EDIT) && share_m == GL_SHARE_DRM) {
406                 gl_dbgW("Selected item is DRM file!");
407                 b_disable_share = true;
408         }
409
410         /* more-share-delete */
411         _gl_ui_disable_each_btn(nf_it, false, b_disable_share, b_disable_del);
412         return 0;
413 }
414
415 Evas_Object *
416 gl_ctrl_create_ctrlbar_view(Evas_Object * parent)
417 {
418         gl_dbg("");
419         GL_CHECK_NULL(parent);
420
421         Evas_Object *layout = NULL;
422         layout = gl_ui_load_edj(parent, GL_EDJ_FILE, GL_GRP_CONTROLBAR);
423         GL_CHECK_NULL(layout);
424         evas_object_show(layout);
425
426         return layout;
427 }
428
429 Evas_Object *gl_ctrl_create_ctrlbar_ly(Evas_Object *parent)
430 {
431         gl_dbg("");
432         gl_dbg_launch("    gl_ctrl_create_ctrlbar_ly:start");
433         GL_CHECK_NULL(parent);
434         Evas_Object *layout = NULL;
435         layout = gl_ui_load_edj(parent, GL_EDJ_FILE, GL_GRP_CONTROLBAR_LY);
436         GL_CHECK_NULL(layout);
437         evas_object_show(layout);
438
439         gl_dbg_launch("    gl_ctrl_create_ctrlbar_ly:end");
440
441         return layout;
442 }
443
444 Evas_Object *gl_ctrl_create_ctrlbar(void *data, int mode)
445 {
446         gl_dbg_launch("      gl_ctrl_create_ctrlbar:start");
447         gl_dbg("mode: %d", mode);
448         GL_CHECK_NULL(data);
449         gl_appdata *ad = (gl_appdata *)data;
450         Evas_Object *cbar = NULL;
451         Elm_Object_Item *item[GL_CTRL_TAB_CNT];
452
453         if (ad->ctrlinfo.ctrlbar != NULL) {
454                 gl_dbg("Remove the existed control bar");
455                 evas_object_del(ad->ctrlinfo.ctrlbar);
456                 ad->ctrlinfo.ctrlbar = NULL;
457         }
458
459         gl_dbg_launch("        elm_toolbar_add:start");
460         cbar = elm_toolbar_add(ad->ctrlinfo.ctrlbar_ly);
461         gl_dbg_launch("        elm_toolbar_add:end");
462         GL_CHECK_NULL(cbar);
463         gl_dbg("elm_toolbar_add:done");
464         elm_toolbar_shrink_mode_set(cbar, ELM_TOOLBAR_SHRINK_EXPAND);
465         elm_toolbar_transverse_expanded_set(cbar, EINA_TRUE);
466
467         if (mode != GL_CTRL_TAB_ALBUMS) {
468                 ad->ctrlinfo.tab_mode = -1;
469                 gl_dbgW("Set tab_mode as -1!");
470         }
471
472         if (mode == GL_CTRL_TAB_ALBUMS || mode == GL_CTRL_TAB_TAGS) {
473                 int rotate_mode = ad->maininfo.rotate_mode;
474                 ad->ctrlinfo.rotate_mode = rotate_mode;
475                 gl_dbg("Rotate_mode is %d", rotate_mode);
476                 if ((rotate_mode == APP_DEVICE_ORIENTATION_270) ||
477                     (rotate_mode == APP_DEVICE_ORIENTATION_90)) {
478                         elm_object_style_set(cbar, GL_CTRL_STYLE_TABBAR_LAND);
479                 } else {
480                         elm_object_style_set(cbar, GL_CTRL_STYLE_TABBAR);
481                 }
482
483                 gl_dbg_launch("        elm_toolbar_item_append:start");
484                 item[GL_CTRL_TAB_ALBUMS] = elm_toolbar_item_append(cbar,
485                                                                GL_CTRL_ICON_ALBUMS,
486                                                                GL_STR_CTRL_ITEM_ALBUMS,
487                                                                _gl_ctrl_view_change_cb,
488                                                                ad);
489                 item[GL_CTRL_TAB_TAGS] = elm_toolbar_item_append(cbar,
490                                                              GL_CTRL_ICON_TAGS,
491                                                              GL_STR_CTRL_ITEM_TAGS,
492                                                              _gl_ctrl_view_change_cb,
493                                                              ad);
494                 gl_dbg_launch("        elm_toolbar_item_append:end");
495                 gl_dbg("elm_toolbar_item_append:done");
496                 elm_toolbar_select_mode_set(cbar, ELM_OBJECT_SELECT_MODE_ALWAYS);
497
498                 if (ad->albuminfo.gallery_launched == true) {
499                         if (gl_check_gallery_empty(ad)) {
500                                 /**
501                                 * disable control bar when none album exists.
502                                 * or file system is unmounted.
503                                 */
504                                 gl_dbg("Disable tabbar items");
505                                 int i = 0;
506                                 for (i = 0; i < GL_CTRL_TAB_CNT; i++)
507                                         elm_object_item_disabled_set(item[i],
508                                                                      EINA_TRUE);
509                         }
510
511                         elm_toolbar_item_selected_set(item[mode], EINA_TRUE);
512                 }
513         }
514         gl_dbg_launch("      gl_ctrl_create_ctrlbar:end");
515
516         return cbar;
517 }
518
519 //disable/enable controlbar tab event.
520 int
521 gl_ctrl_disable_tab_event(void *data, bool disabled)
522 {
523         GL_CHECK_VAL(data, -1);
524         gl_appdata *ad = (gl_appdata *)data;
525         GL_CHECK_VAL(ad->ctrlinfo.ctrlbar, -1);
526         gl_dbgE("TODO: Check me");
527
528         if (gl_get_view_mode(ad) == GL_VIEW_ALBUMS)
529         {
530                 /*if (disabled)
531                 {
532                         evas_object_smart_callback_del(ad->ctrlinfo.ctrlbar,
533                                         "view,change,before",
534                                         _gl_ctrl_view_change_cb);
535                 }
536                 else
537                 {
538                         evas_object_smart_callback_add(ad->ctrlinfo.ctrlbar,
539                                         "view,change,before",
540                                         _gl_ctrl_view_change_cb, ad);
541                 }*/
542         }
543
544         return 0;
545 }
546
547 /* Select new tab, view changed callback would be invoked */
548 int _gl_ctrl_sel_tabbar_item(void *data, const char *aul_type)
549 {
550         GL_CHECK_VAL(data, -1);
551         GL_CHECK_VAL(aul_type, -1);
552         gl_appdata *ad = (gl_appdata *)data;
553         Elm_Object_Item *cbar_it = NULL;
554         cbar_it = elm_toolbar_first_item_get(ad->ctrlinfo.ctrlbar);
555         const char *text = NULL;
556         int len = strlen(aul_type);
557         bool b_found = false;
558         const char *tab_i18n_text = NULL;
559         gl_dbg("AUL type: %s", aul_type);
560
561         if (strncasecmp(aul_type, GL_AUL_ALBUM, len) == 0)
562                 tab_i18n_text = GL_STR_CTRL_ITEM_ALBUMS;
563         else if (strncasecmp(aul_type, GL_AUL_TAG, len) == 0)
564                 tab_i18n_text = GL_STR_CTRL_ITEM_TAGS;
565         else
566                 gl_dbgE("Wrong type!");
567         GL_CHECK_VAL(tab_i18n_text, -1);
568
569         /* Get item to be selected */
570         while (cbar_it) {
571                 text = elm_object_item_text_get(cbar_it);
572                 if (!strncasecmp(text, tab_i18n_text, len)) {
573                         b_found = true;
574                         break;
575                 }
576
577                 cbar_it = elm_toolbar_item_next_get(cbar_it);
578         }
579
580         if (b_found && cbar_it) {
581                 elm_toolbar_item_selected_set(cbar_it, EINA_TRUE);
582                 return 0;
583         } else {
584                 gl_dbgE("Failed to get tabbar item!");
585                 return -1;
586         }
587 }
588
589 int _gl_ctrl_show_tabbar(void *data, bool b_show)
590 {
591         GL_CHECK_VAL(data, -1);
592         gl_appdata *ad = (gl_appdata *)data;
593         GL_CHECK_VAL(ad->ctrlinfo.ctrlbar_ly, -1);
594         GL_CHECK_VAL(ad->ctrlinfo.ctrlbar_view_ly, -1);
595         int rotate_mode = ad->maininfo.rotate_mode;
596         gl_dbg("Tabbar show: %d, rotate_mode: %d", b_show, rotate_mode);
597         Evas_Object *view_ly = ad->ctrlinfo.ctrlbar_view_ly;
598
599         if (gl_get_view_mode(ad) == GL_VIEW_ALBUMS_RENAME ||
600             gl_get_view_mode(ad) == GL_VIEW_ALBUMS_EDIT) {
601                 gl_dbg("Rename album, set edit layout");
602                 view_ly = ad->ctrlinfo.ctrlbar_edit_ly;
603         }
604
605         if (b_show) {
606                 if ((rotate_mode == APP_DEVICE_ORIENTATION_270) ||
607                     (rotate_mode == APP_DEVICE_ORIENTATION_90)) {
608                         edje_object_signal_emit(_EDJ(view_ly),
609                                                 GL_SIGNAL_VIEW_TABBAR_BG_HIDE,
610                                                 "elm");
611                         edje_object_signal_emit(_EDJ(ad->ctrlinfo.ctrlbar_ly),
612                                                 GL_SIGNAL_VIEW_TABBAR_LAND,
613                                                 "elm");
614                 } else {
615                         edje_object_signal_emit(_EDJ(view_ly),
616                                                 GL_SIGNAL_VIEW_TABBAR_BG_HIDE,
617                                                 "elm");
618                         edje_object_signal_emit(_EDJ(ad->ctrlinfo.ctrlbar_ly),
619                                                 GL_SIGNAL_VIEW_TABBAR_DEFAULT,
620                                                 "elm");
621                 }
622         } else {
623                 if ((rotate_mode == APP_DEVICE_ORIENTATION_270) ||
624                     (rotate_mode == APP_DEVICE_ORIENTATION_90)) {
625                         edje_object_signal_emit(_EDJ(view_ly),
626                                                 GL_SIGNAL_VIEW_TABBAR_BG_SHOW_LAND,
627                                                 "elm");
628                         edje_object_signal_emit(_EDJ(ad->ctrlinfo.ctrlbar_ly),
629                                                 "elm,tabbar,state,hide", "elm");
630                 } else {
631                         edje_object_signal_emit(_EDJ(view_ly),
632                                                 GL_SIGNAL_VIEW_TABBAR_BG_SHOW_PORT,
633                                                 "elm");
634                         edje_object_signal_emit(_EDJ(ad->ctrlinfo.ctrlbar_ly),
635                                                 "elm,tabbar,state,hide", "elm");
636                 }
637         }
638         return 0;
639 }
640
641 bool gl_ctrl_rotate_ctrlbar(void *data, int mode)
642 {
643         GL_CHECK_FALSE(data);
644         gl_appdata *ad = (gl_appdata *)data;
645         int view_mode = 0;
646
647         /* Rotate top tabbar */
648         if (mode)
649                 view_mode = mode;
650         else
651                 view_mode = gl_get_view_mode(ad);
652         gl_dbg("view mode: %d.", view_mode);
653
654         bool b_show_tabbar = true;
655
656         if (view_mode == GL_VIEW_ALBUMS || view_mode == GL_VIEW_ALBUMS_EDIT ||
657             view_mode == GL_VIEW_TAGS || view_mode == GL_VIEW_TAGS_EDIT) {
658                 int rotate_mode = ad->maininfo.rotate_mode;
659                 if (view_mode == GL_VIEW_TAGS &&
660                     (ad->entryinfo.entry_mode == GL_ENTRY_NEW_TAG ||
661                     ad->entryinfo.entry_mode == GL_ENTRY_RENAME_TAG)) {
662                         /* New tag view, return */
663                         gl_dbg("Add an empty tag.");
664                         return 0;
665                 }
666                 char *cbar_style = GL_CTRL_STYLE_TABBAR;
667                 if (rotate_mode == APP_DEVICE_ORIENTATION_270 ||
668                     rotate_mode == APP_DEVICE_ORIENTATION_90) {
669                         gl_dbg("Landscape, small mode.");
670                         /* set horizontal style: icon+text */
671                         cbar_style = GL_CTRL_STYLE_TABBAR_LAND;
672                 }
673                 elm_object_style_set(ad->ctrlinfo.ctrlbar, cbar_style);
674
675                 if (b_show_tabbar)
676                         _gl_ctrl_show_tabbar(ad, b_show_tabbar);
677         }
678
679         return true;
680 }
681
682 //disable/enable controlbar items.
683 int gl_ctrl_disable_ctrlbar(void *data, bool disabled)
684 {
685         GL_CHECK_VAL(data, -1);
686         gl_appdata *ad = (gl_appdata *)data;
687         GL_CHECK_VAL(ad->ctrlinfo.ctrlbar, -1);
688         gl_dbg("Controlbar items disabled: %d.", disabled);
689
690         if (disabled)
691                 elm_toolbar_select_mode_set(ad->ctrlinfo.ctrlbar,
692                                             ELM_OBJECT_SELECT_MODE_NONE);
693         else
694                 elm_toolbar_select_mode_set(ad->ctrlinfo.ctrlbar,
695                                             ELM_OBJECT_SELECT_MODE_ALWAYS);
696         return 0;
697 }
698
699 int _gl_ctrl_disable_btn(void *data, bool disabled, int mode)
700 {
701         GL_CHECK_VAL(data, -1);
702         gl_dbg("Title button disabled: %d.", disabled);
703         if (disabled)
704                 __gl_ctrl_disable_btn(data, mode);
705         else
706                 __gl_ctrl_enable_btn(data, mode);
707
708         return 0;
709 }
710
711 int _gl_ctrl_disable_btns(void *data, Elm_Object_Item *nf_it, bool b_disable)
712 {
713         gl_dbg("b_disable: %d", b_disable);
714         GL_CHECK_VAL(data, -1);
715         GL_CHECK_VAL(nf_it, -1);
716
717         if (!b_disable)
718                 __gl_ctrl_enable_btns(data, nf_it);
719         else
720                 _gl_ui_disable_btns(nf_it, true);
721         return 0;
722 }
723