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;
190 #ifndef GRADIENT_DRAWING
191 rectangle(220, 385, 180, 25, DrawStyle::VIEWBACKGROUND);
194 sprintf(showing, tr("%i to %i of %i"), topOption, sl.getBottomOption(), sl.getNumOptions());
195 drawText(showing, 220, 385, DrawStyle::LIGHTTEXT);
198 void VRecordingList::quickUpdate() { //only quick for plattform that need it!
199 #ifdef GRADIENT_DRAWING
207 void VRecordingList::processMessage(Message* m)
209 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Got message value %lu", m->message);
211 if (m->message == Message::MOUSE_MOVE)
213 if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
216 boxstack->update(this);
219 else if (m->message == Message::MOUSE_LBDOWN)
221 if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
223 boxstack->handleCommand(Remote::OK); //simulate OK press
227 //check if press is outside this view! then simulate cancel
228 int x=(m->parameter>>16)-getScreenX();
229 int y=(m->parameter&0xFFFF)-getScreenY();
230 if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
232 boxstack->handleCommand(Remote::BACK); //simulate cancel press
236 else if (m->message == Message::DELETE_SELECTED_RECORDING)
238 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Doing delete selected");
241 else if (m->message == Message::MOVE_RECORDING)
243 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Doing move recording");
244 doMoveRecording((Directory*)m->parameter);
246 else if (m->message == Message::PLAY_SELECTED_RECORDING)
250 else if (m->message == Message::RESUME_SELECTED_RECORDING)
256 void VRecordingList::doDeleteSelected()
258 Recording* toDelete = getCurrentOptionRecording();
260 if (!toDelete) return;
262 Log::getInstance()->log("VRecordingList", Log::DEBUG, "FOUND: %i %s %s", toDelete->index, toDelete->getProgName(), toDelete->getFileName());
264 int success = recman->deleteRecording(toDelete);
265 if (!VDR::getInstance()->isConnected())
267 Command::getInstance()->connectionLost();
273 VInfo* vi = new VInfo();
274 vi->setSize(360, 200);
276 if (Video::getInstance()->getFormat() == Video::PAL)
277 vi->setPosition(190, 170);
279 vi->setPosition(180, 120);
280 vi->setOneLiner(tr("Failed to delete recording"));
283 vi->setTitleBarColour(DrawStyle::DANGER);
287 boxstack->update(vi);
292 boxstack->update(this);
297 void VRecordingList::doMoveRecording(Directory* toDir)
299 Recording* toMove = getCurrentOptionRecording();
300 if (!toMove || !toDir) return;
302 Log::getInstance()->log("VRecordingList", Log::DEBUG, "MOVE: %s %s", toMove->getProgName(), toDir->name);
304 int success = recman->moveRecording(toMove, toDir);
305 if (!VDR::getInstance()->isConnected())
307 Command::getInstance()->connectionLost();
313 VInfo* vi = new VInfo();
314 vi->setSize(360, 200);
316 if (Video::getInstance()->getFormat() == Video::PAL)
317 vi->setPosition(190, 170);
319 vi->setPosition(180, 120);
320 vi->setOneLiner(tr("Failed to move recording"));
323 vi->setTitleBarColour(DrawStyle::DANGER);
327 boxstack->update(vi);
332 boxstack->update(this);
336 int VRecordingList::doPlay(bool resume)
338 Recording* toPlay = getCurrentOptionRecording();
341 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);
354 toPlay->setNew(false);
356 boxstack->update(this);
360 if (ish264 && !Video::getInstance()->supportsh264())
362 VInfo* vi = new VInfo();
363 vi->setSize(360, 200);
365 if (Video::getInstance()->getFormat() == Video::PAL)
366 vi->setPosition(190, 170);
368 vi->setPosition(180, 120);
369 vi->setOneLiner(tr("H264 video not supported"));
372 vi->setTitleBarColour(DrawStyle::DANGER);
376 boxstack->update(vi);
378 else if (!ish264 && !Video::getInstance()->supportsmpeg2())
380 VInfo* vi = new VInfo();
381 vi->setSize(360, 200);
383 if (Video::getInstance()->getFormat() == Video::PAL)
384 vi->setPosition(190, 170);
386 vi->setPosition(180, 120);
387 vi->setOneLiner(tr("Mpeg2 video not supported"));
390 vi->setTitleBarColour(DrawStyle::DANGER);
394 boxstack->update(vi);
398 VVideoRec* vidrec = new VVideoRec(toPlay, ish264);
400 boxstack->add(vidrec);
401 boxstack->update(vidrec);
404 toPlay->setNew(false);
406 boxstack->update(this);
411 // should not get to here
415 Recording* VRecordingList::getCurrentOptionRecording()
417 Recording* currentRec;
418 RecordingList::iterator j;
419 RecordingList* recList = recman->getRecordings();
420 for (j = recList->begin(); j != recList->end(); j++)
423 if (currentRec->index == sl.getCurrentOption()) return currentRec;
429 int VRecordingList::handleCommand(int command)
439 boxstack->update(this);
442 case Remote::DF_DOWN:
448 boxstack->update(this);
451 case Remote::SKIPBACK:
456 boxstack->update(this);
459 case Remote::SKIPFORWARD:
464 boxstack->update(this);
469 if (sl.getNumOptions() == 0) return 2;
471 // Check to see if it is a sub directory
472 Directory* currentSubDir;
473 DirectoryList::iterator i;
474 DirectoryList* dirList = recman->getDirectories();
475 for (i = dirList->begin(); i != dirList->end(); i++)
478 if (currentSubDir->index == sl.getCurrentOption())
480 if (recman->down(currentSubDir))
482 slIndexStack.push(sl.getCurrentOption());
485 boxstack->update(this);
491 // check to see if it's a recording
492 Recording* current = getCurrentOptionRecording();
495 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Found the option you pointed at. %s %s", current->getProgName(), current->getFileName());
498 VRecordingMenu* v = new VRecordingMenu(recman);
500 v->setRecording(current);
505 VRecording* vr = new VRecording(recman, current);
509 boxstack->update(vr);
513 // should not get to here
518 if (recman->isSubDir())
523 boxstack->update(this);
531 case Remote::PLAYPAUSE:
534 if (doPlay(true)) return 2;
545 // stop command getting to any more views
549 bool VRecordingList::load()
551 VDR* vdr = VDR::getInstance();
553 recman = new RecMan();
555 bool success = vdr->getRecordingsList(recman);
560 char* defaultSortOrder = vdr->configLoad("General", "Recordings Sort Order");
561 if (defaultSortOrder)
563 if (!STRCASECMP(defaultSortOrder, "Chronological")) recman->setSortOrderChron();
564 delete[] defaultSortOrder;
568 boxstack->update(this);
574 void VRecordingList::reSort()
576 recman->toggleSortOrder();
580 boxstack->update(this);