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();
50 VRecordingList::~VRecordingList()
55 void VRecordingList::processMessage(Message* m)
57 LogNT::getInstance()->debug(TAG, "Got message value {}", m->message);
59 if (m->message == Message::MOUSE_MOVE)
61 if (sl.mouseMove(m->parameter - getScreenX(), m->tag - getScreenY()))
64 boxstack->update(this);
67 else if (m->message == Message::MOUSE_LBDOWN)
69 if (sl.mouseLBDOWN(m->parameter - getScreenX(), m->tag - getScreenY()))
71 boxstack->handleCommand(Input::OK); //simulate OK press
73 else if (coordsOutsideBox(m))
75 boxstack->handleCommand(Input::BACK); //simulate cancel press
78 else if (m->message == Message::DELETE_SELECTED_RECORDING)
80 LogNT::getInstance()->debug(TAG, "Doing delete selected");
83 else if (m->message == Message::MOVE_RECORDING)
85 LogNT::getInstance()->debug(TAG, "Doing move recording");
86 doMoveRecording(reinterpret_cast<Directory*>(m->parameter));
88 else if (m->message == Message::PLAY_SELECTED_RECORDING)
92 else if (m->message == Message::RESUME_SELECTED_RECORDING)
96 else if (m->message == Message::REDRAW)
99 BoxStack::getInstance()->update(this);
103 void VRecordingList::doDeleteSelected()
105 Recording* toDelete = getCurrentOptionRecording();
107 if (!toDelete) return;
109 LogNT::getInstance()->debug(TAG, "FOUND: {} {} {}", toDelete->index, toDelete->getProgName(), toDelete->getFileName());
111 int success = recman->deleteRecording(toDelete);
112 if (!VDR::getInstance()->isConnected())
114 Control::getInstance()->connectionLost();
120 VInfo* vi = new VInfo();
121 vi->setSize(360, 200);
123 if (Video::getInstance()->getFormat() == Video::PAL)
124 vi->setPosition(190, 170);
126 vi->setPosition(180, 120);
127 vi->setOneLiner(tr("Failed to delete recording"));
130 vi->setTitleBarColour(DrawStyle::DANGER);
134 boxstack->update(vi);
139 boxstack->update(this);
144 void VRecordingList::doMoveRecording(Directory* toDir)
146 Recording* toMove = getCurrentOptionRecording();
147 if (!toMove || !toDir) return;
149 LogNT::getInstance()->debug(TAG, "MOVE: {} {}", toMove->getProgName(), toDir->name);
151 int success = recman->moveRecording(toMove, toDir);
152 if (!VDR::getInstance()->isConnected())
154 Control::getInstance()->connectionLost();
160 VInfo* vi = new VInfo();
161 vi->setSize(360, 200);
163 if (Video::getInstance()->getFormat() == Video::PAL)
164 vi->setPosition(190, 170);
166 vi->setPosition(180, 120);
167 vi->setOneLiner(tr("Failed to move recording"));
170 vi->setTitleBarColour(DrawStyle::DANGER);
174 boxstack->update(vi);
179 boxstack->update(this);
183 int VRecordingList::doPlay(bool resume)
185 Recording* toPlay = getCurrentOptionRecording();
189 toPlay->loadRecInfo();
191 if (toPlay->recInfo == NULL)
193 VInfo* vi = new VInfo();
194 vi->setSize(360, 200);
196 if (Video::getInstance()->getFormat() == Video::PAL)
197 vi->setPosition(190, 170);
199 vi->setPosition(180, 120);
200 vi->setOneLiner(tr("Error playing recording"));
203 vi->setTitleBarColour(DrawStyle::DANGER);
207 boxstack->update(vi);
213 bool isRadio = toPlay->isRadio(ish264);
217 VRadioRec* radrec = new VRadioRec(toPlay);
219 boxstack->add(radrec);
220 boxstack->update(radrec);
223 toPlay->setNew(false);
225 boxstack->update(this);
229 if (ish264 && !Video::getInstance()->supportsh264())
231 VInfo* vi = new VInfo();
232 vi->setSize(360, 200);
234 if (Video::getInstance()->getFormat() == Video::PAL)
235 vi->setPosition(190, 170);
237 vi->setPosition(180, 120);
238 vi->setOneLiner(tr("H264 video not supported"));
241 vi->setTitleBarColour(DrawStyle::DANGER);
245 boxstack->update(vi);
247 else if (!ish264 && !Video::getInstance()->supportsmpeg2())
249 VInfo* vi = new VInfo();
250 vi->setSize(360, 200);
252 if (Video::getInstance()->getFormat() == Video::PAL)
253 vi->setPosition(190, 170);
255 vi->setPosition(180, 120);
256 vi->setOneLiner(tr("Mpeg2 video not supported"));
259 vi->setTitleBarColour(DrawStyle::DANGER);
263 boxstack->update(vi);
267 VVideoRec* vidrec = new VVideoRec(toPlay, ish264);
269 boxstack->add(vidrec);
270 boxstack->update(vidrec);
273 toPlay->setNew(false);
275 boxstack->update(this);
280 // should not get to here
284 Recording* VRecordingList::getCurrentOptionRecording()
286 Recording* currentRec;
287 RecordingList::iterator j;
288 RecordingList* recList = recman->getRecordings();
289 for (j = recList->begin(); j != recList->end(); j++)
292 if (currentRec->index == sl.getCurrentOption()) return currentRec;
298 Directory* VRecordingList::getCurrentOptionDirectory()
300 Directory* currentSubDir;
301 DirectoryList::iterator i;
302 DirectoryList* dirList = recman->getDirectories();
303 for (i = dirList->begin(); i != dirList->end(); i++)
306 if (currentSubDir->index == sl.getCurrentOption())
309 return currentSubDir;
316 int VRecordingList::handleCommand(int command)
325 boxstack->update(this);
333 boxstack->update(this);
336 case Input::SKIPBACK:
341 boxstack->update(this);
344 case Input::SKIPFORWARD:
349 boxstack->update(this);
354 if (sl.getNumOptions() == 0) return 2;
356 // Check to see if it is a sub directory
357 Directory* currentSubDir=getCurrentOptionDirectory();
361 if (recman->down(currentSubDir))
363 slIndexStack.push(sl.getCurrentOption());
366 boxstack->update(this);
372 // check to see if it's a recording
373 Recording* current = getCurrentOptionRecording();
376 LogNT::getInstance()->debug(TAG, "Found the option you pointed at. {} {}", current->getProgName(), current->getFileName());
379 VRecordingMenu* v = new VRecordingMenu(recman);
381 v->setRecording(current);
386 VRecording* vr = new VRecording(recman, current);
390 boxstack->update(vr);
394 // should not get to here
399 if (recman->isSubDir())
404 boxstack->update(this);
412 case Input::PLAYPAUSE:
415 if (doPlay(true)) return 2;
426 // stop command getting to any more views
430 bool VRecordingList::load()
432 VDR* vdr = VDR::getInstance();
434 recman = new RecMan();
436 bool success = vdr->getRecordingsList(recman);
441 char* defaultSortOrder = vdr->configLoad("General", "Recordings Sort Order");
442 if (defaultSortOrder)
444 if (!STRCASECMP(defaultSortOrder, "Chronological")) recman->setSortOrderChron();
445 delete[] defaultSortOrder;
449 boxstack->update(this);
455 void VRecordingList::reSort()
457 recman->toggleSortOrder();
461 boxstack->update(this);