]> git.vomp.tv Git - vompclient.git/blob - vrecordinglist.cc
Display channel name, duration, resume point and size on recording info screen
[vompclient.git] / vrecordinglist.cc
1 /*
2     Copyright 2004-2007 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 */
20
21 #include "vrecordinglist.h"
22
23 #include "recman.h"
24 #include "directory.h"
25 #include "recording.h"
26 #include "remote.h"
27 #include "wsymbol.h"
28 #include "boxstack.h"
29 #include "vrecordingmenu.h"
30 #include "vrecording.h"
31 #include "vdr.h"
32 #include "vvideorec.h"
33 #include "vradiorec.h"
34 #include "colour.h"
35 #include "video.h"
36 #include "i18n.h"
37 #include "command.h"
38 #include "vinfo.h"
39 #include "log.h"
40
41 VRecordingList::VRecordingList()
42 {
43   boxstack = BoxStack::getInstance();
44   recman = NULL;
45   loading = true;
46
47 }
48
49 VRecordingList::~VRecordingList()
50 {
51   delete recman;
52 }
53
54 void VRecordingList::processMessage(Message* m)
55 {
56   Log::getInstance()->log("VRecordingList", Log::DEBUG, "Got message value %lu", m->message);
57
58   if (m->message == Message::MOUSE_MOVE)
59   {
60     if (sl.mouseMove((m->parameter.num>>16)-getScreenX(),(m->parameter.num&0xFFFF)-getScreenY()))
61     {
62       quickUpdate();
63       boxstack->update(this);
64     }
65   }
66   else if (m->message == Message::MOUSE_LBDOWN)
67   {
68     if (sl.mouseLBDOWN((m->parameter.num>>16)-getScreenX(),(m->parameter.num&0xFFFF)-getScreenY()))
69     {
70       boxstack->handleCommand(Remote::OK); //simulate OK press
71     }
72     else
73     {
74       //check if press is outside this view! then simulate cancel
75       int x=(m->parameter.num>>16)-getScreenX();
76       int y=(m->parameter.num&0xFFFF)-getScreenY();
77       if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
78       {
79         boxstack->handleCommand(Remote::BACK); //simulate cancel press
80       }
81     }
82   }
83   else if (m->message == Message::DELETE_SELECTED_RECORDING)
84   {
85     Log::getInstance()->log("VRecordingList", Log::DEBUG, "Doing delete selected");
86     doDeleteSelected();
87   }
88   else if (m->message == Message::MOVE_RECORDING)
89   {
90     Log::getInstance()->log("VRecordingList", Log::DEBUG, "Doing move recording");
91     doMoveRecording((Directory*)m->parameter.num);
92   }
93   else if (m->message == Message::PLAY_SELECTED_RECORDING)
94   {
95     doPlay(false);
96   }
97   else if (m->message == Message::RESUME_SELECTED_RECORDING)
98   {
99     doPlay(true);
100   }
101 }
102
103 void VRecordingList::doDeleteSelected()
104 {
105   Recording* toDelete = getCurrentOptionRecording();
106
107   if (!toDelete) return;
108
109   Log::getInstance()->log("VRecordingList", Log::DEBUG, "FOUND: %i %s %s", toDelete->index, toDelete->getProgName(), toDelete->getFileName());
110
111   int success = recman->deleteRecording(toDelete);
112   if (!VDR::getInstance()->isConnected())
113   {
114     Command::getInstance()->connectionLost();
115     return;
116   }
117
118   if (success != 1)
119   {
120     VInfo* vi = new VInfo();
121     vi->setSize(360, 200);
122     vi->createBuffer();
123     if (Video::getInstance()->getFormat() == Video::PAL)
124       vi->setPosition(190, 170);
125     else
126       vi->setPosition(180, 120);
127     vi->setOneLiner(tr("Failed to delete recording"));
128     vi->setExitable();
129     vi->setBorderOn(1);
130     vi->setTitleBarColour(DrawStyle::DANGER);
131     vi->okButton();
132     vi->draw();
133     boxstack->add(vi);
134     boxstack->update(vi);
135   }
136   else
137   {
138     draw();
139     boxstack->update(this);
140   }
141
142 }
143
144 void VRecordingList::doMoveRecording(Directory* toDir)
145 {
146   Recording* toMove = getCurrentOptionRecording();
147   if (!toMove || !toDir) return;
148
149   Log::getInstance()->log("VRecordingList", Log::DEBUG, "MOVE: %s %s", toMove->getProgName(), toDir->name);
150
151   int success = recman->moveRecording(toMove, toDir);
152   if (!VDR::getInstance()->isConnected())
153   {
154     Command::getInstance()->connectionLost();
155     return;
156   }
157
158   if (success != 1)
159   {
160     VInfo* vi = new VInfo();
161     vi->setSize(360, 200);
162     vi->createBuffer();
163     if (Video::getInstance()->getFormat() == Video::PAL)
164       vi->setPosition(190, 170);
165     else
166       vi->setPosition(180, 120);
167     vi->setOneLiner(tr("Failed to move recording"));
168     vi->setExitable();
169     vi->setBorderOn(1);
170     vi->setTitleBarColour(DrawStyle::DANGER);
171     vi->okButton();
172     vi->draw();
173     boxstack->add(vi);
174     boxstack->update(vi);
175   }
176   else
177   {
178     draw();
179     boxstack->update(this);
180   }
181 }
182
183 int VRecordingList::doPlay(bool resume)
184 {
185   Recording* toPlay = getCurrentOptionRecording();
186   if (toPlay)
187   {
188     toPlay->loadRecInfo(); // check if still need this
189     toPlay->loadMarks();
190     bool ish264;
191     bool isRadio = toPlay->isRadio(ish264);
192
193     if (isRadio)
194     {
195       VRadioRec* radrec = new VRadioRec(toPlay);
196       radrec->draw();
197       boxstack->add(radrec);
198       boxstack->update(radrec);
199       radrec->go();
200       
201       toPlay->setNew(false);
202       draw();
203       boxstack->update(this);
204     }
205     else
206     {
207       if (ish264 && !Video::getInstance()->supportsh264())
208       {
209         VInfo* vi = new VInfo();
210         vi->setSize(360, 200);
211         vi->createBuffer();
212         if (Video::getInstance()->getFormat() == Video::PAL)
213           vi->setPosition(190, 170);
214         else
215           vi->setPosition(180, 120);
216         vi->setOneLiner(tr("H264 video not supported"));
217         vi->setExitable();
218         vi->setBorderOn(1);
219         vi->setTitleBarColour(DrawStyle::DANGER);
220         vi->okButton();
221         vi->draw();
222         boxstack->add(vi);
223         boxstack->update(vi);
224       }
225       else if (!ish264 && !Video::getInstance()->supportsmpeg2())
226       {
227         VInfo* vi = new VInfo();
228         vi->setSize(360, 200);
229         vi->createBuffer();
230         if (Video::getInstance()->getFormat() == Video::PAL)
231           vi->setPosition(190, 170);
232         else
233           vi->setPosition(180, 120);
234         vi->setOneLiner(tr("Mpeg2 video not supported"));
235         vi->setExitable();
236         vi->setBorderOn(1);
237         vi->setTitleBarColour(DrawStyle::DANGER);
238         vi->okButton();
239         vi->draw();
240         boxstack->add(vi);
241         boxstack->update(vi);
242       }
243       else
244       {
245         VVideoRec* vidrec = new VVideoRec(toPlay, ish264);
246         vidrec->draw();
247         boxstack->add(vidrec);
248         boxstack->update(vidrec);
249         vidrec->go(resume);
250
251         toPlay->setNew(false);
252         draw();
253         boxstack->update(this);
254       }
255     }
256     return 1;
257   }
258   // should not get to here
259   return 0;
260 }
261
262 Recording* VRecordingList::getCurrentOptionRecording()
263 {
264   Recording* currentRec;
265   RecordingList::iterator j;
266   RecordingList* recList = recman->getRecordings();
267   for (j = recList->begin(); j != recList->end(); j++)
268   {
269     currentRec = *j;
270     if (currentRec->index == sl.getCurrentOption()) return currentRec;
271   }
272
273   return NULL;
274 }
275
276 Directory* VRecordingList::getCurrentOptionDirectory()
277 {
278         Directory* currentSubDir;
279         DirectoryList::iterator i;
280         DirectoryList* dirList = recman->getDirectories();
281         for (i = dirList->begin(); i != dirList->end(); i++)
282         {
283                 currentSubDir = *i;
284                 if (currentSubDir->index == sl.getCurrentOption())
285                 {
286
287                         return currentSubDir;
288                 }
289         }
290
291         return NULL;
292 }
293
294 int VRecordingList::handleCommand(int command)
295 {
296   switch(command)
297   {
298     case Remote::DF_UP:
299     case Remote::UP:
300     {
301       sl.up();
302       quickUpdate();
303
304       boxstack->update(this);
305       return 2;
306     }
307     case Remote::DF_DOWN:
308     case Remote::DOWN:
309     {
310       sl.down();
311       quickUpdate();
312
313       boxstack->update(this);
314       return 2;
315     }
316     case Remote::SKIPBACK:
317     {
318       sl.pageUp();
319       quickUpdate();
320
321       boxstack->update(this);
322       return 2;
323     }
324     case Remote::SKIPFORWARD:
325     {
326       sl.pageDown();
327       quickUpdate();
328
329       boxstack->update(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* currentSubDir=getCurrentOptionDirectory();
338
339       if (currentSubDir)
340       {
341           if (recman->down(currentSubDir))
342           {
343                   slIndexStack.push(sl.getCurrentOption());
344                   sl.clear();
345                   draw();
346                   boxstack->update(this);
347           }
348           return 2;
349       }
350
351
352       // check to see if it's a recording
353       Recording* current = getCurrentOptionRecording();
354       if (current)
355       {
356         Log::getInstance()->log("VRecordingList", Log::DEBUG, "Found the option you pointed at. %s %s", current->getProgName(), current->getFileName());
357
358 /*
359         VRecordingMenu* v = new VRecordingMenu(recman);
360         v->setParent(this);
361         v->setRecording(current);
362         v->draw();
363         boxstack->add(v);
364         boxstack->update(v);
365 */        
366         VRecording* vr = new VRecording(recman, current);
367         vr->setParent(this);
368         vr->draw();
369         boxstack->add(vr);
370         boxstack->update(vr);
371         
372         return 2;
373       }
374       // should not get to here
375       return 1;
376     }
377     case Remote::BACK:
378     {
379       if (recman->isSubDir())
380       {
381         recman->up();
382         sl.clear();
383         draw(true);
384         boxstack->update(this);
385         return 2;
386       }
387       else
388       {
389         return 4;
390       }
391     }
392     case Remote::PLAYPAUSE:
393     case Remote::PLAY:
394     {
395       if (doPlay(true)) return 2;
396       return 1;
397     }
398     case Remote::LEFT:
399     case Remote::RIGHT:
400     case Remote::ZERO:
401     {
402       reSort();
403       return 2;
404     }
405   }
406   // stop command getting to any more views
407   return 1;
408 }
409
410 bool VRecordingList::load()
411 {
412   VDR* vdr = VDR::getInstance();
413
414   recman = new RecMan();
415
416   bool success = vdr->getRecordingsList(recman);
417
418   if (success)
419   {
420     loading = false;
421     char* defaultSortOrder = vdr->configLoad("General", "Recordings Sort Order");
422     if (defaultSortOrder)
423     {
424       if (!STRCASECMP(defaultSortOrder, "Chronological")) recman->setSortOrderChron();
425       delete[] defaultSortOrder;
426     }
427     recman->sort();
428     draw();
429     boxstack->update(this);
430   }
431
432   return success;
433 }
434
435 void VRecordingList::reSort()
436 {
437   recman->toggleSortOrder();
438   recman->sort();
439   sl.clear();
440   draw();
441   boxstack->update(this);
442 }
443