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* tparent)
29 if (Video::getInstance()->getFormat() == Video::PAL)
38 setBackgroundColour(Colour::VIEWBACKGROUND);
40 setTitleBarColour(Colour::TITLEBARBACKGROUND);
42 sl.setSurface(surface);
43 sl.setSurfaceOffset(10, 30 + 5);
44 sl.setDimensions(width - 20, height - 30 - 15 - 30);
46 Log::getInstance()->log("VRecordingList", Log::DEBUG, "this=%p parent=%p\n", this, myParent);
49 VRecordingList::~VRecordingList()
51 // only delete the list if this is not a sub dir window
52 if (recDir->isRoot) delete recDir;
55 void VRecordingList::setDir(Directory* tdir)
64 snprintf(title, 299, "Recordings - %s", recDir->name);
69 setTitleText("Recordings");
73 void VRecordingList::drawData()
81 char tempA[300]; // FIXME this is guesswork!
82 char tempB[300]; // FIXME
86 DirectoryList::iterator i;
88 // First go through to delete 1 empty dir if necessary
90 for (i = recDir->dirList.begin(); i != recDir->dirList.end(); i++)
93 if (dir->getNumRecordings() == 0)
95 recDir->dirList.erase(i);
101 // Then go through again to draw data. Don't merge these two loops!
103 for (i = recDir->dirList.begin(); i != recDir->dirList.end(); i++)
106 snprintf(tempA, 299, "<dir> %lu\t%s", dir->getNumRecordings(), dir->name);
107 dir->index = sl.addOption(tempA, first);
111 // FIXME convert the whole program to time_t's
115 for (UINT j = 0; j < recDir->recList.size(); j++)
117 rec = recDir->recList[j];
118 btime = localtime((time_t*)&rec->start);
119 strftime(tempA, 299, "%0d/%0m %0H:%0M ", btime);
120 sprintf(tempB, "%s\t%s", tempA, rec->getProgName());
121 rec->index = sl.addOption(tempB, first);
128 void VRecordingList::draw()
132 if (dataInvalid) drawData();
136 // Put the status stuff at the bottom
139 w.setSurface(surface);
141 w.nextSymbol = WSymbol::UP;
142 w.setSurfaceOffset(20, 385);
145 w.nextSymbol = WSymbol::DOWN;
146 w.setSurfaceOffset(50, 385);
149 w.nextSymbol = WSymbol::SKIPBACK;
150 w.setSurfaceOffset(85, 385);
153 w.nextSymbol = WSymbol::SKIPFORWARD;
154 w.setSurfaceOffset(115, 385);
157 w.nextSymbol = WSymbol::PLAY;
158 w.setSurfaceOffset(150, 385);
161 // FIXME Right justify this!
162 drawText("[ok] = menu", 450, 385, Colour::LIGHTTEXT);
167 int gigFree = Directory::freeSpace / 1024;
168 snprintf(freeSpace, 49, "%lu%% used, %iGB free", Directory::usedPercent, gigFree);
169 drawTextRJ(freeSpace, 560, 5, Colour::LIGHTTEXT);
172 void VRecordingList::doShowingBar()
174 int topOption = sl.getTopOption() + 1;
175 if (sl.getNumOptions() == 0) topOption = 0;
178 sprintf(showing, "%i to %i of %i", topOption, sl.getBottomOption(), sl.getNumOptions());
181 // b.setSurfaceOffset(220, 385);
182 // b.setDimensions(160, 25);
183 // b.fillColour(Colour::VIEWBACKGROUND);
184 // b.drawText(showing, 0, 0, Colour::LIGHTTEXT);
186 rectangle(220, 385, 220+160, 385+25, Colour::VIEWBACKGROUND);
187 drawText(showing, 220, 385, Colour::LIGHTTEXT);
192 void VRecordingList::processMessage(Message* m)
194 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Got message value %lu", m->message);
195 if (m->message == Message::DELETE_SELECTED_RECORDING)
197 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Doing delete selected");
202 if (m->message == Message::PLAY_SELECTED_RECORDING)
208 if (m->message == Message::RESUME_SELECTED_RECORDING)
214 if (m->message == Message::REDRAW_DATA)
222 void VRecordingList::doDeleteSelected()
224 Recording* toDelete = getCurrentOptionRecording();
231 saveIndex = toDelete->index;
232 saveTop = sl.getTopOption();
233 Log::getInstance()->log("VRecordingList", Log::DEBUG, "FOUND: %i %s %s", toDelete->index, toDelete->getProgName(), toDelete->fileName);
235 for(RecordingList::iterator i = recDir->recList.begin(); i != recDir->recList.end(); i++)
239 recDir->recList.erase(i);
240 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Removed from vector: %s %s", toDelete->getProgName(), toDelete->fileName);
245 VDR* vdr = VDR::getInstance();
246 vdr->deleteRecording(toDelete->fileName);
252 sl.hintSetCurrent(saveIndex);
253 sl.hintSetTop(saveTop);
257 if (myParent) // if this is not root send a message to parent to say redraw data
259 Message* m1 = new Message();
261 m1->message = Message::REDRAW_DATA;
262 ViewMan::getInstance()->postMessage(m1);
268 Message* m2 = new Message();
270 m2->to = ViewMan::getInstance();
271 m2->message = Message::UPDATE_SCREEN;
272 ViewMan::getInstance()->postMessage(m2);
276 int VRecordingList::doPlay()
278 Recording* toPlay = getCurrentOptionRecording();
281 VVideoRec* vidrec = new VVideoRec(toPlay);
282 ViewMan::getInstance()->addNoLock(vidrec);
288 // should not get to here
292 int VRecordingList::doResume()
294 Recording* toResume = getCurrentOptionRecording();
297 ULLONG position = VDR::getInstance()->getResumePoint(toResume->fileName);
299 VVideoRec* vidrec = new VVideoRec(toResume);
300 ViewMan::getInstance()->addNoLock(vidrec);
303 vidrec->go(position);
306 // should not get to here
310 Recording* VRecordingList::getCurrentOptionRecording()
313 for (UINT i = 0; i < recDir->recList.size(); i++)
315 current = recDir->recList[i];
316 if (current->index == sl.getCurrentOption()) return current;
321 int VRecordingList::handleCommand(int command)
335 case Remote::DF_DOWN:
345 case Remote::SKIPBACK:
354 case Remote::SKIPFORWARD:
365 if (sl.getNumOptions() == 0) return 2;
367 // Check to see if it is a sub directory
369 for(UINT i = 0; i < recDir->dirList.size(); i++)
371 curDir = recDir->dirList[i];
372 if (curDir->index == sl.getCurrentOption())
374 VRecordingList* sub = new VRecordingList(this);
376 ViewMan::getInstance()->addNoLock(sub);
385 // check to see if it's a recording
386 Recording* current = getCurrentOptionRecording();
389 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Found the option you pointed at. %s %s", current->getProgName(), current->fileName);
391 VRecordingMenu* v = new VRecordingMenu();
393 v->setRecording(current);
394 ViewMan::getInstance()->addNoLock(v);
399 // should not get to here
408 if (doPlay()) return 2;
413 // stop command getting to any more views