]> git.vomp.tv Git - vompclient.git/blob - vrecordinglist.cc
Switch over to updateView rather than show, EPG tweaks
[vompclient.git] / vrecordinglist.cc
1 /*
2     Copyright 2004-2005 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20
21 #include "vrecordinglist.h"
22
23 VRecordingList::VRecordingList(VRecordingList* tparent)
24 {
25   myParent = tparent;
26   dataInvalid = 0;
27   viewman = ViewMan::getInstance();
28
29   create(570, 420);
30   if (Video::getInstance()->getFormat() == Video::PAL)
31   {
32     setScreenPos(80, 70);
33   }
34   else
35   {
36     setScreenPos(70, 35);
37   }
38
39   setBackgroundColour(Colour::VIEWBACKGROUND);
40   setTitleBarOn(1);
41   setTitleBarColour(Colour::TITLEBARBACKGROUND);
42
43   sl.setSurface(surface);
44   sl.setSurfaceOffset(10, 30 + 5);
45   sl.setDimensions(area.w - 20, area.h - 30 - 15 - 30);
46 }
47
48 VRecordingList::~VRecordingList()
49 {
50   // if this is a child window, inform the parent of our destruct
51   if (myParent)
52   {
53     Message* m = new Message();
54     m->to = myParent;
55     m->message = Message::CHILD_CLOSE;
56     viewman->postMessage(m);
57   }
58
59   // only delete the list if this is not a sub dir window
60   if (recDir->isRoot)
61   {
62     delete recDir;
63   }
64 }
65
66 void VRecordingList::setDir(Directory* tdir)
67 {
68   recDir = tdir;
69
70   drawData();
71
72   char title[300];
73   if (!recDir->isRoot)
74   {
75     snprintf(title, 299, tr("Recordings - %s"), recDir->name);
76     setTitleText(title);
77   }
78   else
79   {
80     setTitleText(tr("Recordings"));
81   }
82 }
83
84 void VRecordingList::drawData()
85 {
86   sl.clear();
87   sl.addColumn(0);
88   sl.addColumn(110);
89
90   int first = 1;
91
92   char tempA[300]; // FIXME  this is guesswork!
93   char tempB[300]; // FIXME
94   struct tm* btime;
95
96   Directory* dir;
97   DirectoryList::iterator i;
98
99   if (dataInvalid == 2) // special case, a child list has closed, check for 0 dir entries
100   {
101
102     // First go through to delete 1 empty dir if necessary
103
104     for (i = recDir->dirList.begin(); i != recDir->dirList.end(); i++)
105     {
106       dir = *i;
107       if (dir->getNumRecordings() == 0)
108       {
109         delete dir;
110         recDir->dirList.erase(i);
111         break;
112       }
113     }
114   }
115
116   // Then go through again to draw data. Don't merge these two loops!
117
118   for (i = recDir->dirList.begin(); i != recDir->dirList.end(); i++)
119   {
120     dir = *i;
121     snprintf(tempA, 299, tr("<dir> %lu\t%s"), dir->getNumRecordings(), dir->name);
122     dir->index = sl.addOption(tempA, first);
123     first = 0;
124   }
125
126   // FIXME convert the whole program to time_t's
127
128
129   Recording* rec;
130   for (UINT j = 0; j < recDir->recList.size(); j++)
131   {
132     rec = recDir->recList[j];
133     btime = localtime((time_t*)&rec->start);
134     strftime(tempA, 299, "%0d/%0m %0H:%0M ", btime);
135     sprintf(tempB, "%s\t%s", tempA, rec->getProgName());
136     rec->index = sl.addOption(tempB, first);
137     first = 0;
138   }
139
140   dataInvalid = 0;
141 }
142
143 void VRecordingList::draw()
144 {
145   View::draw();
146
147   if (dataInvalid) drawData();
148
149   sl.draw();
150
151   // Put the status stuff at the bottom
152
153   WSymbol w;
154   w.setSurface(surface);
155
156   w.nextSymbol = WSymbol::UP;
157   w.setSurfaceOffset(20, 385);
158   w.draw();
159
160   w.nextSymbol = WSymbol::DOWN;
161   w.setSurfaceOffset(50, 385);
162   w.draw();
163
164   w.nextSymbol = WSymbol::SKIPBACK;
165   w.setSurfaceOffset(85, 385);
166   w.draw();
167
168   w.nextSymbol = WSymbol::SKIPFORWARD;
169   w.setSurfaceOffset(115, 385);
170   w.draw();
171
172   w.nextSymbol = WSymbol::PLAY;
173   w.setSurfaceOffset(150, 385);
174   w.draw();
175
176   // FIXME Right justify this!
177   drawText(tr("[ok] = menu"), 450, 385, Colour::LIGHTTEXT);
178
179   doShowingBar();
180
181   char freeSpace[50];
182   int gigFree = Directory::freeSpace / 1024;
183   snprintf(freeSpace, 49, tr("%lu%% used, %iGB free"), Directory::usedPercent, gigFree);
184   drawTextRJ(freeSpace, 560, 5, Colour::LIGHTTEXT);
185 }
186
187 void VRecordingList::doShowingBar()
188 {
189   int topOption = sl.getTopOption() + 1;
190   if (sl.getNumOptions() == 0) topOption = 0;
191
192   char showing[200];
193   sprintf(showing, tr("%i to %i of %i"), topOption, sl.getBottomOption(), sl.getNumOptions());
194
195 //  Box b;
196 //  b.setSurfaceOffset(220, 385);
197 //  b.setDimensions(160, 25);
198 //  b.fillColour(Colour::VIEWBACKGROUND);
199 //  b.drawText(showing, 0, 0, Colour::LIGHTTEXT);
200
201   rectangle(220, 385, 220+160, 385+25, Colour::VIEWBACKGROUND);
202   drawText(showing, 220, 385, Colour::LIGHTTEXT);
203 }
204
205
206
207 void VRecordingList::processMessage(Message* m)
208 {
209   Log::getInstance()->log("VRecordingList", Log::DEBUG, "Got message value %lu", m->message);
210   if (m->message == Message::DELETE_SELECTED_RECORDING)
211   {
212     Log::getInstance()->log("VRecordingList", Log::DEBUG, "Doing delete selected");
213     doDeleteSelected();
214     return;
215   }
216
217   if (m->message == Message::PLAY_SELECTED_RECORDING)
218   {
219     doPlay();
220     return;
221   }
222
223   if (m->message == Message::RESUME_SELECTED_RECORDING)
224   {
225     doResume();
226     return;
227   }
228
229   if (m->message == Message::REDRAW_DATA)
230   {
231     dataInvalid = 1;
232     draw();
233     return;
234   }
235
236   if (m->message == Message::CHILD_CLOSE)
237   {
238     dataInvalid = 2;
239     draw();
240     show();
241     return;
242   }
243 }
244
245 void VRecordingList::doDeleteSelected()
246 {
247   Recording* toDelete = getCurrentOptionRecording();
248
249   int saveIndex;
250   int saveTop;
251
252   if (toDelete)
253   {
254     saveIndex = toDelete->index;
255     saveTop = sl.getTopOption();
256     Log::getInstance()->log("VRecordingList", Log::DEBUG, "FOUND: %i %s %s", toDelete->index, toDelete->getProgName(), toDelete->fileName);
257
258     VDR* vdr = VDR::getInstance();
259     vdr->deleteRecording(toDelete->fileName);
260
261     delete toDelete;
262
263     for(RecordingList::iterator i = recDir->recList.begin(); i != recDir->recList.end(); i++)
264     {
265       if (*i == toDelete)
266       {
267         recDir->recList.erase(i);
268         break;
269       }
270     }
271
272     sl.clear();
273     setDir(recDir);
274     sl.hintSetCurrent(saveIndex);
275     sl.hintSetTop(saveTop);
276     draw();
277   }
278
279   if (myParent) // if this is not root send a message to parent to say redraw data
280   { // FIXME not really necessary any more ?
281     Message* m1 = new Message();
282     m1->to = myParent;
283     m1->message = Message::REDRAW_DATA;
284     viewman->postMessage(m1);
285   }
286
287   show();
288 }
289
290 int VRecordingList::doPlay()
291 {
292   Recording* toPlay = getCurrentOptionRecording();
293   if (toPlay)
294   {
295     VVideoRec* vidrec = new VVideoRec(toPlay);
296     vidrec->draw();
297     viewman->add(vidrec);
298     viewman->updateView(vidrec);
299     vidrec->go(0);
300     return 1;
301   }
302   // should not get to here
303   return 0;
304 }
305
306 int VRecordingList::doResume()
307 {
308   Recording* toResume = getCurrentOptionRecording();
309   if (toResume)
310   {
311     ULLONG position = VDR::getInstance()->getResumePoint(toResume->fileName);
312
313     VVideoRec* vidrec = new VVideoRec(toResume);
314     vidrec->draw();
315     viewman->add(vidrec);
316     viewman->updateView(vidrec);
317     vidrec->go(position);
318     return 1;
319   }
320   // should not get to here
321   return 0;
322 }
323
324 Recording* VRecordingList::getCurrentOptionRecording()
325 {
326   Recording* current;
327   for (UINT i = 0; i < recDir->recList.size(); i++)
328   {
329     current = recDir->recList[i];
330     if (current->index == sl.getCurrentOption()) return current;
331   }
332   return NULL;
333 }
334
335 int VRecordingList::handleCommand(int command)
336 {
337   switch(command)
338   {
339     case Remote::DF_UP:
340     case Remote::UP:
341     {
342       sl.up();
343       sl.draw();
344
345       doShowingBar();
346       viewman->updateView(this);
347       return 2;
348     }
349     case Remote::DF_DOWN:
350     case Remote::DOWN:
351     {
352       sl.down();
353       sl.draw();
354
355       doShowingBar();
356       viewman->updateView(this);
357       return 2;
358     }
359     case Remote::SKIPBACK:
360     {
361       sl.pageUp();
362       sl.draw();
363
364       doShowingBar();
365       viewman->updateView(this);
366       return 2;
367     }
368     case Remote::SKIPFORWARD:
369     {
370       sl.pageDown();
371       sl.draw();
372
373       doShowingBar();
374       viewman->updateView(this);
375       return 2;
376     }
377     case Remote::OK:
378     {
379       if (sl.getNumOptions() == 0) return 2;
380
381       // Check to see if it is a sub directory
382       Directory* curDir;
383       for(UINT i = 0; i < recDir->dirList.size(); i++)
384       {
385         curDir = recDir->dirList[i];
386         if (curDir->index == sl.getCurrentOption())
387         {
388           VRecordingList* sub = new VRecordingList(this);
389           sub->setDir(curDir);
390           viewman->add(sub);
391
392           sub->draw();
393           sub->show();
394
395           return 2;
396         }
397       }
398
399       // check to see if it's a recording
400       Recording* current = getCurrentOptionRecording();
401       if (current)
402       {
403         Log::getInstance()->log("VRecordingList", Log::DEBUG, "Found the option you pointed at. %s %s", current->getProgName(), current->fileName);
404
405         VRecordingMenu* v = new VRecordingMenu();
406         v->setParent(this);
407         v->setRecording(current);
408         viewman->add(v);
409         v->draw();
410         v->show();
411         return 2;
412       }
413       // should not get to here
414       return 1;
415     }
416     case Remote::BACK:
417     {
418       return 4;
419     }
420     case Remote::PLAY:
421     {
422       if (doResume()) return 2;
423       return 1;
424     }
425
426   }
427   // stop command getting to any more views
428   return 1;
429 }