2 Copyright 2004-2007 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "vrecordinglist.h"
24 #include "directory.h"
25 #include "recording.h"
29 #include "vrecordingmenu.h"
31 #include "vvideorec.h"
32 #include "vradiorec.h"
40 VRecordingList::VRecordingList()
42 boxstack = BoxStack::getInstance();
48 if (Video::getInstance()->getFormat() == Video::PAL)
58 setTitleBarColour(Colour::TITLEBARBACKGROUND);
60 sl.setPosition(10, 30 + 5);
61 sl.setSize(area.w - 20, area.h - 30 - 15 - 30);
65 VRecordingList::~VRecordingList()
70 void VRecordingList::drawData(bool doIndexPop)
72 int saveIndex = sl.getCurrentOption();
73 int saveTop = sl.getTopOption();
81 char tempA[300]; // FIXME this is guesswork!
82 char tempB[300]; // FIXME
85 Directory* currentSubDir;
86 DirectoryList::iterator i;
87 DirectoryList* dirList = recman->getDirectories();
88 for (i = dirList->begin(); i != dirList->end(); i++)
91 SNPRINTF(tempA, 299, tr("<dir> %lu\t%s"), currentSubDir->getNumRecordings(), currentSubDir->name);
92 currentSubDir->index = sl.addOption(tempA, 0, first);
96 // FIXME convert the whole program to time_t's
98 Recording* currentRec;
99 RecordingList::iterator j;
100 RecordingList* recList = recman->getRecordings();
101 for (j = recList->begin(); j != recList->end(); j++)
104 time_t recStartTime = (time_t)currentRec->getStartTime();
105 btime = localtime(&recStartTime);
107 strftime(tempA, 299, "%0d/%0m %0H:%0M ", btime);
109 strftime(tempA, 299, "%d/%m %H:%M ", btime);
111 sprintf(tempB, "%s\t%s", tempA, currentRec->getProgName());
112 currentRec->index = sl.addOption(tempB, 0, first);
118 sl.hintSetCurrent(slIndexStack.top());
123 sl.hintSetCurrent(saveIndex);
124 sl.hintSetTop(saveTop);
130 void VRecordingList::draw(bool doIndexPop)
134 if (recman->isSubDir())
137 SNPRINTF(title, 299, tr("Recordings - %s"), recman->getCurDirName());
138 setTitleText(title, 364);
142 setTitleText(tr("Recordings"));
150 drawText(tr("Loading..."), 240, 180, Colour::LIGHTTEXT);
155 int gigFree = recman->getFreeSpace() / 1024;
156 SNPRINTF(freeSpace, 49, tr("%lu%% used, %iGB free"), recman->getUsedPercent(), gigFree);
157 drawTextRJ(freeSpace, 560, 5, Colour::LIGHTTEXT);
164 w.nextSymbol = WSymbol::UP;
165 w.setPosition(20, 385);
168 w.nextSymbol = WSymbol::DOWN;
169 w.setPosition(50, 385);
172 w.nextSymbol = WSymbol::SKIPBACK;
173 w.setPosition(85, 385);
176 w.nextSymbol = WSymbol::SKIPFORWARD;
177 w.setPosition(115, 385);
180 w.nextSymbol = WSymbol::PLAY;
181 w.setPosition(150, 385);
184 drawTextRJ(tr("[ok] = menu"), 560, 385, Colour::LIGHTTEXT);
186 // All static stuff done
188 drawData(doIndexPop);
192 void VRecordingList::doShowingBar()
194 int topOption = sl.getTopOption() + 1;
195 if (sl.getNumOptions() == 0) topOption = 0;
197 rectangle(220, 385, 180, 25, Colour::VIEWBACKGROUND);
199 sprintf(showing, tr("%i to %i of %i"), topOption, sl.getBottomOption(), sl.getNumOptions());
200 drawText(showing, 220, 385, Colour::LIGHTTEXT);
203 void VRecordingList::processMessage(Message* m)
205 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Got message value %lu", m->message);
207 if (m->message == Message::MOUSE_MOVE)
209 if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
213 boxstack->update(this);
216 else if (m->message == Message::MOUSE_LBDOWN)
218 if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
220 boxstack->handleCommand(Remote::OK); //simulate OK press
224 //check if press is outside this view! then simulate cancel
225 int x=(m->parameter>>16)-getScreenX();
226 int y=(m->parameter&0xFFFF)-getScreenY();
227 if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
229 boxstack->handleCommand(Remote::BACK); //simulate cancel press
233 else if (m->message == Message::DELETE_SELECTED_RECORDING)
235 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Doing delete selected");
238 else if (m->message == Message::MOVE_RECORDING)
240 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Doing move recording");
241 doMoveRecording((Directory*)m->parameter);
243 else if (m->message == Message::PLAY_SELECTED_RECORDING)
247 else if (m->message == Message::RESUME_SELECTED_RECORDING)
253 void VRecordingList::doDeleteSelected()
255 Recording* toDelete = getCurrentOptionRecording();
257 if (!toDelete) return;
259 Log::getInstance()->log("VRecordingList", Log::DEBUG, "FOUND: %i %s %s", toDelete->index, toDelete->getProgName(), toDelete->getFileName());
261 int success = recman->deleteRecording(toDelete);
262 if (!VDR::getInstance()->isConnected())
264 Command::getInstance()->connectionLost();
270 VInfo* vi = new VInfo();
271 vi->setSize(360, 200);
273 if (Video::getInstance()->getFormat() == Video::PAL)
274 vi->setPosition(190, 170);
276 vi->setPosition(180, 120);
277 vi->setOneLiner(tr("Failed to delete recording"));
280 vi->setTitleBarColour(Colour::DANGER);
284 boxstack->update(vi);
289 boxstack->update(this);
294 void VRecordingList::doMoveRecording(Directory* toDir)
296 Recording* toMove = getCurrentOptionRecording();
297 if (!toMove || !toDir) return;
299 Log::getInstance()->log("VRecordingList", Log::DEBUG, "MOVE: %s %s", toMove->getProgName(), toDir->name);
301 int success = recman->moveRecording(toMove, toDir);
302 if (!VDR::getInstance()->isConnected())
304 Command::getInstance()->connectionLost();
310 VInfo* vi = new VInfo();
311 vi->setSize(360, 200);
313 if (Video::getInstance()->getFormat() == Video::PAL)
314 vi->setPosition(190, 170);
316 vi->setPosition(180, 120);
317 vi->setOneLiner(tr("Failed to move recording"));
320 vi->setTitleBarColour(Colour::DANGER);
324 boxstack->update(vi);
329 boxstack->update(this);
333 int VRecordingList::doPlay(bool resume)
335 Recording* toPlay = getCurrentOptionRecording();
338 toPlay->loadRecInfo(); // check if still need this
341 bool isRadio = toPlay->isRadio();
345 VRadioRec* radrec = new VRadioRec(toPlay);
347 boxstack->add(radrec);
348 boxstack->update(radrec);
353 VVideoRec* vidrec = new VVideoRec(toPlay);
355 boxstack->add(vidrec);
356 boxstack->update(vidrec);
361 // should not get to here
365 Recording* VRecordingList::getCurrentOptionRecording()
367 Recording* currentRec;
368 RecordingList::iterator j;
369 RecordingList* recList = recman->getRecordings();
370 for (j = recList->begin(); j != recList->end(); j++)
373 if (currentRec->index == sl.getCurrentOption()) return currentRec;
379 int VRecordingList::handleCommand(int command)
390 boxstack->update(this);
393 case Remote::DF_DOWN:
400 boxstack->update(this);
403 case Remote::SKIPBACK:
409 boxstack->update(this);
412 case Remote::SKIPFORWARD:
418 boxstack->update(this);
423 if (sl.getNumOptions() == 0) return 2;
425 // Check to see if it is a sub directory
426 Directory* currentSubDir;
427 DirectoryList::iterator i;
428 DirectoryList* dirList = recman->getDirectories();
429 for (i = dirList->begin(); i != dirList->end(); i++)
432 if (currentSubDir->index == sl.getCurrentOption())
434 if (recman->down(currentSubDir))
436 slIndexStack.push(sl.getCurrentOption());
439 boxstack->update(this);
445 // check to see if it's a recording
446 Recording* current = getCurrentOptionRecording();
449 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Found the option you pointed at. %s %s", current->getProgName(), current->getFileName());
451 VRecordingMenu* v = new VRecordingMenu(recman);
453 v->setRecording(current);
459 // should not get to here
464 if (recman->isSubDir())
469 boxstack->update(this);
479 if (doPlay(true)) return 2;
490 // stop command getting to any more views
494 bool VRecordingList::load()
496 VDR* vdr = VDR::getInstance();
498 recman = new RecMan();
499 bool success = vdr->getRecordingsList(recman);
504 char* defaultSortOrder = vdr->configLoad("General", "Recordings Sort Order");
505 if (defaultSortOrder)
507 if (!STRCASECMP(defaultSortOrder, "Chronological")) recman->setSortOrderChron();
508 delete[] defaultSortOrder;
514 boxstack->update(this);
520 void VRecordingList::reSort()
522 recman->toggleSortOrder();
526 boxstack->update(this);