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(area.w - 20, area.h - 30 - 15 - 30);
47 VRecordingList::~VRecordingList()
49 // if this is a child window, inform the parent of our destruct
52 Message* m = new Message();
54 m->message = Message::CHILD_CLOSE;
55 ViewMan::getInstance()->postMessage(m);
58 // only delete the list if this is not a sub dir window
65 void VRecordingList::setDir(Directory* tdir)
74 snprintf(title, 299, tr("Recordings - %s"), recDir->name);
79 setTitleText(tr("Recordings"));
83 void VRecordingList::drawData()
91 char tempA[300]; // FIXME this is guesswork!
92 char tempB[300]; // FIXME
96 DirectoryList::iterator i;
98 if (dataInvalid == 2) // special case, a child list has closed, check for 0 dir entries
101 // First go through to delete 1 empty dir if necessary
103 for (i = recDir->dirList.begin(); i != recDir->dirList.end(); i++)
106 if (dir->getNumRecordings() == 0)
109 recDir->dirList.erase(i);
115 // Then go through again to draw data. Don't merge these two loops!
117 for (i = recDir->dirList.begin(); i != recDir->dirList.end(); i++)
120 snprintf(tempA, 299, tr("<dir> %lu\t%s"), dir->getNumRecordings(), dir->name);
121 dir->index = sl.addOption(tempA, first);
125 // FIXME convert the whole program to time_t's
129 for (UINT j = 0; j < recDir->recList.size(); j++)
131 rec = recDir->recList[j];
132 btime = localtime((time_t*)&rec->start);
133 strftime(tempA, 299, "%0d/%0m %0H:%0M ", btime);
134 sprintf(tempB, "%s\t%s", tempA, rec->getProgName());
135 rec->index = sl.addOption(tempB, first);
142 void VRecordingList::draw()
146 if (dataInvalid) drawData();
150 // Put the status stuff at the bottom
153 w.setSurface(surface);
155 w.nextSymbol = WSymbol::UP;
156 w.setSurfaceOffset(20, 385);
159 w.nextSymbol = WSymbol::DOWN;
160 w.setSurfaceOffset(50, 385);
163 w.nextSymbol = WSymbol::SKIPBACK;
164 w.setSurfaceOffset(85, 385);
167 w.nextSymbol = WSymbol::SKIPFORWARD;
168 w.setSurfaceOffset(115, 385);
171 w.nextSymbol = WSymbol::PLAY;
172 w.setSurfaceOffset(150, 385);
175 // FIXME Right justify this!
176 drawText(tr("[ok] = menu"), 450, 385, Colour::LIGHTTEXT);
181 int gigFree = Directory::freeSpace / 1024;
182 snprintf(freeSpace, 49, tr("%lu%% used, %iGB free"), Directory::usedPercent, gigFree);
183 drawTextRJ(freeSpace, 560, 5, Colour::LIGHTTEXT);
186 void VRecordingList::doShowingBar()
188 int topOption = sl.getTopOption() + 1;
189 if (sl.getNumOptions() == 0) topOption = 0;
192 sprintf(showing, tr("%i to %i of %i"), topOption, sl.getBottomOption(), sl.getNumOptions());
195 // b.setSurfaceOffset(220, 385);
196 // b.setDimensions(160, 25);
197 // b.fillColour(Colour::VIEWBACKGROUND);
198 // b.drawText(showing, 0, 0, Colour::LIGHTTEXT);
200 rectangle(220, 385, 220+160, 385+25, Colour::VIEWBACKGROUND);
201 drawText(showing, 220, 385, Colour::LIGHTTEXT);
206 void VRecordingList::processMessage(Message* m)
208 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Got message value %lu", m->message);
209 if (m->message == Message::DELETE_SELECTED_RECORDING)
211 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Doing delete selected");
216 if (m->message == Message::PLAY_SELECTED_RECORDING)
222 if (m->message == Message::RESUME_SELECTED_RECORDING)
228 if (m->message == Message::REDRAW_DATA)
235 if (m->message == Message::CHILD_CLOSE)
244 void VRecordingList::doDeleteSelected()
246 Recording* toDelete = getCurrentOptionRecording();
253 saveIndex = toDelete->index;
254 saveTop = sl.getTopOption();
255 Log::getInstance()->log("VRecordingList", Log::DEBUG, "FOUND: %i %s %s", toDelete->index, toDelete->getProgName(), toDelete->fileName);
257 VDR* vdr = VDR::getInstance();
258 vdr->deleteRecording(toDelete->fileName);
262 for(RecordingList::iterator i = recDir->recList.begin(); i != recDir->recList.end(); i++)
266 recDir->recList.erase(i);
273 sl.hintSetCurrent(saveIndex);
274 sl.hintSetTop(saveTop);
278 if (myParent) // if this is not root send a message to parent to say redraw data
279 { // FIXME not really necessary any more ?
280 Message* m1 = new Message();
282 m1->message = Message::REDRAW_DATA;
283 ViewMan::getInstance()->postMessage(m1);
289 int VRecordingList::doPlay()
291 Recording* toPlay = getCurrentOptionRecording();
294 VVideoRec* vidrec = new VVideoRec(toPlay);
295 ViewMan::getInstance()->add(vidrec);
301 // should not get to here
305 int VRecordingList::doResume()
307 Recording* toResume = getCurrentOptionRecording();
310 ULLONG position = VDR::getInstance()->getResumePoint(toResume->fileName);
312 VVideoRec* vidrec = new VVideoRec(toResume);
313 ViewMan::getInstance()->add(vidrec);
316 vidrec->go(position);
319 // should not get to here
323 Recording* VRecordingList::getCurrentOptionRecording()
326 for (UINT i = 0; i < recDir->recList.size(); i++)
328 current = recDir->recList[i];
329 if (current->index == sl.getCurrentOption()) return current;
334 int VRecordingList::handleCommand(int command)
348 case Remote::DF_DOWN:
358 case Remote::SKIPBACK:
367 case Remote::SKIPFORWARD:
378 if (sl.getNumOptions() == 0) return 2;
380 // Check to see if it is a sub directory
382 for(UINT i = 0; i < recDir->dirList.size(); i++)
384 curDir = recDir->dirList[i];
385 if (curDir->index == sl.getCurrentOption())
387 VRecordingList* sub = new VRecordingList(this);
389 ViewMan::getInstance()->add(sub);
398 // check to see if it's a recording
399 Recording* current = getCurrentOptionRecording();
402 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Found the option you pointed at. %s %s", current->getProgName(), current->fileName);
404 VRecordingMenu* v = new VRecordingMenu();
406 v->setRecording(current);
407 ViewMan::getInstance()->add(v);
412 // should not get to here
421 if (doResume()) return 2;
426 // stop command getting to any more views