]> git.vomp.tv Git - vompclient.git/blob - vrecordinglist.cc
Fix text corruption in channel number display on live tv
[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
192   if (toPlay)
193   {
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         toPlay->loadRecInfo();
251
252         if (toPlay->recInfo == NULL)
253         {
254           VInfo* vi = new VInfo();
255           vi->setSize(360, 200);
256           vi->createBuffer();
257           if (Video::getInstance()->getFormat() == Video::PAL)
258             vi->setPosition(190, 170);
259           else
260             vi->setPosition(180, 120);
261           vi->setOneLiner(tr("Error playing recording"));
262           vi->setExitable();
263           vi->setBorderOn(1);
264           vi->setTitleBarColour(DrawStyle::DANGER);
265           vi->okButton();
266           vi->draw();
267           boxstack->add(vi);
268           boxstack->update(vi);
269           return 0;
270         }
271
272         VVideoRec* vidrec = new VVideoRec(toPlay, ish264);
273         vidrec->draw();
274         boxstack->add(vidrec);
275         boxstack->update(vidrec);
276         vidrec->go(resume);
277
278         toPlay->setNew(false);
279         draw();
280         boxstack->update(this);
281       }
282     }
283     return 1;
284   }
285   // should not get to here
286   return 0;
287 }
288
289 Recording* VRecordingList::getCurrentOptionRecording()
290 {
291   Recording* currentRec;
292   RecordingList::iterator j;
293   RecordingList* recList = recman->getRecordings();
294   for (j = recList->begin(); j != recList->end(); j++)
295   {
296     currentRec = *j;
297     if (currentRec->index == sl.getCurrentOption()) return currentRec;
298   }
299
300   return NULL;
301 }
302
303 Directory* VRecordingList::getCurrentOptionDirectory()
304 {
305         Directory* currentSubDir;
306         DirectoryList::iterator i;
307         DirectoryList* dirList = recman->getDirectories();
308         for (i = dirList->begin(); i != dirList->end(); i++)
309         {
310                 currentSubDir = *i;
311                 if (currentSubDir->index == sl.getCurrentOption())
312                 {
313
314                         return currentSubDir;
315                 }
316         }
317
318         return NULL;
319 }
320
321 int VRecordingList::handleCommand(int command)
322 {
323   switch(command)
324   {
325     case Remote::DF_UP:
326     case Remote::UP:
327     {
328       sl.up();
329       quickUpdate();
330
331       boxstack->update(this);
332       return 2;
333     }
334     case Remote::DF_DOWN:
335     case Remote::DOWN:
336     {
337       sl.down();
338       quickUpdate();
339
340       boxstack->update(this);
341       return 2;
342     }
343     case Remote::SKIPBACK:
344     {
345       sl.pageUp();
346       quickUpdate();
347
348       boxstack->update(this);
349       return 2;
350     }
351     case Remote::SKIPFORWARD:
352     {
353       sl.pageDown();
354       quickUpdate();
355
356       boxstack->update(this);
357       return 2;
358     }
359     case Remote::OK:
360     {
361       if (sl.getNumOptions() == 0) return 2;
362
363       // Check to see if it is a sub directory
364       Directory* currentSubDir=getCurrentOptionDirectory();
365
366       if (currentSubDir)
367       {
368           if (recman->down(currentSubDir))
369           {
370                   slIndexStack.push(sl.getCurrentOption());
371                   sl.clear();
372                   draw();
373                   boxstack->update(this);
374           }
375           return 2;
376       }
377
378
379       // check to see if it's a recording
380       Recording* current = getCurrentOptionRecording();
381       if (current)
382       {
383         Log::getInstance()->log("VRecordingList", Log::DEBUG, "Found the option you pointed at. %s %s", current->getProgName(), current->getFileName());
384
385 /*
386         VRecordingMenu* v = new VRecordingMenu(recman);
387         v->setParent(this);
388         v->setRecording(current);
389         v->draw();
390         boxstack->add(v);
391         boxstack->update(v);
392 */        
393         VRecording* vr = new VRecording(recman, current);
394         vr->setParent(this);
395         vr->draw();
396         boxstack->add(vr);
397         boxstack->update(vr);
398         
399         return 2;
400       }
401       // should not get to here
402       return 1;
403     }
404     case Remote::BACK:
405     {
406       if (recman->isSubDir())
407       {
408         recman->up();
409         sl.clear();
410         draw(true);
411         boxstack->update(this);
412         return 2;
413       }
414       else
415       {
416         return 4;
417       }
418     }
419     case Remote::PLAYPAUSE:
420     case Remote::PLAY:
421     {
422       if (doPlay(true)) return 2;
423       return 1;
424     }
425     case Remote::LEFT:
426     case Remote::RIGHT:
427     case Remote::ZERO:
428     {
429       reSort();
430       return 2;
431     }
432   }
433   // stop command getting to any more views
434   return 1;
435 }
436
437 bool VRecordingList::load()
438 {
439   VDR* vdr = VDR::getInstance();
440
441   recman = new RecMan();
442
443   bool success = vdr->getRecordingsList(recman);
444
445   if (success)
446   {
447     loading = false;
448     char* defaultSortOrder = vdr->configLoad("General", "Recordings Sort Order");
449     if (defaultSortOrder)
450     {
451       if (!STRCASECMP(defaultSortOrder, "Chronological")) recman->setSortOrderChron();
452       delete[] defaultSortOrder;
453     }
454     recman->sort();
455     draw();
456     boxstack->update(this);
457   }
458
459   return success;
460 }
461
462 void VRecordingList::reSort()
463 {
464   recman->toggleSortOrder();
465   recman->sort();
466   sl.clear();
467   draw();
468   boxstack->update(this);
469 }
470