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