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_contents.h>
21 #include <app_media.h>
28 #include "data/datamgr.h"
29 #include "grid/grid.h"
30 #include "util/util.h"
32 #define STR_PLACE_NAME "City"
34 static void _create_thumbnail_completed_cb(media_content_error_e err,
35 const char *path, void *user_data)
45 media_content_connect();
47 am = elm_object_item_data_get(it);
51 elm_gengrid_item_fields_update(it, PART_ELM_SWALLOW_THUMBNAIL,
52 ELM_GENGRID_ITEM_FIELD_CONTENT);
54 media_content_disconnect();
57 static char *_media_text_get(void *data, Evas_Object *obj, const char *part)
68 info = app_media_get_info(am);
70 _ERR("failed to get media info");
74 if (info->media_type != MEDIA_CONTENT_TYPE_VIDEO)
77 if (!strcmp(part, PART_ELM_TEXT_PLAYTIME)) {
78 util_time_string(buf, sizeof(buf),
79 info->video->duration, false);
87 static Evas_Object *_media_content_get(void *data,
88 Evas_Object *obj, const char *part)
99 info = app_media_get_info(am);
101 _ERR("failed to get media info");
106 if (!strcmp(part, PART_ELM_SWALLOW_THUMBNAIL)) {
107 if (!info->thumbnail_path) {
108 util_create_thumbnail(obj, am,
109 _create_thumbnail_completed_cb);
113 eo = util_add_image(obj, info->thumbnail_path);
115 _ERR("failed to create image object");
118 } else if (!strcmp(part, PART_ELM_SWALLOW_PICTURE)) {
119 if (info->media_type != MEDIA_CONTENT_TYPE_IMAGE)
122 if (info->thumbnail_path)
125 eo = util_add_image(obj, IMAGE_THUMBNAIL_PICTURE);
127 _ERR("failed to create image object");
130 } else if (!strcmp(part, PART_ELM_SWALLOW_VIDEO)) {
131 if (info->media_type != MEDIA_CONTENT_TYPE_VIDEO)
134 eo = util_add_image(obj, IMAGE_THUMBNAIL_PLAY);
136 _ERR("failed to create image object");
139 } else if (!strcmp(part, PART_ELM_SWALLOW_FAVORITE)) {
143 eo = util_add_image(obj, IMAGE_THUMBNAIL_FAVORITE);
145 _ERR("failed to create image object");
151 evas_object_show(eo);
156 static char *_place_text_get(void *data, Evas_Object *obj, const char *part)
158 struct group_info *gi;
161 char *city, *country, *tmp;
168 snprintf(buf, sizeof(buf), "%s", gi->name);
169 city = strtok_r(buf, "/", &tmp);
170 country = strtok_r(tmp, "", &tmp);
172 if (!strcmp(part, PART_ELM_TEXT_COUNT)) {
173 cnt = eina_list_count(gi->list);
174 snprintf(buf, sizeof(buf), "%d", cnt);
176 } else if (!strcmp(part, PART_ELM_TEXT_CITY)) {
181 } else if (!strcmp(part, PART_ELM_TEXT_COUNTRY)) {
185 return strdup(country);
191 static Evas_Object *_place_content_get(void *data, Evas_Object *obj,
195 struct group_info *gi;
196 struct color_data bg;
204 if (!strcmp(part, PART_ELM_SWALLOW_BG)) {
205 eo = evas_object_rectangle_add(obj);
207 _ERR("failed to create rectangle object");
211 app_contents_get_color(gi->name, &bg, NULL);
212 evas_object_color_set(eo, bg.r, bg.g, bg.b, bg.a);
214 evas_object_show(eo);
220 static Eina_List *_get_event_list(struct datamgr *dmgr)
223 _ERR("invalid argument");
227 return dmgr->ops->get_group(dmgr->handle, E_GROUP_MEDIA_DATE, NULL);
230 static Eina_List *_get_place_list(struct datamgr *dmgr)
233 struct group_info *gi;
236 _ERR("invalid argument");
240 gi = calloc(1, sizeof(*gi));
242 _ERR("failed to allocate memory");
246 gi->name = STR_PLACE_NAME;
247 gi->list = dmgr->ops->get_group(dmgr->handle,
248 E_GROUP_MEDIA_PLACE, NULL);
251 list = eina_list_append(list, gi);
256 static Eina_List *_get_type_list(struct datamgr *dmgr)
259 _ERR("invalid argument");
263 return dmgr->ops->get_group(dmgr->handle, E_GROUP_MEDIA_TYPE, NULL);
266 static void _free_media_list(struct datamgr *dmgr, Eina_List *list)
269 _ERR("invalid argument");
273 dmgr->ops->free_group(list);
276 static void _free_place_list(struct datamgr *dmgr, Eina_List *list)
278 struct group_info *gi;
281 _ERR("invalid argument");
285 EINA_LIST_FREE(list, gi) {
286 dmgr->ops->free_group(gi->list);
291 static void _get_media_info(struct datamgr *dmgr, Eina_List *list, char *str,
296 photo = dmgr->ops->get_count(dmgr->handle, E_FILE_PHOTO);
297 video = dmgr->ops->get_count(dmgr->handle, E_FILE_VIDEO);
300 _ERR("failed to get media count");
305 _ERR("failed to get media count");
309 snprintf(str, size, "%d Photos, %d Videos", photo, video);
312 static void _get_place_info(struct datamgr *dmgr, Eina_List *list, char *str,
316 struct group_info *gi;
320 EINA_LIST_FOREACH(list, l, gi)
321 cnt += eina_list_count(gi->list);
323 snprintf(str, size, "%d Cities", cnt);
326 static void _key_down_cb(void *data, Elm_Object_Item *it,
327 Evas_Event_Key_Down *ev)
329 struct view_update_data vdata;
330 struct datamgr *dmgr;
334 _ERR("invalid argument");
340 if (!strcmp(ev->keyname, KEY_MENU) ||
341 !strcmp(ev->keyname, KEY_CONTEXT_MENU)) {
342 am = elm_object_item_data_get(it);
344 _ERR("failed to get app media");
348 vdata.list = dmgr->ops->get_list(dmgr->handle,
350 vdata.index = util_get_media_index(vdata.list, am);
352 viewmgr_update_view(VIEW_ACTION_MENU, UPDATE_CONTENT, &vdata);
353 viewmgr_show_view(VIEW_ACTION_MENU);
357 static void _media_selected_cb(void *data, Elm_Object_Item *it)
359 struct view_update_data vdata;
360 struct datamgr *dmgr;
364 _ERR("invalid argument");
370 am = elm_object_item_data_get(it);
372 _ERR("failed to get app media");
376 vdata.list = dmgr->ops->get_list(dmgr->handle, E_LIST_MEDIA, NULL);
377 vdata.index = util_get_media_index(vdata.list, am);
378 vdata.id = VIEW_BASE;
380 viewmgr_update_view(VIEW_VIEWER, UPDATE_CONTENT, &vdata);
381 viewmgr_push_view(VIEW_VIEWER);
384 static void _place_selected_cb(void *data, Elm_Object_Item *it)
386 struct view_update_data vdata;
387 struct group_info *gi;
390 _ERR("invalid argument");
394 gi = elm_object_item_data_get(it);
396 _ERR("failed to get group info");
400 vdata.list = gi->list;
401 vdata.index = E_DETAIL_GALLERY_PLACE;
404 viewmgr_update_view(VIEW_DETAIL, UPDATE_CONTENT, &vdata);
405 viewmgr_push_view(VIEW_DETAIL);
408 static struct grid_class _gclass[] = {
409 [E_GALLERY_EVENT] = {
410 .item_style = STYLE_GALLERY_EVENT,
411 .text_get = _media_text_get,
412 .content_get = _media_content_get
414 [E_GALLERY_PLACE] = {
415 .item_style = STYLE_GALLERY_PLACE,
416 .text_get = _place_text_get,
417 .content_get = _place_content_get
419 /* Other view mode class will be added later */
422 static struct grid_data _gdata[] = {
423 [E_GALLERY_EVENT] = {
424 .item_x = GALLERY_EVENT_ITEM_X,
425 .item_y = GALLERY_EVENT_ITEM_Y,
426 .item_num = GALLERY_EVENT_ITEM_NUM,
427 .grid_padding = GALLERY_EVENT_GRID_PADDING,
428 .gclass = &_gclass[E_GALLERY_EVENT],
429 .get_item_list = _get_event_list,
430 .free_item_list = _free_media_list,
431 .get_item_info = _get_media_info,
432 .key_down_cb = _key_down_cb,
433 .selected_cb = _media_selected_cb
435 [E_GALLERY_PLACE] = {
436 .item_x = GALLERY_PLACE_ITEM_X,
437 .item_y = GALLERY_PLACE_ITEM_Y,
438 .item_num = GALLERY_PLACE_ITEM_NUM,
439 .grid_padding = GALLERY_PLACE_GRID_PADDING,
440 .gclass = &_gclass[E_GALLERY_PLACE],
441 .get_item_list = _get_place_list,
442 .free_item_list = _free_place_list,
443 .get_item_info = _get_place_info,
444 .selected_cb = _place_selected_cb
446 [E_GALLERY_VIDEO] = {
447 .item_x = GALLERY_EVENT_ITEM_X,
448 .item_y = GALLERY_EVENT_ITEM_Y,
449 .item_num = GALLERY_EVENT_ITEM_NUM,
450 .grid_padding = GALLERY_EVENT_GRID_PADDING,
451 .gclass = &_gclass[E_GALLERY_EVENT],
452 .get_item_list = _get_type_list,
453 .free_item_list = _free_media_list,
454 .get_item_info = _get_media_info,
455 .key_down_cb = _key_down_cb,
456 .selected_cb = _media_selected_cb
458 /* Other view mode data will be added later */
461 struct grid_data *get_gallery_grid_data(int type)
463 if (type < 0 || type >= E_GALLERY_MAX) {
464 _ERR("invalid argument");
468 return &_gdata[type];