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>
24 #include <layoutmgr.h>
30 #include "data/datamgr.h"
31 #include "grid/grid.h"
32 #include "util/listmgr.h"
33 #include "util/progressbar.h"
34 #include "util/util.h"
36 #define TEXT_NOCONTENT "No Movies"
37 #define TEXT_RECENTLY_WATCHED "Recently watched"
39 #define GRID_PADDING 26
40 #define GRID_ITEM_X (378 + GRID_PADDING)
41 #define GRID_ITEM_Y (294 + GRID_PADDING)
42 #define GRID_NUM_ITEM 2
44 #define BOX_PADDING (62 - GRID_PADDING)
50 Evas_Object *menu_btn;
51 Evas_Object *view_btn;
55 struct listmgr *listmgr;
56 struct listmgr_data *ldata;
58 struct datamgr *dmgr[E_DATA_MAX];
60 struct progressbar *prog;
62 Eina_List *media_list;
64 app_media *recent_info;
67 struct grid_data *gdata;
70 static bool _update_recent_info(Evas_Object *base, app_media_info *info)
72 Evas_Object *image, *text_bg;
77 image = elm_object_part_content_get(base,
78 PART_RECENT_CONTENT_THUMBNAIL);
80 _ERR("failed to get image object");
84 text_bg = elm_object_part_content_get(base, PART_RECENT_CONTENT_TEXTBG);
86 _ERR("failed to get textbg part");
90 elm_image_file_set(image, info->thumbnail_path, NULL);
91 elm_image_aspect_fixed_set(image, EINA_FALSE);
93 app_contents_get_color(info->title, NULL, &bg);
94 evas_object_color_set(text_bg, bg.r, bg.g, bg.b, bg.a);
96 elm_object_part_text_set(base, PART_RECENT_CONTENT_TITLE,
99 localtime_r(&info->played_time, &tm);
100 strftime(buf, sizeof(buf), "%Y.%m.%d", &tm);
101 elm_object_part_text_set(base, PART_RECENT_CONTENT_DATE, buf);
104 elm_object_signal_emit(base, SIG_RECENT_SHOW_FAV,
107 elm_object_signal_emit(base, SIG_RECENT_HIDE_FAV,
113 static bool _update_recent(void *data, Evas_Object *base)
116 app_media_info *info;
119 if (!data || !base) {
120 _ERR("invalid argument");
126 recent = elm_object_part_content_get(base, PART_ITEM_CONTENT);
128 _ERR("failed to get recent content part");
132 info = app_media_get_info(priv->recent_info);
134 _ERR("failed to get app media info");
138 if (!_update_recent_info(recent, info)) {
139 _ERR("failed to update recent info");
143 progressbar_reset(priv->prog, info->video->position,
144 info->video->duration);
146 progressbar_show(priv->prog);
151 static bool _draw_recent_title(Evas_Object *base)
155 btn = elm_button_add(base);
157 _ERR("failed to create button object");
161 elm_object_style_set(btn, STYLE_BTN_INDEX);
162 elm_object_text_set(btn, TEXT_RECENTLY_WATCHED);
164 elm_object_part_content_set(base, PART_ITEM_TITLE, btn);
169 static bool _draw_recent_content(struct _priv *priv, Evas_Object *base)
171 Evas_Object *btn, *image, *text_bg;
172 struct progressbar *prog;
174 btn = elm_button_add(base);
176 _ERR("failed to create button object");
180 elm_object_style_set(btn, STYLE_BTN_RECENT_CONTENT);
182 image = elm_image_add(btn);
184 _ERR("failed to create image object");
188 text_bg = evas_object_rectangle_add(btn);
190 _ERR("failed to create rectangle object");
194 elm_object_part_content_set(btn, PART_RECENT_CONTENT_THUMBNAIL, image);
195 elm_object_part_content_set(btn, PART_RECENT_CONTENT_TEXTBG, text_bg);
197 elm_object_part_content_set(base, PART_ITEM_CONTENT, btn);
199 prog = progressbar_create(btn, STYLE_BASE_PROGRESS);
201 _ERR("failed to create progressbar");
205 progressbar_set_parts(prog, PART_RECENT_CONTENT_SLIDER,
206 PART_RECENT_CONTENT_TOTAL,
207 PART_RECENT_CONTENT_PROGRESS, "");
214 static bool _draw_recent(void *data, Evas_Object *base)
218 if (!data || !base) {
219 _ERR("invalid argument");
225 if (!_draw_recent_title(base)) {
226 _ERR("failed to draw recent title");
230 if (!_draw_recent_content(priv, base)) {
231 _ERR("failed to draw recent content");
238 static void _recent_item_selected(struct _priv *priv, app_media *am)
240 app_media_info *info;
241 struct view_update_data vdata;
242 struct datamgr *dmgr;
244 info = app_media_get_info(am);
246 _ERR("failed to get app media info");
250 dmgr = priv->dmgr[E_DATA_MEDIA];
254 vdata.list = dmgr->ops->get_list(dmgr->handle, E_LIST_MEDIA, NULL);
255 vdata.index = util_get_media_index_from_id(vdata.list, info->media_id);
256 vdata.id = VIEW_BASE;
258 viewmgr_update_view(VIEW_VIEWER, UPDATE_CONTENT, &vdata);
259 viewmgr_push_view(VIEW_VIEWER);
262 static void _recent_key_down_cb(void *data, Evas_Object *obj,
263 Evas_Event_Key_Down *ev)
265 struct view_update_data vdata;
266 struct datamgr *dmgr;
274 dmgr = priv->dmgr[E_DATA_MEDIA];
278 if (!strcmp(ev->keyname, KEY_MENU) ||
279 !strcmp(ev->keyname, KEY_CONTEXT_MENU)) {
280 vdata.list = dmgr->ops->get_list(dmgr->handle,
282 vdata.index = util_get_media_index(vdata.list,
284 vdata.id = VIEW_BASE;
286 viewmgr_update_view(VIEW_ACTION_MENU, UPDATE_CONTENT, &vdata);
287 viewmgr_show_view(VIEW_ACTION_MENU);
291 static void _recent_selected_cb(void *data, Evas_Object *obj)
294 struct view_update_data vdata;
295 struct datamgr *dmgr;
302 dmgr = priv->dmgr[E_DATA_MEDIA];
306 vdata.list = dmgr->ops->get_list(dmgr->handle, E_LIST_MEDIA, NULL);
307 vdata.index = util_get_media_index(vdata.list, priv->recent_info);
308 vdata.id = VIEW_BASE;
310 viewmgr_update_view(VIEW_VIEWER, UPDATE_CONTENT, &vdata);
311 viewmgr_push_view(VIEW_VIEWER);
314 static struct listmgr_data *_create_listmgr_data(struct _priv *priv)
316 struct listmgr_data *data;
317 struct play_info_data *pdata;
319 data = calloc(1, sizeof(*data));
323 data->menu_btn = priv->menu_btn;
324 data->view_btn = priv->view_btn;
326 pdata = calloc(1, sizeof(*pdata));
330 pdata->draw = _draw_recent;
331 pdata->update = _update_recent;
332 pdata->key_down_cb = _recent_key_down_cb;
333 pdata->selected_cb = _recent_selected_cb;
334 pdata->cb_data = priv;
343 _ERR("failed to allocate memory");
347 static void _update_content_info(struct _priv *priv)
349 struct datamgr *dmgr;
352 dmgr = priv->dmgr[E_DATA_MEDIA];
356 priv->gdata->get_item_info(dmgr, priv->media_list, buf, sizeof(buf));
358 elm_object_part_text_set(priv->base, PART_BASE_CONTENT_INFO, buf);
361 static void _clear_content_list(struct _priv *priv)
363 if (priv->media_list) {
364 priv->gdata->free_item_list(priv->dmgr[E_DATA_MEDIA],
366 priv->media_list = NULL;
369 listmgr_clear_content_list(priv->listmgr);
372 static void _update_content_list(struct _priv *priv)
376 if (priv->media_list) {
377 _update_content_info(priv);
381 priv->gdata = get_movie_grid_data(priv->view_mode);
383 list = priv->gdata->get_item_list(priv->dmgr[E_DATA_MEDIA]);
385 elm_object_part_text_set(priv->layout,
386 PART_NOCONTENT, TEXT_NOCONTENT);
390 priv->gdata->data = priv->dmgr[E_DATA_MEDIA];
392 if (!listmgr_update_content_list(priv->listmgr, list, priv->gdata)) {
393 _ERR("failed to update list area");
397 priv->media_list = list;
399 _update_content_info(priv);
402 static app_media *_get_recent_item(Eina_List *list)
406 struct recent_data *rdata;
411 r = app_contents_get_recent_list(CONTENTS_MOVIE, 1, &rlist);
412 if (r != APP_CONTENTS_ERROR_NONE) {
413 _ERR("failed to get movie recent list");
417 rdata = g_list_nth_data(rlist, 0);
418 if (rdata && rdata->id)
419 am = util_find_media_info(list, rdata->id);
421 app_contents_free_recent_list(rlist);
426 static void _update_recent_item(struct _priv *priv, const char *id)
430 app_media_info *info;
431 struct datamgr *dmgr;
433 dmgr = priv->dmgr[E_DATA_MEDIA];
437 list = dmgr->ops->get_list(dmgr->handle, E_LIST_MEDIA, NULL);
440 am = util_find_media_info(list, id);
442 am = _get_recent_item(list);
445 _ERR("failed to get app media");
449 info = app_media_get_info(am);
451 _ERR("failed to get app media info");
455 priv->recent_info = am;
457 if (!listmgr_update_play_info(priv->listmgr, info))
458 _ERR("failed to update recently watched item");
461 static void _destroy_datamgr(struct _priv *priv)
465 for (i = 0; i < E_DATA_MAX; i++)
466 datamgr_destroy(priv->dmgr[i]);
469 static void _destroy_utils(struct _priv *priv)
471 _destroy_datamgr(priv);
473 listmgr_destroy(priv->listmgr);
474 free(priv->ldata->pdata);
478 static bool _create_utils(struct _priv *priv)
480 struct listmgr *listmgr;
481 struct listmgr_data *ldata;
482 struct datamgr *dmgr;
485 for (i = 0; i < E_DATA_MAX; i++) {
486 dmgr = datamgr_create(i, MOVIE_MEDIA_COND, E_SOURCE_ALL);
488 _ERR("failed to create datamgr");
489 _destroy_datamgr(priv);
493 priv->dmgr[i] = dmgr;
496 ldata = _create_listmgr_data(priv);
498 _ERR("failed to create listmgr data");
499 _destroy_datamgr(priv);
503 listmgr = listmgr_create(priv->layout, (void *)ldata);
505 _ERR("failed to create listmgr");
506 _destroy_datamgr(priv);
512 priv->listmgr = listmgr;
517 static bool _create(layoutmgr *lmgr, void *data)
519 struct layout_data *ld;
521 Evas_Object *base, *layout;
524 _ERR("failed to get layoutmgr");
529 _ERR("invalid argument");
535 priv = calloc(1, sizeof(*priv));
537 _ERR("failed to allocate priv");
541 base = layoutmgr_get_base(lmgr);
543 _ERR("failed to get base object");
547 layout = elm_layout_add(base);
549 _ERR("failed to create layout");
553 if (!elm_layout_file_set(layout, EDJEFILE, GRP_MOVIE_LAYOUT)) {
554 _ERR("failed to set layout file");
559 priv->layout = layout;
560 priv->menu_btn = ld->top;
561 priv->view_btn = ld->bottom;
563 priv->gdata = get_movie_grid_data(E_MOVIE_NAME);
565 if (!_create_utils(priv)) {
566 _ERR("failed to create utils");
570 layoutmgr_set_layout_data(lmgr, LAYOUT_MOVIE, priv);
572 if (!listmgr_draw_list_area(priv->listmgr)) {
573 _ERR("failed to draw list area");
580 _destroy_utils(priv);
582 evas_object_del(layout);
588 static void _destroy(void *layout_data)
593 _ERR("failed to get layout data");
599 progressbar_destroy(priv->prog);
601 priv->gdata->free_item_list(priv->dmgr[E_DATA_MEDIA], priv->media_list);
603 _destroy_utils(priv);
605 evas_object_del(priv->layout);
610 static void _show(void *layout_data)
615 _ERR("failed to layout data");
621 evas_object_show(priv->layout);
622 elm_object_part_content_set(priv->base,
623 PART_BASE_THUMBNAIL_AREA, priv->layout);
626 static void _hide(void *layout_data)
631 _ERR("failed to get layout data");
637 evas_object_hide(priv->layout);
638 elm_object_part_content_unset(priv->base, PART_BASE_THUMBNAIL_AREA);
641 static void _update(void *layout_data, int update_type, void *data)
643 struct view_update_data *vdata;
648 _ERR("failed to get layout data");
654 switch (update_type) {
656 _update_content_list(priv);
657 _update_recent_item(priv, NULL);
659 case UPDATE_CONTENT_ITEM:
660 listmgr_update_content_item(priv->listmgr);
661 _update_recent_item(priv, NULL);
663 case UPDATE_PLAY_INFO:
665 _ERR("invalid argument");
671 _update_recent_item(priv, vdata->id);
674 listmgr_focus_play_info(priv->listmgr);
677 listmgr_focus_content_list(priv->listmgr, NULL);
681 _ERR("invalid argument");
685 _update_content_list(priv);
686 _recent_item_selected(priv, data);
688 case UPDATE_FOCUS_STATE:
689 listmgr_set_focus_state(priv->listmgr, EINA_FALSE);
691 case UPDATE_VIEW_MODE:
693 _ERR("invalid argument");
700 /* Folder view mode will be implemented later */
701 if (mode == E_MOVIE_FOLDER)
704 if (mode == priv->view_mode)
707 _clear_content_list(priv);
709 priv->view_mode = mode;
710 _update_content_list(priv);
717 static layout_class _lclass = {
718 .layout_id = LAYOUT_MOVIE,
726 layout_class *layout_movie_get_lclass(void)