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/progressbar.h"
30 #include "util/util.h"
32 #define LIST_MEDIA_COND "media_type=1 AND copyright NOT LIKE \"Unknown\""
34 #define TEXT_NOCONTENT "No Movies"
35 #define TEXT_RECENTLY_WATCHED "Recently watched"
37 #define GRID_PADDING 26
38 #define GRID_ITEM_X (378 + GRID_PADDING)
39 #define GRID_ITEM_Y (294 + GRID_PADDING)
40 #define GRID_NUM_ITEM 2
42 #define BOX_PADDING (62 - GRID_PADDING)
44 #define IMAGE_FAVORITE_ALPHA 150
50 Evas_Object *menu_btn;
54 struct listmgr *listmgr;
55 struct listmgr_data *ldata;
59 struct progressbar *prog;
61 Eina_List *media_list;
64 app_media *recent_info;
67 static char *_grid_text_get(void *data, Evas_Object *obj, const char *part)
77 if (!strcmp(part, PART_ELM_TEXT_TITLE)) {
78 info = app_media_get_info(am);
80 _ERR("failed to get media info");
84 return strdup(info->title);
90 static Evas_Object *_grid_content_get(void *data,
91 Evas_Object *obj, const char *part)
101 info = app_media_get_info(am);
103 _ERR("failed to get media info");
108 if (!strcmp(part, PART_ELM_SWALLOW_THUMBNAIL)) {
109 image = util_add_image(obj, info->thumbnail_path);
111 _ERR("failed to create image object");
115 evas_object_show(image);
116 } else if (!strcmp(part, PART_ELM_SWALLOW_FAVORITE)) {
122 image = util_add_image(obj, IMAGE_THUMBNAIL_FAVORITE);
124 _ERR("failed to create image object");
128 evas_object_color_get(image, &r, &g, &b, &a);
129 evas_object_color_set(image, r, g, b, IMAGE_FAVORITE_ALPHA);
131 evas_object_show(image);
137 static struct grid_class _gclass = {
138 .item_style = STYLE_GRID_MOVIE_ITEM,
139 .text_get = _grid_text_get,
140 .content_get = _grid_content_get
143 static bool _update_recent(void *data, Evas_Object *base)
145 Evas_Object *recent, *image;
146 app_media_info *info;
151 if (!data || !base) {
152 _ERR("invalid argument");
158 recent = elm_object_part_content_get(base, PART_ITEM_CONTENT);
160 _ERR("failed to get recent content part");
164 image = elm_object_part_content_get(recent,
165 PART_RECENT_CONTENT_THUMBNAIL);
167 _ERR("failed to get image object");
171 info = app_media_get_info(priv->recent_info);
173 _ERR("failed to get app media info");
177 elm_image_file_set(image, info->thumbnail_path, NULL);
178 elm_image_aspect_fixed_set(image, EINA_FALSE);
180 elm_object_part_text_set(recent, PART_RECENT_CONTENT_TITLE,
183 localtime_r(&info->played_time, &tm);
184 strftime(buf, sizeof(buf), "%Y.%m.%d", &tm);
185 elm_object_part_text_set(recent, PART_RECENT_CONTENT_DATE, buf);
188 elm_object_signal_emit(recent, SIG_RECENT_SHOW_FAV,
191 elm_object_signal_emit(recent, SIG_RECENT_HIDE_FAV,
194 progressbar_reset(priv->prog, info->video->position,
195 info->video->duration);
197 progressbar_show(priv->prog);
202 static bool _draw_recent_title(Evas_Object *base)
206 btn = elm_button_add(base);
208 _ERR("failed to create button object");
212 elm_object_style_set(btn, STYLE_BTN_INDEX);
213 elm_object_text_set(btn, TEXT_RECENTLY_WATCHED);
215 elm_object_part_content_set(base, PART_ITEM_TITLE, btn);
220 static bool _draw_recent_content(struct _priv *priv, Evas_Object *base)
222 Evas_Object *btn, *image;
223 struct progressbar *prog;
225 btn = elm_button_add(base);
227 _ERR("failed to create button object");
231 elm_object_style_set(btn, STYLE_BTN_RECENT_CONTENT);
233 image = elm_image_add(btn);
235 _ERR("failed to create image object");
239 elm_object_part_content_set(btn, PART_RECENT_CONTENT_THUMBNAIL, image);
241 elm_object_part_content_set(base, PART_ITEM_CONTENT, btn);
243 prog = progressbar_create(btn, STYLE_BASE_PROGRESS);
245 _ERR("failed to create progressbar");
249 progressbar_set_parts(prog, PART_RECENT_CONTENT_SLIDER,
250 PART_RECENT_CONTENT_TOTAL,
251 PART_RECENT_CONTENT_PROGRESS, "");
258 static bool _draw_recent(void *data, Evas_Object *base)
262 if (!data || !base) {
263 _ERR("invalid argument");
269 if (!_draw_recent_title(base)) {
270 _ERR("failed to draw recent title");
274 if (!_draw_recent_content(priv, base)) {
275 _ERR("failed to draw recent content");
282 static void _item_selected_cb(struct _priv *priv, app_media *am)
284 struct view_update_data vdata;
286 vdata.list = mediadata_get_medialist(priv->md);
287 vdata.index = util_get_media_index(vdata.list, am);
288 priv->cur_index = vdata.index;
290 viewmgr_update_view(VIEW_VIEWER, UPDATE_CONTENT, &vdata);
291 viewmgr_push_view(VIEW_VIEWER);
294 static void _recent_selected_cb(void *data, Evas_Object *obj)
303 _item_selected_cb(priv, priv->recent_info);
306 static void _grid_selected_cb(void *data, Elm_Object_Item *it)
312 _ERR("invalid argument");
318 am = elm_object_item_data_get(it);
320 _ERR("failed to get app media");
324 _item_selected_cb(priv, am);
327 static struct listmgr_data *_create_listmgr_data(struct _priv *priv)
329 struct listmgr_data *data;
330 struct play_info_ops *pops;
331 struct grid_ops *gops;
333 data = calloc(1, sizeof(*data));
337 data->menu_btn = priv->menu_btn;
339 data->grid_item_x = GRID_ITEM_X;
340 data->grid_item_y = GRID_ITEM_Y;
341 data->grid_num_item = GRID_NUM_ITEM;
342 data->box_padding = BOX_PADDING;
344 pops = calloc(1, sizeof(*pops));
348 pops->draw = _draw_recent;
349 pops->update = _update_recent;
350 pops->selected_cb = _recent_selected_cb;
351 pops->ops_data = priv;
353 gops = calloc(1, sizeof(*gops));
357 gops->gclass = &_gclass;
358 gops->selected_cb = _grid_selected_cb;
359 gops->ops_data = priv;
367 _ERR("failed to allocate memory");
371 static void _update_content_info(struct _priv *priv)
376 count = mediadata_get_media_count(priv->md, E_MEDIA_VIDEO);
378 _ERR("failed to get media count");
382 snprintf(buf, sizeof(buf), "%d Movies", count);
384 elm_object_part_text_set(priv->layout, PART_CONTENT_INFO, buf);
387 static void _update_content_list(struct _priv *priv)
391 if (priv->media_list)
394 list = mediadata_get_list(priv->md, E_LIST_NAME);
396 elm_object_part_text_set(priv->layout,
397 PART_NOCONTENT, TEXT_NOCONTENT);
401 if (!listmgr_update_content_list(priv->listmgr, list)) {
402 _ERR("failed to update list area");
406 priv->media_list = list;
408 _update_content_info(priv);
411 static void _update_recent_item(struct _priv *priv, int index)
415 app_media_info *info;
417 list = mediadata_get_medialist(priv->md);
418 am = eina_list_nth(list, index);
420 _ERR("failed to get app media");
424 info = app_media_get_info(am);
426 _ERR("failed to get app media info");
430 priv->recent_info = am;
432 if (!listmgr_update_play_info(priv->listmgr, info))
433 _ERR("failed to update recently watched item");
436 static bool _create(layoutmgr *lmgr, void *data)
438 struct listmgr *listmgr;
439 struct listmgr_data *ldata;
440 struct mediadata *md;
442 Evas_Object *base, *layout;
445 _ERR("failed to get layoutmgr");
450 _ERR("invalid argument");
454 priv = calloc(1, sizeof(*priv));
456 _ERR("failed to allocate priv");
460 priv->menu_btn = (Evas_Object *)data;
462 base = layoutmgr_get_base(lmgr);
464 _ERR("failed to get base object");
468 layout = elm_layout_add(base);
470 _ERR("failed to create layout");
474 if (!elm_layout_file_set(layout, EDJEFILE, GRP_MOVIE_LAYOUT)) {
475 _ERR("failed to set layout file");
479 ldata = _create_listmgr_data(priv);
481 _ERR("failed to create listmgr data");
485 listmgr = listmgr_create(layout, (void *)ldata);
487 _ERR("failed to create listmgr");
491 md = mediadata_create(LIST_MEDIA_COND, E_SOURCE_ALL, E_SORT_NAME);
493 _ERR("failed to create mediadata");
494 listmgr_destroy(listmgr);
499 priv->layout = layout;
501 priv->listmgr = listmgr;
505 layoutmgr_set_layout_data(lmgr, LAYOUT_MOVIE, priv);
507 if (!listmgr_draw_list_area(priv->listmgr)) {
508 _ERR("failed to draw list area");
509 mediadata_destroy(md);
510 listmgr_destroy(listmgr);
519 evas_object_del(layout);
525 static void _destroy(void *layout_data)
530 _ERR("failed to get layout data");
536 progressbar_destroy(priv->prog);
538 mediadata_free_list(priv->media_list);
539 mediadata_destroy(priv->md);
541 listmgr_destroy(priv->listmgr);
542 free(priv->ldata->pops);
543 free(priv->ldata->gops);
546 evas_object_del(priv->layout);
551 static void _show(void *layout_data)
556 _ERR("failed to layout data");
562 evas_object_show(priv->layout);
563 elm_object_part_content_set(priv->base,
564 PART_THUMBNAIL_AREA, priv->layout);
567 static void _hide(void *layout_data)
572 _ERR("failed to get layout data");
578 evas_object_hide(priv->layout);
579 elm_object_part_content_unset(priv->base, PART_THUMBNAIL_AREA);
582 static void _update(void *layout_data, int update_type, void *data)
584 struct view_update_data *vdata;
588 _ERR("failed to get layout data");
595 switch (update_type) {
597 _update_content_list(priv);
601 _ERR("invalid argument");
605 listmgr_focus_play_info(priv->listmgr);
606 _update_recent_item(priv, vdata->index);
609 listmgr_focus_content_list(priv->listmgr,
610 priv->cur_index, false);
617 static layout_class _lclass = {
618 .layout_id = LAYOUT_MOVIE,
626 layout_class *layout_movie_get_lclass(void)