2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <Elementary.h>
18 #include <media_content.h>
19 #include <app_debug.h>
20 #include <app_media.h>
22 #include <layoutmgr.h>
25 #include "data/mediadata.h"
26 #include "util/listmgr.h"
27 #include "util/util.h"
29 #define LIST_MEDIA_COND "media_type=0 OR media_type=1"
31 #define TEXT_NOCONTENT "No Photo & Video"
33 #define GRID_ITEM_X 206
34 #define GRID_ITEM_Y 206
35 #define GRID_NUM_ITEM 3
37 #define BOX_PADDING 62
45 struct listmgr *listmgr;
49 Eina_List *media_list;
52 static Evas_Object *_grid_content_get(void *data,
53 Evas_Object *obj, const char *part)
63 info = app_media_get_info(am);
65 _ERR("failed to get media info");
70 if (!strcmp(part, PART_ELM_SWALLOW_THUMBNAIL)) {
71 image = util_add_image(obj, info->thumbnail_path);
73 _ERR("failed to create image object");
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);
82 _ERR("failed to create image object");
86 evas_object_show(image);
93 static struct grid_class _gclass = {
94 .item_style = STYLE_GRID_GALLERY_ITEM,
95 .content_get = _grid_content_get
98 static struct listmgr_data *_create_listmgr_data(void)
100 struct listmgr_data *data;
102 data = calloc(1, sizeof(*data));
104 _ERR("failed to allocate listmgr data");
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;
117 static void _update_list_area(struct _priv *priv)
121 if (priv->media_list)
124 list = mediadata_get_list(priv->md, E_LIST_DATE);
126 elm_object_part_text_set(priv->layout,
127 PART_NOCONTENT, TEXT_NOCONTENT);
131 if (!listmgr_update_list_area(priv->listmgr, list))
132 _ERR("failed to update list area");
134 priv->media_list = list;
137 static bool _create(layoutmgr *lmgr, void *data)
139 struct listmgr *listmgr;
140 struct listmgr_data *ldata;
141 struct mediadata *md;
143 Evas_Object *base, *layout;
146 _ERR("failed to get layoutmgr");
150 priv = calloc(1, sizeof(*priv));
152 _ERR("failed to allocate priv");
156 base = layoutmgr_get_base(lmgr);
158 _ERR("failed to get base object");
162 layout = elm_layout_add(base);
164 _ERR("failed to create layout");
168 if (!elm_layout_file_set(layout, EDJEFILE, GRP_GALLERY_LAYOUT)) {
169 _ERR("failed to set layout file");
173 ldata = _create_listmgr_data();
175 _ERR("failed to create listmgr data");
179 listmgr = listmgr_create(layout, (void *)ldata);
181 _ERR("failed to create listmgr");
185 md = mediadata_create(LIST_MEDIA_COND, E_SOURCE_ALL, E_SORT_DATE);
187 _ERR("failed to create mediadata");
188 listmgr_destroy(listmgr);
193 priv->layout = layout;
195 priv->listmgr = listmgr;
198 layoutmgr_set_layout_data(lmgr, LAYOUT_GALLERY, priv);
200 if (!listmgr_draw_list_area(listmgr)) {
201 _ERR("failed to draw list area");
202 mediadata_destroy(md);
203 listmgr_destroy(listmgr);
212 evas_object_del(layout);
218 static void _destroy(void *layout_data)
223 _ERR("failed to get layout data");
229 mediadata_free_list(priv->media_list);
230 mediadata_destroy(priv->md);
232 listmgr_destroy(priv->listmgr);
234 evas_object_del(priv->layout);
238 static void _show(void *layout_data)
243 _ERR("failed to layout data");
249 evas_object_show(priv->layout);
250 elm_object_part_content_set(priv->base,
251 PART_THUMBNAIL_AREA, priv->layout);
254 static void _hide(void *layout_data)
259 _ERR("failed to get layout data");
265 evas_object_hide(priv->layout);
266 elm_object_part_content_unset(priv->base, PART_THUMBNAIL_AREA);
269 static void _update(void *layout_data, int update_type, void *data)
274 _ERR("failed to get layout data");
280 _update_list_area(priv);
283 static layout_class _lclass = {
284 .layout_id = LAYOUT_GALLERY,
292 layout_class *layout_gallery_get_lclass(void)