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