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_GENRE_NAME "Genre"
34 static char *_media_text_get(void *data, Evas_Object *obj, const char *part)
44 info = app_media_get_info(am);
46 _ERR("failed to get media info");
50 if (!strcmp(part, PART_ELM_TEXT_TITLE))
51 return strdup(info->title);
52 else if (!strcmp(part, PART_ELM_TEXT_ARTIST))
53 return strdup(info->audio->artist);
54 else if (!strcmp(part, PART_ELM_TEXT_ALBUM))
55 return strdup(info->audio->album);
60 static Evas_Object *_media_content_get(void *data,
61 Evas_Object *obj, const char *part)
72 info = app_media_get_info(am);
74 _ERR("failed to get media info");
79 if (!strcmp(part, PART_ELM_SWALLOW_THUMBNAIL)) {
80 eo = util_add_image(obj, info->thumbnail_path);
82 _ERR("failed to create image object");
85 } else if (!strcmp(part, PART_ELM_SWALLOW_FAVORITE)) {
89 eo = util_add_image(obj, IMAGE_THUMBNAIL_FAVORITE);
91 _ERR("failed to create image object");
102 static char *_album_text_get(void *data, Evas_Object *obj, const char *part)
104 struct album_info *ai;
111 return strdup(ai->name);
114 static Evas_Object *_album_content_get(void *data, Evas_Object *obj,
118 struct album_info *ai;
119 struct color_data bg;
127 if (!strcmp(part, PART_ELM_SWALLOW_THUMBNAIL)) {
129 eo = util_add_image(obj, ai->album_art);
131 _ERR("failed to create image object");
135 eo = evas_object_rectangle_add(obj);
137 _ERR("failed to create rectangle object");
142 app_contents_get_color(ai->name, &bg, NULL);
143 evas_object_color_set(eo, bg.r, bg.g, bg.b, bg.a);
145 } else if (!strcmp(part, PART_ELM_SWALLOW_ICON)) {
149 eo = util_add_image(obj, IMAGE_THUMBNAIL_SONG_ALBUM);
151 _ERR("failed to create image object");
154 } else if (!strcmp(part, PART_ELM_SWALLOW_TEXTBG)) {
155 eo = evas_object_rectangle_add(obj);
157 _ERR("failed to create rectangle object");
161 app_contents_get_color(ai->name, NULL, &bg);
162 evas_object_color_set(eo, bg.r, bg.g, bg.b, bg.a);
166 evas_object_show(eo);
171 static char *_artist_text_get(void *data, Evas_Object *obj, const char *part)
173 struct album_info *ai;
180 return strdup(ai->artist);
183 static Evas_Object *_artist_content_get(void *data, Evas_Object *obj,
187 struct album_info *ai;
188 struct color_data bg;
196 if (!strcmp(part, PART_ELM_SWALLOW_THUMBNAIL)) {
198 eo = util_add_image(obj, ai->album_art);
200 _ERR("failed to create image object");
204 eo = evas_object_rectangle_add(obj);
206 _ERR("failed to create rectangle object");
211 app_contents_get_color(ai->name, &bg, NULL);
212 evas_object_color_set(eo, bg.r, bg.g, bg.b, bg.a);
214 } else if (!strcmp(part, PART_ELM_SWALLOW_ICON)) {
218 eo = util_add_image(obj, IMAGE_THUMBNAIL_ARTIST);
220 _ERR("failed to create image object");
223 } else if (!strcmp(part, PART_ELM_SWALLOW_TEXTBG)) {
224 eo = evas_object_rectangle_add(obj);
226 _ERR("failed to create rectangle object");
230 app_contents_get_color(ai->name, NULL, &bg);
231 evas_object_color_set(eo, bg.r, bg.g, bg.b, bg.a);
235 evas_object_show(eo);
240 static char *_group_text_get(void *data, Evas_Object *obj, const char *part)
242 struct group_info *gi;
251 if (!strcmp(part, PART_ELM_TEXT_TITLE))
252 return strdup(gi->name);
253 else if (!strcmp(part, PART_ELM_TEXT_COUNT)) {
254 cnt = eina_list_count(gi->list);
255 snprintf(buf, sizeof(buf), "%d", cnt);
262 static Evas_Object *_group_content_get(void *data, Evas_Object *obj,
266 struct group_info *gi;
267 struct color_data bg;
275 if (!strcmp(part, PART_ELM_SWALLOW_BG)) {
276 eo = evas_object_rectangle_add(obj);
278 _ERR("failed to create rectangle object");
282 app_contents_get_color(gi->name, &bg, NULL);
283 evas_object_color_set(eo, bg.r, bg.g, bg.b, bg.a);
285 evas_object_show(eo);
291 static Eina_List *_get_song_list(struct datamgr *dmgr)
294 _ERR("invalid argument");
298 return dmgr->ops->get_group(dmgr->handle, E_GROUP_MEDIA_NAME, NULL);
301 static Eina_List *_get_album_list(struct datamgr *dmgr)
304 _ERR("invalid argument");
308 return dmgr->ops->get_group(dmgr->handle, E_GROUP_ALBUM_NAME, NULL);
311 static Eina_List *_get_artist_list(struct datamgr *dmgr)
314 _ERR("invalid argument");
318 return dmgr->ops->get_group(dmgr->handle, E_GROUP_ALBUM_ARTIST, NULL);
321 static Eina_List *_get_genre_list(struct datamgr *dmgr)
324 struct group_info *gi;
327 _ERR("invalid argument");
331 gi = calloc(1, sizeof(*gi));
333 _ERR("failed to allocate memory");
337 gi->name = STR_GENRE_NAME;
338 gi->list = dmgr->ops->get_group(dmgr->handle,
339 E_GROUP_MEDIA_GENRE, NULL);
342 list = eina_list_append(list, gi);
347 static void _free_item_list(struct datamgr *dmgr, Eina_List *list)
350 _ERR("invalid argument");
354 dmgr->ops->free_group(list);
357 static void _free_group_list(struct datamgr *dmgr, Eina_List *list)
359 struct group_info *gi;
362 _ERR("invalid argument");
366 EINA_LIST_FREE(list, gi) {
367 dmgr->ops->free_group(gi->list);
372 static void _get_media_info(struct datamgr *dmgr, Eina_List *list, char *str,
377 cnt = dmgr->ops->get_count(dmgr->handle, E_FILE_MUSIC);
379 _ERR("failed to get media count");
383 snprintf(str, size, "%d Songs", cnt);
386 static void _get_album_info(struct datamgr *dmgr, Eina_List *list, char *str,
390 struct group_info *gi;
394 EINA_LIST_FOREACH(list, l, gi)
395 cnt += eina_list_count(gi->list);
397 snprintf(str, size, "%d Albums", cnt);
400 static void _get_artist_info(struct datamgr *dmgr, Eina_List *list, char *str,
404 struct group_info *gi;
408 EINA_LIST_FOREACH(list, l, gi)
409 cnt += eina_list_count(gi->list);
411 snprintf(str, size, "%d Artists", cnt);
414 static void _get_genre_info(struct datamgr *dmgr, Eina_List *list, char *str,
417 struct group_info *gi;
420 gi = eina_list_nth(list, 0);
421 cnt = eina_list_count(gi->list);
423 snprintf(str, size, "%d Genre", cnt);
426 static void _key_down_cb(void *data, Elm_Object_Item *it,
427 Evas_Event_Key_Down *ev)
429 struct view_update_data vdata;
430 struct datamgr *dmgr;
434 _ERR("invalid argument");
440 if (!strcmp(ev->keyname, KEY_MENU) ||
441 !strcmp(ev->keyname, KEY_CONTEXT_MENU)) {
442 am = elm_object_item_data_get(it);
444 _ERR("failed to get app media");
448 vdata.list = dmgr->ops->get_list(dmgr->handle,
450 vdata.index = util_get_media_index(vdata.list, am);
452 viewmgr_update_view(VIEW_ACTION_MENU, UPDATE_CONTENT, &vdata);
453 viewmgr_show_view(VIEW_ACTION_MENU);
457 static void _media_selected_cb(void *data, Elm_Object_Item *it)
459 struct view_update_data vdata;
460 struct datamgr *dmgr;
464 _ERR("invalid argument");
470 am = elm_object_item_data_get(it);
472 _ERR("failed to get app media");
476 vdata.list = dmgr->ops->get_list(dmgr->handle, E_LIST_MEDIA, NULL);
477 vdata.index = util_get_media_index(vdata.list, am);
478 vdata.id = VIEW_BASE;
480 viewmgr_update_view(VIEW_MPLAYER, UPDATE_CONTENT, &vdata);
481 viewmgr_push_view(VIEW_MPLAYER);
484 static void _album_selected_cb(void *data, Elm_Object_Item *it)
486 struct view_update_data vdata;
487 struct datamgr *dmgr;
488 struct album_info *ai;
491 _ERR("invalid argument");
497 ai = elm_object_item_data_get(it);
499 _ERR("failed to get album info");
503 vdata.list = dmgr->ops->get_list(dmgr->handle,
504 E_LIST_ALBUM_MEDIA, &ai->id);
505 vdata.index = E_DETAIL_MUSIC_ALBUM;
508 viewmgr_update_view(VIEW_DETAIL, UPDATE_CONTENT, &vdata);
509 viewmgr_push_view(VIEW_DETAIL);
512 static void _artist_selected_cb(void *data, Elm_Object_Item *it)
514 struct view_update_data vdata;
515 struct datamgr *dmgr;
516 struct album_info *ai;
519 _ERR("invalid argument");
525 ai = elm_object_item_data_get(it);
527 _ERR("failed to get album info");
531 vdata.list = dmgr->ops->get_list(dmgr->handle,
532 E_LIST_ARTIST_ALBUM, ai->artist);
533 vdata.index = E_DETAIL_MUSIC_ARTIST;
534 vdata.id = ai->artist;
536 viewmgr_update_view(VIEW_DETAIL, UPDATE_CONTENT, &vdata);
537 viewmgr_push_view(VIEW_DETAIL);
540 static void _genre_selected_cb(void *data, Elm_Object_Item *it)
542 struct view_update_data vdata;
543 struct group_info *gi;
546 _ERR("invalid argument");
550 gi = elm_object_item_data_get(it);
552 _ERR("failed to get group info");
556 vdata.list = gi->list;
557 vdata.index = E_DETAIL_MUSIC_GENRE;
560 viewmgr_update_view(VIEW_DETAIL, UPDATE_CONTENT, &vdata);
561 viewmgr_push_view(VIEW_DETAIL);
564 static struct grid_class _gclass[] = {
566 .item_style = STYLE_MUSIC_SONG,
567 .text_get = _media_text_get,
568 .content_get = _media_content_get
571 .item_style = STYLE_MUSIC_ALBUM,
572 .text_get = _album_text_get,
573 .content_get = _album_content_get
576 .item_style = STYLE_MUSIC_ARTIST,
577 .text_get = _artist_text_get,
578 .content_get = _artist_content_get
581 .item_style = STYLE_MUSIC_GENRE,
582 .text_get = _group_text_get,
583 .content_get = _group_content_get
585 /* Other view mode class will be added later */
588 static struct grid_data _gdata[] = {
590 .item_x = MUSIC_SONG_ITEM_X,
591 .item_y = MUSIC_SONG_ITEM_Y,
592 .item_num = MUSIC_SONG_ITEM_NUM,
593 .grid_padding = MUSIC_SONG_GRID_PADDING,
594 .gclass = &_gclass[E_MUSIC_SONG],
595 .get_item_list = _get_song_list,
596 .free_item_list = _free_item_list,
597 .get_item_info = _get_media_info,
598 .key_down_cb = _key_down_cb,
599 .selected_cb = _media_selected_cb,
602 .item_x = MUSIC_ALBUM_ITEM_X,
603 .item_y = MUSIC_ALBUM_ITEM_Y,
604 .item_num = MUSIC_ALBUM_ITEM_NUM,
605 .grid_padding = MUSIC_ALBUM_GRID_PADDING,
606 .gclass = &_gclass[E_MUSIC_ALBUM],
607 .get_item_list = _get_album_list,
608 .free_item_list = _free_item_list,
609 .get_item_info = _get_album_info,
610 .selected_cb = _album_selected_cb,
613 .item_x = MUSIC_ARTIST_ITEM_X,
614 .item_y = MUSIC_ARTIST_ITEM_Y,
615 .item_num = MUSIC_ARTIST_ITEM_NUM,
616 .grid_padding = MUSIC_ARTIST_GRID_PADDING,
617 .gclass = &_gclass[E_MUSIC_ARTIST],
618 .get_item_list = _get_artist_list,
619 .free_item_list = _free_item_list,
620 .get_item_info = _get_artist_info,
621 .selected_cb = _artist_selected_cb,
624 .item_x = MUSIC_GENRE_ITEM_X,
625 .item_y = MUSIC_GENRE_ITEM_Y,
626 .item_num = MUSIC_GENRE_ITEM_NUM,
627 .grid_padding = MUSIC_GENRE_GRID_PADDING,
628 .gclass = &_gclass[E_MUSIC_GENRE],
629 .get_item_list = _get_genre_list,
630 .free_item_list = _free_group_list,
631 .get_item_info = _get_genre_info,
632 .selected_cb = _genre_selected_cb,
634 /* Other view mode data will be added later */
637 struct grid_data *get_music_grid_data(int type)
639 if (type < 0 || type >= E_MUSIC_MAX) {
640 _ERR("invalid argument");
644 return &_gdata[type];