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