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();
81 char tempA[300]; // FIXME this is guesswork!
82 char tempB[300]; // FIXME
85 Directory* currentSubDir;
86 DirectoryList::iterator i;
87 DirectoryList* dirList = recman->getDirectories();
88 for (i = dirList->begin(); i != dirList->end(); i++)
91 SNPRINTF(tempA, 299, tr("<dir> %lu\t%s"), currentSubDir->getNumRecordings(), currentSubDir->name);
92 currentSubDir->index = sl.addOption(tempA, 0, first);
95 // FIXME convert the whole program to time_t's
97 Recording* currentRec;
98 RecordingList::iterator j;
99 RecordingList* recList = recman->getRecordings();
100 for (j = recList->begin(); j != recList->end(); j++)
103 time_t recStartTime = (time_t)currentRec->getStartTime();
104 btime = localtime(&recStartTime);
105 //NMT does not like this too!
107 // strftime(tempA, 299, "%0d/%0m %0H:%0M ", btime);
109 strftime(tempA, 299, "%d/%m %H:%M ", btime);
111 sprintf(tempB, "%s\t%s", tempA, currentRec->getProgName());
112 currentRec->index = sl.addOption(tempB, 0, first);
118 sl.hintSetCurrent(slIndexStack.top());
123 sl.hintSetCurrent(saveIndex);
124 sl.hintSetTop(saveTop);
130 void VRecordingList::draw(bool doIndexPop)
134 if (recman->isSubDir())
137 SNPRINTF(title, 299, tr("Recordings - %s"), recman->getCurDirName());
138 setTitleText(title, 364);
142 setTitleText(tr("Recordings"));
150 drawText(tr("Loading..."), 240, 180, DrawStyle::LIGHTTEXT);
155 int gigFree = recman->getFreeSpace() / 1024;
156 SNPRINTF(freeSpace, 49, tr("%lu%% used, %iGB free"), recman->getUsedPercent(), gigFree);
157 drawTextRJ(freeSpace, 560, 5, DrawStyle::LIGHTTEXT);
162 w.nextSymbol = WSymbol::UP;
163 w.setPosition(20, 385);
165 w.nextSymbol = WSymbol::DOWN;
166 w.setPosition(50, 385);
168 w.nextSymbol = WSymbol::SKIPBACK;
169 w.setPosition(85, 385);
171 w.nextSymbol = WSymbol::SKIPFORWARD;
172 w.setPosition(115, 385);
174 w.nextSymbol = WSymbol::PLAY;
175 w.setPosition(150, 385);
177 drawTextRJ(tr("[ok] = menu"), 560, 385, DrawStyle::LIGHTTEXT);
179 // All static stuff done
180 drawData(doIndexPop);
184 void VRecordingList::doShowingBar()
186 int topOption = sl.getTopOption() + 1;
187 if (sl.getNumOptions() == 0) topOption = 0;
189 rectangle(220, 385, 180, 25, DrawStyle::VIEWBACKGROUND);
191 sprintf(showing, tr("%i to %i of %i"), topOption, sl.getBottomOption(), sl.getNumOptions());
192 drawText(showing, 220, 385, DrawStyle::LIGHTTEXT);
195 void VRecordingList::processMessage(Message* m)
197 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Got message value %lu", m->message);
199 if (m->message == Message::MOUSE_MOVE)
201 if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
205 boxstack->update(this);
208 else if (m->message == Message::MOUSE_LBDOWN)
210 if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
212 boxstack->handleCommand(Remote::OK); //simulate OK press
216 //check if press is outside this view! then simulate cancel
217 int x=(m->parameter>>16)-getScreenX();
218 int y=(m->parameter&0xFFFF)-getScreenY();
219 if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
221 boxstack->handleCommand(Remote::BACK); //simulate cancel press
225 else if (m->message == Message::DELETE_SELECTED_RECORDING)
227 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Doing delete selected");
230 else if (m->message == Message::MOVE_RECORDING)
232 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Doing move recording");
233 doMoveRecording((Directory*)m->parameter);
235 else if (m->message == Message::PLAY_SELECTED_RECORDING)
239 else if (m->message == Message::RESUME_SELECTED_RECORDING)
245 void VRecordingList::doDeleteSelected()
247 Recording* toDelete = getCurrentOptionRecording();
249 if (!toDelete) return;
251 Log::getInstance()->log("VRecordingList", Log::DEBUG, "FOUND: %i %s %s", toDelete->index, toDelete->getProgName(), toDelete->getFileName());
253 int success = recman->deleteRecording(toDelete);
254 if (!VDR::getInstance()->isConnected())
256 Command::getInstance()->connectionLost();
262 VInfo* vi = new VInfo();
263 vi->setSize(360, 200);
265 if (Video::getInstance()->getFormat() == Video::PAL)
266 vi->setPosition(190, 170);
268 vi->setPosition(180, 120);
269 vi->setOneLiner(tr("Failed to delete recording"));
272 vi->setTitleBarColour(DrawStyle::DANGER);
276 boxstack->update(vi);
281 boxstack->update(this);
286 void VRecordingList::doMoveRecording(Directory* toDir)
288 Recording* toMove = getCurrentOptionRecording();
289 if (!toMove || !toDir) return;
291 Log::getInstance()->log("VRecordingList", Log::DEBUG, "MOVE: %s %s", toMove->getProgName(), toDir->name);
293 int success = recman->moveRecording(toMove, toDir);
294 if (!VDR::getInstance()->isConnected())
296 Command::getInstance()->connectionLost();
302 VInfo* vi = new VInfo();
303 vi->setSize(360, 200);
305 if (Video::getInstance()->getFormat() == Video::PAL)
306 vi->setPosition(190, 170);
308 vi->setPosition(180, 120);
309 vi->setOneLiner(tr("Failed to move recording"));
312 vi->setTitleBarColour(DrawStyle::DANGER);
316 boxstack->update(vi);
321 boxstack->update(this);
325 int VRecordingList::doPlay(bool resume)
327 Recording* toPlay = getCurrentOptionRecording();
330 toPlay->loadRecInfo(); // check if still need this
334 bool isRadio = toPlay->isRadio(ish264);
338 VRadioRec* radrec = new VRadioRec(toPlay);
340 boxstack->add(radrec);
341 boxstack->update(radrec);
346 if (ish264 && !Video::getInstance()->supportsh264()) {
347 VInfo* vi = new VInfo();
348 vi->setSize(360, 200);
350 if (Video::getInstance()->getFormat() == Video::PAL)
351 vi->setPosition(190, 170);
353 vi->setPosition(180, 120);
354 vi->setOneLiner(tr("H264 video not supported"));
357 vi->setTitleBarColour(DrawStyle::DANGER);
361 boxstack->update(vi);
364 VVideoRec* vidrec = new VVideoRec(toPlay, ish264);
366 boxstack->add(vidrec);
367 boxstack->update(vidrec);
373 // should not get to here
377 Recording* VRecordingList::getCurrentOptionRecording()
379 Recording* currentRec;
380 RecordingList::iterator j;
381 RecordingList* recList = recman->getRecordings();
382 for (j = recList->begin(); j != recList->end(); j++)
385 if (currentRec->index == sl.getCurrentOption()) return currentRec;
391 int VRecordingList::handleCommand(int command)
402 boxstack->update(this);
405 case Remote::DF_DOWN:
412 boxstack->update(this);
415 case Remote::SKIPBACK:
421 boxstack->update(this);
424 case Remote::SKIPFORWARD:
430 boxstack->update(this);
435 if (sl.getNumOptions() == 0) return 2;
437 // Check to see if it is a sub directory
438 Directory* currentSubDir;
439 DirectoryList::iterator i;
440 DirectoryList* dirList = recman->getDirectories();
441 for (i = dirList->begin(); i != dirList->end(); i++)
444 if (currentSubDir->index == sl.getCurrentOption())
446 if (recman->down(currentSubDir))
448 slIndexStack.push(sl.getCurrentOption());
451 boxstack->update(this);
457 // check to see if it's a recording
458 Recording* current = getCurrentOptionRecording();
461 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Found the option you pointed at. %s %s", current->getProgName(), current->getFileName());
464 VRecordingMenu* v = new VRecordingMenu(recman);
466 v->setRecording(current);
471 VRecording* vr = new VRecording(recman, current);
475 boxstack->update(vr);
479 // should not get to here
484 if (recman->isSubDir())
489 boxstack->update(this);
497 case Remote::PLAYPAUSE:
500 if (doPlay(true)) return 2;
511 // stop command getting to any more views
515 bool VRecordingList::load()
517 VDR* vdr = VDR::getInstance();
519 recman = new RecMan();
521 bool success = vdr->getRecordingsList(recman);
526 char* defaultSortOrder = vdr->configLoad("General", "Recordings Sort Order");
527 if (defaultSortOrder)
529 if (!STRCASECMP(defaultSortOrder, "Chronological")) recman->setSortOrderChron();
530 delete[] defaultSortOrder;
534 boxstack->update(this);
540 void VRecordingList::reSort()
542 recman->toggleSortOrder();
546 boxstack->update(this);