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"
33 #define LIST_MEDIA_COND "media_type=0 OR \
34 (media_type=1 AND copyright LIKE \"Unknown\")"
36 #define LIST_MEDIA_COND "(media_type=0 OR media_type=1) AND copyright LIKE \"Unknown\""
38 #define TEXT_NOCONTENT "No Photo & Video"
40 #define GRID_ITEM_X 206
41 #define GRID_ITEM_Y 206
42 #define GRID_NUM_ITEM 3
44 #define BOX_PADDING 62
49 Evas_Object *menu_btn;
53 struct listmgr *listmgr;
54 struct listmgr_data *ldata;
59 Eina_List *media_list;
62 static char *_grid_text_get(void *data, Evas_Object *obj, const char *part)
72 info = app_media_get_info(am);
74 _ERR("failed to get media info");
78 if (info->media_type != MEDIA_CONTENT_TYPE_VIDEO)
81 if (!strcmp(part, PART_ELM_TEXT_PLAYTIME)) {
82 util_time_string(buf, sizeof(buf),
83 info->video->duration, false);
91 static Evas_Object *_grid_content_get(void *data,
92 Evas_Object *obj, const char *part)
102 info = app_media_get_info(am);
104 _ERR("failed to get media info");
109 if (!strcmp(part, PART_ELM_SWALLOW_THUMBNAIL)) {
110 image = util_add_image(obj, info->thumbnail_path);
112 _ERR("failed to create image object");
116 evas_object_show(image);
117 } else if (!strcmp(part, PART_ELM_SWALLOW_VIDEO)) {
118 if (info->media_type == MEDIA_CONTENT_TYPE_VIDEO) {
119 image = util_add_image(obj, IMAGE_THUMBNAIL_PLAY);
121 _ERR("failed to create image object");
125 evas_object_show(image);
132 static struct grid_class _gclass = {
133 .item_style = STYLE_GRID_GALLERY_ITEM,
134 .text_get = _grid_text_get,
135 .content_get = _grid_content_get
138 static void _grid_selected_cb(void *data, Elm_Object_Item *it)
141 struct view_update_data vdata;
145 _ERR("invalid argument");
151 am = elm_object_item_data_get(it);
153 _ERR("failed to get app media");
157 vdata.list = mediadata_get_medialist(priv->md);
158 vdata.index = util_get_media_index(vdata.list, am);
159 priv->cur_index = vdata.index;
161 viewmgr_update_view(VIEW_VIEWER, UPDATE_CONTENT, &vdata);
162 viewmgr_push_view(VIEW_VIEWER);
165 static struct listmgr_data *_create_listmgr_data(struct _priv *priv)
167 struct listmgr_data *data;
168 struct grid_ops *gops;
170 data = calloc(1, sizeof(*data));
174 data->menu_btn = priv->menu_btn;
176 data->grid_item_x = GRID_ITEM_X;
177 data->grid_item_y = GRID_ITEM_Y;
178 data->grid_num_item = GRID_NUM_ITEM;
179 data->box_padding = BOX_PADDING;
181 gops = calloc(1, sizeof(*gops));
185 gops->gclass = &_gclass;
186 gops->selected_cb = _grid_selected_cb;
187 gops->ops_data = priv;
194 _ERR("failed to allocate memory");
198 static void _update_content_info(struct _priv *priv)
203 photo = mediadata_get_media_count(priv->md, E_MEDIA_PHOTO);
204 video = mediadata_get_media_count(priv->md, E_MEDIA_VIDEO);
206 if (photo < 0 || video < 0) {
207 _ERR("failed to get media count");
211 snprintf(buf, sizeof(buf), "%d Photos, %d Videos", photo, video);
213 elm_object_part_text_set(priv->layout, PART_CONTENT_INFO, buf);
216 static void _update_content_list(struct _priv *priv)
220 if (priv->media_list)
223 list = mediadata_get_list(priv->md, E_LIST_DATE);
225 elm_object_part_text_set(priv->layout,
226 PART_NOCONTENT, TEXT_NOCONTENT);
230 if (!listmgr_update_content_list(priv->listmgr, list))
231 _ERR("failed to update list area");
233 priv->media_list = list;
235 _update_content_info(priv);
238 static bool _create(layoutmgr *lmgr, void *data)
240 struct listmgr *listmgr;
241 struct listmgr_data *ldata;
242 struct mediadata *md;
244 Evas_Object *base, *layout;
247 _ERR("failed to get layoutmgr");
252 _ERR("invalid argument");
256 priv = calloc(1, sizeof(*priv));
258 _ERR("failed to allocate priv");
262 priv->menu_btn = (Evas_Object *)data;
264 base = layoutmgr_get_base(lmgr);
266 _ERR("failed to get base object");
270 layout = elm_layout_add(base);
272 _ERR("failed to create layout");
276 if (!elm_layout_file_set(layout, EDJEFILE, GRP_GALLERY_LAYOUT)) {
277 _ERR("failed to set layout file");
281 ldata = _create_listmgr_data(priv);
283 _ERR("failed to create listmgr data");
287 listmgr = listmgr_create(layout, (void *)ldata);
289 _ERR("failed to create listmgr");
293 md = mediadata_create(LIST_MEDIA_COND, E_SOURCE_ALL, E_SORT_DATE);
295 _ERR("failed to create mediadata");
296 listmgr_destroy(listmgr);
301 priv->layout = layout;
303 priv->listmgr = listmgr;
307 layoutmgr_set_layout_data(lmgr, LAYOUT_GALLERY, priv);
309 if (!listmgr_draw_list_area(listmgr)) {
310 _ERR("failed to draw list area");
311 mediadata_destroy(md);
312 listmgr_destroy(listmgr);
321 evas_object_del(layout);
327 static void _destroy(void *layout_data)
332 _ERR("failed to get layout data");
338 mediadata_free_list(priv->media_list);
339 mediadata_destroy(priv->md);
341 listmgr_destroy(priv->listmgr);
342 free(priv->ldata->gops);
345 evas_object_del(priv->layout);
350 static void _show(void *layout_data)
355 _ERR("failed to layout data");
361 evas_object_show(priv->layout);
362 elm_object_part_content_set(priv->base,
363 PART_THUMBNAIL_AREA, priv->layout);
366 static void _hide(void *layout_data)
371 _ERR("failed to get layout data");
377 evas_object_hide(priv->layout);
378 elm_object_part_content_unset(priv->base, PART_THUMBNAIL_AREA);
381 static void _update(void *layout_data, int update_type, void *data)
383 struct view_update_data *vdata;
388 _ERR("failed to get layout data");
395 switch (update_type) {
397 _update_content_list(priv);
401 _ERR("invalid argument");
405 if (priv->cur_index != vdata->index)
410 listmgr_focus_content_list(priv->listmgr, vdata->index, update);
418 static layout_class _lclass = {
419 .layout_id = LAYOUT_GALLERY,
427 layout_class *layout_gallery_get_lclass(void)