2 Copyright 2004-2005 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "vrecordinglist.h"
23 VRecordingList::VRecordingList(VRecordingList* parent)
28 if (Video::getInstance()->getFormat() == Video::PAL)
37 setDimensions(420, 570);
39 setBackgroundColour(Colour::VIEWBACKGROUND);
41 setTitleBarColour(Colour::TITLEBARBACKGROUND);
43 sl.setScreenPos(screenX + 10, screenY + 30 + 5);
44 sl.setDimensions(height - 30 - 15 - 30, width - 20);
47 VRecordingList::~VRecordingList()
49 // only delete the list if this is not a sub dir window
50 if (recDir->isRoot) delete recDir;
53 void VRecordingList::setDir(Directory* tdir)
62 snprintf(title, 299, "Recordings - %s", recDir->name);
67 setTitleText("Recordings");
71 void VRecordingList::drawData()
77 char tempA[300]; // FIXME this is guesswork!
78 char tempB[300]; // FIXME
86 recDir->dirList->reset();
87 while((dir = (Directory*)recDir->dirList->getCurrent()))
89 if (dir->getNumRecordings() == 0)
91 recDir->dirList->remove(dir);
96 theNumberLength = snprintf(theNumber, 9, "%lu", dir->getNumRecordings());
98 spaces[11 - theNumberLength] = '\0';
100 //snprintf(tempA, 299, "<dir> %s", dir->name);
101 snprintf(tempA, 299, "<dir> %s%s%s", theNumber, spaces, dir->name);
102 //int numSize = snprintf(tempA
104 dir->index = sl.addOption(tempA, first);
107 recDir->dirList->next();
111 List* recList = recDir->recList;
113 // FIXME convert the whole program to time_t's
118 while((rec = (Recording*)recList->getCurrent()))
120 btime = localtime((time_t*)&rec->start);
121 strftime(tempA, 299, "%0d/%0m %0H:%0M ", btime);
122 sprintf(tempB, "%s %s", tempA, rec->getProgName());
123 rec->index = sl.addOption(tempB, first);
131 void VRecordingList::draw()
135 if (dataInvalid) drawData();
139 // Put the status stuff at the bottom
143 w.nextSymbol = WSymbol::UP;
144 w.setScreenPos(screenX + 20, screenY + 385);
147 w.nextSymbol = WSymbol::DOWN;
148 w.setScreenPos(screenX + 50, screenY + 385);
151 w.nextSymbol = WSymbol::SKIPBACK;
152 w.setScreenPos(screenX + 85, screenY + 385);
155 w.nextSymbol = WSymbol::SKIPFORWARD;
156 w.setScreenPos(screenX + 115, screenY + 385);
159 w.nextSymbol = WSymbol::PLAY;
160 w.setScreenPos(screenX + 150, screenY + 385);
163 // FIXME Right justify this!
164 drawText("[ok] = menu", 450, 385, Colour::LIGHTTEXT);
169 int gigFree = Directory::freeSpace / 1024;
170 snprintf(freeSpace, 49, "%lu%%, %iGB free", Directory::usedPercent, gigFree);
171 drawTextRJ(freeSpace, 560, 5, Colour::LIGHTTEXT);
174 void VRecordingList::doShowingBar()
176 int topOption = sl.getTopOption() + 1;
177 if (sl.getNumOptions() == 0) topOption = 0;
180 sprintf(showing, "%i to %i of %i", topOption, sl.getBottomOption(), sl.getNumOptions());
182 b.setScreenPos(screenX + 220, screenY + 385);
183 b.setDimensions(25, 160);
184 b.fillColour(Colour::VIEWBACKGROUND);
185 b.drawText(showing, 0, 0, Colour::LIGHTTEXT);
190 void VRecordingList::processMessage(Message* m)
192 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Got message value %lu", m->message);
193 if (m->message == Message::DELETE_SELECTED_RECORDING)
195 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Doing delete selected");
200 if (m->message == Message::PLAY_SELECTED_RECORDING)
206 if (m->message == Message::RESUME_SELECTED_RECORDING)
212 if (m->message == Message::REDRAW_DATA)
219 void VRecordingList::doDeleteSelected()
221 Recording* toDelete = getCurrentOptionRecording();
228 saveIndex = toDelete->index;
229 saveTop = sl.getTopOption();
230 Log::getInstance()->log("VRecordingList", Log::DEBUG, "FOUND: %i %s %s\n", toDelete->index, toDelete->getProgName(), toDelete->fileName);
231 recDir->recList->remove(toDelete);
232 Log::getInstance()->log("VRecordingList", Log::DEBUG, "I have removed: %s %s\n", toDelete->getProgName(), toDelete->fileName);
234 VDR* vdr = VDR::getInstance();
235 vdr->deleteRecording(toDelete->fileName);
241 sl.hintSetCurrent(saveIndex);
242 sl.hintSetTop(saveTop);
246 if (myParent) // if this is not root send a message to parent to say redraw data
248 Message* m1 = new Message();
250 m1->message = Message::REDRAW_DATA;
251 ViewMan::getInstance()->postMessage(m1);
254 Message* m2 = new Message();
256 m2->to = ViewMan::getInstance();
257 m2->message = Message::UPDATE_SCREEN;
258 ViewMan::getInstance()->postMessage(m2);
261 int VRecordingList::doPlay()
263 Recording* toPlay = getCurrentOptionRecording();
266 VVideoRec* vidrec = new VVideoRec(toPlay);
267 ViewMan::getInstance()->addNoLock(vidrec);
273 // should not get to here
277 int VRecordingList::doResume()
279 Recording* toResume = getCurrentOptionRecording();
282 ULLONG position = VDR::getInstance()->getResumePoint(toResume->fileName);
284 VVideoRec* vidrec = new VVideoRec(toResume);
285 ViewMan::getInstance()->addNoLock(vidrec);
288 vidrec->go(position);
291 // should not get to here
295 Recording* VRecordingList::getCurrentOptionRecording()
298 for(recDir->recList->reset(); (current = (Recording*)recDir->recList->getCurrent()); recDir->recList->next())
300 if (current->index == sl.getCurrentOption()) return current;
305 int VRecordingList::handleCommand(int command)
319 case Remote::DF_DOWN:
329 case Remote::SKIPBACK:
338 case Remote::SKIPFORWARD:
349 if (sl.getNumOptions() == 0) return 2;
351 // Check to see if it is a sub directory
353 for(recDir->dirList->reset(); (curDir = (Directory*)recDir->dirList->getCurrent()); recDir->dirList->next())
355 if (curDir->index == sl.getCurrentOption())
357 VRecordingList* sub = new VRecordingList(this);
359 ViewMan::getInstance()->addNoLock(sub);
368 // check to see if it's a recording
370 for(recDir->recList->reset(); (current = (Recording*)recDir->recList->getCurrent()); recDir->recList->next())
372 if (current->index == sl.getCurrentOption())
374 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Found the option you pointed at. %s %s", current->getProgName(), current->fileName);
376 VRecordingMenu* v = new VRecordingMenu();
378 v->setRecording(current);
379 ViewMan::getInstance()->addNoLock(v);
385 // should not get to here
394 if (doPlay()) return 2;
399 // stop command getting to any more views