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