]> git.vomp.tv Git - vompclient.git/blob - vrecordinglistadvanced.cc
Fix leak in picture handling of osdvector, add static fallback pictures, some default...
[vompclient.git] / vrecordinglistadvanced.cc
1 /*
2     Copyright 2004-2007 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, write to the Free Software
18     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 */
20
21 #include "vrecordinglistadvanced.h"
22
23 #include "recman.h"
24 #include "directory.h"
25 #include "recording.h"
26 #include "recinfo.h"
27 #include "remote.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 <sstream>
46
47
48 VRecordingListAdvanced::VRecordingListAdvanced()
49 {
50         setSize(640, 500); //old   setSize(570, 420);
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,150/Osd::getInstance()->getPixelAspect());
77         epg.add(&epgTVmedia);
78
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 tempA[300]; // FIXME  this is guesswork!
98   char tempB[300]; // FIXME
99   struct tm* btime;
100
101   Directory* currentSubDir;
102   DirectoryList::iterator i;
103   DirectoryList* dirList = recman->getDirectories();
104   for (i = dirList->begin(); i != dirList->end(); i++)
105   {
106     currentSubDir = *i;
107     SNPRINTF(tempA, 299, tr("\t%s \n \t <dir> %lu/%lu"),  currentSubDir->name, currentSubDir->getNumNewRecordings(), currentSubDir->getNumRecordings());
108
109     TVMediaInfo *info= NULL;
110     if (currentSubDir->recList.begin() != currentSubDir->recList.end())
111     {
112         info=new TVMediaInfo();
113         info->setPosterThumb((*currentSubDir->recList.begin())->getFileName());
114         info->setStaticFallback(sa_recfolder);
115     } else {
116         info->setStaticArtwork(sa_recfolder);
117     }
118     currentSubDir->index = sl.addOption(tempA, 0, first, info);
119     first = 0;
120
121   }
122   // FIXME convert the whole program to time_t's
123
124   Recording* currentRec;
125   RecordingList::iterator j;
126   RecordingList* recList = recman->getRecordings();
127   for (j = recList->begin(); j != recList->end(); j++)
128   {
129     currentRec = *j;
130     time_t recStartTime = (time_t)currentRec->getStartTime();
131     btime = localtime(&recStartTime);
132 //NMT does not like this too!
133         //#ifndef _MSC_VER
134 //    strftime(tempA, 299, "%0d/%0m %0H:%0M ", btime);
135 //#else
136     strftime(tempA, 299, "%d/%m/%y %H:%M ", btime);
137 //#endif
138     sprintf(tempB, "%c\t%s\n \t%s",  (currentRec->getNew() ? '*': ' '), currentRec->getProgName(),tempA);
139     // New TVMedia stuff
140     TVMediaInfo *info= new TVMediaInfo();
141     info->setPosterThumb(currentRec->getFileName());
142     info->setStaticFallback(sa_recording);
143     currentRec->index = sl.addOption(tempB, 0, first, info);
144     first = 0;
145   }
146
147   if (doIndexPop)
148   {
149     sl.hintSetCurrent(slIndexStack.top());
150     slIndexStack.pop();
151   }
152   else
153   {
154     sl.hintSetCurrent(saveIndex);
155     sl.hintSetTop(saveTop);
156   }
157   updateSelection();
158 }
159
160 void VRecordingListAdvanced::draw(bool doIndexPop)
161 {
162   if (!loading)
163   {
164     if (recman->isSubDir())
165     {
166       char title[300];
167       SNPRINTF(title, 299, tr("Recordings - %s"), recman->getCurDirName());
168       setTitleText(title, 364);
169     }
170     else
171     {
172       setTitleText(tr("Recordings"));
173     }
174     drawData(doIndexPop);
175   }
176
177
178   TBBoxx::draw();
179
180   if (loading)
181   {
182     drawText(tr("Loading..."), area.w*22/100-90, 180, DrawStyle::LIGHTTEXT);
183   }
184   else
185   {
186     char freeSpace[50];
187     int gigFree = recman->getFreeSpace() / 1024;
188     SNPRINTF(freeSpace, 49, tr("%lu%% used, %iGB free"), recman->getUsedPercent(), gigFree);
189     drawTextRJ(freeSpace, 560+70, 5, DrawStyle::LIGHTTEXT);
190     // Symbols
191
192     WSymbol w;
193     TEMPADD(&w);
194     w.nextSymbol = WSymbol::UP;
195     w.setPosition(20, area.h-35);
196     w.draw();
197     w.nextSymbol = WSymbol::DOWN;
198     w.setPosition(50, area.h-35);
199     w.draw();
200     w.nextSymbol = WSymbol::SKIPBACK;
201     w.setPosition(85, area.h-35);
202     w.draw();
203     w.nextSymbol = WSymbol::SKIPFORWARD;
204     w.setPosition(115, area.h-35);
205     w.draw();
206     w.nextSymbol = WSymbol::PLAY;
207     w.setPosition(150, area.h-35);
208     w.draw();
209     drawTextRJ(tr("[ok] = menu"), 560+70, 385+80, DrawStyle::LIGHTTEXT);
210
211     // All static stuff done
212     doShowingBar();
213   }
214 }
215
216 void VRecordingListAdvanced::doShowingBar()
217 { //setSize(640, 500); //old   setSize(570, 420);
218   int topOption = sl.getTopOption() + 1;
219   if (sl.getNumOptions() == 0) topOption = 0;
220 #ifndef GRADIENT_DRAWING
221   rectangle(area.w/2-65, area.h-115, 180, 25, DrawStyle::VIEWBACKGROUND);
222 #endif
223   char showing[200];
224   sprintf(showing, tr("%i to %i of %i"), topOption, sl.getBottomOption(), sl.getNumOptions());
225   drawText(showing, area.w/2-65, area.h-35, DrawStyle::LIGHTTEXT);
226 }
227
228 void VRecordingListAdvanced::updateSelection()
229 {
230         Recording* toShow = getCurrentOptionRecording();
231         if (toShow)
232         {
233                 toShow->loadRecInfo();
234                 std::stringstream description;
235                 if (toShow->recInfo && strlen(toShow->recInfo->summary)){
236                         description << "\n"<< toShow->recInfo->title  << "\n\n";
237                         description << toShow->recInfo->summary;
238                 }else {
239                         description << "\n" << std::string(toShow->getProgName()) << "\n\n";
240                         description << tr("Summary unavailable");
241
242                 }
243                 TVMedia poster;
244                 poster.height=0;
245                 if (toShow->movieInfo) {
246                         poster=toShow->movieInfo->poster;
247                 }
248                 if (toShow->seriesInfo) {
249                         if (toShow->seriesInfo->seasonposter.height) {
250                                 poster=toShow->seriesInfo->seasonposter;
251                         }
252                         else
253                                 if (toShow->seriesInfo->posters.size()) {
254                                         poster=toShow->seriesInfo->posters[0];
255                                 }
256                 }
257                 if (poster.height) {
258                         epgTVmedia.setTVMedia(poster.info, WTVMedia::ZoomHorizontal);
259                         epgTVmedia.setVisible(true);
260                 } else {
261                         epgTVmedia.setVisible(false);
262                 }
263
264                 epg.setText(description.str().c_str());
265         } else {
266                 Directory* toShowDir = getCurrentOptionDirectory();
267                 if (toShowDir)
268                 {
269                         std::stringstream description;
270                         description << "\n"<< std::string(toShowDir->name) << "\n\n";
271
272                         Directory* currentSubDir;
273                         DirectoryList::iterator i;
274                         DirectoryList & dirList = toShowDir->dirList;
275                         for (i = dirList.begin(); i != dirList.end(); i++)
276                         {
277                                 currentSubDir = *i;
278                                 description << tr("<dir> ") <<  std::string(currentSubDir->name) << " "
279                                                 << currentSubDir->getNumNewRecordings() <<"/"<< currentSubDir->getNumRecordings() <<"\n";
280                         }
281                         Recording* currentRec;
282                         RecordingList::iterator j;
283                         RecordingList & recList = toShowDir->recList;
284                         char tempA[300];
285                         struct tm* btime;
286                         for (j = recList.begin(); j != recList.end(); j++)
287                         {
288                                 currentRec = *j;
289
290                                 time_t recStartTime = (time_t)currentRec->getStartTime();
291                                 btime = localtime(&recStartTime);
292                                 strftime(tempA, 299, "%d/%m/%y %H:%M ", btime);
293
294                                 description<< tempA <<" "<< std::string(currentRec->getProgName()) << "\n";
295
296                         }
297                         epgTVmedia.setVisible(false);
298                         epg.setText(description.str().c_str());
299
300
301                 }
302         }
303
304 }
305
306
307
308 void VRecordingListAdvanced::quickUpdate() { //only quick for plattform that need it!
309         updateSelection();
310 #ifdef GRADIENT_DRAWING
311       draw();
312 #else
313       sl.draw();
314       doShowingBar();
315       epg.draw();
316 #endif
317 }