apply FSL(Flora Software License)
[apps/home/gallery.git] / src / features / gl-controlbar.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 "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-gridview.h"
23 #include "gl-listview.h"
24 #include "gl-db-handler.h"
25 #include "gl-strings.h"
26
27 #define GL_CTRL_STYLE_TOOLBAR "gallery/default"
28 #define GL_CTRL_SEG_STYLE "gallery/default"
29 #define GL_SEGMENT_WIDTH_MIN_INC (433*elm_config_scale_get()) //(143+2+143+2+143)
30
31 static void
32 _gl_ctrl_segment_change_cb(void *data, Evas_Object * obj, void *event_info)
33 {
34         GL_CHECK(data);
35         gl_appdata *ad = (gl_appdata *)data;
36         Elm_Object_Item *seg_it = NULL;
37         gl_dbg("");
38
39         if (ad->uginfo.ug_called_by_me ||
40                 ad->gridinfo.append_idler)
41         {
42                 gl_dbg("UG invoked or appending gridview.");
43                 seg_it = elm_segment_control_item_get(obj, ad->albuminfo.seg_mode);
44                 GL_CHECK(seg_it);
45                 elm_segment_control_item_selected_set(seg_it, EINA_TRUE);
46                 return;
47         }
48
49         int idx = 0;
50         seg_it = elm_segment_control_item_selected_get(obj);
51         GL_CHECK(seg_it);
52         idx = elm_segment_control_item_index_get(seg_it);
53         if (idx == 0)
54         {
55                 gl_dbg("Creating all-media view");
56                 ad->albuminfo.seg_mode = GL_CTRL_SEG_ALL;
57                 gl_ui_reset_toolbar_item(ad, GL_CTRL_SEG_ALL, false);
58
59                 if (ad->gridinfo.all_view == NULL)
60                 {
61                         Evas_Object *grid = gl_grid_create_view(ad,
62                                 ad->maininfo.navi_bar, GL_GRID_ALL);
63                         ad->gridinfo.all_view = grid;
64                 } else {
65                         /* just update the data */
66                         ad->gridinfo.grid_view_mode = GL_GRID_ALL;
67                         gl_grid_update_items(ad);
68                 }
69
70                 elm_object_part_content_unset(ad->gridinfo.layout,
71                         "elm.swallow.view");
72                 evas_object_hide(ad->listinfo.video_view);
73                 evas_object_hide(ad->gridinfo.image_view);
74
75                 evas_object_show(ad->gridinfo.all_view);
76                 elm_object_part_content_set(ad->gridinfo.layout,
77                         "elm.swallow.view", ad->gridinfo.all_view);
78                 gl_set_view_mode(ad, GL_VIEW_THUMBS);
79         }
80         else if (idx == 1)
81         {
82                 gl_dbg("Creating image view");
83                 ad->albuminfo.seg_mode = GL_CTRL_SEG_IMAGES;
84                 gl_ui_reset_toolbar_item(ad, GL_CTRL_SEG_IMAGES, false);
85
86                 if(ad->listinfo.video_nocontents)
87                         gl_list_clear_view(ad);
88
89                 if (ad->gridinfo.image_view == NULL)
90                 {
91                         Evas_Object *grid = gl_grid_create_view(ad,
92                                 ad->maininfo.navi_bar, GL_GRID_IMAGES);
93                         ad->gridinfo.image_view = grid;
94                 } else {
95                         /* just update the data */
96                         ad->gridinfo.grid_view_mode = GL_GRID_IMAGES;
97                         gl_grid_update_items(ad);
98                 }
99
100                 elm_object_part_content_unset(ad->gridinfo.layout, "elm.swallow.view");
101                 evas_object_hide(ad->listinfo.video_view);
102                 evas_object_hide(ad->gridinfo.all_view);
103
104                 evas_object_show(ad->gridinfo.image_view);
105                 elm_object_part_content_set(ad->gridinfo.layout,
106                         "elm.swallow.view", ad->gridinfo.image_view);
107                 gl_set_view_mode(ad, GL_VIEW_THUMBS);
108         }
109         else if (idx == 2)
110         {
111                 ad->albuminfo.seg_mode = GL_CTRL_SEG_VIDEOS;
112                 gl_ui_reset_toolbar_item(ad, GL_CTRL_SEG_VIDEOS, false);
113
114                 gl_dbg("Creating video list");
115
116                 /* Set the grid view mode for creating nocontents view */
117                 ad->gridinfo.grid_view_mode = GL_GRID_VIDEOS;
118                 gl_set_view_mode(ad, GL_VIEW_VIDEOLIST);
119
120                 if(ad->gridinfo.image_nocontents)
121                 {
122                         evas_object_del(ad->gridinfo.image_view);
123                         ad->gridinfo.image_nocontents = NULL;
124                         ad->gridinfo.image_view = NULL;
125                 }
126
127                 if (ad->listinfo.video_view == NULL) {
128                         Evas_Object *list_view = gl_list_create_view(ad, ad->maininfo.navi_bar);
129                         ad->listinfo.video_view = list_view;
130                 } else {
131                         /* just update the data */
132                         gl_list_update_view(ad);
133                 }
134
135                 elm_object_part_content_unset(ad->gridinfo.layout, "elm.swallow.view");
136                 evas_object_hide(ad->gridinfo.all_view);
137                 evas_object_hide(ad->gridinfo.image_view);
138
139                 evas_object_show(ad->listinfo.video_view);
140                 elm_object_part_content_set(ad->gridinfo.layout,
141                         "elm.swallow.view", ad->listinfo.video_view);
142         }
143
144 }
145
146 Evas_Object *_gl_ctrl_get_toolbar(Elm_Object_Item *nf_it)
147 {
148         GL_CHECK_NULL(nf_it);
149         gl_dbg("");
150         Evas_Object *obj = NULL;
151
152         obj = elm_object_item_part_content_get(nf_it, GE_NAVIFRAME_CONTROLBAR);
153         if (obj)
154                 return obj;
155         else
156                 gl_dbgE("Title object is NULL!");
157
158         return NULL;
159 }
160
161 Evas_Object *_gl_ctrl_create_toolbar(void *data, Evas_Object *parent)
162 {
163         GL_CHECK_NULL(parent);
164         GL_CHECK_NULL(data);
165         Evas_Object *cbar = NULL;
166         cbar = elm_toolbar_add(parent);
167         GL_CHECK_NULL(cbar);
168         elm_toolbar_shrink_mode_set(cbar, ELM_TOOLBAR_SHRINK_EXPAND);
169         elm_toolbar_homogeneous_set(cbar, EINA_FALSE);
170         elm_object_style_set(cbar, GL_CTRL_STYLE_TOOLBAR);
171         return cbar;
172 }
173
174 /* create segment control in thumbnail view */
175 Evas_Object *_gl_ctrl_create_segment(void *data, Evas_Object *parent)
176 {
177         gl_dbg("");
178         GL_CHECK_NULL(parent);
179         GL_CHECK_NULL(data);
180         gl_appdata *ad = (gl_appdata *)data;
181         Elm_Object_Item *seg_item[GL_CTRL_SEG_CNT];
182         Evas_Object *segment = NULL;
183
184         /**
185         * Stop creating segment bar when launched by appsvc with
186         * specified file-type ( image or video ) only.
187         */
188         if (ad->albuminfo.aul_launch_type == GL_AUL_T_VIEW_ALBUM &&
189             (ad->albuminfo.aul_file_type == GL_AUL_FILE_T_IMAGE ||
190              ad->albuminfo.aul_file_type == GL_AUL_FILE_T_VIDEO)) {
191                 gl_dbgW("Segment bar not created when launched by appsvc.");
192                 return NULL;
193         }
194
195         Evas_Object *layout = elm_layout_add(parent);
196         GL_CHECK_NULL(layout);
197         evas_object_size_hint_min_set(layout, GL_SEGMENT_WIDTH_MIN_INC, 0);
198         elm_layout_file_set(layout, GL_EDJ_FILE, GL_GRP_SEGMENT);
199         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND,
200                                          EVAS_HINT_EXPAND);
201         evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
202
203         segment = elm_segment_control_add(layout);
204         GL_CHECK_NULL(segment);
205         elm_object_style_set(segment, GL_CTRL_SEG_STYLE);
206         seg_item[0] = elm_segment_control_item_add(segment, NULL,
207                                                    GL_CTRL_SEG_ITEM_ALL);
208         seg_item[1] = elm_segment_control_item_add(segment, NULL,
209                                                    GL_CTRL_SEG_ITEM_IMAGES);
210         seg_item[2] = elm_segment_control_item_add(segment, NULL,
211                                                    GL_CTRL_SEG_ITEM_VIDEOS);
212
213         if (ad->albuminfo.seg_mode > GL_CTRL_SEG_VIDEOS) {
214                 gl_dbgE("seg_mode > GL_CTRL_SEG_VIDEOS");
215                 return NULL;
216         }
217         elm_segment_control_item_selected_set(seg_item[ad->albuminfo.seg_mode],
218                                               EINA_TRUE);
219
220         elm_object_part_content_set(layout, "segment", segment);
221         evas_object_show(layout);
222
223         evas_object_smart_callback_add(segment, "changed",
224                                        _gl_ctrl_segment_change_cb, ad);
225         return layout;
226 }