]> git.vomp.tv Git - vompclient.git/blob - vrecordinglistadvanced.cc
Fix black background for 16:9 live TV on 4:3 screen
[vompclient.git] / vrecordinglistadvanced.cc
1 /*
2     Copyright 2004-2020 Chris Tallon
3
4     This file is part of VOMP.
5
6     VOMP is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     VOMP is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with VOMP.  If not, see <https://www.gnu.org/licenses/>.
18 */
19
20 #include <cstdio>
21 #include <sstream>
22
23 #include "recman.h"
24 #include "directory.h"
25 #include "recording.h"
26 #include "recinfo.h"
27 #include "input.h"
28 #include "wsymbol.h"
29 #include "boxstack.h"
30 #include "vrecordingmenu.h"
31 #include "vrecording.h"
32 #include "vdr.h"
33 #include "vvideorec.h"
34 #include "vradiorec.h"
35 #include "colour.h"
36 #include "video.h"
37 #include "i18n.h"
38 #include "command.h"
39 #include "vinfo.h"
40 #include "log.h"
41 #include "movieinfo.h"
42 #include "seriesinfo.h"
43 #include "staticartwork.h"
44
45 #include "vrecordinglistadvanced.h"
46
47
48 VRecordingListAdvanced::VRecordingListAdvanced()
49 {
50   setSize(640, 500);
51   createBuffer();
52
53   setPosition(40, 40);
54
55   setTitleBarOn(1);
56   setTitleBarColour(DrawStyle::TITLEBARBACKGROUND);
57   TVMediaInfo* info = new TVMediaInfo();
58   info->setStaticArtwork(sa_recordings);
59   setTitleBarIcon(info);
60
61   sl.setPosition(10, 30 + 5);
62   sl.setSize(area.w*42/100 - 20, area.h - 30 - 15 - 30);
63   sl.setLinesPerOption(2.4f);
64   add(&sl);
65
66   Region slarea = sl.getRegionR();
67
68   epg.setParaMode(true);
69   epg.setPosition(slarea.x  +slarea.w+10 ,30+5);
70   epg.setSize(area.w -slarea.x -slarea.w -10, area.h - 30 - 15 - 30);
71   add(&epg);
72   epg.setText("");
73   epg.setBackgroundColour(DrawStyle::VIEWBACKGROUND);
74
75   epgTVmedia.setPosition(epg.getRegionR().w-100-10,10);
76   epgTVmedia.setSize(100, static_cast<UINT>(150/Osd::getInstance()->getPixelAspect()));
77   epg.add(&epgTVmedia);
78 }
79
80 VRecordingListAdvanced::~VRecordingListAdvanced()
81 {
82 }
83
84 void VRecordingListAdvanced::drawData(bool doIndexPop)
85 {
86   int saveIndex = sl.getCurrentOption();
87   int saveTop = sl.getTopOption();
88   sl.clear();
89   sl.addColumn(0);
90   sl.addColumn(25 );
91   sl.addColumn(25 + 7);
92   //sl.addColumn(118);
93
94   int first = 1;
95
96   char tempA[300]; // FIXME  this is guesswork!
97   char tempB[300]; // FIXME
98   struct tm btime;
99
100   Directory* currentSubDir;
101   DirectoryList::iterator i;
102   DirectoryList* dirList = recman->getDirectories();
103   for (i = dirList->begin(); i != dirList->end(); i++)
104   {
105     currentSubDir = *i;
106     SNPRINTF(tempA, 300, tr("\t%s \n \t <dir> %lu/%lu"),  currentSubDir->name, currentSubDir->getNumNewRecordings(), currentSubDir->getNumRecordings());
107
108     TVMediaInfo *info=new TVMediaInfo();
109     if (currentSubDir->recList.begin() != currentSubDir->recList.end())
110     {
111         info->setPosterThumb((*currentSubDir->recList.begin())->getFileName());
112         info->setStaticFallback(sa_recfolder);
113     } else {
114         info->setStaticArtwork(sa_recfolder);
115     }
116     currentSubDir->index = sl.addOption(tempA, 0, first, info);
117     first = 0;
118
119   }
120   // FIXME convert the whole program to time_t's
121
122   Recording* currentRec;
123   RecordingList::iterator j;
124   RecordingList* recList = recman->getRecordings();
125   for (j = recList->begin(); j != recList->end(); j++)
126   {
127     currentRec = *j;
128     time_t recStartTime = static_cast<time_t>(currentRec->getStartTime());
129     LOCALTIME_R(&recStartTime, &btime);
130     strftime(tempA, 299, "%d/%m/%y %H:%M ", &btime);
131     int check = SNPRINTF(tempB, 300, "%c\t%s\n \t%s",  (currentRec->getNew() ? '*': ' '), currentRec->getProgName(), tempA);
132     if ((check < 0) || (check > 299)) Log::getInstance()->log("VRecordingsListAdvanced", Log::ERR, "String too big");
133
134     // New TVMedia stuff
135     TVMediaInfo *info= new TVMediaInfo();
136     info->setPosterThumb(currentRec->getFileName());
137     info->setStaticFallback(sa_recording);
138     currentRec->index = sl.addOption(tempB, 0, first, info);
139     first = 0;
140   }
141
142   if (doIndexPop)
143   {
144     sl.hintSetCurrent(slIndexStack.top());
145     slIndexStack.pop();
146   }
147   else
148   {
149     sl.hintSetCurrent(saveIndex);
150     sl.hintSetTop(saveTop);
151   }
152   updateSelection();
153 }
154
155 void VRecordingListAdvanced::draw(bool doIndexPop)
156 {
157   if (!loading)
158   {
159     if (recman->isSubDir())
160     {
161       char title[300];
162       SNPRINTF(title, 300, tr("Recordings - %s"), recman->getCurDirName());
163       setTitleText(title, 364);
164     }
165     else
166     {
167       setTitleText(tr("Recordings"));
168     }
169     drawData(doIndexPop);
170   }
171
172   TBBoxx::draw();
173
174   if (loading)
175   {
176     drawText(tr("Loading..."), area.w*22/100-90, 180, DrawStyle::LIGHTTEXT);
177   }
178   else
179   {
180     char freeSpace[50];
181     int gigFree = recman->getFreeSpace() / 1024;
182     SNPRINTF(freeSpace, 50, tr("%lu%% used, %iGB free"), recman->getUsedPercent(), gigFree);
183     drawTextRJ(freeSpace, 560+70, 5, DrawStyle::LIGHTTEXT);
184     // Symbols
185
186     WSymbol w;
187     TEMPADD(&w);
188     w.nextSymbol = WSymbol::UP;
189     w.setPosition(20, area.h-35);
190     w.draw();
191     w.nextSymbol = WSymbol::DOWN;
192     w.setPosition(50, area.h-35);
193     w.draw();
194     w.nextSymbol = WSymbol::SKIPBACK;
195     w.setPosition(85, area.h-35);
196     w.draw();
197     w.nextSymbol = WSymbol::SKIPFORWARD;
198     w.setPosition(115, area.h-35);
199     w.draw();
200     w.nextSymbol = WSymbol::PLAY;
201     w.setPosition(150, area.h-35);
202     w.draw();
203     drawTextRJ(tr("[ok] = menu"), 560+70, 385+80, DrawStyle::LIGHTTEXT);
204
205     // All static stuff done
206     doShowingBar();
207   }
208 }
209
210 void VRecordingListAdvanced::doShowingBar()
211 { //setSize(640, 500); //old   setSize(570, 420);
212   int topOption = sl.getTopOption() + 1;
213   if (sl.getNumOptions() == 0) topOption = 0;
214 #ifndef GRADIENT_DRAWING
215   rectangle(area.w/2-65, area.h-115, 180, 25, DrawStyle::VIEWBACKGROUND);
216 #endif
217   char showing[200];
218   SNPRINTF(showing, 200, tr("%i to %i of %i"), topOption, sl.getBottomOption(), sl.getNumOptions());
219   drawText(showing, area.w/2-65, area.h-35, DrawStyle::LIGHTTEXT);
220 }
221
222 void VRecordingListAdvanced::updateSelection()
223 {
224         Recording* toShow = getCurrentOptionRecording();
225         if (toShow)
226         {
227                 toShow->loadRecInfo();
228                 std::stringstream description;
229                 if (toShow->recInfo && strlen(toShow->recInfo->summary)){
230                         description << "\n"<< toShow->recInfo->title  << "\n\n";
231                         description << toShow->recInfo->summary;
232                 }else {
233                         description << "\n" << std::string(toShow->getProgName()) << "\n\n";
234                         description << tr("Summary unavailable");
235
236                 }
237                 TVMedia poster;
238                 poster.height=0;
239                 if (toShow->movieInfo) {
240                         poster=toShow->movieInfo->poster;
241                 }
242                 if (toShow->seriesInfo) {
243                         if (toShow->seriesInfo->seasonposter.height) {
244                                 poster=toShow->seriesInfo->seasonposter;
245                         }
246                         else
247                                 if (toShow->seriesInfo->posters.size()) {
248                                         poster=toShow->seriesInfo->posters[0];
249                                 }
250                 }
251                 if (poster.height) {
252                         epgTVmedia.setTVMedia(poster.info, WTVMedia::ZoomHorizontal);
253                         epgTVmedia.setVisible(true);
254                 } else {
255                         epgTVmedia.setVisible(false);
256                 }
257
258                 epg.setText(description.str().c_str());
259         } else {
260                 Directory* toShowDir = getCurrentOptionDirectory();
261                 if (toShowDir)
262                 {
263                         std::stringstream description;
264                         description << "\n"<< std::string(toShowDir->name) << "\n\n";
265
266                         Directory* currentSubDir;
267                         DirectoryList::iterator i;
268                         DirectoryList & dirList = toShowDir->dirList;
269                         for (i = dirList.begin(); i != dirList.end(); i++)
270                         {
271                                 currentSubDir = *i;
272                                 description << tr("<dir> ") <<  std::string(currentSubDir->name) << " "
273                                                 << currentSubDir->getNumNewRecordings() <<"/"<< currentSubDir->getNumRecordings() <<"\n";
274                         }
275                         Recording* currentRec;
276                         RecordingList::iterator j;
277                         RecordingList & recList = toShowDir->recList;
278                         char tempA[300];
279                         struct tm btime;
280                         for (j = recList.begin(); j != recList.end(); j++)
281                         {
282                                 currentRec = *j;
283
284                                 time_t recStartTime = static_cast<time_t>(currentRec->getStartTime());
285                                 LOCALTIME_R(&recStartTime, &btime);
286                                 strftime(tempA, 299, "%d/%m/%y %H:%M ", &btime);
287
288                                 description<< tempA <<" "<< std::string(currentRec->getProgName()) << "\n";
289
290                         }
291                         epgTVmedia.setVisible(false);
292                         epg.setText(description.str().c_str());
293
294
295                 }
296         }
297
298 }
299
300
301
302 void VRecordingListAdvanced::quickUpdate() { //only quick for plattform that need it!
303         updateSelection();
304 #ifdef GRADIENT_DRAWING
305       draw();
306 #else
307       sl.draw();
308       doShowingBar();
309       epg.draw();
310 #endif
311 }