]> git.vomp.tv Git - vompclient.git/blob - vrecordinglist.cc
Bug fix 2 for duplicating epg rows
[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, Directory* tdir)
24 {
25   myParent = tparent;
26   viewman = ViewMan::getInstance();
27   recDir = tdir;
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 (myParent)
51   {
52     // if this is a sub, there can only be recordings. if there are none left, get this dir deleted by parent
53     if (recDir->getNumRecordings() == 0) myParent->zeroCheck();
54     // recDir is now deleted if it was empty
55   }
56   else
57   {
58     // only delete the list if this is not a sub dir window
59     delete recDir;
60   }
61 }
62
63 void VRecordingList::zeroCheck()
64 {
65   // go through to delete 1 empty dir if necessary (there will only ever be 1)
66   Directory* dir;
67   DirectoryList::iterator i;
68   for (i = recDir->dirList.begin(); i != recDir->dirList.end(); i++)
69   {
70     dir = *i;
71     if (dir->getNumRecordings() == 0)
72     {
73       delete dir;
74       recDir->dirList.erase(i);
75       break;
76     }
77   }
78   drawData();
79   viewman->updateView(this);
80 }
81
82 void VRecordingList::drawData()
83 {
84   int saveIndex = sl.getCurrentOption();
85   int saveTop = sl.getTopOption();
86
87   sl.clear();
88   sl.addColumn(0);
89   sl.addColumn(110);
90
91   int first = 1;
92
93   char tempA[300]; // FIXME  this is guesswork!
94   char tempB[300]; // FIXME
95   struct tm* btime;
96
97   Directory* dir;
98   DirectoryList::iterator i;
99   for (i = recDir->dirList.begin(); i != recDir->dirList.end(); i++)
100   {
101     dir = *i;
102     SNPRINTF(tempA, 299, tr("<dir> %lu\t%s"), dir->getNumRecordings(), dir->name);
103     dir->index = sl.addOption(tempA, first);
104     first = 0;
105   }
106
107   // FIXME convert the whole program to time_t's
108
109   Recording* rec;
110   for (UINT j = 0; j < recDir->recList.size(); j++)
111   {
112     rec = recDir->recList[j];
113     btime = localtime((time_t*)&rec->start);
114     strftime(tempA, 299, "%0d/%0m %0H:%0M ", btime);
115     sprintf(tempB, "%s\t%s", tempA, rec->getProgName());
116     rec->index = sl.addOption(tempB, first);
117     first = 0;
118   }
119
120   sl.hintSetCurrent(saveIndex);
121   sl.hintSetTop(saveTop);
122   sl.draw();
123   doShowingBar();
124 }
125
126 void VRecordingList::draw()
127 {
128   char title[300];
129   if (myParent)
130   {
131     SNPRINTF(title, 299, tr("Recordings - %s"), recDir->name);
132     setTitleText(title);
133   }
134   else
135   {
136     setTitleText(tr("Recordings"));
137   }
138
139   View::draw();
140
141   char freeSpace[50];
142   int gigFree = Directory::freeSpace / 1024;
143   SNPRINTF(freeSpace, 49, tr("%lu%% used, %iGB free"), Directory::usedPercent, gigFree);
144   drawTextRJ(freeSpace, 560, 5, Colour::LIGHTTEXT);
145
146   // Symbols
147
148   WSymbol w;
149   w.setSurface(surface);
150
151   w.nextSymbol = WSymbol::UP;
152   w.setSurfaceOffset(20, 385);
153   w.draw();
154
155   w.nextSymbol = WSymbol::DOWN;
156   w.setSurfaceOffset(50, 385);
157   w.draw();
158
159   w.nextSymbol = WSymbol::SKIPBACK;
160   w.setSurfaceOffset(85, 385);
161   w.draw();
162
163   w.nextSymbol = WSymbol::SKIPFORWARD;
164   w.setSurfaceOffset(115, 385);
165   w.draw();
166
167   w.nextSymbol = WSymbol::PLAY;
168   w.setSurfaceOffset(150, 385);
169   w.draw();
170
171   drawTextRJ(tr("[ok] = menu"), 560, 385, Colour::LIGHTTEXT);
172
173   // All static stuff done
174
175   drawData();
176 }
177
178 void VRecordingList::doShowingBar()
179 {
180   int topOption = sl.getTopOption() + 1;
181   if (sl.getNumOptions() == 0) topOption = 0;
182
183   rectangle(220, 385, 180, 25, Colour::VIEWBACKGROUND);
184   char showing[200];
185   sprintf(showing, tr("%i to %i of %i"), topOption, sl.getBottomOption(), sl.getNumOptions());
186   drawText(showing, 220, 385, Colour::LIGHTTEXT);
187 }
188
189 void VRecordingList::processMessage(Message* m)
190 {
191   Log::getInstance()->log("VRecordingList", Log::DEBUG, "Got message value %lu", m->message);
192   if (m->message == Message::DELETE_SELECTED_RECORDING)
193   {
194     Log::getInstance()->log("VRecordingList", Log::DEBUG, "Doing delete selected");
195     doDeleteSelected();
196     return;
197   }
198
199   if (m->message == Message::PLAY_SELECTED_RECORDING)
200   {
201     doPlay();
202     return;
203   }
204
205   if (m->message == Message::RESUME_SELECTED_RECORDING)
206   {
207     doResume();
208     return;
209   }
210 }
211
212 void VRecordingList::doDeleteSelected()
213 {
214   Log::getInstance()->log("VRecordingList", Log::DEBUG, "Parent = %p, isRoot = %i", myParent, recDir->isRoot);
215   Recording* toDelete = getCurrentOptionRecording();
216
217   if (toDelete)
218   {
219     Log::getInstance()->log("VRecordingList", Log::DEBUG, "FOUND: %i %s %s", toDelete->index, toDelete->getProgName(), toDelete->fileName);
220
221     VDR* vdr = VDR::getInstance();
222     int success = vdr->deleteRecording(toDelete->fileName);
223     if (!vdr->isConnected())
224     {
225       Command::getInstance()->connectionLost();
226     }
227
228     if (success != 1)
229     {
230       VInfo* vi = new VInfo();
231       vi->create(360, 200);
232       if (Video::getInstance()->getFormat() == Video::PAL)
233         vi->setScreenPos(190, 170);
234       else
235         vi->setScreenPos(180, 120);
236       vi->setOneLiner(tr("Failed to delete recording"));
237       vi->setExitable();
238       vi->setBorderOn(1);
239       vi->setTitleBarColour(Colour::DANGER);
240       vi->okButton();
241       vi->draw();
242       viewman->add(vi);
243       viewman->updateView(vi);
244     }
245     else
246     {
247       delete toDelete;
248
249       for(RecordingList::iterator i = recDir->recList.begin(); i != recDir->recList.end(); i++)
250       {
251         if (*i == toDelete)
252         {
253           recDir->recList.erase(i);
254           break;
255         }
256       }
257
258       drawData();
259       viewman->updateView(this);
260
261       if (myParent) myParent->drawData(); // if this is not root get parent to redraw data
262     }
263     Log::getInstance()->log("VRecordingList", Log::DEBUG, "Parent = %p, isRoot = %i", myParent, recDir->isRoot);
264   }
265 }
266
267 int VRecordingList::doPlay()
268 {
269   Recording* toPlay = getCurrentOptionRecording();
270   if (toPlay)
271   {
272     VVideoRec* vidrec = new VVideoRec(toPlay);
273     vidrec->draw();
274     viewman->add(vidrec);
275     viewman->updateView(vidrec);
276     vidrec->go(0);
277     return 1;
278   }
279   // should not get to here
280   return 0;
281 }
282
283 int VRecordingList::doResume()
284 {
285   Recording* toResume = getCurrentOptionRecording();
286   if (toResume)
287   {
288     ULLONG position = VDR::getInstance()->getResumePoint(toResume->fileName);
289
290     VVideoRec* vidrec = new VVideoRec(toResume);
291     vidrec->draw();
292     viewman->add(vidrec);
293     viewman->updateView(vidrec);
294     vidrec->go(position);
295     return 1;
296   }
297   // should not get to here
298   return 0;
299 }
300
301 Recording* VRecordingList::getCurrentOptionRecording()
302 {
303   Recording* current;
304   for (UINT i = 0; i < recDir->recList.size(); i++)
305   {
306     current = recDir->recList[i];
307     if (current->index == sl.getCurrentOption()) return current;
308   }
309   return NULL;
310 }
311
312 int VRecordingList::handleCommand(int command)
313 {
314   switch(command)
315   {
316     case Remote::DF_UP:
317     case Remote::UP:
318     {
319       sl.up();
320       sl.draw();
321
322       doShowingBar();
323       viewman->updateView(this);
324       return 2;
325     }
326     case Remote::DF_DOWN:
327     case Remote::DOWN:
328     {
329       sl.down();
330       sl.draw();
331
332       doShowingBar();
333       viewman->updateView(this);
334       return 2;
335     }
336     case Remote::SKIPBACK:
337     {
338       sl.pageUp();
339       sl.draw();
340
341       doShowingBar();
342       viewman->updateView(this);
343       return 2;
344     }
345     case Remote::SKIPFORWARD:
346     {
347       sl.pageDown();
348       sl.draw();
349
350       doShowingBar();
351       viewman->updateView(this);
352       return 2;
353     }
354     case Remote::OK:
355     {
356       if (sl.getNumOptions() == 0) return 2;
357
358       // Check to see if it is a sub directory
359       Directory* curDir;
360       for(UINT i = 0; i < recDir->dirList.size(); i++)
361       {
362         curDir = recDir->dirList[i];
363         if (curDir->index == sl.getCurrentOption())
364         {
365           VRecordingList* sub = new VRecordingList(this, curDir);
366           sub->draw();
367           viewman->add(sub);
368           viewman->updateView(sub);
369           return 2;
370         }
371       }
372
373       // check to see if it's a recording
374       Recording* current = getCurrentOptionRecording();
375       if (current)
376       {
377         Log::getInstance()->log("VRecordingList", Log::DEBUG, "Found the option you pointed at. %s %s", current->getProgName(), current->fileName);
378
379         VRecordingMenu* v = new VRecordingMenu();
380         v->setParent(this);
381         v->setRecording(current);
382         v->draw();
383         viewman->add(v);
384         viewman->updateView(v);
385         return 2;
386       }
387       // should not get to here
388       return 1;
389     }
390     case Remote::BACK:
391     {
392       return 4;
393     }
394     case Remote::PLAY:
395     {
396       if (doResume()) return 2;
397       return 1;
398     }
399
400   }
401   // stop command getting to any more views
402   return 1;
403 }