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(Colour::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\t%s"), currentSubDir->getNumRecordings(), currentSubDir->name);
93 currentSubDir->index = sl.addOption(tempA, 0, first);
97 // FIXME convert the whole program to time_t's
99 Recording* currentRec;
100 RecordingList::iterator j;
101 RecordingList* recList = recman->getRecordings();
102 for (j = recList->begin(); j != recList->end(); j++)
105 time_t recStartTime = (time_t)currentRec->getStartTime();
106 btime = localtime(&recStartTime);
107 //NMT does not like this too!
109 // strftime(tempA, 299, "%0d/%0m %0H:%0M ", btime);
111 strftime(tempA, 299, "%d/%m %H:%M ", btime);
113 sprintf(tempB, "%s\t%s", tempA, 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, Colour::LIGHTTEXT);
157 int gigFree = recman->getFreeSpace() / 1024;
158 SNPRINTF(freeSpace, 49, tr("%lu%% used, %iGB free"), recman->getUsedPercent(), gigFree);
159 drawTextRJ(freeSpace, 560, 5, Colour::LIGHTTEXT);
166 w.nextSymbol = WSymbol::UP;
167 w.setPosition(20, 385);
170 w.nextSymbol = WSymbol::DOWN;
171 w.setPosition(50, 385);
174 w.nextSymbol = WSymbol::SKIPBACK;
175 w.setPosition(85, 385);
178 w.nextSymbol = WSymbol::SKIPFORWARD;
179 w.setPosition(115, 385);
182 w.nextSymbol = WSymbol::PLAY;
183 w.setPosition(150, 385);
186 drawTextRJ(tr("[ok] = menu"), 560, 385, Colour::LIGHTTEXT);
188 // All static stuff done
190 drawData(doIndexPop);
194 void VRecordingList::doShowingBar()
196 int topOption = sl.getTopOption() + 1;
197 if (sl.getNumOptions() == 0) topOption = 0;
199 rectangle(220, 385, 180, 25, Colour::VIEWBACKGROUND);
201 sprintf(showing, tr("%i to %i of %i"), topOption, sl.getBottomOption(), sl.getNumOptions());
202 drawText(showing, 220, 385, Colour::LIGHTTEXT);
205 void VRecordingList::processMessage(Message* m)
207 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Got message value %lu", m->message);
209 if (m->message == Message::MOUSE_MOVE)
211 if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
215 boxstack->update(this);
218 else if (m->message == Message::MOUSE_LBDOWN)
220 if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
222 boxstack->handleCommand(Remote::OK); //simulate OK press
226 //check if press is outside this view! then simulate cancel
227 int x=(m->parameter>>16)-getScreenX();
228 int y=(m->parameter&0xFFFF)-getScreenY();
229 if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
231 boxstack->handleCommand(Remote::BACK); //simulate cancel press
235 else if (m->message == Message::DELETE_SELECTED_RECORDING)
237 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Doing delete selected");
240 else if (m->message == Message::MOVE_RECORDING)
242 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Doing move recording");
243 doMoveRecording((Directory*)m->parameter);
245 else if (m->message == Message::PLAY_SELECTED_RECORDING)
249 else if (m->message == Message::RESUME_SELECTED_RECORDING)
255 void VRecordingList::doDeleteSelected()
257 Recording* toDelete = getCurrentOptionRecording();
259 if (!toDelete) return;
261 Log::getInstance()->log("VRecordingList", Log::DEBUG, "FOUND: %i %s %s", toDelete->index, toDelete->getProgName(), toDelete->getFileName());
263 int success = recman->deleteRecording(toDelete);
264 if (!VDR::getInstance()->isConnected())
266 Command::getInstance()->connectionLost();
272 VInfo* vi = new VInfo();
273 vi->setSize(360, 200);
275 if (Video::getInstance()->getFormat() == Video::PAL)
276 vi->setPosition(190, 170);
278 vi->setPosition(180, 120);
279 vi->setOneLiner(tr("Failed to delete recording"));
282 vi->setTitleBarColour(Colour::DANGER);
286 boxstack->update(vi);
291 boxstack->update(this);
296 void VRecordingList::doMoveRecording(Directory* toDir)
298 Recording* toMove = getCurrentOptionRecording();
299 if (!toMove || !toDir) return;
301 Log::getInstance()->log("VRecordingList", Log::DEBUG, "MOVE: %s %s", toMove->getProgName(), toDir->name);
303 int success = recman->moveRecording(toMove, toDir);
304 if (!VDR::getInstance()->isConnected())
306 Command::getInstance()->connectionLost();
312 VInfo* vi = new VInfo();
313 vi->setSize(360, 200);
315 if (Video::getInstance()->getFormat() == Video::PAL)
316 vi->setPosition(190, 170);
318 vi->setPosition(180, 120);
319 vi->setOneLiner(tr("Failed to move recording"));
322 vi->setTitleBarColour(Colour::DANGER);
326 boxstack->update(vi);
331 boxstack->update(this);
335 int VRecordingList::doPlay(bool resume)
337 Recording* toPlay = getCurrentOptionRecording();
340 toPlay->loadRecInfo(); // check if still need this
344 bool isRadio = toPlay->isRadio(ish264);
348 VRadioRec* radrec = new VRadioRec(toPlay);
350 boxstack->add(radrec);
351 boxstack->update(radrec);
356 if (ish264 && !Video::getInstance()->supportsh264()) {
357 VInfo* vi = new VInfo();
358 vi->setSize(360, 200);
360 if (Video::getInstance()->getFormat() == Video::PAL)
361 vi->setPosition(190, 170);
363 vi->setPosition(180, 120);
364 vi->setOneLiner(tr("H264 video not supported"));
367 vi->setTitleBarColour(Colour::DANGER);
371 boxstack->update(vi);
374 VVideoRec* vidrec = new VVideoRec(toPlay, ish264);
376 boxstack->add(vidrec);
377 boxstack->update(vidrec);
383 // should not get to here
387 Recording* VRecordingList::getCurrentOptionRecording()
389 Recording* currentRec;
390 RecordingList::iterator j;
391 RecordingList* recList = recman->getRecordings();
392 for (j = recList->begin(); j != recList->end(); j++)
395 if (currentRec->index == sl.getCurrentOption()) return currentRec;
401 int VRecordingList::handleCommand(int command)
412 boxstack->update(this);
415 case Remote::DF_DOWN:
422 boxstack->update(this);
425 case Remote::SKIPBACK:
431 boxstack->update(this);
434 case Remote::SKIPFORWARD:
440 boxstack->update(this);
445 if (sl.getNumOptions() == 0) return 2;
447 // Check to see if it is a sub directory
448 Directory* currentSubDir;
449 DirectoryList::iterator i;
450 DirectoryList* dirList = recman->getDirectories();
451 for (i = dirList->begin(); i != dirList->end(); i++)
454 if (currentSubDir->index == sl.getCurrentOption())
456 if (recman->down(currentSubDir))
458 slIndexStack.push(sl.getCurrentOption());
461 boxstack->update(this);
467 // check to see if it's a recording
468 Recording* current = getCurrentOptionRecording();
471 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Found the option you pointed at. %s %s", current->getProgName(), current->getFileName());
474 VRecordingMenu* v = new VRecordingMenu(recman);
476 v->setRecording(current);
481 VRecording* vr = new VRecording(recman, current);
485 boxstack->update(vr);
489 // should not get to here
494 if (recman->isSubDir())
499 boxstack->update(this);
509 if (doPlay(true)) return 2;
520 // stop command getting to any more views
524 bool VRecordingList::load()
526 VDR* vdr = VDR::getInstance();
528 recman = new RecMan();
529 bool success = vdr->getRecordingsList(recman);
534 char* defaultSortOrder = vdr->configLoad("General", "Recordings Sort Order");
535 if (defaultSortOrder)
537 if (!STRCASECMP(defaultSortOrder, "Chronological")) recman->setSortOrderChron();
538 delete[] defaultSortOrder;
544 boxstack->update(this);
550 void VRecordingList::reSort()
552 recman->toggleSortOrder();
556 boxstack->update(this);