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 "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 VTimerList::~VTimerList()
74 Timers::getInstance()->cancelTimer(this, 1);
77 for (UINT i = 0; i < recTimerList->size(); i++)
79 delete (*recTimerList)[i];
82 recTimerList->clear();
87 void VTimerList::draw()
96 w.nextSymbol = WSymbol::UP;
97 w.setPosition(20, 385);
100 w.nextSymbol = WSymbol::DOWN;
101 w.setPosition(50, 385);
104 w.nextSymbol = WSymbol::SKIPBACK;
105 w.setPosition(85, 385);
108 w.nextSymbol = WSymbol::SKIPFORWARD;
109 w.setPosition(115, 385);
112 drawTextRJ("[ok] = edit", 560, 385, Colour::LIGHTTEXT);
119 bool VTimerList::load()
121 recTimerList = VDR::getInstance()->getRecTimersList();
123 if (!recTimerList) return false;
130 // FIXME all drawing stuff in this class and sl.clear somewhere?!
138 for (UINT i = 0; i < recTimerList->size(); i++)
140 recTimer = (*recTimerList)[i];
142 btime = localtime((time_t*)&recTimer->startTime);
143 strftime(strA, 299, "%d/%m %H:%M ", btime);
144 SNPRINTF(strB, 299, "%s\t%s", strA, recTimer->getName());
145 sl.addOption(strB, (ULONG)recTimer, first);
152 void VTimerList::drawClock()
154 // Blank the area first
155 rectangle(area.w - 150, 0, 150, 30, titleBarColour);
160 struct tm* tms = localtime(&t);
161 strftime(timeString, 19, "%d/%m %H:%M:%S", tms);
162 drawTextRJ(timeString, 560, 5, Colour::LIGHTTEXT);
164 Timers::getInstance()->setTimerT(this, 1, t + 1);
167 void VTimerList::drawShowing()
169 int topOption = sl.getTopOption() + 1;
170 if (sl.getNumOptions() == 0) topOption = 0;
172 rectangle(220, 385, 180, 25, Colour::VIEWBACKGROUND);
174 sprintf(showing, tr("%i to %i of %i"), topOption, sl.getBottomOption(), sl.getNumOptions());
175 drawText(showing, 220, 385, Colour::LIGHTTEXT);
178 void VTimerList::drawIndicators()
180 int top = sl.getTopOption();
181 int bottom = sl.getBottomOption();
182 int yinc = surface->getFontHeight() + 1;
185 rectangle(6, 44, 18, 15*yinc, Colour::VIEWBACKGROUND);
187 // The indexes recorded from the wselectlist into the index member of the RecTimer
188 // Is the same as the position in the vector of RecTimers
189 // Because they are in order, they don't change order and wselectlist starts from 0 up consecutively
192 for (int current = top; current < bottom; current++)
194 recTimer = (*recTimerList)[current];
196 if (recTimer->recording) // Flashing red square
200 rectangle(6, ypos, 18, 16, Colour::RED);
201 drawText("R", 8, ypos-3, Colour::LIGHTTEXT);
204 else if (recTimer->pending)
206 rectangle(6, ypos, 18, 16, Colour::RED);
207 drawText("X", 8, ypos-3, Colour::BLACK);
209 else if (recTimer->active == 0)
211 rectangle(6, ypos, 18, 16, Colour::SELECTHIGHLIGHT);
212 drawText("X", 8, ypos-3, Colour::BLACK);
216 // if (flipflop) rectangle(6, ypos, 18, 16, Colour::GREEN);
223 void VTimerList::timercall(int clientReference)
227 Message* m = new Message();
228 m->message = Message::REDRAW;
229 m->to = BoxStack::getInstance();
231 m->parameter = (ULONG)&clockRegion;
232 Command::getInstance()->postMessageFromOuterSpace(m);
234 flipflop = !flipflop;
238 m->message = Message::REDRAW;
239 m->to = BoxStack::getInstance();
241 m->parameter = (ULONG)&indicatorsRegion;
242 Command::getInstance()->postMessageFromOuterSpace(m);
245 int VTimerList::handleCommand(int command)
256 BoxStack::getInstance()->update(this);
259 case Remote::DF_DOWN:
266 BoxStack::getInstance()->update(this);
269 case Remote::SKIPBACK:
275 BoxStack::getInstance()->update(this);
278 case Remote::SKIPFORWARD:
284 BoxStack::getInstance()->update(this);
289 RecTimer* recTimer = NULL;
290 if (recTimerList) recTimer = (RecTimer*)sl.getCurrentOptionData();
291 if (recTimer == NULL) return 2;
293 VTimerEdit* v = new VTimerEdit(recTimer);
296 BoxStack::getInstance()->add(v);
297 BoxStack::getInstance()->update(v);
306 // stop command getting to any more views
310 void VTimerList::processMessage(Message* m)
312 if (m->message == Message::MOUSE_MOVE)
314 if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
317 BoxStack::getInstance()->update(this);
320 else if (m->message == Message::MOUSE_LBDOWN)
322 if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
324 BoxStack::getInstance()->handleCommand(Remote::OK); //simulate OK press
328 //check if press is outside this view! then simulate cancel
329 int x=(m->parameter>>16)-getScreenX();
330 int y=(m->parameter&0xFFFF)-getScreenY();
331 if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
333 BoxStack::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
337 else if (m->message == Message::DELETE_SELECTED_TIMER)
339 RecTimer* recTimer = (RecTimer*)sl.getCurrentOptionData();
340 if (recTimer == NULL) return;
341 Log::getInstance()->log("VTimerList", Log::DEBUG, "Got timer to delete");
344 ULONG retval = VDR::getInstance()->deleteTimer(recTimer);
345 Log::getInstance()->log("VTimerList", Log::DEBUG, "Got return fron delete timer: %lu", retval);
349 VInfo* errorBox = new VInfo();
350 errorBox->setSize(360, 200);
351 errorBox->createBuffer();
352 if (Video::getInstance()->getFormat() == Video::PAL)
353 errorBox->setPosition(190, 170);
355 errorBox->setPosition(180, 120);
358 if (retval == 1) errorBox->setOneLiner(tr("Timers being edited at VDR, please try later"));
359 else if (retval == 3) errorBox->setOneLiner(tr("Unable to delete timer - timer is running"));
360 else if (retval == 4) errorBox->setOneLiner(tr("Error - timer not found at VDR"));
361 else errorBox->setOneLiner(tr("Unknown error"));
363 errorBox->setExitable();
364 errorBox->setBorderOn(1);
365 errorBox->setTitleBarColour(Colour::DANGER);
366 errorBox->okButton();
368 BoxStack::getInstance()->add(errorBox);
369 BoxStack::getInstance()->update(errorBox);
372 int saveIndex = sl.getCurrentOption();
373 int saveTop = sl.getTopOption();
377 for (UINT i = 0; i < recTimerList->size(); i++)
379 delete (*recTimerList)[i];
382 recTimerList->clear();
389 sl.hintSetCurrent(saveIndex);
390 sl.hintSetTop(saveTop);
392 BoxStack::getInstance()->update(this);