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);
108 strftime(tempA, 299, "%0d/%0m %0H:%0M ", btime);
110 strftime(tempA, 299, "%d/%m %H:%M ", btime);
112 sprintf(tempB, "%s\t%s", tempA, currentRec->getProgName());
113 currentRec->index = sl.addOption(tempB, 0, first);
119 sl.hintSetCurrent(slIndexStack.top());
124 sl.hintSetCurrent(saveIndex);
125 sl.hintSetTop(saveTop);
131 void VRecordingList::draw(bool doIndexPop)
135 if (recman->isSubDir())
138 SNPRINTF(title, 299, tr("Recordings - %s"), recman->getCurDirName());
139 setTitleText(title, 364);
143 setTitleText(tr("Recordings"));
151 drawText(tr("Loading..."), 240, 180, Colour::LIGHTTEXT);
156 int gigFree = recman->getFreeSpace() / 1024;
157 SNPRINTF(freeSpace, 49, tr("%lu%% used, %iGB free"), recman->getUsedPercent(), gigFree);
158 drawTextRJ(freeSpace, 560, 5, Colour::LIGHTTEXT);
165 w.nextSymbol = WSymbol::UP;
166 w.setPosition(20, 385);
169 w.nextSymbol = WSymbol::DOWN;
170 w.setPosition(50, 385);
173 w.nextSymbol = WSymbol::SKIPBACK;
174 w.setPosition(85, 385);
177 w.nextSymbol = WSymbol::SKIPFORWARD;
178 w.setPosition(115, 385);
181 w.nextSymbol = WSymbol::PLAY;
182 w.setPosition(150, 385);
185 drawTextRJ(tr("[ok] = menu"), 560, 385, Colour::LIGHTTEXT);
187 // All static stuff done
189 drawData(doIndexPop);
193 void VRecordingList::doShowingBar()
195 int topOption = sl.getTopOption() + 1;
196 if (sl.getNumOptions() == 0) topOption = 0;
198 rectangle(220, 385, 180, 25, Colour::VIEWBACKGROUND);
200 sprintf(showing, tr("%i to %i of %i"), topOption, sl.getBottomOption(), sl.getNumOptions());
201 drawText(showing, 220, 385, Colour::LIGHTTEXT);
204 void VRecordingList::processMessage(Message* m)
206 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Got message value %lu", m->message);
208 if (m->message == Message::MOUSE_MOVE)
210 if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
214 boxstack->update(this);
217 else if (m->message == Message::MOUSE_LBDOWN)
219 if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
221 boxstack->handleCommand(Remote::OK); //simulate OK press
225 //check if press is outside this view! then simulate cancel
226 int x=(m->parameter>>16)-getScreenX();
227 int y=(m->parameter&0xFFFF)-getScreenY();
228 if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
230 boxstack->handleCommand(Remote::BACK); //simulate cancel press
234 else if (m->message == Message::DELETE_SELECTED_RECORDING)
236 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Doing delete selected");
239 else if (m->message == Message::MOVE_RECORDING)
241 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Doing move recording");
242 doMoveRecording((Directory*)m->parameter);
244 else if (m->message == Message::PLAY_SELECTED_RECORDING)
248 else if (m->message == Message::RESUME_SELECTED_RECORDING)
254 void VRecordingList::doDeleteSelected()
256 Recording* toDelete = getCurrentOptionRecording();
258 if (!toDelete) return;
260 Log::getInstance()->log("VRecordingList", Log::DEBUG, "FOUND: %i %s %s", toDelete->index, toDelete->getProgName(), toDelete->getFileName());
262 int success = recman->deleteRecording(toDelete);
263 if (!VDR::getInstance()->isConnected())
265 Command::getInstance()->connectionLost();
271 VInfo* vi = new VInfo();
272 vi->setSize(360, 200);
274 if (Video::getInstance()->getFormat() == Video::PAL)
275 vi->setPosition(190, 170);
277 vi->setPosition(180, 120);
278 vi->setOneLiner(tr("Failed to delete recording"));
281 vi->setTitleBarColour(Colour::DANGER);
285 boxstack->update(vi);
290 boxstack->update(this);
295 void VRecordingList::doMoveRecording(Directory* toDir)
297 Recording* toMove = getCurrentOptionRecording();
298 if (!toMove || !toDir) return;
300 Log::getInstance()->log("VRecordingList", Log::DEBUG, "MOVE: %s %s", toMove->getProgName(), toDir->name);
302 int success = recman->moveRecording(toMove, toDir);
303 if (!VDR::getInstance()->isConnected())
305 Command::getInstance()->connectionLost();
311 VInfo* vi = new VInfo();
312 vi->setSize(360, 200);
314 if (Video::getInstance()->getFormat() == Video::PAL)
315 vi->setPosition(190, 170);
317 vi->setPosition(180, 120);
318 vi->setOneLiner(tr("Failed to move recording"));
321 vi->setTitleBarColour(Colour::DANGER);
325 boxstack->update(vi);
330 boxstack->update(this);
334 int VRecordingList::doPlay(bool resume)
336 Recording* toPlay = getCurrentOptionRecording();
339 toPlay->loadRecInfo(); // check if still need this
342 bool isRadio = toPlay->isRadio();
346 VRadioRec* radrec = new VRadioRec(toPlay);
348 boxstack->add(radrec);
349 boxstack->update(radrec);
354 VVideoRec* vidrec = new VVideoRec(toPlay);
356 boxstack->add(vidrec);
357 boxstack->update(vidrec);
362 // should not get to here
366 Recording* VRecordingList::getCurrentOptionRecording()
368 Recording* currentRec;
369 RecordingList::iterator j;
370 RecordingList* recList = recman->getRecordings();
371 for (j = recList->begin(); j != recList->end(); j++)
374 if (currentRec->index == sl.getCurrentOption()) return currentRec;
380 int VRecordingList::handleCommand(int command)
391 boxstack->update(this);
394 case Remote::DF_DOWN:
401 boxstack->update(this);
404 case Remote::SKIPBACK:
410 boxstack->update(this);
413 case Remote::SKIPFORWARD:
419 boxstack->update(this);
424 if (sl.getNumOptions() == 0) return 2;
426 // Check to see if it is a sub directory
427 Directory* currentSubDir;
428 DirectoryList::iterator i;
429 DirectoryList* dirList = recman->getDirectories();
430 for (i = dirList->begin(); i != dirList->end(); i++)
433 if (currentSubDir->index == sl.getCurrentOption())
435 if (recman->down(currentSubDir))
437 slIndexStack.push(sl.getCurrentOption());
440 boxstack->update(this);
446 // check to see if it's a recording
447 Recording* current = getCurrentOptionRecording();
450 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Found the option you pointed at. %s %s", current->getProgName(), current->getFileName());
453 VRecordingMenu* v = new VRecordingMenu(recman);
455 v->setRecording(current);
460 VRecording* vr = new VRecording(recman, current);
464 boxstack->update(vr);
468 // should not get to here
473 if (recman->isSubDir())
478 boxstack->update(this);
488 if (doPlay(true)) return 2;
499 // stop command getting to any more views
503 bool VRecordingList::load()
505 VDR* vdr = VDR::getInstance();
507 recman = new RecMan();
508 bool success = vdr->getRecordingsList(recman);
513 char* defaultSortOrder = vdr->configLoad("General", "Recordings Sort Order");
514 if (defaultSortOrder)
516 if (!STRCASECMP(defaultSortOrder, "Chronological")) recman->setSortOrderChron();
517 delete[] defaultSortOrder;
523 boxstack->update(this);
529 void VRecordingList::reSort()
531 recman->toggleSortOrder();
535 boxstack->update(this);