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>
27 #include "data/mediadata.h"
28 #include "util/listmgr.h"
29 #include "util/util.h"
31 #define LIST_MEDIA_COND "media_type=0 OR media_type=1"
33 #define TEXT_NOCONTENT "No Photo & Video"
35 #define GRID_ITEM_X 206
36 #define GRID_ITEM_Y 206
37 #define GRID_NUM_ITEM 3
39 #define BOX_PADDING 62
47 struct listmgr *listmgr;
51 Eina_List *media_list;
54 static Evas_Object *_grid_content_get(void *data,
55 Evas_Object *obj, const char *part)
65 info = app_media_get_info(am);
67 _ERR("failed to get media info");
72 if (!strcmp(part, PART_ELM_SWALLOW_THUMBNAIL)) {
73 image = util_add_image(obj, info->thumbnail_path);
75 _ERR("failed to create image object");
79 evas_object_show(image);
80 } else if (!strcmp(part, PART_ELM_SWALLOW_VIDEO)) {
81 if (info->media_type == MEDIA_CONTENT_TYPE_VIDEO) {
82 image = util_add_image(obj, IMAGE_THUMBNAIL_PLAY);
84 _ERR("failed to create image object");
88 evas_object_show(image);
95 static struct grid_class _gclass = {
96 .item_style = STYLE_GRID_GALLERY_ITEM,
97 .content_get = _grid_content_get
100 static void _grid_selected_cb(void *data, Elm_Object_Item *it)
103 struct view_data *vdata;
107 _ERR("invalid argument");
113 am = elm_object_item_data_get(it);
115 _ERR("failed to get app media");
119 vdata = calloc(1, sizeof(*vdata));
121 _ERR("failed to allocate view data");
125 vdata->list = mediadata_get_medialist(priv->md);
126 vdata->index = util_get_media_index(vdata->list, am);
128 viewmgr_update_view(VIEW_VIEWER, UPDATE_CONTENT, vdata);
129 viewmgr_push_view(VIEW_VIEWER);
132 static struct listmgr_data *_create_listmgr_data(struct _priv *priv)
134 struct listmgr_data *data;
136 data = calloc(1, sizeof(*data));
138 _ERR("failed to allocate listmgr data");
142 data->grid_item_x = GRID_ITEM_X;
143 data->grid_item_y = GRID_ITEM_Y;
144 data->grid_num_item = GRID_NUM_ITEM;
145 data->box_padding = BOX_PADDING;
147 data->gclass = &_gclass;
149 data->grid_selected_cb = _grid_selected_cb;
150 data->cb_data = priv;
155 static void _update_list_area(struct _priv *priv)
159 if (priv->media_list)
162 list = mediadata_get_list(priv->md, E_LIST_DATE);
164 elm_object_part_text_set(priv->layout,
165 PART_NOCONTENT, TEXT_NOCONTENT);
169 if (!listmgr_update_list_area(priv->listmgr, list))
170 _ERR("failed to update list area");
172 priv->media_list = list;
175 static bool _create(layoutmgr *lmgr, void *data)
177 struct listmgr *listmgr;
178 struct listmgr_data *ldata;
179 struct mediadata *md;
181 Evas_Object *base, *layout;
184 _ERR("failed to get layoutmgr");
188 priv = calloc(1, sizeof(*priv));
190 _ERR("failed to allocate priv");
194 base = layoutmgr_get_base(lmgr);
196 _ERR("failed to get base object");
200 layout = elm_layout_add(base);
202 _ERR("failed to create layout");
206 if (!elm_layout_file_set(layout, EDJEFILE, GRP_GALLERY_LAYOUT)) {
207 _ERR("failed to set layout file");
211 ldata = _create_listmgr_data(priv);
213 _ERR("failed to create listmgr data");
217 listmgr = listmgr_create(layout, (void *)ldata);
219 _ERR("failed to create listmgr");
223 md = mediadata_create(LIST_MEDIA_COND, E_SOURCE_ALL, E_SORT_DATE);
225 _ERR("failed to create mediadata");
226 listmgr_destroy(listmgr);
231 priv->layout = layout;
233 priv->listmgr = listmgr;
236 layoutmgr_set_layout_data(lmgr, LAYOUT_GALLERY, priv);
238 if (!listmgr_draw_list_area(listmgr)) {
239 _ERR("failed to draw list area");
240 mediadata_destroy(md);
241 listmgr_destroy(listmgr);
250 evas_object_del(layout);
256 static void _destroy(void *layout_data)
261 _ERR("failed to get layout data");
267 mediadata_free_list(priv->media_list);
268 mediadata_destroy(priv->md);
270 listmgr_destroy(priv->listmgr);
272 evas_object_del(priv->layout);
276 static void _show(void *layout_data)
281 _ERR("failed to layout data");
287 evas_object_show(priv->layout);
288 elm_object_part_content_set(priv->base,
289 PART_THUMBNAIL_AREA, priv->layout);
292 static void _hide(void *layout_data)
297 _ERR("failed to get layout data");
303 evas_object_hide(priv->layout);
304 elm_object_part_content_unset(priv->base, PART_THUMBNAIL_AREA);
307 static void _update(void *layout_data, int update_type, void *data)
312 _ERR("failed to get layout data");
318 _update_list_area(priv);
321 static layout_class _lclass = {
322 .layout_id = LAYOUT_GALLERY,
330 layout_class *layout_gallery_get_lclass(void)