2 Copyright 2004-2007 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)
103 void VRecordingList::doDeleteSelected()
105 Recording* toDelete = getCurrentOptionRecording();
107 if (!toDelete) return;
109 Log::getInstance()->log("VRecordingList", Log::DEBUG, "FOUND: %i %s %s", toDelete->index, toDelete->getProgName(), toDelete->getFileName());
111 int success = recman->deleteRecording(toDelete);
112 if (!VDR::getInstance()->isConnected())
114 Command::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 Log::getInstance()->log("VRecordingList", Log::DEBUG, "MOVE: %s %s", toMove->getProgName(), toDir->name);
151 int success = recman->moveRecording(toMove, toDir);
152 if (!VDR::getInstance()->isConnected())
154 Command::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();
188 toPlay->loadRecInfo(); // check if still need this
191 bool isRadio = toPlay->isRadio(ish264);
195 VRadioRec* radrec = new VRadioRec(toPlay);
197 boxstack->add(radrec);
198 boxstack->update(radrec);
201 toPlay->setNew(false);
203 boxstack->update(this);
207 if (ish264 && !Video::getInstance()->supportsh264())
209 VInfo* vi = new VInfo();
210 vi->setSize(360, 200);
212 if (Video::getInstance()->getFormat() == Video::PAL)
213 vi->setPosition(190, 170);
215 vi->setPosition(180, 120);
216 vi->setOneLiner(tr("H264 video not supported"));
219 vi->setTitleBarColour(DrawStyle::DANGER);
223 boxstack->update(vi);
225 else if (!ish264 && !Video::getInstance()->supportsmpeg2())
227 VInfo* vi = new VInfo();
228 vi->setSize(360, 200);
230 if (Video::getInstance()->getFormat() == Video::PAL)
231 vi->setPosition(190, 170);
233 vi->setPosition(180, 120);
234 vi->setOneLiner(tr("Mpeg2 video not supported"));
237 vi->setTitleBarColour(DrawStyle::DANGER);
241 boxstack->update(vi);
245 VVideoRec* vidrec = new VVideoRec(toPlay, ish264);
247 boxstack->add(vidrec);
248 boxstack->update(vidrec);
251 toPlay->setNew(false);
253 boxstack->update(this);
258 // should not get to here
262 Recording* VRecordingList::getCurrentOptionRecording()
264 Recording* currentRec;
265 RecordingList::iterator j;
266 RecordingList* recList = recman->getRecordings();
267 for (j = recList->begin(); j != recList->end(); j++)
270 if (currentRec->index == sl.getCurrentOption()) return currentRec;
276 Directory* VRecordingList::getCurrentOptionDirectory()
278 Directory* currentSubDir;
279 DirectoryList::iterator i;
280 DirectoryList* dirList = recman->getDirectories();
281 for (i = dirList->begin(); i != dirList->end(); i++)
284 if (currentSubDir->index == sl.getCurrentOption())
287 return currentSubDir;
294 int VRecordingList::handleCommand(int command)
304 boxstack->update(this);
307 case Remote::DF_DOWN:
313 boxstack->update(this);
316 case Remote::SKIPBACK:
321 boxstack->update(this);
324 case Remote::SKIPFORWARD:
329 boxstack->update(this);
334 if (sl.getNumOptions() == 0) return 2;
336 // Check to see if it is a sub directory
337 Directory* currentSubDir=getCurrentOptionDirectory();
341 if (recman->down(currentSubDir))
343 slIndexStack.push(sl.getCurrentOption());
346 boxstack->update(this);
352 // check to see if it's a recording
353 Recording* current = getCurrentOptionRecording();
356 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Found the option you pointed at. %s %s", current->getProgName(), current->getFileName());
359 VRecordingMenu* v = new VRecordingMenu(recman);
361 v->setRecording(current);
366 VRecording* vr = new VRecording(recman, current);
370 boxstack->update(vr);
374 // should not get to here
379 if (recman->isSubDir())
384 boxstack->update(this);
392 case Remote::PLAYPAUSE:
395 if (doPlay(true)) return 2;
406 // stop command getting to any more views
410 bool VRecordingList::load()
412 VDR* vdr = VDR::getInstance();
414 recman = new RecMan();
416 bool success = vdr->getRecordingsList(recman);
421 char* defaultSortOrder = vdr->configLoad("General", "Recordings Sort Order");
422 if (defaultSortOrder)
424 if (!STRCASECMP(defaultSortOrder, "Chronological")) recman->setSortOrderChron();
425 delete[] defaultSortOrder;
429 boxstack->update(this);
435 void VRecordingList::reSort()
437 recman->toggleSortOrder();
441 boxstack->update(this);