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()
79 char tempA[300]; // FIXME this is guesswork!
80 char tempB[300]; // FIXME
84 recDir->dirList->reset();
85 while((dir = (Directory*)recDir->dirList->getCurrent()))
87 if (dir->getNumRecordings() == 0)
89 recDir->dirList->remove(dir);
93 snprintf(tempA, 299, "<dir> %lu\t%s", dir->getNumRecordings(), dir->name);
95 dir->index = sl.addOption(tempA, first);
98 recDir->dirList->next();
102 List* recList = recDir->recList;
104 // FIXME convert the whole program to time_t's
109 while((rec = (Recording*)recList->getCurrent()))
111 btime = localtime((time_t*)&rec->start);
112 strftime(tempA, 299, "%0d/%0m %0H:%0M ", btime);
113 sprintf(tempB, "%s\t%s", tempA, rec->getProgName());
114 rec->index = sl.addOption(tempB, first);
122 void VRecordingList::draw()
126 if (dataInvalid) drawData();
130 // Put the status stuff at the bottom
134 w.nextSymbol = WSymbol::UP;
135 w.setScreenPos(screenX + 20, screenY + 385);
138 w.nextSymbol = WSymbol::DOWN;
139 w.setScreenPos(screenX + 50, screenY + 385);
142 w.nextSymbol = WSymbol::SKIPBACK;
143 w.setScreenPos(screenX + 85, screenY + 385);
146 w.nextSymbol = WSymbol::SKIPFORWARD;
147 w.setScreenPos(screenX + 115, screenY + 385);
150 w.nextSymbol = WSymbol::PLAY;
151 w.setScreenPos(screenX + 150, screenY + 385);
154 // FIXME Right justify this!
155 drawText("[ok] = menu", 450, 385, Colour::LIGHTTEXT);
160 int gigFree = Directory::freeSpace / 1024;
161 snprintf(freeSpace, 49, "%lu%%, %iGB free", Directory::usedPercent, gigFree);
162 drawTextRJ(freeSpace, 560, 5, Colour::LIGHTTEXT);
165 void VRecordingList::doShowingBar()
167 int topOption = sl.getTopOption() + 1;
168 if (sl.getNumOptions() == 0) topOption = 0;
171 sprintf(showing, "%i to %i of %i", topOption, sl.getBottomOption(), sl.getNumOptions());
173 b.setScreenPos(screenX + 220, screenY + 385);
174 b.setDimensions(25, 160);
175 b.fillColour(Colour::VIEWBACKGROUND);
176 b.drawText(showing, 0, 0, Colour::LIGHTTEXT);
181 void VRecordingList::processMessage(Message* m)
183 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Got message value %lu", m->message);
184 if (m->message == Message::DELETE_SELECTED_RECORDING)
186 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Doing delete selected");
191 if (m->message == Message::PLAY_SELECTED_RECORDING)
197 if (m->message == Message::RESUME_SELECTED_RECORDING)
203 if (m->message == Message::REDRAW_DATA)
210 void VRecordingList::doDeleteSelected()
212 Recording* toDelete = getCurrentOptionRecording();
219 saveIndex = toDelete->index;
220 saveTop = sl.getTopOption();
221 Log::getInstance()->log("VRecordingList", Log::DEBUG, "FOUND: %i %s %s\n", toDelete->index, toDelete->getProgName(), toDelete->fileName);
222 recDir->recList->remove(toDelete);
223 Log::getInstance()->log("VRecordingList", Log::DEBUG, "I have removed: %s %s\n", toDelete->getProgName(), toDelete->fileName);
225 VDR* vdr = VDR::getInstance();
226 vdr->deleteRecording(toDelete->fileName);
232 sl.hintSetCurrent(saveIndex);
233 sl.hintSetTop(saveTop);
237 if (myParent) // if this is not root send a message to parent to say redraw data
239 Message* m1 = new Message();
241 m1->message = Message::REDRAW_DATA;
242 ViewMan::getInstance()->postMessage(m1);
245 Message* m2 = new Message();
247 m2->to = ViewMan::getInstance();
248 m2->message = Message::UPDATE_SCREEN;
249 ViewMan::getInstance()->postMessage(m2);
252 int VRecordingList::doPlay()
254 Recording* toPlay = getCurrentOptionRecording();
257 VVideoRec* vidrec = new VVideoRec(toPlay);
258 ViewMan::getInstance()->addNoLock(vidrec);
264 // should not get to here
268 int VRecordingList::doResume()
270 Recording* toResume = getCurrentOptionRecording();
273 ULLONG position = VDR::getInstance()->getResumePoint(toResume->fileName);
275 VVideoRec* vidrec = new VVideoRec(toResume);
276 ViewMan::getInstance()->addNoLock(vidrec);
279 vidrec->go(position);
282 // should not get to here
286 Recording* VRecordingList::getCurrentOptionRecording()
289 for(recDir->recList->reset(); (current = (Recording*)recDir->recList->getCurrent()); recDir->recList->next())
291 if (current->index == sl.getCurrentOption()) return current;
296 int VRecordingList::handleCommand(int command)
310 case Remote::DF_DOWN:
320 case Remote::SKIPBACK:
329 case Remote::SKIPFORWARD:
340 if (sl.getNumOptions() == 0) return 2;
342 // Check to see if it is a sub directory
344 for(recDir->dirList->reset(); (curDir = (Directory*)recDir->dirList->getCurrent()); recDir->dirList->next())
346 if (curDir->index == sl.getCurrentOption())
348 VRecordingList* sub = new VRecordingList(this);
350 ViewMan::getInstance()->addNoLock(sub);
359 // check to see if it's a recording
361 for(recDir->recList->reset(); (current = (Recording*)recDir->recList->getCurrent()); recDir->recList->next())
363 if (current->index == sl.getCurrentOption())
365 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Found the option you pointed at. %s %s", current->getProgName(), current->fileName);
367 VRecordingMenu* v = new VRecordingMenu();
369 v->setRecording(current);
370 ViewMan::getInstance()->addNoLock(v);
376 // should not get to here
385 if (doPlay()) return 2;
390 // stop command getting to any more views