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()
25 viewman = ViewMan::getInstance();
30 if (Video::getInstance()->getFormat() == Video::PAL)
39 setBackgroundColour(Colour::VIEWBACKGROUND);
41 setTitleBarColour(Colour::TITLEBARBACKGROUND);
43 sl.setSurface(surface);
44 sl.setSurfaceOffset(10, 30 + 5);
45 sl.setDimensions(area.w - 20, area.h - 30 - 15 - 30);
48 VRecordingList::~VRecordingList()
53 void VRecordingList::drawData(bool doIndexPop)
55 int saveIndex = sl.getCurrentOption();
56 int saveTop = sl.getTopOption();
64 char tempA[300]; // FIXME this is guesswork!
65 char tempB[300]; // FIXME
68 Directory* currentSubDir;
69 DirectoryList::iterator i;
70 DirectoryList* dirList = recman->getDirectories();
71 for (i = dirList->begin(); i != dirList->end(); i++)
74 SNPRINTF(tempA, 299, tr("<dir> %lu\t%s"), currentSubDir->getNumRecordings(), currentSubDir->name);
75 currentSubDir->index = sl.addOption(tempA, first);
79 // FIXME convert the whole program to time_t's
81 Recording* currentRec;
82 RecordingList::iterator j;
83 RecordingList* recList = recman->getRecordings();
84 for (j = recList->begin(); j != recList->end(); j++)
87 time_t recStartTime = (time_t)currentRec->getStartTime();
88 btime = localtime(&recStartTime);
90 strftime(tempA, 299, "%0d/%0m %0H:%0M ", btime);
92 strftime(tempA, 299, "%d/%m %H:%M ", btime);
94 sprintf(tempB, "%s\t%s", tempA, currentRec->getProgName());
95 currentRec->index = sl.addOption(tempB, first);
101 sl.hintSetCurrent(slIndexStack.top());
106 sl.hintSetCurrent(saveIndex);
107 sl.hintSetTop(saveTop);
113 void VRecordingList::draw(bool doIndexPop)
117 if (recman->isSubDir())
120 SNPRINTF(title, 299, tr("Recordings - %s"), recman->getCurDirName());
125 setTitleText(tr("Recordings"));
133 drawText(tr("Loading..."), 240, 180, Colour::LIGHTTEXT);
138 int gigFree = recman->getFreeSpace() / 1024;
139 SNPRINTF(freeSpace, 49, tr("%lu%% used, %iGB free"), recman->getUsedPercent(), gigFree);
140 drawTextRJ(freeSpace, 560, 5, Colour::LIGHTTEXT);
145 w.setSurface(surface);
147 w.nextSymbol = WSymbol::UP;
148 w.setSurfaceOffset(20, 385);
151 w.nextSymbol = WSymbol::DOWN;
152 w.setSurfaceOffset(50, 385);
155 w.nextSymbol = WSymbol::SKIPBACK;
156 w.setSurfaceOffset(85, 385);
159 w.nextSymbol = WSymbol::SKIPFORWARD;
160 w.setSurfaceOffset(115, 385);
163 w.nextSymbol = WSymbol::PLAY;
164 w.setSurfaceOffset(150, 385);
167 drawTextRJ(tr("[ok] = menu"), 560, 385, Colour::LIGHTTEXT);
169 // All static stuff done
171 drawData(doIndexPop);
175 void VRecordingList::doShowingBar()
177 int topOption = sl.getTopOption() + 1;
178 if (sl.getNumOptions() == 0) topOption = 0;
180 rectangle(220, 385, 180, 25, Colour::VIEWBACKGROUND);
182 sprintf(showing, tr("%i to %i of %i"), topOption, sl.getBottomOption(), sl.getNumOptions());
183 drawText(showing, 220, 385, Colour::LIGHTTEXT);
186 void VRecordingList::processMessage(Message* m)
188 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Got message value %lu", m->message);
189 if (m->message == Message::DELETE_SELECTED_RECORDING)
191 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Doing delete selected");
196 if (m->message == Message::PLAY_SELECTED_RECORDING)
202 if (m->message == Message::RESUME_SELECTED_RECORDING)
209 void VRecordingList::doDeleteSelected()
211 Recording* toDelete = getCurrentOptionRecording();
215 Log::getInstance()->log("VRecordingList", Log::DEBUG, "FOUND: %i %s %s", toDelete->index, toDelete->getProgName(), toDelete->getFileName());
217 int success = recman->deleteRecording(toDelete);
218 if (!VDR::getInstance()->isConnected())
220 Command::getInstance()->connectionLost();
226 VInfo* vi = new VInfo();
227 vi->create(360, 200);
228 if (Video::getInstance()->getFormat() == Video::PAL)
229 vi->setScreenPos(190, 170);
231 vi->setScreenPos(180, 120);
232 vi->setOneLiner(tr("Failed to delete recording"));
235 vi->setTitleBarColour(Colour::DANGER);
239 viewman->updateView(vi);
244 viewman->updateView(this);
249 int VRecordingList::doPlay()
251 Recording* toPlay = getCurrentOptionRecording();
254 VVideoRec* vidrec = new VVideoRec(toPlay);
256 viewman->add(vidrec);
257 viewman->updateView(vidrec);
261 // should not get to here
265 int VRecordingList::doResume()
267 Recording* toResume = getCurrentOptionRecording();
269 printf("%s\n", toResume->getFileName());
273 ULLONG position = VDR::getInstance()->getResumePoint(toResume->getFileName());
275 VVideoRec* vidrec = new VVideoRec(toResume);
277 viewman->add(vidrec);
278 viewman->updateView(vidrec);
279 vidrec->go(position);
283 // should not get to here
287 Recording* VRecordingList::getCurrentOptionRecording()
289 Recording* currentRec;
290 RecordingList::iterator j;
291 RecordingList* recList = recman->getRecordings();
292 for (j = recList->begin(); j != recList->end(); j++)
295 if (currentRec->index == sl.getCurrentOption()) return currentRec;
301 int VRecordingList::handleCommand(int command)
312 viewman->updateView(this);
315 case Remote::DF_DOWN:
318 Log::getInstance()->log("P", Log::DEBUG, "1");
320 Log::getInstance()->log("P", Log::DEBUG, "1.5");
322 Log::getInstance()->log("P", Log::DEBUG, "2");
325 Log::getInstance()->log("P", Log::DEBUG, "3");
326 viewman->updateView(this);
327 Log::getInstance()->log("P", Log::DEBUG, "4");
330 case Remote::SKIPBACK:
336 viewman->updateView(this);
339 case Remote::SKIPFORWARD:
345 viewman->updateView(this);
350 if (sl.getNumOptions() == 0) return 2;
352 // Check to see if it is a sub directory
353 Directory* currentSubDir;
354 DirectoryList::iterator i;
355 DirectoryList* dirList = recman->getDirectories();
356 for (i = dirList->begin(); i != dirList->end(); i++)
359 if (currentSubDir->index == sl.getCurrentOption())
361 if (recman->down(currentSubDir))
363 slIndexStack.push(sl.getCurrentOption());
366 viewman->updateView(this);
372 // check to see if it's a recording
373 Recording* current = getCurrentOptionRecording();
376 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Found the option you pointed at. %s %s", current->getProgName(), current->getFileName());
378 VRecordingMenu* v = new VRecordingMenu();
380 v->setRecording(current);
383 viewman->updateView(v);
386 // should not get to here
391 if (recman->isSubDir())
396 viewman->updateView(this);
406 if (doResume()) return 2;
411 // stop command getting to any more views
415 bool VRecordingList::load()
417 recman = new RecMan();
418 bool success = VDR::getInstance()->getRecordingsList(recman);
423 viewman->updateView(this);