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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "vtimerlist.h"
30 #include "vtimeredit.h"
36 VTimerList::VTimerList()
45 indicatorsRegion.x = 6;
46 indicatorsRegion.y = 44;
47 indicatorsRegion.w = 18;
48 indicatorsRegion.h = 15 * (surface->getFontHeight() + 1);
54 if (Video::getInstance()->getFormat() == Video::PAL)
64 setTitleText(tr("Timers"));
65 setTitleBarColour(Colour::TITLEBARBACKGROUND);
67 sl.setPosition(30, 30 + 5);
68 sl.setSize(area.w - 40, area.h - 30 - 15 - 30);
72 void VTimerList::preDelete()
74 Timers::getInstance()->cancelTimer(this, 1);
77 VTimerList::~VTimerList()
81 for (UINT i = 0; i < recTimerList->size(); i++)
83 delete (*recTimerList)[i];
86 recTimerList->clear();
91 void VTimerList::draw()
100 w.nextSymbol = WSymbol::UP;
101 w.setPosition(20, 385);
104 w.nextSymbol = WSymbol::DOWN;
105 w.setPosition(50, 385);
108 w.nextSymbol = WSymbol::SKIPBACK;
109 w.setPosition(85, 385);
112 w.nextSymbol = WSymbol::SKIPFORWARD;
113 w.setPosition(115, 385);
116 drawTextRJ("[ok] = edit", 560, 385, Colour::LIGHTTEXT);
123 bool VTimerList::load()
125 recTimerList = VDR::getInstance()->getRecTimersList();
127 if (!recTimerList) return false;
134 // FIXME all drawing stuff in this class and sl.clear somewhere?!
142 for (UINT i = 0; i < recTimerList->size(); i++)
144 recTimer = (*recTimerList)[i];
146 btime = localtime((time_t*)&recTimer->startTime);
147 strftime(strA, 299, "%d/%m %H:%M ", btime);
148 SNPRINTF(strB, 299, "%s\t%s", strA, recTimer->getName());
149 sl.addOption(strB, (ULONG)recTimer, first);
156 void VTimerList::drawClock()
158 // Blank the area first
159 rectangle(area.w - 150, 0, 150, 30, titleBarColour);
164 struct tm* tms = localtime(&t);
165 strftime(timeString, 19, "%d/%m %H:%M:%S", tms);
166 drawTextRJ(timeString, 560, 5, Colour::LIGHTTEXT);
168 Timers::getInstance()->setTimerT(this, 1, t + 1);
171 void VTimerList::drawShowing()
173 int topOption = sl.getTopOption() + 1;
174 if (sl.getNumOptions() == 0) topOption = 0;
176 rectangle(220, 385, 180, 25, Colour::VIEWBACKGROUND);
178 sprintf(showing, tr("%i to %i of %i"), topOption, sl.getBottomOption(), sl.getNumOptions());
179 drawText(showing, 220, 385, Colour::LIGHTTEXT);
182 void VTimerList::drawIndicators()
184 int top = sl.getTopOption();
185 int bottom = sl.getBottomOption();
186 int yinc = surface->getFontHeight() + 1;
189 rectangle(6, 44, 18, 15*yinc, Colour::VIEWBACKGROUND);
191 // The indexes recorded from the wselectlist into the index member of the RecTimer
192 // Is the same as the position in the vector of RecTimers
193 // Because they are in order, they don't change order and wselectlist starts from 0 up consecutively
196 for (int current = top; current < bottom; current++)
198 recTimer = (*recTimerList)[current];
200 if (recTimer->recording) // Flashing red square
204 rectangle(6, ypos, 18, 16, Colour::RED);
205 drawText("R", 8, ypos-3, Colour::LIGHTTEXT);
208 else if (recTimer->pending)
210 rectangle(6, ypos, 18, 16, Colour::RED);
211 drawText("X", 8, ypos-3, Colour::BLACK);
213 else if (recTimer->active == 0)
215 rectangle(6, ypos, 18, 16, Colour::SELECTHIGHLIGHT);
216 drawText("X", 8, ypos-3, Colour::BLACK);
220 // if (flipflop) rectangle(6, ypos, 18, 16, Colour::GREEN);
227 void VTimerList::timercall(int clientReference)
230 BoxStack::getInstance()->update(this, &clockRegion);
232 flipflop = !flipflop;
234 BoxStack::getInstance()->update(this, &indicatorsRegion);
237 int VTimerList::handleCommand(int command)
248 BoxStack::getInstance()->update(this);
251 case Remote::DF_DOWN:
258 BoxStack::getInstance()->update(this);
261 case Remote::SKIPBACK:
267 BoxStack::getInstance()->update(this);
270 case Remote::SKIPFORWARD:
276 BoxStack::getInstance()->update(this);
281 RecTimer* recTimer = NULL;
282 if (recTimerList) recTimer = (RecTimer*)sl.getCurrentOptionData();
283 if (recTimer == NULL) return 2;
285 VTimerEdit* v = new VTimerEdit(recTimer);
288 BoxStack::getInstance()->add(v);
289 BoxStack::getInstance()->update(v);
298 // stop command getting to any more views
302 void VTimerList::processMessage(Message* m)
304 if (m->message == Message::MOUSE_MOVE)
306 if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
309 BoxStack::getInstance()->update(this);
312 else if (m->message == Message::MOUSE_LBDOWN)
314 if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
316 BoxStack::getInstance()->handleCommand(Remote::OK); //simulate OK press
320 //check if press is outside this view! then simulate cancel
321 int x=(m->parameter>>16)-getScreenX();
322 int y=(m->parameter&0xFFFF)-getScreenY();
323 if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
325 BoxStack::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
329 else if (m->message == Message::DELETE_SELECTED_TIMER)
331 RecTimer* recTimer = (RecTimer*)sl.getCurrentOptionData();
332 if (recTimer == NULL) return;
333 Log::getInstance()->log("VTimerList", Log::DEBUG, "Got timer to delete");
336 ULONG retval = VDR::getInstance()->deleteTimer(recTimer);
337 if (!VDR::getInstance()->isConnected()) { Command::getInstance()->connectionLost(); return; }
338 Log::getInstance()->log("VTimerList", Log::DEBUG, "Got return fron delete timer: %lu", retval);
342 VInfo* errorBox = new VInfo();
343 errorBox->setSize(360, 200);
344 errorBox->createBuffer();
345 if (Video::getInstance()->getFormat() == Video::PAL)
346 errorBox->setPosition(190, 170);
348 errorBox->setPosition(180, 120);
351 if (retval == 1) errorBox->setOneLiner(tr("Timers being edited at VDR, please try later"));
352 else if (retval == 3) errorBox->setOneLiner(tr("Unable to delete timer - timer is running"));
353 else if (retval == 4) errorBox->setOneLiner(tr("Error - timer not found at VDR"));
354 else errorBox->setOneLiner(tr("Unknown error"));
356 errorBox->setExitable();
357 errorBox->setBorderOn(1);
358 errorBox->setTitleBarColour(Colour::DANGER);
359 errorBox->okButton();
361 BoxStack::getInstance()->add(errorBox);
362 BoxStack::getInstance()->update(errorBox);
365 int saveIndex = sl.getCurrentOption();
366 int saveTop = sl.getTopOption();
370 for (UINT i = 0; i < recTimerList->size(); i++)
372 delete (*recTimerList)[i];
375 recTimerList->clear();
382 sl.hintSetCurrent(saveIndex);
383 sl.hintSetTop(saveTop);
385 BoxStack::getInstance()->update(this);