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