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"
39 VRecordingList::VRecordingList()
41 boxstack = BoxStack::getInstance();
47 if (Video::getInstance()->getFormat() == Video::PAL)
57 setTitleBarColour(Colour::TITLEBARBACKGROUND);
59 sl.setPosition(10, 30 + 5);
60 sl.setSize(area.w - 20, area.h - 30 - 15 - 30);
64 VRecordingList::~VRecordingList()
69 void VRecordingList::drawData(bool doIndexPop)
71 int saveIndex = sl.getCurrentOption();
72 int saveTop = sl.getTopOption();
80 char tempA[300]; // FIXME this is guesswork!
81 char tempB[300]; // FIXME
84 Directory* currentSubDir;
85 DirectoryList::iterator i;
86 DirectoryList* dirList = recman->getDirectories();
87 for (i = dirList->begin(); i != dirList->end(); i++)
90 SNPRINTF(tempA, 299, tr("<dir> %lu\t%s"), currentSubDir->getNumRecordings(), currentSubDir->name);
91 currentSubDir->index = sl.addOption(tempA, 0, first);
95 // FIXME convert the whole program to time_t's
97 Recording* currentRec;
98 RecordingList::iterator j;
99 RecordingList* recList = recman->getRecordings();
100 for (j = recList->begin(); j != recList->end(); j++)
103 time_t recStartTime = (time_t)currentRec->getStartTime();
104 btime = localtime(&recStartTime);
106 strftime(tempA, 299, "%0d/%0m %0H:%0M ", btime);
108 strftime(tempA, 299, "%d/%m %H:%M ", btime);
110 sprintf(tempB, "%s\t%s", tempA, currentRec->getProgName());
111 currentRec->index = sl.addOption(tempB, 0, first);
117 sl.hintSetCurrent(slIndexStack.top());
122 sl.hintSetCurrent(saveIndex);
123 sl.hintSetTop(saveTop);
129 void VRecordingList::draw(bool doIndexPop)
133 if (recman->isSubDir())
136 SNPRINTF(title, 299, tr("Recordings - %s"), recman->getCurDirName());
137 setTitleText(title, 364);
141 setTitleText(tr("Recordings"));
149 drawText(tr("Loading..."), 240, 180, Colour::LIGHTTEXT);
154 int gigFree = recman->getFreeSpace() / 1024;
155 SNPRINTF(freeSpace, 49, tr("%lu%% used, %iGB free"), recman->getUsedPercent(), gigFree);
156 drawTextRJ(freeSpace, 560, 5, Colour::LIGHTTEXT);
163 w.nextSymbol = WSymbol::UP;
164 w.setPosition(20, 385);
167 w.nextSymbol = WSymbol::DOWN;
168 w.setPosition(50, 385);
171 w.nextSymbol = WSymbol::SKIPBACK;
172 w.setPosition(85, 385);
175 w.nextSymbol = WSymbol::SKIPFORWARD;
176 w.setPosition(115, 385);
179 w.nextSymbol = WSymbol::PLAY;
180 w.setPosition(150, 385);
183 drawTextRJ(tr("[ok] = menu"), 560, 385, Colour::LIGHTTEXT);
185 // All static stuff done
187 drawData(doIndexPop);
191 void VRecordingList::doShowingBar()
193 int topOption = sl.getTopOption() + 1;
194 if (sl.getNumOptions() == 0) topOption = 0;
196 rectangle(220, 385, 180, 25, Colour::VIEWBACKGROUND);
198 sprintf(showing, tr("%i to %i of %i"), topOption, sl.getBottomOption(), sl.getNumOptions());
199 drawText(showing, 220, 385, Colour::LIGHTTEXT);
202 void VRecordingList::processMessage(Message* m)
204 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Got message value %lu", m->message);
206 if (m->message == Message::MOUSE_MOVE)
208 if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
212 boxstack->update(this);
215 else if (m->message == Message::MOUSE_LBDOWN)
217 if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
219 boxstack->handleCommand(Remote::OK); //simulate OK press
223 //check if press is outside this view! then simulate cancel
224 int x=(m->parameter>>16)-getScreenX();
225 int y=(m->parameter&0xFFFF)-getScreenY();
226 if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
228 boxstack->handleCommand(Remote::BACK); //simulate cancel press
232 else if (m->message == Message::DELETE_SELECTED_RECORDING)
234 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Doing delete selected");
237 else if (m->message == Message::MOVE_RECORDING)
239 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Doing move recording");
240 doMoveRecording((Directory*)m->parameter);
242 else if (m->message == Message::PLAY_SELECTED_RECORDING)
246 else if (m->message == Message::RESUME_SELECTED_RECORDING)
252 void VRecordingList::doDeleteSelected()
254 Recording* toDelete = getCurrentOptionRecording();
256 if (!toDelete) return;
258 Log::getInstance()->log("VRecordingList", Log::DEBUG, "FOUND: %i %s %s", toDelete->index, toDelete->getProgName(), toDelete->getFileName());
260 int success = recman->deleteRecording(toDelete);
261 if (!VDR::getInstance()->isConnected())
263 Command::getInstance()->connectionLost();
269 VInfo* vi = new VInfo();
270 vi->setSize(360, 200);
272 if (Video::getInstance()->getFormat() == Video::PAL)
273 vi->setPosition(190, 170);
275 vi->setPosition(180, 120);
276 vi->setOneLiner(tr("Failed to delete recording"));
279 vi->setTitleBarColour(Colour::DANGER);
283 boxstack->update(vi);
288 boxstack->update(this);
293 void VRecordingList::doMoveRecording(Directory* toDir)
295 Recording* toMove = getCurrentOptionRecording();
296 if (!toMove || !toDir) return;
298 Log::getInstance()->log("VRecordingList", Log::DEBUG, "MOVE: %s %s", toMove->getProgName(), toDir->name);
300 int success = recman->moveRecording(toMove, toDir);
301 if (!VDR::getInstance()->isConnected())
303 Command::getInstance()->connectionLost();
309 VInfo* vi = new VInfo();
310 vi->setSize(360, 200);
312 if (Video::getInstance()->getFormat() == Video::PAL)
313 vi->setPosition(190, 170);
315 vi->setPosition(180, 120);
316 vi->setOneLiner(tr("Failed to move recording"));
319 vi->setTitleBarColour(Colour::DANGER);
323 boxstack->update(vi);
328 boxstack->update(this);
332 int VRecordingList::doPlay(bool resume)
334 Recording* toPlay = getCurrentOptionRecording();
337 toPlay->loadRecInfo(); // check if still need this
340 bool isRadio = toPlay->isRadio();
344 VRadioRec* radrec = new VRadioRec(toPlay);
346 boxstack->add(radrec);
347 boxstack->update(radrec);
352 VVideoRec* vidrec = new VVideoRec(toPlay);
354 boxstack->add(vidrec);
355 boxstack->update(vidrec);
360 // should not get to here
364 Recording* VRecordingList::getCurrentOptionRecording()
366 Recording* currentRec;
367 RecordingList::iterator j;
368 RecordingList* recList = recman->getRecordings();
369 for (j = recList->begin(); j != recList->end(); j++)
372 if (currentRec->index == sl.getCurrentOption()) return currentRec;
378 int VRecordingList::handleCommand(int command)
389 boxstack->update(this);
392 case Remote::DF_DOWN:
395 Log::getInstance()->log("P", Log::DEBUG, "1");
397 Log::getInstance()->log("P", Log::DEBUG, "1.5");
399 Log::getInstance()->log("P", Log::DEBUG, "2");
402 Log::getInstance()->log("P", Log::DEBUG, "3");
403 boxstack->update(this);
404 Log::getInstance()->log("P", Log::DEBUG, "4");
407 case Remote::SKIPBACK:
413 boxstack->update(this);
416 case Remote::SKIPFORWARD:
422 boxstack->update(this);
427 if (sl.getNumOptions() == 0) return 2;
429 // Check to see if it is a sub directory
430 Directory* currentSubDir;
431 DirectoryList::iterator i;
432 DirectoryList* dirList = recman->getDirectories();
433 for (i = dirList->begin(); i != dirList->end(); i++)
436 if (currentSubDir->index == sl.getCurrentOption())
438 if (recman->down(currentSubDir))
440 slIndexStack.push(sl.getCurrentOption());
443 boxstack->update(this);
449 // check to see if it's a recording
450 Recording* current = getCurrentOptionRecording();
453 Log::getInstance()->log("VRecordingList", Log::DEBUG, "Found the option you pointed at. %s %s", current->getProgName(), current->getFileName());
455 VRecordingMenu* v = new VRecordingMenu(recman);
457 v->setRecording(current);
463 // should not get to here
468 if (recman->isSubDir())
473 boxstack->update(this);
483 if (doPlay(true)) return 2;
494 // stop command getting to any more views
498 bool VRecordingList::load()
500 VDR* vdr = VDR::getInstance();
502 recman = new RecMan();
503 bool success = vdr->getRecordingsList(recman);
508 char* defaultSortOrder = vdr->configLoad("General", "Recordings Sort Order");
509 if (defaultSortOrder)
511 if (!STRCASECMP(defaultSortOrder, "Chronological")) recman->setSortOrderChron();
512 delete[] defaultSortOrder;
518 boxstack->update(this);
524 void VRecordingList::reSort()
526 recman->toggleSortOrder();
530 boxstack->update(this);