2 Copyright 2004-2019 Chris Tallon
4 This file is part of VOMP.
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.
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.
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/>.
20 #include "vrecordinglist.h"
23 #include "directory.h"
24 #include "recording.h"
28 #include "vrecordingmenu.h"
29 #include "vrecording.h"
31 #include "vvideorec.h"
32 #include "vradiorec.h"
40 VRecordingList::VRecordingList()
42 boxstack = BoxStack::getInstance();
48 VRecordingList::~VRecordingList()
53 void VRecordingList::processMessage(Message* m)
55 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Got message value %lu", m->message);
57 if (m->message == Message::MOUSE_MOVE)
59 if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
62 boxstack->update(this);
65 else if (m->message == Message::MOUSE_LBDOWN)
67 if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
69 boxstack->handleCommand(Input::OK); //simulate OK press
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())
78 boxstack->handleCommand(Input::BACK); //simulate cancel press
82 else if (m->message == Message::DELETE_SELECTED_RECORDING)
84 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Doing delete selected");
87 else if (m->message == Message::MOVE_RECORDING)
89 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Doing move recording");
90 doMoveRecording(reinterpret_cast<Directory*>(m->parameter));
92 else if (m->message == Message::PLAY_SELECTED_RECORDING)
96 else if (m->message == Message::RESUME_SELECTED_RECORDING)
100 else if (m->message == Message::REDRAW)
103 BoxStack::getInstance()->update(this);
107 void VRecordingList::doDeleteSelected()
109 Recording* toDelete = getCurrentOptionRecording();
111 if (!toDelete) return;
113 Log::getInstance()->log("VRecordingList", Log::DEBUG, "FOUND: %i %s %s", toDelete->index, toDelete->getProgName(), toDelete->getFileName());
115 int success = recman->deleteRecording(toDelete);
116 if (!VDR::getInstance()->isConnected())
118 Command::getInstance()->connectionLost();
124 VInfo* vi = new VInfo();
125 vi->setSize(360, 200);
127 if (Video::getInstance()->getFormat() == Video::PAL)
128 vi->setPosition(190, 170);
130 vi->setPosition(180, 120);
131 vi->setOneLiner(tr("Failed to delete recording"));
134 vi->setTitleBarColour(DrawStyle::DANGER);
138 boxstack->update(vi);
143 boxstack->update(this);
148 void VRecordingList::doMoveRecording(Directory* toDir)
150 Recording* toMove = getCurrentOptionRecording();
151 if (!toMove || !toDir) return;
153 Log::getInstance()->log("VRecordingList", Log::DEBUG, "MOVE: %s %s", toMove->getProgName(), toDir->name);
155 int success = recman->moveRecording(toMove, toDir);
156 if (!VDR::getInstance()->isConnected())
158 Command::getInstance()->connectionLost();
164 VInfo* vi = new VInfo();
165 vi->setSize(360, 200);
167 if (Video::getInstance()->getFormat() == Video::PAL)
168 vi->setPosition(190, 170);
170 vi->setPosition(180, 120);
171 vi->setOneLiner(tr("Failed to move recording"));
174 vi->setTitleBarColour(DrawStyle::DANGER);
178 boxstack->update(vi);
183 boxstack->update(this);
187 int VRecordingList::doPlay(bool resume)
189 Recording* toPlay = getCurrentOptionRecording();
193 toPlay->loadRecInfo();
195 if (toPlay->recInfo == NULL)
197 VInfo* vi = new VInfo();
198 vi->setSize(360, 200);
200 if (Video::getInstance()->getFormat() == Video::PAL)
201 vi->setPosition(190, 170);
203 vi->setPosition(180, 120);
204 vi->setOneLiner(tr("Error playing recording"));
207 vi->setTitleBarColour(DrawStyle::DANGER);
211 boxstack->update(vi);
217 bool isRadio = toPlay->isRadio(ish264);
221 VRadioRec* radrec = new VRadioRec(toPlay);
223 boxstack->add(radrec);
224 boxstack->update(radrec);
227 toPlay->setNew(false);
229 boxstack->update(this);
233 if (ish264 && !Video::getInstance()->supportsh264())
235 VInfo* vi = new VInfo();
236 vi->setSize(360, 200);
238 if (Video::getInstance()->getFormat() == Video::PAL)
239 vi->setPosition(190, 170);
241 vi->setPosition(180, 120);
242 vi->setOneLiner(tr("H264 video not supported"));
245 vi->setTitleBarColour(DrawStyle::DANGER);
249 boxstack->update(vi);
251 else if (!ish264 && !Video::getInstance()->supportsmpeg2())
253 VInfo* vi = new VInfo();
254 vi->setSize(360, 200);
256 if (Video::getInstance()->getFormat() == Video::PAL)
257 vi->setPosition(190, 170);
259 vi->setPosition(180, 120);
260 vi->setOneLiner(tr("Mpeg2 video not supported"));
263 vi->setTitleBarColour(DrawStyle::DANGER);
267 boxstack->update(vi);
271 VVideoRec* vidrec = new VVideoRec(toPlay, ish264);
273 boxstack->add(vidrec);
274 boxstack->update(vidrec);
277 toPlay->setNew(false);
279 boxstack->update(this);
284 // should not get to here
288 Recording* VRecordingList::getCurrentOptionRecording()
290 Recording* currentRec;
291 RecordingList::iterator j;
292 RecordingList* recList = recman->getRecordings();
293 for (j = recList->begin(); j != recList->end(); j++)
296 if (currentRec->index == sl.getCurrentOption()) return currentRec;
302 Directory* VRecordingList::getCurrentOptionDirectory()
304 Directory* currentSubDir;
305 DirectoryList::iterator i;
306 DirectoryList* dirList = recman->getDirectories();
307 for (i = dirList->begin(); i != dirList->end(); i++)
310 if (currentSubDir->index == sl.getCurrentOption())
313 return currentSubDir;
320 int VRecordingList::handleCommand(int command)
329 boxstack->update(this);
337 boxstack->update(this);
340 case Input::SKIPBACK:
345 boxstack->update(this);
348 case Input::SKIPFORWARD:
353 boxstack->update(this);
358 if (sl.getNumOptions() == 0) return 2;
360 // Check to see if it is a sub directory
361 Directory* currentSubDir=getCurrentOptionDirectory();
365 if (recman->down(currentSubDir))
367 slIndexStack.push(sl.getCurrentOption());
370 boxstack->update(this);
376 // check to see if it's a recording
377 Recording* current = getCurrentOptionRecording();
380 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Found the option you pointed at. %s %s", current->getProgName(), current->getFileName());
383 VRecordingMenu* v = new VRecordingMenu(recman);
385 v->setRecording(current);
390 VRecording* vr = new VRecording(recman, current);
394 boxstack->update(vr);
398 // should not get to here
403 if (recman->isSubDir())
408 boxstack->update(this);
416 case Input::PLAYPAUSE:
419 if (doPlay(true)) return 2;
430 // stop command getting to any more views
434 bool VRecordingList::load()
436 VDR* vdr = VDR::getInstance();
438 recman = new RecMan();
440 bool success = vdr->getRecordingsList(recman);
445 char* defaultSortOrder = vdr->configLoad("General", "Recordings Sort Order");
446 if (defaultSortOrder)
448 if (!STRCASECMP(defaultSortOrder, "Chronological")) recman->setSortOrderChron();
449 delete[] defaultSortOrder;
453 boxstack->update(this);
459 void VRecordingList::reSort()
461 recman->toggleSortOrder();
465 boxstack->update(this);