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)) {
120 image = util_add_image(obj, IMAGE_THUMBNAIL_FAVORITE);
122 _ERR("failed to create image object");
126 util_set_alpha_color(image, IMAGE_FAVORITE_ALPHA);
128 evas_object_show(image);
134 static struct grid_class _gclass = {
135 .item_style = STYLE_GRID_MOVIE_ITEM,
136 .text_get = _grid_text_get,
137 .content_get = _grid_content_get
140 static bool _update_recent(void *data, Evas_Object *base)
142 Evas_Object *recent, *image;
143 app_media_info *info;
148 if (!data || !base) {
149 _ERR("invalid argument");
155 recent = elm_object_part_content_get(base, PART_ITEM_CONTENT);
157 _ERR("failed to get recent content part");
161 image = elm_object_part_content_get(recent,
162 PART_RECENT_CONTENT_THUMBNAIL);
164 _ERR("failed to get image object");
168 info = app_media_get_info(priv->recent_info);
170 _ERR("failed to get app media info");
174 elm_image_file_set(image, info->thumbnail_path, NULL);
175 elm_image_aspect_fixed_set(image, EINA_FALSE);
177 elm_object_part_text_set(recent, PART_RECENT_CONTENT_TITLE,
180 localtime_r(&info->played_time, &tm);
181 strftime(buf, sizeof(buf), "%Y.%m.%d", &tm);
182 elm_object_part_text_set(recent, PART_RECENT_CONTENT_DATE, buf);
185 elm_object_signal_emit(recent, SIG_RECENT_SHOW_FAV,
188 elm_object_signal_emit(recent, SIG_RECENT_HIDE_FAV,
191 progressbar_reset(priv->prog, info->video->position,
192 info->video->duration);
194 progressbar_show(priv->prog);
199 static bool _draw_recent_title(Evas_Object *base)
203 btn = elm_button_add(base);
205 _ERR("failed to create button object");
209 elm_object_style_set(btn, STYLE_BTN_INDEX);
210 elm_object_text_set(btn, TEXT_RECENTLY_WATCHED);
212 elm_object_part_content_set(base, PART_ITEM_TITLE, btn);
217 static bool _draw_recent_content(struct _priv *priv, Evas_Object *base)
219 Evas_Object *btn, *image;
220 struct progressbar *prog;
222 btn = elm_button_add(base);
224 _ERR("failed to create button object");
228 elm_object_style_set(btn, STYLE_BTN_RECENT_CONTENT);
230 image = elm_image_add(btn);
232 _ERR("failed to create image object");
236 elm_object_part_content_set(btn, PART_RECENT_CONTENT_THUMBNAIL, image);
238 elm_object_part_content_set(base, PART_ITEM_CONTENT, btn);
240 prog = progressbar_create(btn, STYLE_BASE_PROGRESS);
242 _ERR("failed to create progressbar");
246 progressbar_set_parts(prog, PART_RECENT_CONTENT_SLIDER,
247 PART_RECENT_CONTENT_TOTAL,
248 PART_RECENT_CONTENT_PROGRESS, "");
255 static bool _draw_recent(void *data, Evas_Object *base)
259 if (!data || !base) {
260 _ERR("invalid argument");
266 if (!_draw_recent_title(base)) {
267 _ERR("failed to draw recent title");
271 if (!_draw_recent_content(priv, base)) {
272 _ERR("failed to draw recent content");
279 static void _item_selected_cb(struct _priv *priv, app_media *am)
281 struct view_update_data vdata;
283 vdata.list = mediadata_get_medialist(priv->md);
284 vdata.index = util_get_media_index(vdata.list, am);
285 priv->cur_index = vdata.index;
287 viewmgr_update_view(VIEW_VIEWER, UPDATE_CONTENT, &vdata);
288 viewmgr_push_view(VIEW_VIEWER);
291 static void _recent_selected_cb(void *data, Evas_Object *obj)
300 _item_selected_cb(priv, priv->recent_info);
303 static void _grid_selected_cb(void *data, Elm_Object_Item *it)
309 _ERR("invalid argument");
315 am = elm_object_item_data_get(it);
317 _ERR("failed to get app media");
321 _item_selected_cb(priv, am);
324 static struct listmgr_data *_create_listmgr_data(struct _priv *priv)
326 struct listmgr_data *data;
327 struct play_info_ops *pops;
328 struct grid_ops *gops;
330 data = calloc(1, sizeof(*data));
334 data->menu_btn = priv->menu_btn;
336 data->grid_item_x = GRID_ITEM_X;
337 data->grid_item_y = GRID_ITEM_Y;
338 data->grid_num_item = GRID_NUM_ITEM;
339 data->box_padding = BOX_PADDING;
341 pops = calloc(1, sizeof(*pops));
345 pops->draw = _draw_recent;
346 pops->update = _update_recent;
347 pops->selected_cb = _recent_selected_cb;
348 pops->ops_data = priv;
350 gops = calloc(1, sizeof(*gops));
354 gops->gclass = &_gclass;
355 gops->selected_cb = _grid_selected_cb;
356 gops->ops_data = priv;
364 _ERR("failed to allocate memory");
368 static void _update_content_info(struct _priv *priv)
373 count = mediadata_get_media_count(priv->md, E_MEDIA_VIDEO);
375 _ERR("failed to get media count");
379 snprintf(buf, sizeof(buf), "%d Movies", count);
381 elm_object_part_text_set(priv->layout, PART_CONTENT_INFO, buf);
384 static void _update_content_list(struct _priv *priv)
388 if (priv->media_list)
391 list = mediadata_get_list(priv->md, E_LIST_NAME);
393 elm_object_part_text_set(priv->layout,
394 PART_NOCONTENT, TEXT_NOCONTENT);
398 if (!listmgr_update_content_list(priv->listmgr, list)) {
399 _ERR("failed to update list area");
403 priv->media_list = list;
405 _update_content_info(priv);
408 static void _update_recent_item(struct _priv *priv, int index)
412 app_media_info *info;
414 list = mediadata_get_medialist(priv->md);
415 am = eina_list_nth(list, index);
417 _ERR("failed to get app media");
421 info = app_media_get_info(am);
423 _ERR("failed to get app media info");
427 priv->recent_info = am;
429 if (!listmgr_update_play_info(priv->listmgr, info))
430 _ERR("failed to update recently watched item");
433 static bool _create(layoutmgr *lmgr, void *data)
435 struct listmgr *listmgr;
436 struct listmgr_data *ldata;
437 struct mediadata *md;
439 Evas_Object *base, *layout;
442 _ERR("failed to get layoutmgr");
447 _ERR("invalid argument");
451 priv = calloc(1, sizeof(*priv));
453 _ERR("failed to allocate priv");
457 priv->menu_btn = (Evas_Object *)data;
459 base = layoutmgr_get_base(lmgr);
461 _ERR("failed to get base object");
465 layout = elm_layout_add(base);
467 _ERR("failed to create layout");
471 if (!elm_layout_file_set(layout, EDJEFILE, GRP_MOVIE_LAYOUT)) {
472 _ERR("failed to set layout file");
476 ldata = _create_listmgr_data(priv);
478 _ERR("failed to create listmgr data");
482 listmgr = listmgr_create(layout, (void *)ldata);
484 _ERR("failed to create listmgr");
488 md = mediadata_create(LIST_MEDIA_COND, E_SOURCE_ALL, E_SORT_NAME);
490 _ERR("failed to create mediadata");
491 listmgr_destroy(listmgr);
496 priv->layout = layout;
498 priv->listmgr = listmgr;
502 layoutmgr_set_layout_data(lmgr, LAYOUT_MOVIE, priv);
504 if (!listmgr_draw_list_area(priv->listmgr)) {
505 _ERR("failed to draw list area");
506 mediadata_destroy(md);
507 listmgr_destroy(listmgr);
516 evas_object_del(layout);
522 static void _destroy(void *layout_data)
527 _ERR("failed to get layout data");
533 progressbar_destroy(priv->prog);
535 mediadata_free_list(priv->media_list);
536 mediadata_destroy(priv->md);
538 listmgr_destroy(priv->listmgr);
539 free(priv->ldata->pops);
540 free(priv->ldata->gops);
543 evas_object_del(priv->layout);
548 static void _show(void *layout_data)
553 _ERR("failed to layout data");
559 evas_object_show(priv->layout);
560 elm_object_part_content_set(priv->base,
561 PART_THUMBNAIL_AREA, priv->layout);
564 static void _hide(void *layout_data)
569 _ERR("failed to get layout data");
575 evas_object_hide(priv->layout);
576 elm_object_part_content_unset(priv->base, PART_THUMBNAIL_AREA);
579 static void _update(void *layout_data, int update_type, void *data)
581 struct view_update_data *vdata;
585 _ERR("failed to get layout data");
592 switch (update_type) {
594 _update_content_list(priv);
598 _ERR("invalid argument");
602 listmgr_focus_play_info(priv->listmgr);
603 _update_recent_item(priv, vdata->index);
606 listmgr_focus_content_list(priv->listmgr,
607 priv->cur_index, false);
614 static layout_class _lclass = {
615 .layout_id = LAYOUT_MOVIE,
623 layout_class *layout_movie_get_lclass(void)