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