Merge "add progressbar including slider and info of progress time" into tizen
[profile/tv/apps/native/air_mediahub.git] / src / layout / gallery.c
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
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 <Elementary.h>
18 #include <media_content.h>
19 #include <app_debug.h>
20 #include <app_media.h>
21 #include <gridmgr.h>
22 #include <layoutmgr.h>
23
24 #include "define.h"
25 #include "data/mediadata.h"
26 #include "util/listmgr.h"
27 #include "util/util.h"
28
29 #define LIST_MEDIA_COND "media_type=0 OR media_type=1"
30
31 #define TEXT_NOCONTENT "No Photo & Video"
32
33 #define GRID_ITEM_X 206
34 #define GRID_ITEM_Y 206
35 #define GRID_NUM_ITEM 3
36
37 #define BOX_PADDING 62
38
39 struct _priv {
40         Evas_Object *base;
41         Evas_Object *layout;
42
43         layoutmgr *lmgr;
44
45         struct listmgr *listmgr;
46
47         struct mediadata *md;
48
49         Eina_List *media_list;
50 };
51
52 static Evas_Object *_grid_content_get(void *data,
53                         Evas_Object *obj, const char *part)
54 {
55         Evas_Object *image;
56         app_media *am;
57         app_media_info *info;
58
59         if (!data)
60                 return NULL;
61
62         am = data;
63         info = app_media_get_info(am);
64         if (!info) {
65                 _ERR("failed to get media info");
66                 return NULL;
67         }
68
69         image = NULL;
70         if (!strcmp(part, PART_ELM_SWALLOW_THUMBNAIL)) {
71                 image = util_add_image(obj, info->thumbnail_path);
72                 if (!image) {
73                         _ERR("failed to create image object");
74                         return NULL;
75                 }
76
77                 evas_object_show(image);
78         } else if (!strcmp(part, PART_ELM_SWALLOW_VIDEO)) {
79                 if (info->media_type == MEDIA_CONTENT_TYPE_VIDEO) {
80                         image = util_add_image(obj, IMAGE_THUMBNAIL_PLAY);
81                         if (!image) {
82                                 _ERR("failed to create image object");
83                                 return NULL;
84                         }
85
86                         evas_object_show(image);
87                 }
88         }
89
90         return image;
91 }
92
93 static struct grid_class _gclass = {
94         .item_style = STYLE_GRID_GALLERY_ITEM,
95         .content_get = _grid_content_get
96 };
97
98 static struct listmgr_data *_create_listmgr_data(void)
99 {
100         struct listmgr_data *data;
101
102         data = calloc(1, sizeof(*data));
103         if (!data) {
104                 _ERR("failed to allocate listmgr data");
105                 return NULL;
106         }
107
108         data->grid_item_x = GRID_ITEM_X;
109         data->grid_item_y = GRID_ITEM_Y;
110         data->grid_num_item = GRID_NUM_ITEM;
111         data->box_padding = BOX_PADDING;
112         data->gclass = &_gclass;
113
114         return data;
115 }
116
117 static void _update_list_area(struct _priv *priv)
118 {
119         Eina_List *list;
120
121         if (priv->media_list)
122                 return;
123
124         list = mediadata_get_list(priv->md, E_LIST_DATE);
125         if (!list) {
126                 elm_object_part_text_set(priv->layout,
127                                 PART_NOCONTENT, TEXT_NOCONTENT);
128                 return;
129         }
130
131         if (!listmgr_update_list_area(priv->listmgr, list))
132                 _ERR("failed to update list area");
133
134         priv->media_list = list;
135 }
136
137 static bool _create(layoutmgr *lmgr, void *data)
138 {
139         struct listmgr *listmgr;
140         struct listmgr_data *ldata;
141         struct mediadata *md;
142         struct _priv *priv;
143         Evas_Object *base, *layout;
144
145         if (!lmgr) {
146                 _ERR("failed to get layoutmgr");
147                 return false;
148         }
149
150         priv = calloc(1, sizeof(*priv));
151         if (!priv) {
152                 _ERR("failed to allocate priv");
153                 return false;
154         }
155
156         base = layoutmgr_get_base(lmgr);
157         if (!base) {
158                 _ERR("failed to get base object");
159                 goto err;
160         }
161
162         layout = elm_layout_add(base);
163         if (!layout) {
164                 _ERR("failed to create layout");
165                 goto err;
166         }
167
168         if (!elm_layout_file_set(layout, EDJEFILE, GRP_GALLERY_LAYOUT)) {
169                 _ERR("failed to set layout file");
170                 goto err2;
171         }
172
173         ldata = _create_listmgr_data();
174         if (!ldata) {
175                 _ERR("failed to create listmgr data");
176                 goto err2;
177         }
178
179         listmgr = listmgr_create(layout, (void *)ldata);
180         if (!listmgr) {
181                 _ERR("failed to create listmgr");
182                 goto err3;
183         }
184
185         md = mediadata_create(LIST_MEDIA_COND, E_SOURCE_ALL, E_SORT_DATE);
186         if (!md) {
187                 _ERR("failed to create mediadata");
188                 listmgr_destroy(listmgr);
189                 goto err3;
190         }
191
192         priv->base = base;
193         priv->layout = layout;
194         priv->lmgr = lmgr;
195         priv->listmgr = listmgr;
196         priv->md = md;
197
198         layoutmgr_set_layout_data(lmgr, LAYOUT_GALLERY, priv);
199
200         if (!listmgr_draw_list_area(listmgr)) {
201                 _ERR("failed to draw list area");
202                 mediadata_destroy(md);
203                 listmgr_destroy(listmgr);
204                 goto err3;
205         }
206
207         return true;
208
209 err3:
210         free(ldata);
211 err2:
212         evas_object_del(layout);
213 err:
214         free(priv);
215         return false;
216 }
217
218 static void _destroy(void *layout_data)
219 {
220         struct _priv *priv;
221
222         if (!layout_data) {
223                 _ERR("failed to get layout data");
224                 return;
225         }
226
227         priv = layout_data;
228
229         mediadata_free_list(priv->media_list);
230         mediadata_destroy(priv->md);
231
232         listmgr_destroy(priv->listmgr);
233
234         evas_object_del(priv->layout);
235         free(priv);
236 }
237
238 static void _show(void *layout_data)
239 {
240         struct _priv *priv;
241
242         if (!layout_data) {
243                 _ERR("failed to layout data");
244                 return;
245         }
246
247         priv = layout_data;
248
249         evas_object_show(priv->layout);
250         elm_object_part_content_set(priv->base,
251                         PART_THUMBNAIL_AREA, priv->layout);
252 }
253
254 static void _hide(void *layout_data)
255 {
256         struct _priv *priv;
257
258         if (!layout_data) {
259                 _ERR("failed to get layout data");
260                 return;
261         }
262
263         priv = layout_data;
264
265         evas_object_hide(priv->layout);
266         elm_object_part_content_unset(priv->base, PART_THUMBNAIL_AREA);
267 }
268
269 static void _update(void *layout_data, int update_type, void *data)
270 {
271         struct _priv *priv;
272
273         if (!layout_data) {
274                 _ERR("failed to get layout data");
275                 return;
276         }
277
278         priv = layout_data;
279
280         _update_list_area(priv);
281 }
282
283 static layout_class _lclass = {
284         .layout_id = LAYOUT_GALLERY,
285         .create = _create,
286         .show = _show,
287         .hide = _hide,
288         .destroy = _destroy,
289         .update = _update,
290 };
291
292 layout_class *layout_gallery_get_lclass(void)
293 {
294         return &_lclass;
295 }