]> git.vomp.tv Git - vompclient.git/blob - vrecordinglist.cc
WIP [broken]
[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::UP:
325     {
326       sl.up();
327       quickUpdate();
328
329       boxstack->update(this);
330       return 2;
331     }
332     case Input::DOWN:
333     {
334       sl.down();
335       quickUpdate();
336
337       boxstack->update(this);
338       return 2;
339     }
340     case Input::SKIPBACK:
341     {
342       sl.pageUp();
343       quickUpdate();
344
345       boxstack->update(this);
346       return 2;
347     }
348     case Input::SKIPFORWARD:
349     {
350       sl.pageDown();
351       quickUpdate();
352
353       boxstack->update(this);
354       return 2;
355     }
356     case Input::OK:
357     {
358       if (sl.getNumOptions() == 0) return 2;
359
360       // Check to see if it is a sub directory
361       Directory* currentSubDir=getCurrentOptionDirectory();
362
363       if (currentSubDir)
364       {
365           if (recman->down(currentSubDir))
366           {
367                   slIndexStack.push(sl.getCurrentOption());
368                   sl.clear();
369                   draw();
370                   boxstack->update(this);
371           }
372           return 2;
373       }
374
375
376       // check to see if it's a recording
377       Recording* current = getCurrentOptionRecording();
378       if (current)
379       {
380         Log::getInstance()->log("VRecordingList", Log::DEBUG, "Found the option you pointed at. %s %s", current->getProgName(), current->getFileName());
381
382 /*
383         VRecordingMenu* v = new VRecordingMenu(recman);
384         v->setParent(this);
385         v->setRecording(current);
386         v->draw();
387         boxstack->add(v);
388         boxstack->update(v);
389 */        
390         VRecording* vr = new VRecording(recman, current);
391         vr->setParent(this);
392         vr->draw();
393         boxstack->add(vr);
394         boxstack->update(vr);
395         
396         return 2;
397       }
398       // should not get to here
399       return 1;
400     }
401     case Input::BACK:
402     {
403       if (recman->isSubDir())
404       {
405         recman->up();
406         sl.clear();
407         draw(true);
408         boxstack->update(this);
409         return 2;
410       }
411       else
412       {
413         return 4;
414       }
415     }
416     case Input::PLAYPAUSE:
417     case Input::PLAY:
418     {
419       if (doPlay(true)) return 2;
420       return 1;
421     }
422     case Input::LEFT:
423     case Input::RIGHT:
424     case Input::ZERO:
425     {
426       reSort();
427       return 2;
428     }
429   }
430   // stop command getting to any more views
431   return 1;
432 }
433
434 bool VRecordingList::load()
435 {
436   VDR* vdr = VDR::getInstance();
437
438   recman = new RecMan();
439
440   bool success = vdr->getRecordingsList(recman);
441
442   if (success)
443   {
444     loading = false;
445     char* defaultSortOrder = vdr->configLoad("General", "Recordings Sort Order");
446     if (defaultSortOrder)
447     {
448       if (!STRCASECMP(defaultSortOrder, "Chronological")) recman->setSortOrderChron();
449       delete[] defaultSortOrder;
450     }
451     recman->sort();
452     draw();
453     boxstack->update(this);
454   }
455
456   return success;
457 }
458
459 void VRecordingList::reSort()
460 {
461   recman->toggleSortOrder();
462   recman->sort();
463   sl.clear();
464   draw();
465   boxstack->update(this);
466 }
467