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, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #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"
41 VRecordingList::VRecordingList()
43 boxstack = BoxStack::getInstance();
49 VRecordingList::~VRecordingList()
54 void VRecordingList::processMessage(Message* m)
56 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Got message value %lu", m->message);
58 if (m->message == Message::MOUSE_MOVE)
60 if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
63 boxstack->update(this);
66 else if (m->message == Message::MOUSE_LBDOWN)
68 if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
70 boxstack->handleCommand(Remote::OK); //simulate OK press
74 //check if press is outside this view! then simulate cancel
75 int x=(m->parameter>>16)-getScreenX();
76 int y=(m->parameter&0xFFFF)-getScreenY();
77 if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
79 boxstack->handleCommand(Remote::BACK); //simulate cancel press
83 else if (m->message == Message::DELETE_SELECTED_RECORDING)
85 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Doing delete selected");
88 else if (m->message == Message::MOVE_RECORDING)
90 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Doing move recording");
91 doMoveRecording((Directory*)m->parameter);
93 else if (m->message == Message::PLAY_SELECTED_RECORDING)
97 else if (m->message == Message::RESUME_SELECTED_RECORDING)
101 else if (m->message == Message::REDRAW)
104 BoxStack::getInstance()->update(this);
108 void VRecordingList::doDeleteSelected()
110 Recording* toDelete = getCurrentOptionRecording();
112 if (!toDelete) return;
114 Log::getInstance()->log("VRecordingList", Log::DEBUG, "FOUND: %i %s %s", toDelete->index, toDelete->getProgName(), toDelete->getFileName());
116 int success = recman->deleteRecording(toDelete);
117 if (!VDR::getInstance()->isConnected())
119 Command::getInstance()->connectionLost();
125 VInfo* vi = new VInfo();
126 vi->setSize(360, 200);
128 if (Video::getInstance()->getFormat() == Video::PAL)
129 vi->setPosition(190, 170);
131 vi->setPosition(180, 120);
132 vi->setOneLiner(tr("Failed to delete recording"));
135 vi->setTitleBarColour(DrawStyle::DANGER);
139 boxstack->update(vi);
144 boxstack->update(this);
149 void VRecordingList::doMoveRecording(Directory* toDir)
151 Recording* toMove = getCurrentOptionRecording();
152 if (!toMove || !toDir) return;
154 Log::getInstance()->log("VRecordingList", Log::DEBUG, "MOVE: %s %s", toMove->getProgName(), toDir->name);
156 int success = recman->moveRecording(toMove, toDir);
157 if (!VDR::getInstance()->isConnected())
159 Command::getInstance()->connectionLost();
165 VInfo* vi = new VInfo();
166 vi->setSize(360, 200);
168 if (Video::getInstance()->getFormat() == Video::PAL)
169 vi->setPosition(190, 170);
171 vi->setPosition(180, 120);
172 vi->setOneLiner(tr("Failed to move recording"));
175 vi->setTitleBarColour(DrawStyle::DANGER);
179 boxstack->update(vi);
184 boxstack->update(this);
188 int VRecordingList::doPlay(bool resume)
190 Recording* toPlay = getCurrentOptionRecording();
194 toPlay->loadRecInfo();
196 if (toPlay->recInfo == NULL)
198 VInfo* vi = new VInfo();
199 vi->setSize(360, 200);
201 if (Video::getInstance()->getFormat() == Video::PAL)
202 vi->setPosition(190, 170);
204 vi->setPosition(180, 120);
205 vi->setOneLiner(tr("Error playing recording"));
208 vi->setTitleBarColour(DrawStyle::DANGER);
212 boxstack->update(vi);
218 bool isRadio = toPlay->isRadio(ish264);
222 VRadioRec* radrec = new VRadioRec(toPlay);
224 boxstack->add(radrec);
225 boxstack->update(radrec);
228 toPlay->setNew(false);
230 boxstack->update(this);
234 if (ish264 && !Video::getInstance()->supportsh264())
236 VInfo* vi = new VInfo();
237 vi->setSize(360, 200);
239 if (Video::getInstance()->getFormat() == Video::PAL)
240 vi->setPosition(190, 170);
242 vi->setPosition(180, 120);
243 vi->setOneLiner(tr("H264 video not supported"));
246 vi->setTitleBarColour(DrawStyle::DANGER);
250 boxstack->update(vi);
252 else if (!ish264 && !Video::getInstance()->supportsmpeg2())
254 VInfo* vi = new VInfo();
255 vi->setSize(360, 200);
257 if (Video::getInstance()->getFormat() == Video::PAL)
258 vi->setPosition(190, 170);
260 vi->setPosition(180, 120);
261 vi->setOneLiner(tr("Mpeg2 video not supported"));
264 vi->setTitleBarColour(DrawStyle::DANGER);
268 boxstack->update(vi);
272 VVideoRec* vidrec = new VVideoRec(toPlay, ish264);
274 boxstack->add(vidrec);
275 boxstack->update(vidrec);
278 toPlay->setNew(false);
280 boxstack->update(this);
285 // should not get to here
289 Recording* VRecordingList::getCurrentOptionRecording()
291 Recording* currentRec;
292 RecordingList::iterator j;
293 RecordingList* recList = recman->getRecordings();
294 for (j = recList->begin(); j != recList->end(); j++)
297 if (currentRec->index == sl.getCurrentOption()) return currentRec;
303 Directory* VRecordingList::getCurrentOptionDirectory()
305 Directory* currentSubDir;
306 DirectoryList::iterator i;
307 DirectoryList* dirList = recman->getDirectories();
308 for (i = dirList->begin(); i != dirList->end(); i++)
311 if (currentSubDir->index == sl.getCurrentOption())
314 return currentSubDir;
321 int VRecordingList::handleCommand(int command)
331 boxstack->update(this);
334 case Remote::DF_DOWN:
340 boxstack->update(this);
343 case Remote::SKIPBACK:
348 boxstack->update(this);
351 case Remote::SKIPFORWARD:
356 boxstack->update(this);
361 if (sl.getNumOptions() == 0) return 2;
363 // Check to see if it is a sub directory
364 Directory* currentSubDir=getCurrentOptionDirectory();
368 if (recman->down(currentSubDir))
370 slIndexStack.push(sl.getCurrentOption());
373 boxstack->update(this);
379 // check to see if it's a recording
380 Recording* current = getCurrentOptionRecording();
383 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Found the option you pointed at. %s %s", current->getProgName(), current->getFileName());
386 VRecordingMenu* v = new VRecordingMenu(recman);
388 v->setRecording(current);
393 VRecording* vr = new VRecording(recman, current);
397 boxstack->update(vr);
401 // should not get to here
406 if (recman->isSubDir())
411 boxstack->update(this);
419 case Remote::PLAYPAUSE:
422 if (doPlay(true)) return 2;
433 // stop command getting to any more views
437 bool VRecordingList::load()
439 VDR* vdr = VDR::getInstance();
441 recman = new RecMan();
443 bool success = vdr->getRecordingsList(recman);
448 char* defaultSortOrder = vdr->configLoad("General", "Recordings Sort Order");
449 if (defaultSortOrder)
451 if (!STRCASECMP(defaultSortOrder, "Chronological")) recman->setSortOrderChron();
452 delete[] defaultSortOrder;
456 boxstack->update(this);
462 void VRecordingList::reSort()
464 recman->toggleSortOrder();
468 boxstack->update(this);