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()
26 setDimensions(420, 570);
28 setBackgroundColour(0, 0, 100, 255);
30 setTitleBarColour(0, 0, 200, 255);
32 sl.setScreenPos(screenX + 10, screenY + 30 + 5);
33 sl.setDimensions(height - 30 - 15 - 30, width - 20);
36 VRecordingList::~VRecordingList()
38 // only delete the list if this is not a sub dir window
39 if (recDir->isRoot) delete recDir;
42 void VRecordingList::setDir(Directory* tdir)
47 char tempA[300]; // FIXME this is guesswork!
48 char tempB[300]; // FIXME
56 recDir->dirList->reset();
57 while((dir = (Directory*)recDir->dirList->getCurrent()))
60 theNumberLength = snprintf(theNumber, 9, "%lu", dir->getNumRecordings());
62 spaces[11 - theNumberLength] = '\0';
64 //snprintf(tempA, 299, "<dir> %s", dir->name);
65 snprintf(tempA, 299, "<dir> %s%s%s", theNumber, spaces, dir->name);
66 //int numSize = snprintf(tempA
68 dir->index = sl.addOption(tempA, first);
70 recDir->dirList->next();
74 List* recList = recDir->recList;
76 // FIXME convert the whole program to time_t's
81 while((rec = (Recording*)recList->getCurrent()))
83 btime = localtime((time_t*)&rec->start);
84 strftime(tempA, 299, "%0d/%0m %0H:%0M ", btime);
85 sprintf(tempB, "%s %s", tempA, rec->getProgName());
86 rec->index = sl.addOption(tempB, first);
93 snprintf(tempA, 299, "Recordings - %s", recDir->name);
98 setTitleText("Recordings");
102 void VRecordingList::draw()
107 // Put the status stuff at the bottom
111 w.nextSymbol = WSymbol::UP;
112 w.setScreenPos(screenX + 20, screenY + 385);
115 w.nextSymbol = WSymbol::DOWN;
116 w.setScreenPos(screenX + 50, screenY + 385);
119 w.nextSymbol = WSymbol::SKIPBACK;
120 w.setScreenPos(screenX + 85, screenY + 385);
123 w.nextSymbol = WSymbol::SKIPFORWARD;
124 w.setScreenPos(screenX + 115, screenY + 385);
127 w.nextSymbol = WSymbol::PLAY;
128 w.setScreenPos(screenX + 150, screenY + 385);
131 // FIXME Right justify this!
132 drawText("[ok] = menu", 450, 385, 255, 255, 255);
137 int gigFree = Directory::freeSpace / 1024;
138 snprintf(freeSpace, 49, "%lu%%, %iGB free", Directory::usedPercent, gigFree);
139 drawTextRJ(freeSpace, 560, 5, 255, 255, 255);
142 void VRecordingList::doShowingBar()
144 int topOption = sl.getTopOption() + 1;
145 if (sl.getNumOptions() == 0) topOption = 0;
148 sprintf(showing, "%i to %i of %i", topOption, sl.getBottomOption(), sl.getNumOptions());
150 b.setScreenPos(screenX + 220, screenY + 385);
151 b.setDimensions(25, 160);
152 b.fillColour(0, 0, 100, 255);
153 b.drawText(showing, 0, 0, 255, 255, 255);
158 void VRecordingList::processMessage(Message* m)
160 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Got message value %lu", m->message);
161 if (m->message == Message::DELETE_SELECTED_RECORDING)
163 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Doing delete selected");
168 if (m->message == Message::PLAY_SELECTED_RECORDING)
174 if (m->message == Message::RESUME_SELECTED_RECORDING)
181 void VRecordingList::doDeleteSelected()
183 Recording* toDelete = getCurrentOptionRecording();
190 saveIndex = toDelete->index;
191 saveTop = sl.getTopOption();
192 Log::getInstance()->log("VRecordingList", Log::DEBUG, "FOUND: %i %s %s\n", toDelete->index, toDelete->getProgName(), toDelete->fileName);
193 recDir->recList->remove(toDelete);
194 Log::getInstance()->log("VRecordingList", Log::DEBUG, "I have removed: %s %s\n", toDelete->getProgName(), toDelete->fileName);
196 VDR* vdr = VDR::getInstance();
197 vdr->deleteRecording(toDelete->fileName);
203 sl.hintSetCurrent(saveIndex);
204 sl.hintSetTop(saveTop);
208 Message* m2 = new Message();
210 m2->to = ViewMan::getInstance();
211 m2->message = Message::UPDATE_SCREEN;
212 ViewMan::getInstance()->postMessage(m2);
215 int VRecordingList::doPlay()
217 Recording* toPlay = getCurrentOptionRecording();
220 VVideoRec* vidrec = new VVideoRec(toPlay);
221 ViewMan::getInstance()->addNoLock(vidrec);
227 // should not get to here
231 int VRecordingList::doResume()
233 Recording* toResume = getCurrentOptionRecording();
236 ULLONG position = VDR::getInstance()->getResumePoint(toResume->fileName);
238 VVideoRec* vidrec = new VVideoRec(toResume);
239 ViewMan::getInstance()->addNoLock(vidrec);
242 vidrec->go(position);
245 // should not get to here
249 Recording* VRecordingList::getCurrentOptionRecording()
252 for(recDir->recList->reset(); (current = (Recording*)recDir->recList->getCurrent()); recDir->recList->next())
254 if (current->index == sl.getCurrentOption()) return current;
259 int VRecordingList::handleCommand(int command)
261 if (command == Remote::UP)
270 else if (command == Remote::DOWN)
279 else if (command == Remote::SKIPBACK)
288 else if (command == Remote::SKIPFORWARD)
297 else if (command == Remote::OK)
299 if (sl.getNumOptions() == 0) return 2;
301 // Check to see if it is a sub directory
303 for(recDir->dirList->reset(); (curDir = (Directory*)recDir->dirList->getCurrent()); recDir->dirList->next())
305 if (curDir->index == sl.getCurrentOption())
307 VRecordingList* sub = new VRecordingList();
309 ViewMan::getInstance()->addNoLock(sub);
318 // check to see if it's a recording
320 for(recDir->recList->reset(); (current = (Recording*)recDir->recList->getCurrent()); recDir->recList->next())
322 if (current->index == sl.getCurrentOption())
324 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Found the option you pointed at. %s %s", current->getProgName(), current->fileName);
326 VRecordingMenu* v = new VRecordingMenu();
328 v->setRecording(current);
329 ViewMan::getInstance()->addNoLock(v);
335 // should not get to here
338 else if (command == Remote::BACK)
342 else if (command == Remote::PLAY)
344 if (doPlay()) return 2;
348 // stop command getting to any more views