]> git.vomp.tv Git - vompclient.git/blob - vrecordinglistclassic.cc
Fix VRecording showing graphic at bottom left when it shouldn't
[vompclient.git] / vrecordinglistclassic.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 <fmt/core.h>
21
22 #include "recman.h"
23 #include "directory.h"
24 #include "recording.h"
25 #include "input.h"
26 #include "wsymbol.h"
27 #include "boxstack.h"
28 #include "vrecordingmenu.h"
29 #include "vrecording.h"
30 #include "vdr.h"
31 #include "vvideorec.h"
32 #include "vradiorec.h"
33 #include "colour.h"
34 #include "video.h"
35 #include "i18n.h"
36 #include "control.h"
37 #include "vinfo.h"
38 #include "log.h"
39
40 #include "vrecordinglistclassic.h"
41
42 VRecordingListClassic::VRecordingListClassic()
43 {
44   setSize(570, 420);
45   createBuffer();
46   if (Video::getInstance()->getFormat() == Video::PAL)
47   {
48     setPosition(80, 70);
49   }
50   else
51   {
52     setPosition(70, 35);
53   }
54
55   setTitleBarOn(1);
56   setTitleBarColour(DrawStyle::TITLEBARBACKGROUND);
57
58   sl.setPosition(10, 30 + 5);
59   sl.setSize(area.w - 20, area.h - 30 - 15 - 30);
60   add(&sl);
61 }
62
63 VRecordingListClassic::~VRecordingListClassic()
64 {
65 }
66
67 void VRecordingListClassic::drawData(bool doIndexPop)
68 {
69   int saveIndex = sl.getCurrentOption();
70   int saveTop = sl.getTopOption();
71   sl.clear();
72   sl.addColumn(0);
73   sl.addColumn(102);
74   sl.addColumn(118);
75
76   int first = 1;
77
78   char timeString[16]; // "dd/mm hh:mm"
79   struct tm btime;
80
81   Directory* currentSubDir;
82   DirectoryList::iterator i;
83   DirectoryList* dirList = recman->getDirectories();
84   for (i = dirList->begin(); i != dirList->end(); i++)
85   {
86     currentSubDir = *i;
87     std::string dirString = fmt::format("<dir> {}/{}\t \t{}", currentSubDir->getNumNewRecordings(), currentSubDir->getNumRecordings(), currentSubDir->name);
88     currentSubDir->index = sl.addOption(dirString, 0, first);
89     first = 0;
90   }
91   // FIXME convert the whole program to time_t's
92
93   Recording* currentRec;
94   RecordingList::iterator j;
95   RecordingList* recList = recman->getRecordings();
96   for (j = recList->begin(); j != recList->end(); j++)
97   {
98     currentRec = *j;
99     time_t recStartTime = static_cast<time_t>(currentRec->getStartTime());
100     LOCALTIME_R(&recStartTime, &btime);
101     strftime(timeString, 16, "%d/%m %H:%M", &btime);
102     std::string fileString = fmt::format("{} \t{}\t{}", timeString, (currentRec->getNew() ? '*': ' '), currentRec->getProgName());
103     currentRec->index = sl.addOption(fileString, 0, first);
104     first = 0;
105   }
106
107   if (doIndexPop)
108   {
109     sl.hintSetCurrent(slIndexStack.top());
110     slIndexStack.pop();
111   }
112   else
113   {
114     sl.hintSetCurrent(saveIndex);
115     sl.hintSetTop(saveTop);
116   }
117   sl.draw();
118   doShowingBar();
119 }
120
121 void VRecordingListClassic::draw(bool doIndexPop)
122 {
123   if (!loading)
124   {
125     if (recman->isSubDir())
126     {
127       char title[300];
128       SNPRINTF(title, 300, tr("Recordings - %s"), recman->getCurDirName());
129       setTitleText(title, 364);
130     }
131     else
132     {
133       setTitleText(tr("Recordings"));
134     }
135   }
136
137   TBBoxx::draw();
138
139   if (loading)
140   {
141     drawText(tr("Loading..."), 240, 180, DrawStyle::LIGHTTEXT);
142   }
143   else
144   {
145     char freeSpace[50];
146     int gigFree = recman->getFreeSpace() / 1024;
147     SNPRINTF(freeSpace, 50, tr("%lu%% used, %iGB free"), recman->getUsedPercent(), gigFree);
148     drawTextRJ(freeSpace, 560, 5, DrawStyle::LIGHTTEXT);
149     // Symbols
150
151     WSymbol w;
152     TEMPADD(&w);
153     w.nextSymbol = WSymbol::UP;
154     w.setPosition(20, 385);
155     w.draw();
156     w.nextSymbol = WSymbol::DOWN;
157     w.setPosition(50, 385);
158     w.draw();
159     w.nextSymbol = WSymbol::SKIPBACK;
160     w.setPosition(85, 385);
161     w.draw();
162     w.nextSymbol = WSymbol::SKIPFORWARD;
163     w.setPosition(115, 385);
164     w.draw();
165     w.nextSymbol = WSymbol::PLAY;
166     w.setPosition(150, 385);
167     w.draw();
168     drawTextRJ(tr("[ok] = menu"), 560, 385, DrawStyle::LIGHTTEXT);
169
170     // All static stuff done
171     drawData(doIndexPop);
172   }
173 }
174
175 void VRecordingListClassic::doShowingBar()
176 {
177   int topOption = sl.getTopOption() + 1;
178   if (sl.getNumOptions() == 0) topOption = 0;
179 #ifndef GRADIENT_DRAWING
180   rectangle(220, 385, 180, 25, DrawStyle::VIEWBACKGROUND);
181 #endif
182   char showing[200];
183   SNPRINTF(showing, 200, tr("%i to %i of %i"), topOption, sl.getBottomOption(), sl.getNumOptions());
184   drawText(showing, 220, 385, DrawStyle::LIGHTTEXT);
185 }
186
187 void VRecordingListClassic::quickUpdate() { //only quick for plattform that need it!
188 #ifdef GRADIENT_DRAWING
189       draw();
190 #else
191       sl.draw();
192       doShowingBar();
193 #endif
194 }