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 - getScreenX(), m->tag - getScreenY()))
62 boxstack->update(this);
65 else if (m->message == Message::MOUSE_LBDOWN)
67 if (sl.mouseLBDOWN(m->parameter - getScreenX(), m->tag - getScreenY()))
69 boxstack->handleCommand(Input::OK); //simulate OK press
71 else if (coordsOutsideBox(m))
73 boxstack->handleCommand(Input::BACK); //simulate cancel press
76 else if (m->message == Message::DELETE_SELECTED_RECORDING)
78 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Doing delete selected");
81 else if (m->message == Message::MOVE_RECORDING)
83 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Doing move recording");
84 doMoveRecording(reinterpret_cast<Directory*>(m->parameter));
86 else if (m->message == Message::PLAY_SELECTED_RECORDING)
90 else if (m->message == Message::RESUME_SELECTED_RECORDING)
94 else if (m->message == Message::REDRAW)
97 BoxStack::getInstance()->update(this);
101 void VRecordingList::doDeleteSelected()
103 Recording* toDelete = getCurrentOptionRecording();
105 if (!toDelete) return;
107 Log::getInstance()->log("VRecordingList", Log::DEBUG, "FOUND: %i %s %s", toDelete->index, toDelete->getProgName(), toDelete->getFileName());
109 int success = recman->deleteRecording(toDelete);
110 if (!VDR::getInstance()->isConnected())
112 Control::getInstance()->connectionLost();
118 VInfo* vi = new VInfo();
119 vi->setSize(360, 200);
121 if (Video::getInstance()->getFormat() == Video::PAL)
122 vi->setPosition(190, 170);
124 vi->setPosition(180, 120);
125 vi->setOneLiner(tr("Failed to delete recording"));
128 vi->setTitleBarColour(DrawStyle::DANGER);
132 boxstack->update(vi);
137 boxstack->update(this);
142 void VRecordingList::doMoveRecording(Directory* toDir)
144 Recording* toMove = getCurrentOptionRecording();
145 if (!toMove || !toDir) return;
147 Log::getInstance()->log("VRecordingList", Log::DEBUG, "MOVE: %s %s", toMove->getProgName(), toDir->name);
149 int success = recman->moveRecording(toMove, toDir);
150 if (!VDR::getInstance()->isConnected())
152 Control::getInstance()->connectionLost();
158 VInfo* vi = new VInfo();
159 vi->setSize(360, 200);
161 if (Video::getInstance()->getFormat() == Video::PAL)
162 vi->setPosition(190, 170);
164 vi->setPosition(180, 120);
165 vi->setOneLiner(tr("Failed to move recording"));
168 vi->setTitleBarColour(DrawStyle::DANGER);
172 boxstack->update(vi);
177 boxstack->update(this);
181 int VRecordingList::doPlay(bool resume)
183 Recording* toPlay = getCurrentOptionRecording();
187 toPlay->loadRecInfo();
189 if (toPlay->recInfo == NULL)
191 VInfo* vi = new VInfo();
192 vi->setSize(360, 200);
194 if (Video::getInstance()->getFormat() == Video::PAL)
195 vi->setPosition(190, 170);
197 vi->setPosition(180, 120);
198 vi->setOneLiner(tr("Error playing recording"));
201 vi->setTitleBarColour(DrawStyle::DANGER);
205 boxstack->update(vi);
211 bool isRadio = toPlay->isRadio(ish264);
215 VRadioRec* radrec = new VRadioRec(toPlay);
217 boxstack->add(radrec);
218 boxstack->update(radrec);
221 toPlay->setNew(false);
223 boxstack->update(this);
227 if (ish264 && !Video::getInstance()->supportsh264())
229 VInfo* vi = new VInfo();
230 vi->setSize(360, 200);
232 if (Video::getInstance()->getFormat() == Video::PAL)
233 vi->setPosition(190, 170);
235 vi->setPosition(180, 120);
236 vi->setOneLiner(tr("H264 video not supported"));
239 vi->setTitleBarColour(DrawStyle::DANGER);
243 boxstack->update(vi);
245 else if (!ish264 && !Video::getInstance()->supportsmpeg2())
247 VInfo* vi = new VInfo();
248 vi->setSize(360, 200);
250 if (Video::getInstance()->getFormat() == Video::PAL)
251 vi->setPosition(190, 170);
253 vi->setPosition(180, 120);
254 vi->setOneLiner(tr("Mpeg2 video not supported"));
257 vi->setTitleBarColour(DrawStyle::DANGER);
261 boxstack->update(vi);
265 VVideoRec* vidrec = new VVideoRec(toPlay, ish264);
267 boxstack->add(vidrec);
268 boxstack->update(vidrec);
271 toPlay->setNew(false);
273 boxstack->update(this);
278 // should not get to here
282 Recording* VRecordingList::getCurrentOptionRecording()
284 Recording* currentRec;
285 RecordingList::iterator j;
286 RecordingList* recList = recman->getRecordings();
287 for (j = recList->begin(); j != recList->end(); j++)
290 if (currentRec->index == sl.getCurrentOption()) return currentRec;
296 Directory* VRecordingList::getCurrentOptionDirectory()
298 Directory* currentSubDir;
299 DirectoryList::iterator i;
300 DirectoryList* dirList = recman->getDirectories();
301 for (i = dirList->begin(); i != dirList->end(); i++)
304 if (currentSubDir->index == sl.getCurrentOption())
307 return currentSubDir;
314 int VRecordingList::handleCommand(int command)
323 boxstack->update(this);
331 boxstack->update(this);
334 case Input::SKIPBACK:
339 boxstack->update(this);
342 case Input::SKIPFORWARD:
347 boxstack->update(this);
352 if (sl.getNumOptions() == 0) return 2;
354 // Check to see if it is a sub directory
355 Directory* currentSubDir=getCurrentOptionDirectory();
359 if (recman->down(currentSubDir))
361 slIndexStack.push(sl.getCurrentOption());
364 boxstack->update(this);
370 // check to see if it's a recording
371 Recording* current = getCurrentOptionRecording();
374 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Found the option you pointed at. %s %s", current->getProgName(), current->getFileName());
377 VRecordingMenu* v = new VRecordingMenu(recman);
379 v->setRecording(current);
384 VRecording* vr = new VRecording(recman, current);
388 boxstack->update(vr);
392 // should not get to here
397 if (recman->isSubDir())
402 boxstack->update(this);
410 case Input::PLAYPAUSE:
413 if (doPlay(true)) return 2;
424 // stop command getting to any more views
428 bool VRecordingList::load()
430 VDR* vdr = VDR::getInstance();
432 recman = new RecMan();
434 bool success = vdr->getRecordingsList(recman);
439 char* defaultSortOrder = vdr->configLoad("General", "Recordings Sort Order");
440 if (defaultSortOrder)
442 if (!STRCASECMP(defaultSortOrder, "Chronological")) recman->setSortOrderChron();
443 delete[] defaultSortOrder;
447 boxstack->update(this);
453 void VRecordingList::reSort()
455 recman->toggleSortOrder();
459 boxstack->update(this);