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, Directory* tdir)
26 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()
52 // if this is a sub, there can only be recordings. if there are none left, get this dir deleted by parent
53 if (recDir->getNumRecordings() == 0) myParent->zeroCheck();
54 // recDir is now deleted if it was empty
58 // only delete the list if this is not a sub dir window
63 void VRecordingList::zeroCheck()
65 // go through to delete 1 empty dir if necessary (there will only ever be 1)
67 DirectoryList::iterator i;
68 for (i = recDir->dirList.begin(); i != recDir->dirList.end(); i++)
71 if (dir->getNumRecordings() == 0)
74 recDir->dirList.erase(i);
79 viewman->updateView(this);
82 void VRecordingList::drawData()
84 int saveIndex = sl.getCurrentOption();
85 int saveTop = sl.getTopOption();
93 char tempA[300]; // FIXME this is guesswork!
94 char tempB[300]; // FIXME
98 DirectoryList::iterator i;
99 for (i = recDir->dirList.begin(); i != recDir->dirList.end(); i++)
102 SNPRINTF(tempA, 299, tr("<dir> %lu\t%s"), dir->getNumRecordings(), dir->name);
103 dir->index = sl.addOption(tempA, first);
107 // FIXME convert the whole program to time_t's
110 for (UINT j = 0; j < recDir->recList.size(); j++)
112 rec = recDir->recList[j];
113 btime = localtime((time_t*)&rec->start);
115 strftime(tempA, 299, "%0d/%0m %0H:%0M ", btime);
117 strftime(tempA, 299, "%d/%m %H:%M ", btime);
119 sprintf(tempB, "%s\t%s", tempA, rec->getProgName());
120 rec->index = sl.addOption(tempB, first);
124 sl.hintSetCurrent(saveIndex);
125 sl.hintSetTop(saveTop);
130 void VRecordingList::draw()
135 SNPRINTF(title, 299, tr("Recordings - %s"), recDir->name);
140 setTitleText(tr("Recordings"));
146 int gigFree = Directory::freeSpace / 1024;
147 SNPRINTF(freeSpace, 49, tr("%lu%% used, %iGB free"), Directory::usedPercent, gigFree);
148 drawTextRJ(freeSpace, 560, 5, Colour::LIGHTTEXT);
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 drawTextRJ(tr("[ok] = menu"), 560, 385, Colour::LIGHTTEXT);
177 // All static stuff done
182 void VRecordingList::doShowingBar()
184 int topOption = sl.getTopOption() + 1;
185 if (sl.getNumOptions() == 0) topOption = 0;
187 rectangle(220, 385, 180, 25, Colour::VIEWBACKGROUND);
189 sprintf(showing, tr("%i to %i of %i"), topOption, sl.getBottomOption(), sl.getNumOptions());
190 drawText(showing, 220, 385, Colour::LIGHTTEXT);
193 void VRecordingList::processMessage(Message* m)
195 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Got message value %lu", m->message);
196 if (m->message == Message::DELETE_SELECTED_RECORDING)
198 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Doing delete selected");
203 if (m->message == Message::PLAY_SELECTED_RECORDING)
209 if (m->message == Message::RESUME_SELECTED_RECORDING)
216 void VRecordingList::doDeleteSelected()
218 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Parent = %p, isRoot = %i", myParent, recDir->isRoot);
219 Recording* toDelete = getCurrentOptionRecording();
223 Log::getInstance()->log("VRecordingList", Log::DEBUG, "FOUND: %i %s %s", toDelete->index, toDelete->getProgName(), toDelete->fileName);
225 VDR* vdr = VDR::getInstance();
226 int success = vdr->deleteRecording(toDelete->fileName);
227 if (!vdr->isConnected())
229 Command::getInstance()->connectionLost();
234 VInfo* vi = new VInfo();
235 vi->create(360, 200);
236 if (Video::getInstance()->getFormat() == Video::PAL)
237 vi->setScreenPos(190, 170);
239 vi->setScreenPos(180, 120);
240 vi->setOneLiner(tr("Failed to delete recording"));
243 vi->setTitleBarColour(Colour::DANGER);
247 viewman->updateView(vi);
253 for(RecordingList::iterator i = recDir->recList.begin(); i != recDir->recList.end(); i++)
257 recDir->recList.erase(i);
263 viewman->updateView(this);
265 if (myParent) myParent->drawData(); // if this is not root get parent to redraw data
267 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Parent = %p, isRoot = %i", myParent, recDir->isRoot);
271 int VRecordingList::doPlay()
273 Recording* toPlay = getCurrentOptionRecording();
276 VVideoRec* vidrec = new VVideoRec(toPlay);
278 viewman->add(vidrec);
279 viewman->updateView(vidrec);
283 // should not get to here
287 int VRecordingList::doResume()
289 Recording* toResume = getCurrentOptionRecording();
292 ULLONG position = VDR::getInstance()->getResumePoint(toResume->fileName);
294 VVideoRec* vidrec = new VVideoRec(toResume);
296 viewman->add(vidrec);
297 viewman->updateView(vidrec);
298 vidrec->go(position);
301 // should not get to here
305 Recording* VRecordingList::getCurrentOptionRecording()
308 for (UINT i = 0; i < recDir->recList.size(); i++)
310 current = recDir->recList[i];
311 if (current->index == sl.getCurrentOption()) return current;
316 int VRecordingList::handleCommand(int command)
327 viewman->updateView(this);
330 case Remote::DF_DOWN:
333 Log::getInstance()->log("P", Log::DEBUG, "1");
335 Log::getInstance()->log("P", Log::DEBUG, "1.5");
337 Log::getInstance()->log("P", Log::DEBUG, "2");
340 Log::getInstance()->log("P", Log::DEBUG, "3");
341 viewman->updateView(this);
342 Log::getInstance()->log("P", Log::DEBUG, "4");
345 case Remote::SKIPBACK:
351 viewman->updateView(this);
354 case Remote::SKIPFORWARD:
360 viewman->updateView(this);
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, curDir);
377 viewman->updateView(sub);
382 // check to see if it's a recording
383 Recording* current = getCurrentOptionRecording();
386 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Found the option you pointed at. %s %s", current->getProgName(), current->fileName);
388 VRecordingMenu* v = new VRecordingMenu();
390 v->setRecording(current);
393 viewman->updateView(v);
396 // should not get to here
405 if (doResume()) return 2;
410 // stop command getting to any more views