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
|
#include "menudetailview.h"
#include "services/epgsearch.h"
#include <sstream>
#include <iostream>
#include <dirent.h>
#include <vector>
cNopacityMenuDetailView::cNopacityMenuDetailView(cOsd *osd) {
this->osd = osd;
hasScrollbar = false;
hasAdditionalMedia = false;
pixmapPoster = NULL;
}
cNopacityMenuDetailView::~cNopacityMenuDetailView(void) {
delete font;
if (fontSmall)
delete fontSmall;
if (fontHeader)
delete fontHeader;
if (fontHeaderLarge)
delete fontHeaderLarge;
}
void cNopacityMenuDetailView::SetGeometry(int x, int width, int height, int top, int contentBorder, int headerHeight) {
this->x = x;
this->width = width;
this->height = height;
this->top = top;
this->border = contentBorder;
this->headerHeight = headerHeight;
contentHeight = height - headerHeight;
widthPoster = 30 * width / 100;
}
void cNopacityMenuDetailView::DrawTextWrapper(cTextWrapper *wrapper, int top) {
int linesText = wrapper->Lines();
int textHeight = font->Height();
int currentHeight = top;
for (int i=0; i < linesText; i++) {
pixmapContent->DrawText(cPoint(border, currentHeight), wrapper->GetLine(i), Theme.Color(clrMenuFontDetailViewText), clrTransparent, font);
currentHeight += textHeight;
}
}
int cNopacityMenuDetailView::HeightActorPics(void) {
int numActors = mediaInfo.actors.size();
if (numActors < 1)
return 0;
if (mediaInfo.type == typeMovie) {
actorThumbWidth = mediaInfo.actors[0].thumb.width/2;
actorThumbHeight = mediaInfo.actors[0].thumb.height/2;
} else if (mediaInfo.type == typeSeries) {
actorThumbWidth = mediaInfo.actors[0].thumb.width/2;
actorThumbHeight = mediaInfo.actors[0].thumb.height/2;
}
int picsPerLine = contentWidth / (actorThumbWidth + 2*border);
int picLines = numActors / picsPerLine;
if (numActors%picsPerLine != 0)
picLines++;
int actorsHeight = picLines * (actorThumbHeight + 2*fontSmall->Height()) + font->Height() + fontHeader->Height();
return actorsHeight;
}
int cNopacityMenuDetailView::HeightFanart(void) {
int retVal = 0;
if (mediaInfo.fanart.size() >= 1) {
int fanartWidthOrig = mediaInfo.fanart[0].width;
int fanartHeightOrig = mediaInfo.fanart[0].height;
int fanartWidth = fanartWidthOrig;
int fanartHeight = fanartHeightOrig;
retVal = fanartHeight;
if (fanartWidthOrig > (contentWidth - 2*border)) {
fanartWidth = contentWidth - 2*border;
fanartHeight = fanartHeightOrig * ((double)fanartWidth / (double)fanartWidthOrig);
retVal = fanartHeight;
}
}
return retVal;
}
void cNopacityMenuDetailView::DrawPoster(void) {
if (mediaInfo.posters.size() < 1)
return;
int posterWidthOrig = mediaInfo.posters[0].width;
int posterHeightOrig = mediaInfo.posters[0].height;
int posterWidth = posterWidthOrig;
int posterHeight = posterHeightOrig;
if ((posterWidthOrig > widthPoster) && (posterHeightOrig < contentHeight)) {
posterWidth = widthPoster - 2*border;
posterHeight = posterHeightOrig * ((double)posterWidth / (double)posterWidthOrig);
} else if ((posterWidthOrig < widthPoster) && (posterHeightOrig > contentHeight)) {
posterHeight = contentHeight - 2*border;
posterWidth = posterWidthOrig * ((double)posterHeight / (double)posterHeightOrig);
} else if ((posterWidthOrig > widthPoster) && (posterHeightOrig > contentHeight)) {
int overlapWidth = posterWidthOrig - widthPoster;
int overlapHeight = posterHeightOrig - contentHeight;
if (overlapWidth >= overlapHeight) {
posterWidth = widthPoster - 2*border;
posterHeight = posterHeightOrig * ((double)posterWidth / (double)posterWidthOrig);
} else {
posterHeight = contentHeight - 2*border;
posterWidth = posterWidthOrig * ((double)posterHeight / (double)posterHeightOrig);
}
}
if (!Running())
return;
cImageLoader imgLoader;
if (imgLoader.LoadPoster(mediaInfo.posters[0].path.c_str(), posterWidth, posterHeight)) {
int posterX = (widthPoster - posterWidth) / 2;
int posterY = (contentHeight - posterHeight) / 2;
if (Running() && pixmapPoster)
pixmapPoster->DrawImage(cPoint(posterX, posterY), imgLoader.GetImage());
}
}
void cNopacityMenuDetailView::DrawBanner(int height) {
int bannerWidthOrig = mediaInfo.banner.width;
int bannerHeightOrig = mediaInfo.banner.height;
int bannerWidth = bannerWidthOrig;
int bannerHeight = bannerHeightOrig;
if (bannerWidthOrig > contentWidth - 2*border) {
bannerWidth = contentWidth - 2*border;
bannerHeight = bannerHeightOrig * ((double)bannerWidth / (double)bannerWidthOrig);
}
if (!Running())
return;
cImageLoader imgLoader;
if (imgLoader.LoadPoster(mediaInfo.banner.path.c_str(), bannerWidth, bannerHeight)) {
int bannerX = (contentWidth - bannerWidth) / 2;
if (Running() && pixmapContent)
pixmapContent->DrawImage(cPoint(bannerX, height), imgLoader.GetImage());
}
}
void cNopacityMenuDetailView::DrawActors(int height) {
int numActors = mediaInfo.actors.size();
if (numActors < 1)
return;
cString header = cString::sprintf("%s:", tr("Actors"));
pixmapContent->DrawText(cPoint(border, height), *header, Theme.Color(clrMenuFontDetailViewText), clrTransparent, fontHeader);
int picsPerLine = contentWidth / (actorThumbWidth + 2*border);
int picLines = numActors / picsPerLine;
if (numActors%picsPerLine != 0)
picLines++;
int x = 0;
int y = height + fontHeader->Height();
if (!Running())
return;
cImageLoader imgLoader;
int actor = 0;
for (int row = 0; row < picLines; row++) {
for (int col = 0; col < picsPerLine; col++) {
if (!Running())
return;
if (actor == numActors)
break;
std::string path = mediaInfo.actors[actor].thumb.path;
if (imgLoader.LoadPoster(path.c_str(), actorThumbWidth, actorThumbHeight)) {
if (Running() && pixmapContent)
pixmapContent->DrawImage(cPoint(x + border, y), imgLoader.GetImage());
}
std::string name = mediaInfo.actors[actor].name;
std::stringstream sstrRole;
sstrRole << "\"" << mediaInfo.actors[actor].role << "\"";
std::string role = sstrRole.str();
if (fontSmall->Width(name.c_str()) > actorThumbWidth + 2*border)
name = CutText(name, actorThumbWidth + 2*border, fontSmall);
if (fontSmall->Width(role.c_str()) > actorThumbWidth + 2*border)
role = CutText(role, actorThumbWidth + 2*border, fontSmall);
int xName = x + ((actorThumbWidth+2*border) - fontSmall->Width(name.c_str()))/2;
int xRole = x + ((actorThumbWidth+2*border) - fontSmall->Width(role.c_str()))/2;
if (Running() && pixmapContent) {
pixmapContent->DrawText(cPoint(xName, y + actorThumbHeight), name.c_str(), Theme.Color(clrMenuFontDetailViewText), clrTransparent, fontSmall);
pixmapContent->DrawText(cPoint(xRole, y + actorThumbHeight + fontSmall->Height()), role.c_str(), Theme.Color(clrMenuFontDetailViewText), clrTransparent, fontSmall);
x += actorThumbWidth + 2*border;
}
actor++;
}
x = 0;
y += actorThumbHeight + 2 * fontSmall->Height();
}
}
void cNopacityMenuDetailView::DrawFanart(int height) {
if (mediaInfo.fanart.size() < 1)
return;
int fanartWidthOrig = mediaInfo.fanart[0].width;
int fanartHeightOrig = mediaInfo.fanart[0].height;
int fanartWidth = fanartWidthOrig;
int fanartHeight = fanartHeightOrig;
if (fanartWidthOrig > contentWidth - 2*border) {
fanartWidth = contentWidth - 2*border;
fanartHeight = fanartHeightOrig * ((double)fanartWidth / (double)fanartWidthOrig);
}
if (!Running())
return;
cImageLoader imgLoader;
if (imgLoader.LoadPoster(mediaInfo.fanart[0].path.c_str(), fanartWidth, fanartHeight)) {
int fanartX = (contentWidth - fanartWidth) / 2;
if (Running() && pixmapContent)
pixmapContent->DrawImage(cPoint(fanartX, height), imgLoader.GetImage());
}
}
double cNopacityMenuDetailView::ScrollbarSize(void) {
double barSize = (double)contentHeight / (double)contentDrawPortHeight;
return barSize;
}
double cNopacityMenuDetailView::Offset(void) {
double offset;
if (((-1)*pixmapContent->DrawPort().Point().Y() + contentHeight + font->Height()) > contentDrawPortHeight)
offset = (double)1 - ScrollbarSize();
else
offset = (double)((-1)*pixmapContent->DrawPort().Point().Y())/(double)((-1)*pixmapContent->DrawPort().Point().Y() + contentHeight);
return offset;
}
bool cNopacityMenuDetailView::Scroll(bool Up, bool Page) {
int aktHeight = pixmapContent->DrawPort().Point().Y();
int totalHeight = pixmapContent->DrawPort().Height();
int screenHeight = pixmapContent->ViewPort().Height();
int lineHeight = font->Height();
bool scrolled = false;
if (Up) {
if (Page) {
int newY = aktHeight + screenHeight;
if (newY > 0)
newY = 0;
pixmapContent->SetDrawPortPoint(cPoint(0, newY));
scrolled = true;
} else {
if (aktHeight < 0) {
pixmapContent->SetDrawPortPoint(cPoint(0, aktHeight + lineHeight));
scrolled = true;
}
}
} else {
if (Page) {
int newY = aktHeight - screenHeight;
if ((-1)*newY > totalHeight - screenHeight)
newY = (-1)*(totalHeight - screenHeight);
pixmapContent->SetDrawPortPoint(cPoint(0, newY));
scrolled = true;
} else {
if (totalHeight - ((-1)*aktHeight + lineHeight) > screenHeight) {
pixmapContent->SetDrawPortPoint(cPoint(0, aktHeight - lineHeight));
scrolled = true;
}
}
}
return scrolled;
}
//---------------cNopacityMenuDetailEventView---------------------
cNopacityMenuDetailEventView::cNopacityMenuDetailEventView(cOsd *osd, const cEvent *Event) : cNopacityMenuDetailView(osd) {
event = Event;
numEPGPics = 0;
}
cNopacityMenuDetailEventView::~cNopacityMenuDetailEventView(void) {
Cancel(-1);
while (Active())
cCondWait::SleepMs(10);
osd->DestroyPixmap(pixmapHeader);
pixmapHeader = NULL;
osd->DestroyPixmap(pixmapContent);
pixmapContent = NULL;
osd->DestroyPixmap(pixmapLogo);
pixmapLogo = NULL;
if (pixmapPoster) {
osd->DestroyPixmap(pixmapPoster);
pixmapLogo = NULL;
}
}
void cNopacityMenuDetailEventView::SetFonts(void) {
font = cFont::CreateFont(config.fontName, contentHeight / 25 + 3 + config.fontDetailView);
fontSmall = cFont::CreateFont(config.fontName, contentHeight / 30 + config.fontDetailViewSmall);
fontHeaderLarge = cFont::CreateFont(config.fontName, headerHeight / 4 + config.fontDetailViewHeaderLarge);
fontHeader = cFont::CreateFont(config.fontName, headerHeight / 6 + config.fontDetailViewHeader);
}
void cNopacityMenuDetailEventView::SetContent(void) {
if (event) {
static cPlugin *pTVScraper = cPluginManager::GetPlugin("tvscraper");
if (pTVScraper) {
mediaInfo.event = event;
mediaInfo.isRecording = false;
if (pTVScraper->Service("TVScraperGetFullInformation", &mediaInfo)) {
hasAdditionalMedia = true;
}
}
contentWidth = width;
contentX = 0;
if (hasAdditionalMedia) {
if (mediaInfo.posters.size() >= 1) {
contentWidth -= widthPoster;
contentX = widthPoster;
}
}
epgText.Set(event->Description(), font, contentWidth - 2 * border);
if (config.displayRerunsDetailEPGView) {
LoadReruns();
}
}
}
void cNopacityMenuDetailEventView::SetContentHeight(void) {
int lineHeight = font->Height();
//Height of banner (only for series)
int heightBanner = 0;
if (hasAdditionalMedia && (mediaInfo.type == typeSeries)) {
heightBanner = mediaInfo.banner.height + lineHeight;
}
//Height of EPG Text
int heightEPG = (epgText.Lines()+1) * lineHeight;
//Height of rerun information
int heightReruns = 0;
if (config.displayRerunsDetailEPGView) {
heightReruns = reruns.Lines() * lineHeight;
}
//Height of actor pictures
int heightActors = 0;
if (hasAdditionalMedia) {
heightActors = HeightActorPics();
}
//Height of fanart
int heightFanart = 0;
if (hasAdditionalMedia) {
heightFanart = HeightFanart() + lineHeight;
}
//Height of EPG Pictures
int heightEPGPics = 0;
if ((config.displayAdditionalEPGPictures == 1) || ((config.displayAdditionalEPGPictures == 2) && !hasAdditionalMedia)) {
heightEPGPics = HeightEPGPics();
}
yBanner = 0;
yEPGText = heightBanner;
yActors = heightBanner + heightEPG;
yFanart = heightBanner + heightEPG + heightActors;
yAddInf = heightBanner + heightEPG + heightActors + heightFanart;
yEPGPics = heightBanner + heightEPG + heightActors + heightFanart + heightReruns;
int totalHeight = heightBanner + heightEPG + heightActors + heightFanart + heightReruns + heightEPGPics;
//check if pixmap content has to be scrollable
if (totalHeight > contentHeight) {
contentDrawPortHeight = totalHeight;
hasScrollbar = true;
} else {
contentDrawPortHeight = contentHeight;
}
}
void cNopacityMenuDetailEventView::CreatePixmaps(void) {
pixmapHeader = osd->CreatePixmap(3, cRect(x, top, width, headerHeight));
pixmapContent = osd->CreatePixmap(3, cRect(x + contentX, top + headerHeight, contentWidth, contentHeight),
cRect(0, 0, contentWidth, contentDrawPortHeight));
pixmapLogo = osd->CreatePixmap(4, cRect(x + border, top + max((headerHeight-config.logoHeight)/2,1), config.detailViewLogoWidth, config.detailViewLogoHeight));
pixmapHeader->Fill(clrTransparent);
pixmapHeader->DrawRectangle(cRect(0, headerHeight - 2, width, 2), Theme.Color(clrMenuBorder));
pixmapContent->Fill(clrTransparent);
pixmapLogo->Fill(clrTransparent);
if (hasAdditionalMedia) {
pixmapPoster = osd->CreatePixmap(4, cRect(x, top + headerHeight, widthPoster, contentHeight));
pixmapPoster->Fill(clrTransparent);
}
}
void cNopacityMenuDetailEventView::Render(void) {
DrawHeader();
//draw EPG text
DrawTextWrapper(&epgText, yEPGText);
//draw reruns
if (config.displayRerunsDetailEPGView) {
DrawTextWrapper(&reruns, yAddInf);
}
}
void cNopacityMenuDetailEventView::Action(void) {
if (hasAdditionalMedia && Running()) {
DrawPoster();
osd->Flush();
}
//draw banner only for series
if (hasAdditionalMedia && (mediaInfo.type == typeSeries) && Running()) {
DrawBanner(yBanner);
osd->Flush();
}
//draw actors
if (hasAdditionalMedia && Running()) {
DrawActors(yActors);
osd->Flush();
}
//draw fanart
if (hasAdditionalMedia && Running()) {
DrawFanart(yFanart);
osd->Flush();
}
//draw additional EPG Pictures
if (((config.displayAdditionalEPGPictures == 1) || ((config.displayAdditionalEPGPictures == 2) && !hasAdditionalMedia)) && Running()) {
DrawEPGPictures(yEPGPics);
osd->Flush();
}
}
int cNopacityMenuDetailEventView::HeightEPGPics(void) {
int numPicsAvailable = 0;
for (int i=1; i <= config.numAdditionalEPGPictures; i++) {
cString epgimage;
if (config.epgImagePathSet) {
epgimage = cString::sprintf("%s%d_%d.jpg", *config.epgImagePath, event->EventID(), i);
} else {
epgimage = cString::sprintf("%s%d_%d.jpg", *config.epgImagePathDefault, event->EventID(), i);
}
FILE *fp = fopen(*epgimage, "r");
if (fp) {
numPicsAvailable = i;
fclose(fp);
} else {
break;
}
}
numEPGPics = numPicsAvailable;
int picsPerLine = contentWidth / (config.epgImageWidthLarge + border);
int picLines = numPicsAvailable / picsPerLine;
if (numPicsAvailable%picsPerLine != 0)
picLines++;
return picLines * (config.epgImageHeightLarge + border) + 2*border;
}
void cNopacityMenuDetailEventView::DrawHeader(void) {
cImageLoader imgLoader;
int logoWidth = config.detailViewLogoWidth;
cChannel *channel = Channels.GetByChannelID(event->ChannelID(), true);
if (channel && channel->Name() && imgLoader.LoadLogo(channel->Name(), logoWidth, config.detailViewLogoHeight)) {
pixmapLogo->DrawImage(cPoint(0, max((headerHeight - config.detailViewLogoHeight - border)/2, 0)), imgLoader.GetImage());
} else if (channel && imgLoader.LoadLogo(*(channel->GetChannelID().ToString()), logoWidth, config.detailViewLogoHeight)) {
pixmapLogo->DrawImage(cPoint(0, max((headerHeight - config.detailViewLogoHeight - border)/2, 0)), imgLoader.GetImage());
}
int widthTextHeader = width - 4 * border - logoWidth;
if (imgLoader.LoadEPGImage(event->EventID())) {
pixmapHeader->DrawImage(cPoint(width - config.epgImageWidth - border, (headerHeight-config.epgImageHeight)/2), imgLoader.GetImage());
if (config.roundedCorners) {
int radius = config.cornerRadius;
if (radius > 2) {
int x = width - config.epgImageWidth - border;
int y = (headerHeight-config.epgImageHeight)/2;
pixmapHeader->DrawEllipse(cRect(x,y,radius,radius), clrTransparent, -2);
pixmapHeader->DrawEllipse(cRect(x + config.epgImageWidth - radius,y,radius,radius), clrTransparent, -1);
pixmapHeader->DrawEllipse(cRect(x,y + config.epgImageHeight - radius,radius,radius), clrTransparent, -3);
pixmapHeader->DrawEllipse(cRect(x + config.epgImageWidth - radius,y + config.epgImageHeight - radius,radius,radius), clrTransparent, -4);
}
}
widthTextHeader -= config.epgImageWidth;
}
int lineHeight = fontHeaderLarge->Height();
cString dateTime = cString::sprintf("%s %s - %s", *event->GetDateString(), *event->GetTimeString(), *event->GetEndTimeString());
pixmapHeader->DrawText(cPoint(logoWidth + 2*border, (lineHeight - fontHeader->Height())/2), *dateTime, Theme.Color(clrMenuFontDetailViewHeader), clrTransparent, fontHeader);
cTextWrapper title;
title.Set(event->Title(), fontHeaderLarge, widthTextHeader);
int currentLineHeight = lineHeight;
for (int i=0; i < title.Lines(); i++) {
pixmapHeader->DrawText(cPoint(logoWidth + 2*border, currentLineHeight), title.GetLine(i), Theme.Color(clrMenuFontDetailViewHeaderTitle), clrTransparent, fontHeaderLarge);
currentLineHeight += lineHeight;
}
cTextWrapper shortText;
shortText.Set(event->ShortText(), fontHeader, widthTextHeader);
currentLineHeight += (lineHeight - fontHeader->Height())/2;
for (int i=0; i < shortText.Lines(); i++) {
if ((currentLineHeight + fontHeader->Height()) < headerHeight) {
pixmapHeader->DrawText(cPoint(logoWidth + 2*border, currentLineHeight), shortText.GetLine(i), Theme.Color(clrMenuFontDetailViewHeader), clrTransparent, fontHeader);
currentLineHeight += fontHeader->Height();
} else
break;
}
}
void cNopacityMenuDetailEventView::LoadReruns(void) {
cPlugin *epgSearchPlugin = cPluginManager::GetPlugin("epgsearch");
if (epgSearchPlugin && !isempty(event->Title())) {
std::stringstream sstrReruns;
Epgsearch_searchresults_v1_0 data;
std::string strQuery = event->Title();
if (config.useSubtitleRerun > 0) {
if (config.useSubtitleRerun == 2 || !isempty(event->ShortText()))
strQuery += "~";
if (!isempty(event->ShortText()))
strQuery += event->ShortText();
data.useSubTitle = true;
} else {
data.useSubTitle = false;
}
data.query = (char *)strQuery.c_str();
data.mode = 0;
data.channelNr = 0;
data.useTitle = true;
data.useDescription = false;
if (epgSearchPlugin->Service("Epgsearch-searchresults-v1.0", &data)) {
cList<Epgsearch_searchresults_v1_0::cServiceSearchResult>* list = data.pResultList;
if (list && (list->Count() > 1)) {
sstrReruns << tr("RERUNS OF THIS SHOW") << ':' << std::endl;
int i = 0;
for (Epgsearch_searchresults_v1_0::cServiceSearchResult *r = list->First(); r && i < config.numReruns; r = list->Next(r)) {
if ((event->ChannelID() == r->event->ChannelID()) && (event->StartTime() == r->event->StartTime()))
continue;
i++;
sstrReruns << "- "
<< *DayDateTime(r->event->StartTime());
cChannel *channel = Channels.GetByChannelID(r->event->ChannelID(), true, true);
if (channel) {
sstrReruns << ", " << channel->Number() << ".";
sstrReruns << " " << channel->ShortName(true);
}
sstrReruns << ": " << r->event->Title();
if (!isempty(r->event->ShortText()))
sstrReruns << "~" << r->event->ShortText();
sstrReruns << std::endl;
}
delete list;
}
}
reruns.Set(sstrReruns.str().c_str(), font, contentWidth - 4 * border);
} else
reruns.Set("", font, contentWidth);
}
void cNopacityMenuDetailEventView::DrawEPGPictures(int height) {
int picsPerLine = contentWidth / (config.epgImageWidthLarge + border);
int currentX = border;
int currentY = height + border;
int currentPicsPerLine = 1;
cImageLoader imgLoader;
for (int i=1; i <= numEPGPics; i++) {
cString epgimage = cString::sprintf("%d_%d", event->EventID(), i);
if (imgLoader.LoadAdditionalEPGImage(epgimage)) {
pixmapContent->DrawImage(cPoint(currentX, currentY), imgLoader.GetImage());
if (config.roundedCorners) {
int radius = config.cornerRadius;
if (radius > 2) {
pixmapContent->DrawEllipse(cRect(currentX,currentY,radius,radius), clrTransparent, -2);
pixmapContent->DrawEllipse(cRect(currentX + config.epgImageWidthLarge - radius,currentY,radius,radius), clrTransparent, -1);
pixmapContent->DrawEllipse(cRect(currentX,currentY + config.epgImageHeightLarge - radius,radius,radius), clrTransparent, -3);
pixmapContent->DrawEllipse(cRect(currentX + config.epgImageWidthLarge - radius,currentY + config.epgImageHeightLarge - radius,radius,radius), clrTransparent, -4);
}
}
if (currentPicsPerLine < picsPerLine) {
currentX += config.epgImageWidthLarge + border;
currentPicsPerLine++;
} else {
currentX = border;
currentY += config.epgImageHeightLarge + border;
currentPicsPerLine = 1;
}
} else {
break;
}
}
}
//------------------cNopacityMenuDetailRecordingView------------------
cNopacityMenuDetailRecordingView::cNopacityMenuDetailRecordingView(cOsd *osd, const cRecording *Recording) : cNopacityMenuDetailView(osd) {
recording = Recording;
info = Recording->Info();
}
cNopacityMenuDetailRecordingView::~cNopacityMenuDetailRecordingView(void) {
Cancel(-1);
while (Active())
cCondWait::SleepMs(10);
osd->DestroyPixmap(pixmapHeader);
pixmapHeader = NULL;
osd->DestroyPixmap(pixmapContent);
pixmapContent = NULL;
if (pixmapPoster) {
osd->DestroyPixmap(pixmapPoster);
pixmapLogo = NULL;
}
}
void cNopacityMenuDetailRecordingView::SetFonts(void) {
font = cFont::CreateFont(config.fontName, contentHeight / 25 + config.fontDetailView);
fontSmall = cFont::CreateFont(config.fontName, contentHeight / 30 + config.fontDetailViewSmall);
fontHeaderLarge = cFont::CreateFont(config.fontName, headerHeight / 4 + config.fontDetailViewHeaderLarge);
fontHeader = cFont::CreateFont(config.fontName, headerHeight / 6 + config.fontDetailViewHeader);
}
void cNopacityMenuDetailRecordingView::SetContent(void) {
if (recording) {
const cEvent *event = info->GetEvent();
if (event) {
static cPlugin *pTVScraper = cPluginManager::GetPlugin("tvscraper");
if (pTVScraper) {
mediaInfo.event = event;
mediaInfo.isRecording = true;
if (pTVScraper->Service("TVScraperGetFullInformation", &mediaInfo)) {
hasAdditionalMedia = true;
}
}
contentWidth = width;
contentX = 0;
if (hasAdditionalMedia) {
if (mediaInfo.posters.size() >= 1) {
contentWidth -= widthPoster;
contentX = widthPoster;
}
}
}
recInfo.Set(recording->Info()->Description(), font, contentWidth - 2 * border);
LoadRecordingInformation();
}
}
void cNopacityMenuDetailRecordingView::SetContentHeight(void) {
int lineHeight = font->Height();
//Height of banner (only for series)
int heightBanner = 0;
if (hasAdditionalMedia && (mediaInfo.type == typeSeries)) {
heightBanner = mediaInfo.banner.height + lineHeight;
}
//Height of Recording EPG Info
int heightEPG = (recInfo.Lines()+1) * lineHeight;
//Height of actor pictures
int heightActors = 0;
if (hasAdditionalMedia) {
heightActors = HeightActorPics();
}
//Height of fanart
int heightFanart = 0;
if (hasAdditionalMedia) {
heightFanart = HeightFanart() + lineHeight;
}
//Height of EPG Pictures
int heightEPGPics = 0;
if ((config.displayAdditionalRecEPGPictures == 1) || ((config.displayAdditionalRecEPGPictures == 2) && !hasAdditionalMedia)) {
if (LoadEPGPics())
heightEPGPics = HeightEPGPics();
}
//additional recording Info
int heightAdditionalInfo = (additionalInfo.Lines() + 1) * lineHeight;
yBanner = 0;
yEPGText = heightBanner;
yActors = heightBanner + heightEPG;
yFanart = heightBanner + heightEPG + heightActors;
yEPGPics = heightBanner + heightEPG + heightActors + heightFanart;
yAddInf = heightBanner + heightEPG + heightActors + heightFanart + heightEPGPics;
int totalHeight = heightBanner + heightEPG + heightActors + heightFanart + heightAdditionalInfo + heightEPGPics;
//check if pixmap content has to be scrollable
if (totalHeight > contentHeight) {
contentDrawPortHeight = totalHeight;
hasScrollbar = true;
} else {
contentDrawPortHeight = contentHeight;
}
}
void cNopacityMenuDetailRecordingView::CreatePixmaps(void) {
pixmapHeader = osd->CreatePixmap(3, cRect(x, top, width, headerHeight));
pixmapContent = osd->CreatePixmap(3, cRect(x + contentX, top + headerHeight, contentWidth, contentHeight),
cRect(0, 0, contentWidth, contentDrawPortHeight));
pixmapHeader->Fill(clrTransparent);
pixmapHeader->DrawRectangle(cRect(0, headerHeight - 2, width, 2), Theme.Color(clrMenuBorder));
pixmapContent->Fill(clrTransparent);
if (hasAdditionalMedia) {
pixmapPoster = osd->CreatePixmap(4, cRect(x, top + headerHeight, widthPoster, contentHeight));
pixmapPoster->Fill(clrTransparent);
}
}
void cNopacityMenuDetailRecordingView::Render(void) {
DrawHeader();
//draw Recording EPG text
DrawTextWrapper(&recInfo, yEPGText);
//draw additional Info
if (config.displayRerunsDetailEPGView) {
DrawTextWrapper(&additionalInfo, yAddInf);
}
}
void cNopacityMenuDetailRecordingView::Action(void) {
if (hasAdditionalMedia && Running()) {
DrawPoster();
osd->Flush();
}
//draw banner only for series
if (hasAdditionalMedia && (mediaInfo.type == typeSeries) && Running()) {
DrawBanner(yBanner);
osd->Flush();
}
//draw actors
if (hasAdditionalMedia && Running()) {
DrawActors(yActors);
osd->Flush();
}
//draw fanart
if (hasAdditionalMedia && Running()) {
DrawFanart(yFanart);
osd->Flush();
}
//draw additional EPG Pictures
if (((config.displayAdditionalRecEPGPictures == 1) || ((config.displayAdditionalRecEPGPictures == 2) && !hasAdditionalMedia)) && Running()) {
DrawEPGPictures(yEPGPics);
osd->Flush();
}
}
bool cNopacityMenuDetailRecordingView::LoadEPGPics(void) {
DIR *dirHandle;
struct dirent *dirEntry;
dirHandle = opendir(recording->FileName());
int picsFound = 0;
if (dirHandle != NULL) {
while ( 0 != (dirEntry = readdir(dirHandle))) {
if (endswith(dirEntry->d_name, "jpg")) {
std::string fileName = dirEntry->d_name;
if (fileName.length() > 4) {
fileName = fileName.substr(0, fileName.length() - 4);
epgpics.push_back(fileName);
picsFound++;
}
}
if (picsFound >= config.numAdditionalRecEPGPictures)
break;
}
closedir(dirHandle);
}
if (picsFound > 0)
return true;
return false;
}
int cNopacityMenuDetailRecordingView::HeightEPGPics(void) {
int numPicsAvailable = epgpics.size();
int picsPerLine = contentWidth / (config.epgImageWidthLarge + border);
int picLines = numPicsAvailable / picsPerLine;
if (numPicsAvailable%picsPerLine != 0)
picLines++;
return picLines * (config.epgImageHeightLarge + border) + 2*border;
}
void cNopacityMenuDetailRecordingView::DrawEPGPictures(int height) {
int picsPerLine = contentWidth / (config.epgImageWidthLarge + border);
int currentX = border;
int currentY = height + border;
int currentPicsPerLine = 1;
cImageLoader imgLoader;
for (unsigned i=0; i < epgpics.size(); i++) {
cString path = cString::sprintf("%s/", recording->FileName());
cString epgimage = epgpics.at(i).c_str();
if (imgLoader.LoadAdditionalRecordingImage(path, epgimage)) {
pixmapContent->DrawImage(cPoint(currentX, currentY), imgLoader.GetImage());
if (config.roundedCorners) {
int radius = config.cornerRadius;
if (radius > 2) {
pixmapContent->DrawEllipse(cRect(currentX,currentY,radius,radius), clrTransparent, -2);
pixmapContent->DrawEllipse(cRect(currentX + config.epgImageWidthLarge - radius,currentY,radius,radius), clrTransparent, -1);
pixmapContent->DrawEllipse(cRect(currentX,currentY + config.epgImageHeightLarge - radius,radius,radius), clrTransparent, -3);
pixmapContent->DrawEllipse(cRect(currentX + config.epgImageWidthLarge - radius,currentY + config.epgImageHeightLarge - radius,radius,radius), clrTransparent, -4);
}
}
if (currentPicsPerLine < picsPerLine) {
currentX += config.epgImageWidthLarge + border;
currentPicsPerLine++;
} else {
currentX = border;
currentY += config.epgImageHeightLarge + border;
currentPicsPerLine = 1;
}
} else {
break;
}
}
}
void cNopacityMenuDetailRecordingView::DrawHeader(void) {
cImageLoader imgLoader;
int widthTextHeader = width - 4 * border;
if (imgLoader.LoadRecordingImage(recording->FileName())) {
pixmapHeader->DrawImage(cPoint(width - config.epgImageWidth - border, (headerHeight-config.epgImageHeight)/2), imgLoader.GetImage());
if (config.roundedCorners) {
int radius = config.cornerRadius;
int x = width - config.epgImageWidth - border;
int y = (headerHeight-config.epgImageHeight)/2;
if (radius > 2) {
pixmapHeader->DrawEllipse(cRect(x,y,radius,radius), clrTransparent, -2);
pixmapHeader->DrawEllipse(cRect(x + config.epgImageWidth - radius,y,radius,radius), clrTransparent, -1);
pixmapHeader->DrawEllipse(cRect(x,y + config.epgImageHeight - radius,radius,radius), clrTransparent, -3);
pixmapHeader->DrawEllipse(cRect(x + config.epgImageWidth - radius,y + config.epgImageHeight - radius,radius,radius), clrTransparent, -4);
}
}
widthTextHeader -= config.epgImageWidth;
}
int lineHeight = fontHeaderLarge->Height();
cString dateTime = cString::sprintf("%s %s", *DateString(recording->Start()), *TimeString(recording->Start()));
pixmapHeader->DrawText(cPoint(2*border, (lineHeight - fontHeader->Height())/2), *dateTime, Theme.Color(clrMenuFontDetailViewHeader), clrTransparent, fontHeader);
const char *Title = info->Title();
if (isempty(Title))
Title = recording->Name();
cTextWrapper title;
title.Set(Title, fontHeaderLarge, widthTextHeader);
int currentLineHeight = lineHeight;
for (int i=0; i < title.Lines(); i++) {
pixmapHeader->DrawText(cPoint(2*border, currentLineHeight), title.GetLine(i), Theme.Color(clrMenuFontDetailViewHeaderTitle), clrTransparent, fontHeaderLarge);
currentLineHeight += lineHeight;
}
if (!isempty(info->ShortText())) {
cTextWrapper shortText;
shortText.Set(info->ShortText(), fontHeader, widthTextHeader);
for (int i=0; i < shortText.Lines(); i++) {
if ((currentLineHeight + fontHeader->Height()) < headerHeight) {
pixmapHeader->DrawText(cPoint(2*border, currentLineHeight), shortText.GetLine(i), Theme.Color(clrMenuFontDetailViewHeader), clrTransparent, fontHeader);
currentLineHeight += fontHeader->Height();
} else
break;
}
}
}
void cNopacityMenuDetailRecordingView::LoadRecordingInformation(void) {
const cRecordingInfo *Info = recording->Info();
unsigned long long nRecSize = -1;
unsigned long long nFileSize[1000];
nFileSize[0] = 0;
int i = 0;
struct stat filebuf;
cString filename;
int rc = 0;
do {
if (recording->IsPesRecording())
filename = cString::sprintf("%s/%03d.vdr", recording->FileName(), ++i);
else
filename = cString::sprintf("%s/%05d.ts", recording->FileName(), ++i);
rc = stat(filename, &filebuf);
if (rc == 0)
nFileSize[i] = nFileSize[i-1] + filebuf.st_size;
else
if (ENOENT != errno) {
nRecSize = -1;
}
} while (i <= 999 && !rc);
nRecSize = nFileSize[i-1];
cMarks marks;
bool fHasMarks = marks.Load(recording->FileName(), recording->FramesPerSecond(), recording->IsPesRecording()) && marks.Count();
cIndexFile *index = new cIndexFile(recording->FileName(), false, recording->IsPesRecording());
int nCutLength = 0;
long nCutInFrame = 0;
unsigned long long nRecSizeCut = nRecSize < 0 ? -1 : 0;
unsigned long long nCutInOffset = 0;
if (fHasMarks && index) {
uint16_t FileNumber;
off_t FileOffset;
bool fCutIn = true;
cMark *mark = marks.First();
while (mark) {
int pos = mark->Position();
index->Get(pos, &FileNumber, &FileOffset); //TODO: will disc spin up?
if (fCutIn) {
nCutInFrame = pos;
fCutIn = false;
if (nRecSize >= 0)
nCutInOffset = nFileSize[FileNumber-1] + FileOffset;
} else {
nCutLength += pos - nCutInFrame;
fCutIn = true;
if (nRecSize >= 0)
nRecSizeCut += nFileSize[FileNumber-1] + FileOffset - nCutInOffset;
}
cMark *nextmark = marks.Next(mark);
mark = nextmark;
}
if (!fCutIn) {
nCutLength += index->Last() - nCutInFrame;
index->Get(index->Last() - 1, &FileNumber, &FileOffset);
if (nRecSize >= 0)
nRecSizeCut += nFileSize[FileNumber-1] + FileOffset - nCutInOffset;
}
}
std::stringstream sstrInfo;
cChannel *channel = Channels.GetByChannelID(Info->ChannelID());
if (channel)
sstrInfo << trVDR("Channel") << ": " << channel->Number() << " - " << channel->Name() << std::endl;
if (nRecSize < 0) {
if ((nRecSize = ReadSizeVdr(recording->FileName())) < 0) {
nRecSize = DirSizeMB(recording->FileName());
}
}
if (nRecSize >= 0) {
cString strRecSize = "";
if (fHasMarks) {
if (nRecSize > MEGABYTE(1023))
strRecSize = cString::sprintf("%s: %.2f GB (%s: %.2f GB)", tr("Size"), (float)nRecSize / MEGABYTE(1024), tr("cut"), (float)nRecSizeCut / MEGABYTE(1024));
else
strRecSize = cString::sprintf("%s: %lld MB (%s: %lld MB)", tr("Size"), nRecSize / MEGABYTE(1), tr("cut"), nRecSizeCut / MEGABYTE(1));
} else {
if (nRecSize > MEGABYTE(1023))
strRecSize = cString::sprintf("%s: %.2f GB", tr("Size"), (float)nRecSize / MEGABYTE(1024));
else
strRecSize = cString::sprintf("%s: %lld MB", tr("Size"), nRecSize / MEGABYTE(1));
}
sstrInfo << (const char*)strRecSize << std::endl;
}
if (index) {
int nLastIndex = index->Last();
if (nLastIndex) {
cString strLength;
if (fHasMarks) {
strLength = cString::sprintf("%s: %s (%s %s)", tr("Length"), *IndexToHMSF(nLastIndex, false, recording->FramesPerSecond()), tr("cut"), *IndexToHMSF(nCutLength, false, recording->FramesPerSecond()));
} else {
strLength = cString::sprintf("%s: %s", tr("Length"), *IndexToHMSF(nLastIndex, false, recording->FramesPerSecond()));
}
sstrInfo << (const char*)strLength << std::endl;
cString strBitrate = cString::sprintf("%s: %s\n%s: %.2f MBit/s (Video+Audio)", tr("Format"), recording->IsPesRecording() ? "PES" : "TS", tr("Est. bitrate"), (float)nRecSize / nLastIndex * recording->FramesPerSecond() * 8 / MEGABYTE(1));
sstrInfo << (const char*)strBitrate << std::endl;
}
}
delete index;
if (Info) {
const char *aux = NULL;
aux = Info->Aux();
if (aux) {
std::string strAux = aux;
std::string auxEpgsearch = StripXmlTag(strAux, "epgsearch");
if (!auxEpgsearch.empty()) {
std::string searchTimer = StripXmlTag(auxEpgsearch, "searchtimer");
if (!searchTimer.empty()) {
sstrInfo << tr("Search timer") << ": " << searchTimer << std::endl;
}
}
}
}
additionalInfo.Set(sstrInfo.str().c_str(), font, width - 4 * border);
}
std::string cNopacityMenuDetailRecordingView::StripXmlTag(std::string &Line, const char *Tag) {
// set the search strings
std::stringstream strStart, strStop;
strStart << "<" << Tag << ">";
strStop << "</" << Tag << ">";
// find the strings
std::string::size_type locStart = Line.find(strStart.str());
std::string::size_type locStop = Line.find(strStop.str());
if (locStart == std::string::npos || locStop == std::string::npos)
return "";
// extract relevant text
int pos = locStart + strStart.str().size();
int len = locStop - pos;
return len < 0 ? "" : Line.substr(pos, len);
}
int cNopacityMenuDetailRecordingView::ReadSizeVdr(const char *strPath) {
int dirSize = -1;
char buffer[20];
char *strFilename = NULL;
if (-1 != asprintf(&strFilename, "%s/size.vdr", strPath)) {
struct stat st;
if (stat(strFilename, &st) == 0) {
int fd = open(strFilename, O_RDONLY);
if (fd >= 0) {
if (safe_read(fd, &buffer, sizeof(buffer)) >= 0) {
dirSize = atoi(buffer);
}
close(fd);
}
}
free(strFilename);
}
return dirSize;
}
//---------------cNopacityMenuDetailTextView---------------------
cNopacityMenuDetailTextView::cNopacityMenuDetailTextView(cOsd *osd, const char *text) : cNopacityMenuDetailView(osd) {
this->text = text;
}
cNopacityMenuDetailTextView::~cNopacityMenuDetailTextView(void) {
osd->DestroyPixmap(pixmapContent);
}
void cNopacityMenuDetailTextView::SetFonts(void) {
font = cFont::CreateFont(config.fontName, contentHeight / 25 + config.fontDetailView);
fontSmall = NULL;
fontHeaderLarge = NULL;
fontHeader = NULL;
}
void cNopacityMenuDetailTextView::SetContent(void) {
content.Set(text, font, width - 4 * border);
}
void cNopacityMenuDetailTextView::SetContentHeight(void) {
int lineHeight = font->Height();
int linesContent = content.Lines() + 1;
int heightContentText = linesContent * lineHeight;
if (heightContentText > contentHeight) {
contentDrawPortHeight = heightContentText;
hasScrollbar = true;
} else {
contentDrawPortHeight = contentHeight;
}
}
void cNopacityMenuDetailTextView::CreatePixmaps(void) {
pixmapContent = osd->CreatePixmap(3, cRect(x, top + headerHeight, width, contentHeight),
cRect(0, 0, width, contentDrawPortHeight));
pixmapContent->Fill(clrTransparent);
}
void cNopacityMenuDetailTextView::Render(void) {
DrawTextWrapper(&content, 0);
}
|