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 if (Video::getInstance()->getFormat() == Video::PAL)
59 setTitleBarColour(DrawStyle::TITLEBARBACKGROUND);
61 sl.setPosition(10, 30 + 5);
62 sl.setSize(area.w - 20, area.h - 30 - 15 - 30);
66 VRecordingList::~VRecordingList()
71 void VRecordingList::drawData(bool doIndexPop)
73 int saveIndex = sl.getCurrentOption();
74 int saveTop = sl.getTopOption();
82 char tempA[300]; // FIXME this is guesswork!
83 char tempB[300]; // FIXME
86 Directory* currentSubDir;
87 DirectoryList::iterator i;
88 DirectoryList* dirList = recman->getDirectories();
89 for (i = dirList->begin(); i != dirList->end(); i++)
92 SNPRINTF(tempA, 299, tr("<dir> %lu/%lu\t \t%s"), currentSubDir->getNumNewRecordings(), currentSubDir->getNumRecordings(), currentSubDir->name);
93 currentSubDir->index = sl.addOption(tempA, 0, first);
96 // FIXME convert the whole program to time_t's
98 Recording* currentRec;
99 RecordingList::iterator j;
100 RecordingList* recList = recman->getRecordings();
101 for (j = recList->begin(); j != recList->end(); j++)
104 time_t recStartTime = (time_t)currentRec->getStartTime();
105 btime = localtime(&recStartTime);
106 //NMT does not like this too!
108 // strftime(tempA, 299, "%0d/%0m %0H:%0M ", btime);
110 strftime(tempA, 299, "%d/%m %H:%M ", btime);
112 sprintf(tempB, "%s\t%c\t%s", tempA, (currentRec->getNew() ? '*': ' '), currentRec->getProgName());
114 currentRec->index = sl.addOption(tempB, 0, first);
120 sl.hintSetCurrent(slIndexStack.top());
125 sl.hintSetCurrent(saveIndex);
126 sl.hintSetTop(saveTop);
132 void VRecordingList::draw(bool doIndexPop)
136 if (recman->isSubDir())
139 SNPRINTF(title, 299, tr("Recordings - %s"), recman->getCurDirName());
140 setTitleText(title, 364);
144 setTitleText(tr("Recordings"));
152 drawText(tr("Loading..."), 240, 180, DrawStyle::LIGHTTEXT);
157 int gigFree = recman->getFreeSpace() / 1024;
158 SNPRINTF(freeSpace, 49, tr("%lu%% used, %iGB free"), recman->getUsedPercent(), gigFree);
159 drawTextRJ(freeSpace, 560, 5, DrawStyle::LIGHTTEXT);
164 w.nextSymbol = WSymbol::UP;
165 w.setPosition(20, 385);
167 w.nextSymbol = WSymbol::DOWN;
168 w.setPosition(50, 385);
170 w.nextSymbol = WSymbol::SKIPBACK;
171 w.setPosition(85, 385);
173 w.nextSymbol = WSymbol::SKIPFORWARD;
174 w.setPosition(115, 385);
176 w.nextSymbol = WSymbol::PLAY;
177 w.setPosition(150, 385);
179 drawTextRJ(tr("[ok] = menu"), 560, 385, DrawStyle::LIGHTTEXT);
181 // All static stuff done
182 drawData(doIndexPop);
186 void VRecordingList::doShowingBar()
188 int topOption = sl.getTopOption() + 1;
189 if (sl.getNumOptions() == 0) topOption = 0;
191 rectangle(220, 385, 180, 25, DrawStyle::VIEWBACKGROUND);
193 sprintf(showing, tr("%i to %i of %i"), topOption, sl.getBottomOption(), sl.getNumOptions());
194 drawText(showing, 220, 385, DrawStyle::LIGHTTEXT);
197 void VRecordingList::processMessage(Message* m)
199 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Got message value %lu", m->message);
201 if (m->message == Message::MOUSE_MOVE)
203 if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
207 boxstack->update(this);
210 else if (m->message == Message::MOUSE_LBDOWN)
212 if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
214 boxstack->handleCommand(Remote::OK); //simulate OK press
218 //check if press is outside this view! then simulate cancel
219 int x=(m->parameter>>16)-getScreenX();
220 int y=(m->parameter&0xFFFF)-getScreenY();
221 if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
223 boxstack->handleCommand(Remote::BACK); //simulate cancel press
227 else if (m->message == Message::DELETE_SELECTED_RECORDING)
229 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Doing delete selected");
232 else if (m->message == Message::MOVE_RECORDING)
234 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Doing move recording");
235 doMoveRecording((Directory*)m->parameter);
237 else if (m->message == Message::PLAY_SELECTED_RECORDING)
241 else if (m->message == Message::RESUME_SELECTED_RECORDING)
247 void VRecordingList::doDeleteSelected()
249 Recording* toDelete = getCurrentOptionRecording();
251 if (!toDelete) return;
253 Log::getInstance()->log("VRecordingList", Log::DEBUG, "FOUND: %i %s %s", toDelete->index, toDelete->getProgName(), toDelete->getFileName());
255 int success = recman->deleteRecording(toDelete);
256 if (!VDR::getInstance()->isConnected())
258 Command::getInstance()->connectionLost();
264 VInfo* vi = new VInfo();
265 vi->setSize(360, 200);
267 if (Video::getInstance()->getFormat() == Video::PAL)
268 vi->setPosition(190, 170);
270 vi->setPosition(180, 120);
271 vi->setOneLiner(tr("Failed to delete recording"));
274 vi->setTitleBarColour(DrawStyle::DANGER);
278 boxstack->update(vi);
283 boxstack->update(this);
288 void VRecordingList::doMoveRecording(Directory* toDir)
290 Recording* toMove = getCurrentOptionRecording();
291 if (!toMove || !toDir) return;
293 Log::getInstance()->log("VRecordingList", Log::DEBUG, "MOVE: %s %s", toMove->getProgName(), toDir->name);
295 int success = recman->moveRecording(toMove, toDir);
296 if (!VDR::getInstance()->isConnected())
298 Command::getInstance()->connectionLost();
304 VInfo* vi = new VInfo();
305 vi->setSize(360, 200);
307 if (Video::getInstance()->getFormat() == Video::PAL)
308 vi->setPosition(190, 170);
310 vi->setPosition(180, 120);
311 vi->setOneLiner(tr("Failed to move recording"));
314 vi->setTitleBarColour(DrawStyle::DANGER);
318 boxstack->update(vi);
323 boxstack->update(this);
327 int VRecordingList::doPlay(bool resume)
329 Recording* toPlay = getCurrentOptionRecording();
332 toPlay->loadRecInfo(); // check if still need this
335 bool isRadio = toPlay->isRadio(ish264);
339 VRadioRec* radrec = new VRadioRec(toPlay);
341 boxstack->add(radrec);
342 boxstack->update(radrec);
345 toPlay->setNew(false);
347 boxstack->update(this);
351 if (ish264 && !Video::getInstance()->supportsh264())
353 VInfo* vi = new VInfo();
354 vi->setSize(360, 200);
356 if (Video::getInstance()->getFormat() == Video::PAL)
357 vi->setPosition(190, 170);
359 vi->setPosition(180, 120);
360 vi->setOneLiner(tr("H264 video not supported"));
363 vi->setTitleBarColour(DrawStyle::DANGER);
367 boxstack->update(vi);
369 else if (!ish264 && !Video::getInstance()->supportsmpeg2())
371 VInfo* vi = new VInfo();
372 vi->setSize(360, 200);
374 if (Video::getInstance()->getFormat() == Video::PAL)
375 vi->setPosition(190, 170);
377 vi->setPosition(180, 120);
378 vi->setOneLiner(tr("Mpeg2 video not supported"));
381 vi->setTitleBarColour(DrawStyle::DANGER);
385 boxstack->update(vi);
389 VVideoRec* vidrec = new VVideoRec(toPlay, ish264);
391 boxstack->add(vidrec);
392 boxstack->update(vidrec);
395 toPlay->setNew(false);
397 boxstack->update(this);
402 // should not get to here
406 Recording* VRecordingList::getCurrentOptionRecording()
408 Recording* currentRec;
409 RecordingList::iterator j;
410 RecordingList* recList = recman->getRecordings();
411 for (j = recList->begin(); j != recList->end(); j++)
414 if (currentRec->index == sl.getCurrentOption()) return currentRec;
420 int VRecordingList::handleCommand(int command)
431 boxstack->update(this);
434 case Remote::DF_DOWN:
441 boxstack->update(this);
444 case Remote::SKIPBACK:
450 boxstack->update(this);
453 case Remote::SKIPFORWARD:
459 boxstack->update(this);
464 if (sl.getNumOptions() == 0) return 2;
466 // Check to see if it is a sub directory
467 Directory* currentSubDir;
468 DirectoryList::iterator i;
469 DirectoryList* dirList = recman->getDirectories();
470 for (i = dirList->begin(); i != dirList->end(); i++)
473 if (currentSubDir->index == sl.getCurrentOption())
475 if (recman->down(currentSubDir))
477 slIndexStack.push(sl.getCurrentOption());
480 boxstack->update(this);
486 // check to see if it's a recording
487 Recording* current = getCurrentOptionRecording();
490 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Found the option you pointed at. %s %s", current->getProgName(), current->getFileName());
493 VRecordingMenu* v = new VRecordingMenu(recman);
495 v->setRecording(current);
500 VRecording* vr = new VRecording(recman, current);
504 boxstack->update(vr);
508 // should not get to here
513 if (recman->isSubDir())
518 boxstack->update(this);
526 case Remote::PLAYPAUSE:
529 if (doPlay(true)) return 2;
540 // stop command getting to any more views
544 bool VRecordingList::load()
546 VDR* vdr = VDR::getInstance();
548 recman = new RecMan();
550 bool success = vdr->getRecordingsList(recman);
555 char* defaultSortOrder = vdr->configLoad("General", "Recordings Sort Order");
556 if (defaultSortOrder)
558 if (!STRCASECMP(defaultSortOrder, "Chronological")) recman->setSortOrderChron();
559 delete[] defaultSortOrder;
563 boxstack->update(this);
569 void VRecordingList::reSort()
571 recman->toggleSortOrder();
575 boxstack->update(this);