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"
24 #include "directory.h"
25 #include "recording.h"
29 #include "vrecordingmenu.h"
30 #include "vrecording.h"
32 #include "vvideorec.h"
33 #include "vradiorec.h"
40 static const char* TAG = "VRecordingList";
42 VRecordingList::VRecordingList()
44 boxstack = BoxStack::getInstance();
47 MessageQueue::getInstance()->addReceiver(this);
50 VRecordingList::~VRecordingList()
52 MessageQueue::getInstance()->removeReceiver(this);
56 void VRecordingList::processMessage(Message* m)
58 LogNT::getInstance()->debug(TAG, "Got message value {}", m->message);
60 if (m->message == Message::MOUSE_MOVE)
62 if (sl.mouseMove(m->parameter - getScreenX(), m->tag - getScreenY()))
65 boxstack->update(this);
68 else if (m->message == Message::MOUSE_LBDOWN)
70 if (sl.mouseLBDOWN(m->parameter - getScreenX(), m->tag - getScreenY()))
72 Input::sendInputKey(Input::OK);
74 else if (coordsOutsideBox(m))
76 Input::sendInputKey(Input::BACK);
79 else if (m->message == Message::DELETE_SELECTED_RECORDING)
81 LogNT::getInstance()->debug(TAG, "Doing delete selected");
84 else if (m->message == Message::MOVE_RECORDING)
86 LogNT::getInstance()->debug(TAG, "Doing move recording");
87 doMoveRecording(reinterpret_cast<Directory*>(m->parameter));
89 else if (m->message == Message::PLAY_SELECTED_RECORDING)
93 else if (m->message == Message::RESUME_SELECTED_RECORDING)
97 else if (m->message == Message::REDRAW)
100 BoxStack::getInstance()->update(this);
104 void VRecordingList::doDeleteSelected()
106 Recording* toDelete = getCurrentOptionRecording();
108 if (!toDelete) return;
110 LogNT::getInstance()->debug(TAG, "FOUND: {} {} {}", toDelete->index, toDelete->getProgName(), toDelete->getFileName());
112 int success = recman->deleteRecording(toDelete);
113 if (!VDR::getInstance()->isConnected())
115 Control::getInstance()->connectionLost();
121 VInfo* vi = new VInfo();
122 vi->setSize(360, 200);
124 if (Video::getInstance()->getFormat() == Video::PAL)
125 vi->setPosition(190, 170);
127 vi->setPosition(180, 120);
128 vi->setOneLiner(tr("Failed to delete recording"));
131 vi->setTitleBarColour(DrawStyle::DANGER);
135 boxstack->update(vi);
140 boxstack->update(this);
145 void VRecordingList::doMoveRecording(Directory* toDir)
147 Recording* toMove = getCurrentOptionRecording();
148 if (!toMove || !toDir) return;
150 LogNT::getInstance()->debug(TAG, "MOVE: {} {}", toMove->getProgName(), toDir->name);
152 int success = recman->moveRecording(toMove, toDir);
153 if (!VDR::getInstance()->isConnected())
155 Control::getInstance()->connectionLost();
161 VInfo* vi = new VInfo();
162 vi->setSize(360, 200);
164 if (Video::getInstance()->getFormat() == Video::PAL)
165 vi->setPosition(190, 170);
167 vi->setPosition(180, 120);
168 vi->setOneLiner(tr("Failed to move recording"));
171 vi->setTitleBarColour(DrawStyle::DANGER);
175 boxstack->update(vi);
180 boxstack->update(this);
184 int VRecordingList::doPlay(bool resume)
186 Recording* toPlay = getCurrentOptionRecording();
190 toPlay->loadRecInfo();
192 if (toPlay->recInfo == NULL)
194 VInfo* vi = new VInfo();
195 vi->setSize(360, 200);
197 if (Video::getInstance()->getFormat() == Video::PAL)
198 vi->setPosition(190, 170);
200 vi->setPosition(180, 120);
201 vi->setOneLiner(tr("Error playing recording"));
204 vi->setTitleBarColour(DrawStyle::DANGER);
208 boxstack->update(vi);
214 bool isRadio = toPlay->isRadio(ish264);
218 VRadioRec* radrec = new VRadioRec(toPlay);
220 boxstack->add(radrec);
221 boxstack->update(radrec);
224 toPlay->setNew(false);
226 boxstack->update(this);
230 if (ish264 && !Video::getInstance()->supportsh264())
232 VInfo* vi = new VInfo();
233 vi->setSize(360, 200);
235 if (Video::getInstance()->getFormat() == Video::PAL)
236 vi->setPosition(190, 170);
238 vi->setPosition(180, 120);
239 vi->setOneLiner(tr("H264 video not supported"));
242 vi->setTitleBarColour(DrawStyle::DANGER);
246 boxstack->update(vi);
248 else if (!ish264 && !Video::getInstance()->supportsmpeg2())
250 VInfo* vi = new VInfo();
251 vi->setSize(360, 200);
253 if (Video::getInstance()->getFormat() == Video::PAL)
254 vi->setPosition(190, 170);
256 vi->setPosition(180, 120);
257 vi->setOneLiner(tr("Mpeg2 video not supported"));
260 vi->setTitleBarColour(DrawStyle::DANGER);
264 boxstack->update(vi);
268 VVideoRec* vidrec = new VVideoRec(toPlay, ish264);
270 boxstack->add(vidrec);
271 boxstack->update(vidrec);
274 toPlay->setNew(false);
276 boxstack->update(this);
281 // should not get to here
285 Recording* VRecordingList::getCurrentOptionRecording()
287 Recording* currentRec;
288 RecordingList::iterator j;
289 RecordingList* recList = recman->getRecordings();
290 for (j = recList->begin(); j != recList->end(); j++)
293 if (currentRec->index == sl.getCurrentOption()) return currentRec;
299 Directory* VRecordingList::getCurrentOptionDirectory()
301 Directory* currentSubDir;
302 DirectoryList::iterator i;
303 DirectoryList* dirList = recman->getDirectories();
304 for (i = dirList->begin(); i != dirList->end(); i++)
307 if (currentSubDir->index == sl.getCurrentOption())
310 return currentSubDir;
317 int VRecordingList::handleCommand(int command)
326 boxstack->update(this);
327 return BoxStack::COMMAND_HANDLED;
334 boxstack->update(this);
335 return BoxStack::COMMAND_HANDLED;
337 case Input::SKIPBACK:
342 boxstack->update(this);
343 return BoxStack::COMMAND_HANDLED;
345 case Input::SKIPFORWARD:
350 boxstack->update(this);
351 return BoxStack::COMMAND_HANDLED;
355 if (sl.getNumOptions() == 0) return BoxStack::COMMAND_HANDLED;
357 // Check to see if it is a sub directory
358 Directory* currentSubDir=getCurrentOptionDirectory();
362 if (recman->down(currentSubDir))
364 slIndexStack.push(sl.getCurrentOption());
367 boxstack->update(this);
369 return BoxStack::COMMAND_HANDLED;
373 // check to see if it's a recording
374 Recording* current = getCurrentOptionRecording();
377 LogNT::getInstance()->debug(TAG, "Found the option you pointed at. {} {}", current->getProgName(), current->getFileName());
380 VRecordingMenu* v = new VRecordingMenu(recman);
382 v->setRecording(current);
387 VRecording* vr = new VRecording(recman, current);
391 boxstack->update(vr);
393 return BoxStack::COMMAND_HANDLED;
395 // should not get to here
396 return BoxStack::ABANDON_COMMAND;
400 if (recman->isSubDir())
405 boxstack->update(this);
406 return BoxStack::COMMAND_HANDLED;
410 return BoxStack::DELETE_ME;
413 case Input::PLAYPAUSE:
416 if (doPlay(true)) return BoxStack::COMMAND_HANDLED;
417 return BoxStack::ABANDON_COMMAND;
424 return BoxStack::COMMAND_HANDLED;
427 // stop command getting to any more views
428 return BoxStack::ABANDON_COMMAND;
431 bool VRecordingList::load()
433 VDR* vdr = VDR::getInstance();
435 recman = new RecMan();
437 bool success = vdr->getRecordingsList(recman);
442 char* defaultSortOrder = vdr->configLoad("General", "Recordings Sort Order");
443 if (defaultSortOrder)
445 if (!STRCASECMP(defaultSortOrder, "Chronological")) recman->setSortOrderChron();
446 delete[] defaultSortOrder;
450 boxstack->update(this);
456 void VRecordingList::reSort()
458 recman->toggleSortOrder();
462 boxstack->update(this);