summaryrefslogtreecommitdiff
path: root/src/view/detail.c
blob: 59d77a5dbb5c47406988c3f927ea757ffb7c9da6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
/*
 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
 *
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <Elementary.h>
#include <media_content.h>
#include <app_debug.h>
#include <app_contents.h>
#include <app_media.h>
#include <inputmgr.h>
#include <viewmgr.h>

#include "define.h"
#include "view.h"
#include "data/datamgr.h"
#include "grid/grid.h"
#include "util/util.h"

#define STR_NO_PLAY_MOVIE "No recently watched movie"
#define STR_NO_PLAY_MUSIC "No music in playlist"

struct _priv;

static char *_grid_text_get(void *data, Evas_Object *obj, const char *part);
static Evas_Object *_grid_content_get(void *data, Evas_Object *obj,
			const char *part);

static char *_album_text_get(void *data, Evas_Object *obj, const char *part);
static Evas_Object *_album_content_get(void *data, Evas_Object *obj,
			const char *part);

static void _get_movie_info(struct _priv *priv, const char *title);
static void _get_gallery_info(struct _priv *priv, const char *title);
static void _get_album_info(struct _priv *priv, const char *title);
static void _get_artist_info(struct _priv *priv, const char *title);
static void _get_genre_info(struct _priv *priv, const char *title);

static void _album_selected(void *data);

enum _object_type {
	DETAIL_GRID = 0,
	DETAIL_PLAY_INFO
};

struct _list_info {
	Eina_List *list;
	const char *title;
};

struct _view_info {
	const char *grid_style;
	int grid_item_x;
	int grid_item_y;
	char *(*get_grid_text)(void *data, Evas_Object *obj, const char *part);
	Evas_Object *(*get_grid_content)(void *data, Evas_Object *obj,
				const char *part);
	void (*get_content_info)(struct _priv *priv, const char *title);

	void (*selected)(void *data);
	bool detail_update;

	int app_contents_type;
};

static struct _view_info view_info[E_DETAIL_MAX] = {
	[E_DETAIL_MOVIE_GENRE] = {
		.grid_style = STYLE_MOVIE_NAME,
		.grid_item_x = MOVIE_NAME_ITEM_X,
		.grid_item_y = MOVIE_NAME_ITEM_Y,
		.get_grid_text = _grid_text_get,
		.get_grid_content = _grid_content_get,
		.get_content_info = _get_movie_info,
		.detail_update = EINA_FALSE,
		.app_contents_type = CONTENTS_MOVIE,
	},
	[E_DETAIL_GALLERY_PLACE] = {
		.grid_style = STYLE_GALLERY_EVENT,
		.grid_item_x = GALLERY_EVENT_ITEM_X,
		.grid_item_y = GALLERY_EVENT_ITEM_Y,
		.get_grid_text = _grid_text_get,
		.get_grid_content = _grid_content_get,
		.get_content_info = _get_gallery_info,
		.detail_update = EINA_FALSE,
		.app_contents_type = CONTENTS_GALLERY,
	},
	[E_DETAIL_MUSIC_ALBUM] = {
		.grid_style = STYLE_MUSIC_SONG_DETAIL,
		.grid_item_x = MUSIC_SONG_ITEM_X,
		.grid_item_y = MUSIC_SONG_ITEM_Y,
		.get_grid_text = _grid_text_get,
		.get_grid_content = _grid_content_get,
		.get_content_info = _get_album_info,
		.detail_update = EINA_FALSE,
		.app_contents_type = CONTENTS_MUSIC,
	},
	[E_DETAIL_MUSIC_ARTIST] = {
		.grid_style = STYLE_MUSIC_ALBUM,
		.grid_item_x = MUSIC_ALBUM_ITEM_X,
		.grid_item_y = MUSIC_ALBUM_ITEM_Y,
		.get_grid_text = _album_text_get,
		.get_grid_content = _album_content_get,
		.get_content_info = _get_artist_info,
		.selected = _album_selected,
		.detail_update = EINA_TRUE,
		.app_contents_type = CONTENTS_MUSIC,
	},
	[E_DETAIL_MUSIC_GENRE] = {
		.grid_style = STYLE_MUSIC_SONG_DETAIL,
		.grid_item_x = MUSIC_SONG_ITEM_X,
		.grid_item_y = MUSIC_SONG_ITEM_Y,
		.get_grid_text = _grid_text_get,
		.get_grid_content = _grid_content_get,
		.get_content_info = _get_genre_info,
		.detail_update = EINA_FALSE,
		.app_contents_type = CONTENTS_MUSIC,
	},
};

struct _priv {
	Evas_Object *win;
	Evas_Object *base;
	Evas_Object *grid;
	Evas_Object *btn;
	Evas_Object *thumbnail;

	Elm_Object_Item *focused_it;

	Eina_List *media_list;
	Eina_List *view_list;
	Eina_List *play_list;

	struct datamgr *dmgr;

	app_media *play_info;

	int view_type;
	int depth;

	int status;

	struct _view_info *vinfo;
};

static void _destroy_play_list(struct _priv *priv)
{
	eina_list_free(priv->play_list);
	priv->play_list = NULL;
}

static void _update_view(struct _priv *priv)
{
	struct _list_info *linfo;
	struct view_update_data vdata;

	linfo = eina_list_data_get(priv->view_list);
	priv->view_list = eina_list_remove(priv->view_list, linfo);

	vdata.list = linfo->list;
	vdata.index = E_DETAIL_MUSIC_ARTIST;
	vdata.id = linfo->title;

	viewmgr_update_view(VIEW_DETAIL, UPDATE_CONTENT, &vdata);
	viewmgr_push_view(VIEW_DETAIL);

	priv->depth--;

	free(linfo);
}

static void _pop_view(void)
{
	viewmgr_update_view(VIEW_BASE, UPDATE_BACK, NULL);
	viewmgr_pop_view();
}

static void _key_down_cb(int id, void *data, Evas *e, Evas_Object *obj,
			Evas_Event_Key_Down *ev)
{
	struct _priv *priv;

	if (!data || !ev) {
		_ERR("invalid argument");
		return;
	}

	priv = data;

	switch (id) {
	case DETAIL_GRID:
		if (!strcmp(ev->keyname, KEY_BACK) ||
			!strcmp(ev->keyname, KEY_ESC)) {
			if (priv->depth > 0)
				_update_view(priv);
			else
				_pop_view();
		}

		break;
	case DETAIL_PLAY_INFO:
		if (!strcmp(ev->keyname, KEY_BACK) ||
			!strcmp(ev->keyname, KEY_ESC))
			elm_object_focus_set(priv->grid, EINA_TRUE);

		break;
	default:
		break;
	}
}

static void _focused_cb(int id, void *data, Evas_Object *obj,
			Elm_Object_Item *it)
{
	struct _priv *priv;

	if (!data)
		return;

	priv = data;

	if (it)
		priv->focused_it = it;
}

static void _clicked_cb(int id, void *data, Evas_Object *obj)
{
	struct view_update_data vdata;
	struct _priv *priv;
	int type;

	if (!data) {
		_ERR("invalid argument");
		return;
	}

	priv = data;

	type = priv->vinfo->app_contents_type;

	switch (type) {
	case CONTENTS_MOVIE:
		_destroy_play_list(priv);

		priv->play_list = eina_list_append(priv->play_list,
					priv->play_info);

		vdata.list = priv->play_list;
		vdata.index = 0;
		vdata.id = VIEW_DETAIL;

		viewmgr_update_view(VIEW_VIEWER, UPDATE_CONTENT, &vdata);
		viewmgr_push_view(VIEW_VIEWER);

		break;
	case CONTENTS_MUSIC:
		viewmgr_push_view(VIEW_MPLAYER);
		break;
	default:
		break;
	}
}

static void _media_selected(void *data)
{
	struct _priv *priv;
	struct view_update_data vdata;
	app_media *am;

	if (!data) {
		_ERR("invalid argument");
		return;
	}

	priv = data;

	am = elm_object_item_data_get(priv->focused_it);
	if (!am) {
		_ERR("failed to get app media");
		return;
	}

	vdata.list = priv->media_list;
	vdata.index = util_get_media_index(vdata.list, am);
	vdata.id = VIEW_DETAIL;

	switch (priv->view_type) {
	case E_DETAIL_MOVIE_GENRE:
	case E_DETAIL_GALLERY_PLACE:
		viewmgr_update_view(VIEW_VIEWER, UPDATE_CONTENT, &vdata);
		viewmgr_push_view(VIEW_VIEWER);
		break;
	case E_DETAIL_MUSIC_ALBUM:
	case E_DETAIL_MUSIC_GENRE:
		viewmgr_update_view(VIEW_MPLAYER, UPDATE_CONTENT, &vdata);
		viewmgr_push_view(VIEW_MPLAYER);
		break;
	default:
		break;
	}
}

static void _album_selected(void *data)
{
	struct _priv *priv;
	struct view_update_data vdata;
	struct _list_info *linfo;
	struct datamgr *dmgr;
	struct album_info *ai;

	if (!data) {
		_ERR("invalid argument");
		return;
	}

	priv = data;

	dmgr = priv->dmgr;

	ai = elm_object_item_data_get(priv->focused_it);
	if (!ai) {
		_ERR("failed to get album info");
		return;
	}

	linfo = calloc(1, sizeof(*linfo));
	if (!linfo) {
		_ERR("failed to allocate list info");
		return;
	}

	linfo->list = priv->media_list;
	linfo->title = ai->artist;

	priv->view_list = eina_list_append(priv->view_list, linfo);

	vdata.list = dmgr->ops->get_list(dmgr->handle,
				E_LIST_ALBUM_MEDIA, &ai->id);
	vdata.index = E_DETAIL_MUSIC_ALBUM;
	vdata.id = ai->name;

	viewmgr_update_view(VIEW_DETAIL, UPDATE_CONTENT, &vdata);
	viewmgr_push_view(VIEW_DETAIL);

	priv->depth++;
}

static void _selected_cb(int id, void *data, Evas_Object *obj,
			Elm_Object_Item *it)
{
	struct _priv *priv;
	void (*_selected)(void *data);

	if (!data || !it)
		return;

	priv = data;

	if (priv->vinfo->detail_update)
		_selected = priv->vinfo->selected;
	else
		_selected = _media_selected;

	ecore_job_add(_selected, priv);
}

static input_handler _handler = {
	.key_down = _key_down_cb,
	.focused = _focused_cb,
	.clicked = _clicked_cb,
	.selected = _selected_cb
};

static char *_grid_text_get(void *data, Evas_Object *obj, const char *part)
{
	app_media *am;
	app_media_info *mi;
	int duration;
	char buf[32];

	if (!data)
		return NULL;

	am = data;

	mi = app_media_get_info(am);
	if (!mi) {
		_ERR("failed to get media info");
		return NULL;
	}

	if (!strcmp(part, PART_ELM_TEXT_TITLE))
		return strdup(mi->title);
	else if (!strcmp(part, PART_ELM_TEXT_ALBUM))
		return strdup(mi->audio->album);
	else if (!strcmp(part, PART_ELM_TEXT_ARTIST))
		return strdup(mi->audio->artist);
	else if (!strcmp(part, PART_ELM_TEXT_PLAYTIME)) {
		if (mi->media_type == MEDIA_CONTENT_TYPE_VIDEO)
			duration = mi->video->duration;
		else if (mi->media_type == MEDIA_CONTENT_TYPE_MUSIC)
			duration = mi->audio->duration;
		else
			return NULL;

		util_time_string(buf, sizeof(buf), duration, false);

		return strdup(buf);
	}

	return NULL;
}

static Evas_Object *_grid_content_get(void *data, Evas_Object *obj,
			const char *part)
{
	Evas_Object *eo;
	app_media *am;
	app_media_info *mi;
	struct color_data bg;

	if (!data)
		return NULL;

	am = data;

	mi = app_media_get_info(am);
	if (!mi) {
		_ERR("failed to get media info");
		return NULL;
	}

	eo = NULL;
	if (!strcmp(part, PART_ELM_SWALLOW_THUMBNAIL)) {
		eo = util_add_image(obj, mi->thumbnail_path);
		if (!eo) {
			_ERR("failed to create image object");
			return NULL;
		}
	} else if (!strcmp(part, PART_ELM_SWALLOW_FAVORITE)) {
		if (!mi->favorite)
			return NULL;

		eo = util_add_image(obj, IMAGE_THUMBNAIL_FAVORITE);
		if (!eo) {
			_ERR("failed to create image object");
			return NULL;
		}
	} else if (!strcmp(part, PART_ELM_SWALLOW_TEXTBG)) {
		eo = evas_object_rectangle_add(obj);
		if (!eo) {
			_ERR("failed to create rectangle object");
			return NULL;
		}

		app_contents_get_color(mi->title, NULL, &bg);
		evas_object_color_set(eo, bg.r, bg.g, bg.b, bg.a);
	} else if (!strcmp(part, PART_ELM_SWALLOW_VIDEO)) {
		if (mi->media_type != MEDIA_CONTENT_TYPE_VIDEO)
			return NULL;

		eo = util_add_image(obj, IMAGE_THUMBNAIL_PLAY);
		if (!eo) {
			_ERR("failed to create image object");
			return NULL;
		}
	}

	if (eo)
		evas_object_show(eo);

	return eo;
}

static char *_album_text_get(void *data, Evas_Object *obj, const char *part)
{
	struct album_info *ai;

	if (!data)
		return NULL;

	ai = data;

	return strdup(ai->name);
}

static Evas_Object *_album_content_get(void *data, Evas_Object *obj,
			const char *part)
{
	Evas_Object *eo;
	struct album_info *ai;
	struct color_data bg;

	if (!data)
		return NULL;

	ai = data;

	eo = NULL;
	if (!strcmp(part, PART_ELM_SWALLOW_THUMBNAIL)) {
		eo = util_add_image(obj, ai->album_art);
		if (!eo) {
			_ERR("failed to create image object");
			return NULL;
		}
	} else if (!strcmp(part, PART_ELM_SWALLOW_TEXTBG)) {
		eo = evas_object_rectangle_add(obj);
		if (!eo) {
			_ERR("failed to create rectangle object");
			return NULL;
		}

		app_contents_get_color(ai->name, NULL, &bg);
		evas_object_color_set(eo, bg.r, bg.g, bg.b, bg.a);
	}

	if (eo)
		evas_object_show(eo);

	return eo;
}

static Elm_Gengrid_Item_Class *_get_grid_item_class(struct _view_info *vinfo)
{
	Elm_Gengrid_Item_Class *ic;

	ic = elm_gengrid_item_class_new();
	if (!ic) {
		_ERR("failed to create gengrid item calss");
		return NULL;
	}

	ic->item_style = vinfo->grid_style;
	ic->func.text_get = vinfo->get_grid_text;
	ic->func.content_get = vinfo->get_grid_content;

	return ic;
}

static app_media *_get_app_media(const char *id)
{
	media_info_h media;
	app_media *am;
	int r;

	r = media_content_connect();
	if (r != MEDIA_CONTENT_ERROR_NONE) {
		_ERR("failed to connect to media content");
		return NULL;
	}

	r = media_info_get_media_from_db(id, &media);
	if (r != MEDIA_CONTENT_ERROR_NONE) {
		_ERR("failed to get media handle");
		return NULL;
	}

	am = app_media_create(media);
	if (!am) {
		_ERR("failed to create app media");
		return NULL;
	}

	media_content_disconnect();

	return am;
}

static app_media *_get_play_item(struct _priv *priv, const char *id)
{
	GList *rlist;
	app_media *am;
	struct recent_data *rdata;
	int type;
	int r;

	if (id) {
		am = _get_app_media(id);
		return am;
	}

	type = view_info[priv->view_type].app_contents_type;

	rlist = NULL;
	am = NULL;
	r = app_contents_get_recent_list(type, 1, &rlist);
	if (r != APP_CONTENTS_ERROR_NONE) {
		_ERR("failed to get recent list");
		return NULL;
	}

	rdata = g_list_nth_data(rlist, 0);
	if (!rdata || !rdata->id) {
		_ERR("failed to get recent item");
		app_contents_free_recent_list(rlist);
		return NULL;
	}

	am = _get_app_media(rdata->id);

	app_contents_free_recent_list(rlist);

	return am;
}

static void _get_place_title(const char *title, char *str, int size)
{
	char buf[64], s[64];
	char *city, *country, *tmp;

	strcpy(buf, title);

	city = strtok_r(buf, "/", &tmp);
	country = strtok_r(tmp, "", &tmp);

	snprintf(str, size, "%s", city);

	if (country) {
		snprintf(s, sizeof(s), ", %s", country);
		strncat(str, s, strlen(s));
	}
}

static void _get_movie_info(struct _priv *priv, const char *title)
{
	char buf[64];

	elm_object_part_text_set(priv->base, PART_DETAIL_TITLE, title);

	elm_object_signal_emit(priv->base,
				SIG_HIDE_THUMBNAIL, SIG_SOURCE_SRC);

	snprintf(buf, sizeof(buf), "%d movies",
				eina_list_count(priv->media_list));

	elm_object_part_text_set(priv->base, PART_DETAIL_CONTENT_INFO, buf);
}

static void _get_gallery_info(struct _priv *priv, const char *title)
{
	Eina_List *l;
	app_media *am;
	app_media_info *mi;
	int count[E_FILE_MAX] = {0};
	char buf[64];

	_get_place_title(title, buf, sizeof(buf));
	elm_object_part_text_set(priv->base, PART_DETAIL_TITLE, buf);

	elm_object_signal_emit(priv->base,
				SIG_HIDE_THUMBNAIL, SIG_SOURCE_SRC);

	EINA_LIST_FOREACH(priv->media_list, l, am) {
		mi = app_media_get_info(am);
		if (!mi)
			continue;

		count[mi->media_type]++;
	}

	snprintf(buf, sizeof(buf), "%d contents | %d photos, %d videos",
				eina_list_count(priv->media_list),
				count[E_FILE_PHOTO], count[E_FILE_VIDEO]);

	elm_object_part_text_set(priv->base, PART_DETAIL_CONTENT_INFO, buf);
}

static void _get_album_info(struct _priv *priv, const char *title)
{
	app_media *am;
	app_media_info *mi;
	char buf[64];

	elm_object_part_text_set(priv->base, PART_DETAIL_TITLE, title);

	elm_object_signal_emit(priv->base,
				SIG_HIDE_THUMBNAIL, SIG_SOURCE_SRC);

	am = eina_list_nth(priv->media_list, 0);

	mi = app_media_get_info(am);
	if (!mi) {
		snprintf(buf, sizeof(buf), "%d songs",
					eina_list_count(priv->media_list));
		return;
	}

	if (mi->thumbnail_path) {
		elm_image_file_set(priv->thumbnail,
					mi->thumbnail_path, NULL);
		elm_image_aspect_fixed_set(priv->thumbnail, EINA_FALSE);

		elm_object_signal_emit(priv->base, SIG_SHOW_THUMBNAIL,
					SIG_SOURCE_SRC);
	}

	snprintf(buf, sizeof(buf), "%s | %d songs", mi->audio->artist,
				eina_list_count(priv->media_list));

	elm_object_part_text_set(priv->base, PART_DETAIL_CONTENT_INFO, buf);
}

static void _get_artist_info(struct _priv *priv, const char *title)
{
	Eina_List *l;
	struct album_info *ai;
	int cnt;
	char buf[64];

	elm_object_part_text_set(priv->base, PART_DETAIL_TITLE, title);

	elm_object_signal_emit(priv->base,
				SIG_HIDE_THUMBNAIL, SIG_SOURCE_SRC);

	cnt = 0;
	EINA_LIST_FOREACH(priv->media_list, l, ai)
		cnt += ai->media_count;

	snprintf(buf, sizeof(buf), "%d albums, %d songs",
				eina_list_count(priv->media_list), cnt);

	elm_object_part_text_set(priv->base, PART_DETAIL_CONTENT_INFO, buf);
}

static void _get_genre_info(struct _priv *priv, const char *title)
{
	char buf[64];

	elm_object_part_text_set(priv->base, PART_DETAIL_TITLE, title);

	elm_object_signal_emit(priv->base, SIG_HIDE_THUMBNAIL,
					SIG_SOURCE_SRC);

	snprintf(buf, sizeof(buf), "%d songs",
				eina_list_count(priv->media_list));

	elm_object_part_text_set(priv->base, PART_DETAIL_CONTENT_INFO, buf);
}

static void _set_no_play_info(struct _priv *priv)
{
	int type;
	char buf[64] = {0};

	type = view_info[priv->view_type].app_contents_type;

	if (type == CONTENTS_MOVIE)
		snprintf(buf, sizeof(buf), STR_NO_PLAY_MOVIE);
	else if (type == CONTENTS_MUSIC)
		snprintf(buf, sizeof(buf), STR_NO_PLAY_MUSIC);

	elm_object_text_set(priv->btn, buf);

	elm_object_signal_emit(priv->btn, SIG_SET_STATUS_STOP, SIG_SOURCE_SRC);

	elm_object_disabled_set(priv->btn, EINA_TRUE);
}

static void _set_movie_play_info(struct _priv *priv, app_media_info *mi)
{
	struct tm tm;
	char date[32], buf[256];

	elm_object_signal_emit(priv->btn, SIG_SET_STATUS_STOP, SIG_SOURCE_SRC);

	localtime_r(&mi->played_time, &tm);
	strftime(date, sizeof(date), "%Y.%m.%d", &tm);

	snprintf(buf, sizeof(buf), "%s - %s", mi->title, date);

	elm_object_text_set(priv->btn, buf);
	elm_object_disabled_set(priv->btn, EINA_FALSE);
}

static void _set_music_play_info(struct _priv *priv, app_media_info *mi)
{
	char buf[256];

	switch (priv->status) {
	case E_PLAYER_PLAY:
		elm_object_signal_emit(priv->btn, SIG_SET_STATUS_PLAY,
					SIG_SOURCE_SRC);
		break;
	case E_PLAYER_PAUSE:
		elm_object_signal_emit(priv->btn, SIG_SET_STATUS_PAUSE,
					SIG_SOURCE_SRC);
		break;
	default:
		break;
	}

	snprintf(buf, sizeof(buf), "%s - %s", mi->title, mi->audio->artist);

	elm_object_text_set(priv->btn, buf);
	elm_object_disabled_set(priv->btn, EINA_FALSE);
}

static void _update_title_area(struct _priv *priv, const char *title)
{
	view_info[priv->view_type].get_content_info(priv, title);
}

static bool _update_thumbnail_area(struct _priv *priv)
{
	Eina_List *l;
	Elm_Gengrid_Item_Class *ic;
	Elm_Object_Item *it;
	void *data;

	elm_object_focus_set(priv->grid, EINA_FALSE);
	elm_gengrid_clear(priv->grid);

	elm_gengrid_item_size_set(priv->grid,
			elm_config_scale_get() * priv->vinfo->grid_item_x,
			elm_config_scale_get() * priv->vinfo->grid_item_y);

	ic = _get_grid_item_class(priv->vinfo);
	if (!ic) {
		_ERR("failed to get grid item class");
		return false;
	}

	EINA_LIST_FOREACH(priv->media_list, l, data) {
		it = elm_gengrid_item_append(priv->grid, ic, data, NULL, NULL);
		elm_object_item_data_set(it, data);
	}

	elm_gengrid_item_class_free(ic);

	evas_object_show(priv->grid);

	return true;
}

static bool _update_play_info(struct _priv *priv, const char *id)
{
	app_media *am;
	app_media_info *mi;
	int type;

	type = view_info[priv->view_type].app_contents_type;

	if (type == CONTENTS_GALLERY ||
		(type == CONTENTS_MUSIC && priv->status == E_PLAYER_STOP)) {
		_set_no_play_info(priv);
		return true;
	}

	am = _get_play_item(priv, id);
	if (!am) {
		_set_no_play_info(priv);
		return false;
	}

	mi = app_media_get_info(am);
	if (!mi) {
		_ERR("failed to get app media info");
		_set_no_play_info(priv);
		return false;
	}

	if (type == CONTENTS_MOVIE)
		_set_movie_play_info(priv, mi);
	else if (type == CONTENTS_MUSIC)
		_set_music_play_info(priv, mi);

	priv->play_info = am;

	return true;
}

static bool _draw_title_area(struct _priv *priv)
{
	Evas_Object *img;

	img = util_add_image(priv->base, NULL);
	if (!img) {
		_ERR("failed to add image");
		return false;
	}

	elm_object_part_content_set(priv->base, PART_DETAIL_THUMBNAIL, img);

	priv->thumbnail = img;

	return true;
}

static bool _draw_thumbnail_area(struct _priv *priv)
{
	Evas_Object *grid;

	grid = util_add_gengrid(priv->base, 0, 0, EINA_TRUE);
	if (!grid) {
		_ERR("failed to add gengrid");
		return false;
	}

	elm_object_part_content_set(priv->base,
				PART_DETAIL_THUMBNAIL_AREA, grid);

	inputmgr_add_callback(grid, DETAIL_GRID, &_handler, priv);

	priv->grid = grid;

	return true;
}

static bool _draw_play_info(struct _priv *priv)
{
	Evas_Object *btn;

	btn = util_add_button(priv->base, STYLE_BTN_PLAY_INFO, NULL);
	if (!btn) {
		_ERR("failed to add button");
		return false;
	}

	elm_object_part_content_set(priv->base, PART_DETAIL_PLAY_INFO, btn);

	inputmgr_add_callback(btn, DETAIL_PLAY_INFO, &_handler, priv);

	priv->btn = btn;

	return true;
}

static bool _draw_items(struct _priv *priv)
{
	if (!_draw_title_area(priv)) {
		_ERR("failed to draw title area");
		return false;
	}

	if (!_draw_thumbnail_area(priv)) {
		_ERR("failed to draw thumbnail area");
		return false;
	}

	if (!_draw_play_info(priv)) {
		_ERR("failed to draw play info");
		return false;
	}

	return true;
}

static Evas_Object *_create(Evas_Object *win, void *data)
{
	struct _priv *priv;
	Evas_Object *base;
	struct datamgr *dmgr;

	if (!win) {
		_ERR("failed to get win object");
		return NULL;
	}

	priv = calloc(1, sizeof(*priv));
	if (!priv) {
		_ERR("failed to allocate priv");
		return NULL;
	}

	base = elm_layout_add(win);
	if (!base) {
		_ERR("failed to create base object");
		free(priv);
		return NULL;
	}

	elm_layout_file_set(base, EDJEFILE, GRP_DETAIL_VIEW);

	evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND,
				EVAS_HINT_EXPAND);
	elm_win_resize_object_add(win, base);

	dmgr = datamgr_create(E_DATA_ALBUM, MUSIC_MEDIA_COND, E_SOURCE_ALL);
	if (!dmgr) {
		_ERR("failed to create datamgr");
		free(priv);
		return NULL;
	}

	priv->win = win;
	priv->base = base;
	priv->dmgr = dmgr;

	if (!_draw_items(priv)) {
		_ERR("failed to draw items");
		datamgr_destroy(dmgr);
		free(priv);
		return NULL;
	}

	viewmgr_set_view_data(VIEW_DETAIL, priv);

	return base;
}

static Eina_Bool _show_view(void *data)
{
	struct _priv *priv;

	if (!data)
		return ECORE_CALLBACK_CANCEL;

	priv = data;

	elm_object_signal_emit(priv->base, SIG_SHOW_VIEW, "");

	return ECORE_CALLBACK_CANCEL;
}

static void _show(void *view_data)
{
	struct _priv *priv;

	if (!view_data) {
		_ERR("failed to get view data");
		return;
	}

	priv = view_data;

	evas_object_show(priv->base);

	elm_object_focus_set(priv->grid, EINA_TRUE);

	ecore_timer_add(SHOW_VIEW_INTERVAL, _show_view, priv);
}

static void _hide(void *view_data)
{
	struct _priv *priv;

	if (!view_data) {
		_ERR("failed to get view data");
		return;
	}

	priv = view_data;

	evas_object_hide(priv->base);
	elm_object_signal_emit(priv->base, SIG_HIDE_VIEW, "");
}

static void _update(void *view_data, int update_type, void *data)
{
	struct _priv *priv;
	struct view_update_data *vdata;

	if (!view_data) {
		_ERR("failed to get view data");
		return;
	}

	if (!data) {
		_ERR("invalid argument");
		return;
	}

	priv = view_data;
	vdata = data;

	switch (update_type) {
	case UPDATE_CONTENT:
		priv->media_list = vdata->list;
		priv->view_type = vdata->index;

		priv->vinfo = &view_info[priv->view_type];

		_update_title_area(priv, vdata->id);
		_update_thumbnail_area(priv);
		_update_play_info(priv, NULL);

		break;
	case UPDATE_PLAY_INFO:
		_update_play_info(priv, vdata->id);
		break;
	case UPDATE_PLAYER:
		priv->status = vdata->status;
		_update_play_info(priv, NULL);
		break;
	default:
		break;
	}
}

static void _destroy(void *view_data)
{
	struct _priv *priv;

	if (!view_data) {
		_ERR("failed to get view data");
		return;
	}

	priv = view_data;

	_destroy_play_list(priv);
	app_media_destroy(priv->play_info);

	datamgr_destroy(priv->dmgr);

	evas_object_del(priv->base);

	free(priv);
}

static view_class _vclass = {
	.view_id = VIEW_DETAIL,
	.create = _create,
	.show = _show,
	.hide = _hide,
	.update = _update,
	.destroy = _destroy,
};

view_class *view_detail_get_vclass(void)
{
	return &_vclass;
}