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)
96 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 VDR* vdr = VDR::getInstance();
236 vdr->deleteRecording(toDelete->fileName);
240 for(RecordingList::iterator i = recDir->recList.begin(); i != recDir->recList.end(); i++)
244 recDir->recList.erase(i);
251 sl.hintSetCurrent(saveIndex);
252 sl.hintSetTop(saveTop);
256 if (myParent) // if this is not root send a message to parent to say redraw data
258 Message* m1 = new Message();
260 m1->message = Message::REDRAW_DATA;
261 ViewMan::getInstance()->postMessage(m1);
267 Message* m2 = new Message();
269 m2->to = ViewMan::getInstance();
270 m2->message = Message::UPDATE_SCREEN;
271 ViewMan::getInstance()->postMessage(m2);
275 int VRecordingList::doPlay()
277 Recording* toPlay = getCurrentOptionRecording();
280 VVideoRec* vidrec = new VVideoRec(toPlay);
281 ViewMan::getInstance()->addNoLock(vidrec);
287 // should not get to here
291 int VRecordingList::doResume()
293 Recording* toResume = getCurrentOptionRecording();
296 ULLONG position = VDR::getInstance()->getResumePoint(toResume->fileName);
298 VVideoRec* vidrec = new VVideoRec(toResume);
299 ViewMan::getInstance()->addNoLock(vidrec);
302 vidrec->go(position);
305 // should not get to here
309 Recording* VRecordingList::getCurrentOptionRecording()
312 for (UINT i = 0; i < recDir->recList.size(); i++)
314 current = recDir->recList[i];
315 if (current->index == sl.getCurrentOption()) return current;
320 int VRecordingList::handleCommand(int command)
334 case Remote::DF_DOWN:
344 case Remote::SKIPBACK:
353 case Remote::SKIPFORWARD:
364 if (sl.getNumOptions() == 0) return 2;
366 // Check to see if it is a sub directory
368 for(UINT i = 0; i < recDir->dirList.size(); i++)
370 curDir = recDir->dirList[i];
371 if (curDir->index == sl.getCurrentOption())
373 VRecordingList* sub = new VRecordingList(this);
375 ViewMan::getInstance()->addNoLock(sub);
384 // check to see if it's a recording
385 Recording* current = getCurrentOptionRecording();
388 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Found the option you pointed at. %s %s", current->getProgName(), current->fileName);
390 VRecordingMenu* v = new VRecordingMenu();
392 v->setRecording(current);
393 ViewMan::getInstance()->addNoLock(v);
398 // should not get to here
407 if (doPlay()) return 2;
412 // stop command getting to any more views