]> git.vomp.tv Git - vompclient.git/blob - vrecordinglistadvanced.cc
Improve connection failure handling
[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 #include <fmt/core.h>
23
24 #include "recman.h"
25 #include "directory.h"
26 #include "recording.h"
27 #include "recinfo.h"
28 #include "input.h"
29 #include "wsymbol.h"
30 #include "boxstack.h"
31 #include "vrecordingmenu.h"
32 #include "vrecording.h"
33 #include "vdr.h"
34 #include "vvideorec.h"
35 #include "vradiorec.h"
36 #include "colour.h"
37 #include "video.h"
38 #include "i18n.h"
39 #include "control.h"
40 #include "vinfo.h"
41 #include "log.h"
42 #include "movieinfo.h"
43 #include "seriesinfo.h"
44 #include "staticartwork.h"
45
46 #include "vrecordinglistadvanced.h"
47
48
49 VRecordingListAdvanced::VRecordingListAdvanced()
50 {
51   setSize(640, 500);
52   createBuffer();
53
54   setPosition(40, 40);
55
56   setTitleBarOn(1);
57   setTitleBarColour(DrawStyle::TITLEBARBACKGROUND);
58   TVMediaInfo* info = new TVMediaInfo();
59   info->setStaticArtwork(sa_recordings);
60   setTitleBarIcon(info);
61
62   sl.setPosition(10, 30 + 5);
63   sl.setSize(area.w*42/100 - 20, area.h - 30 - 15 - 30);
64   sl.setLinesPerOption(2.4f);
65   add(&sl);
66
67   Region slarea = sl.getRegionR();
68
69   epg.setParaMode(true);
70   epg.setPosition(slarea.x  +slarea.w+10 ,30+5);
71   epg.setSize(area.w -slarea.x -slarea.w -10, area.h - 30 - 15 - 30);
72   add(&epg);
73   epg.setText("");
74   epg.setBackgroundColour(DrawStyle::VIEWBACKGROUND);
75
76   epgTVmedia.setPosition(epg.getRegionR().w-100-10,10);
77   epgTVmedia.setSize(100, static_cast<UINT>(150/Osd::getInstance()->getPixelAspect()));
78   epg.add(&epgTVmedia);
79 }
80
81 VRecordingListAdvanced::~VRecordingListAdvanced()
82 {
83 }
84
85 void VRecordingListAdvanced::drawData(bool doIndexPop)
86 {
87   int saveIndex = sl.getCurrentOption();
88   int saveTop = sl.getTopOption();
89   sl.clear();
90   sl.addColumn(0);
91   sl.addColumn(25 );
92   sl.addColumn(25 + 7);
93   //sl.addColumn(118);
94
95   int first = 1;
96
97   char timeString[16]; // "dd/mm/yy hh:mm"
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     std::string dirString = fmt::format("\t{} \n \t <dir> {}/{}", 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(dirString, 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(timeString, 16, "%d/%m/%y %H:%M", &btime);
131     std::string fileString = fmt::format("{}\t{}\n \t{}", (currentRec->getNew() ? '*': ' '), currentRec->getProgName(), timeString);
132
133     // New TVMedia stuff
134     TVMediaInfo *info= new TVMediaInfo();
135     info->setPosterThumb(currentRec->getFileName());
136     info->setStaticFallback(sa_recording);
137     currentRec->index = sl.addOption(fileString, 0, first, info);
138     first = 0;
139   }
140
141   if (doIndexPop)
142   {
143     sl.hintSetCurrent(slIndexStack.top());
144     slIndexStack.pop();
145   }
146   else
147   {
148     sl.hintSetCurrent(saveIndex);
149     sl.hintSetTop(saveTop);
150   }
151   updateSelection();
152 }
153
154 void VRecordingListAdvanced::draw(bool doIndexPop)
155 {
156   if (!loading)
157   {
158     if (recman->isSubDir())
159     {
160       char title[300];
161       SNPRINTF(title, 300, tr("Recordings - %s"), recman->getCurDirName());
162       setTitleText(title, 364);
163     }
164     else
165     {
166       setTitleText(tr("Recordings"));
167     }
168     drawData(doIndexPop);
169   }
170
171   TBBoxx::draw();
172
173   if (loading)
174   {
175     drawText(tr("Loading..."), area.w*22/100-90, 180, DrawStyle::LIGHTTEXT);
176   }
177   else
178   {
179     char freeSpace[50];
180     int gigFree = recman->getFreeSpace() / 1024;
181     SNPRINTF(freeSpace, 50, tr("%lu%% used, %iGB free"), recman->getUsedPercent(), gigFree);
182     drawTextRJ(freeSpace, 560+70, 5, DrawStyle::LIGHTTEXT);
183     // Symbols
184
185     WSymbol w;
186     TEMPADD(&w);
187     w.nextSymbol = WSymbol::UP;
188     w.setPosition(20, area.h-35);
189     w.draw();
190     w.nextSymbol = WSymbol::DOWN;
191     w.setPosition(50, area.h-35);
192     w.draw();
193     w.nextSymbol = WSymbol::SKIPBACK;
194     w.setPosition(85, area.h-35);
195     w.draw();
196     w.nextSymbol = WSymbol::SKIPFORWARD;
197     w.setPosition(115, area.h-35);
198     w.draw();
199     w.nextSymbol = WSymbol::PLAY;
200     w.setPosition(150, area.h-35);
201     w.draw();
202     drawTextRJ(tr("[ok] = menu"), 560+70, 385+80, DrawStyle::LIGHTTEXT);
203
204     // All static stuff done
205     doShowingBar();
206   }
207 }
208
209 void VRecordingListAdvanced::doShowingBar()
210 { //setSize(640, 500); //old   setSize(570, 420);
211   int topOption = sl.getTopOption() + 1;
212   if (sl.getNumOptions() == 0) topOption = 0;
213 #ifndef GRADIENT_DRAWING
214   rectangle(area.w/2-65, area.h-115, 180, 25, DrawStyle::VIEWBACKGROUND);
215 #endif
216   char showing[200];
217   SNPRINTF(showing, 200, tr("%i to %i of %i"), topOption, sl.getBottomOption(), sl.getNumOptions());
218   drawText(showing, area.w/2-65, area.h-35, DrawStyle::LIGHTTEXT);
219 }
220
221 void VRecordingListAdvanced::updateSelection()
222 {
223         Recording* toShow = getCurrentOptionRecording();
224         if (toShow)
225         {
226                 toShow->loadRecInfo();
227                 std::stringstream description;
228                 if (toShow->recInfo && strlen(toShow->recInfo->summary)){
229                         description << "\n"<< toShow->recInfo->title  << "\n\n";
230                         description << toShow->recInfo->summary;
231                 }else {
232                         description << "\n" << std::string(toShow->getProgName()) << "\n\n";
233                         description << tr("Summary unavailable");
234
235                 }
236                 TVMedia poster;
237                 poster.height=0;
238                 if (toShow->movieInfo) {
239                         poster=toShow->movieInfo->poster;
240                 }
241                 if (toShow->seriesInfo) {
242                         if (toShow->seriesInfo->seasonposter.height) {
243                                 poster=toShow->seriesInfo->seasonposter;
244                         }
245                         else
246                                 if (toShow->seriesInfo->posters.size()) {
247                                         poster=toShow->seriesInfo->posters[0];
248                                 }
249                 }
250                 if (poster.height) {
251                         epgTVmedia.setTVMedia(poster.info, WTVMedia::ZoomHorizontal);
252                         epgTVmedia.setVisible(true);
253                 } else {
254                         epgTVmedia.setVisible(false);
255                 }
256
257                 epg.setText(description.str().c_str());
258         } else {
259                 Directory* toShowDir = getCurrentOptionDirectory();
260                 if (toShowDir)
261                 {
262                         std::stringstream description;
263                         description << "\n"<< std::string(toShowDir->name) << "\n\n";
264
265                         Directory* currentSubDir;
266                         DirectoryList::iterator i;
267                         DirectoryList & dirList = toShowDir->dirList;
268                         for (i = dirList.begin(); i != dirList.end(); i++)
269                         {
270                                 currentSubDir = *i;
271                                 description << tr("<dir> ") <<  std::string(currentSubDir->name) << " "
272                                                 << currentSubDir->getNumNewRecordings() <<"/"<< currentSubDir->getNumRecordings() <<"\n";
273                         }
274                         Recording* currentRec;
275                         RecordingList::iterator j;
276                         RecordingList & recList = toShowDir->recList;
277                         char tempA[300];
278                         struct tm btime;
279                         for (j = recList.begin(); j != recList.end(); j++)
280                         {
281                                 currentRec = *j;
282
283                                 time_t recStartTime = static_cast<time_t>(currentRec->getStartTime());
284                                 LOCALTIME_R(&recStartTime, &btime);
285                                 strftime(tempA, 299, "%d/%m/%y %H:%M ", &btime);
286
287                                 description<< tempA <<" "<< std::string(currentRec->getProgName()) << "\n";
288
289                         }
290                         epgTVmedia.setVisible(false);
291                         epg.setText(description.str().c_str());
292
293
294                 }
295         }
296
297 }
298
299
300
301 void VRecordingListAdvanced::quickUpdate() { //only quick for plattform that need it!
302         updateSelection();
303 #ifdef GRADIENT_DRAWING
304       draw();
305 #else
306       sl.draw();
307       doShowingBar();
308       epg.draw();
309 #endif
310 }