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"
37 VTimerList::VTimerList()
46 indicatorsRegion.x = 6;
47 indicatorsRegion.y = 44;
48 indicatorsRegion.w = 18;
49 indicatorsRegion.h = 15 * (surface->getFontHeight() + 1);
55 if (Video::getInstance()->getFormat() == Video::PAL)
65 setTitleText(tr("Timers"));
66 setTitleBarColour(Colour::TITLEBARBACKGROUND);
68 sl.setPosition(30, 30 + 5);
69 sl.setSize(area.w - 40, area.h - 30 - 15 - 30);
73 void VTimerList::preDelete()
75 Timers::getInstance()->cancelTimer(this, 1);
78 VTimerList::~VTimerList()
82 for (UINT i = 0; i < recTimerList->size(); i++)
84 delete (*recTimerList)[i];
87 recTimerList->clear();
92 void VTimerList::draw()
101 w.nextSymbol = WSymbol::UP;
102 w.setPosition(20, 385);
105 w.nextSymbol = WSymbol::DOWN;
106 w.setPosition(50, 385);
109 w.nextSymbol = WSymbol::SKIPBACK;
110 w.setPosition(85, 385);
113 w.nextSymbol = WSymbol::SKIPFORWARD;
114 w.setPosition(115, 385);
117 drawTextRJ("[ok] = edit", 560, 385, Colour::LIGHTTEXT);
124 bool VTimerList::load()
126 recTimerList = VDR::getInstance()->getRecTimersList();
128 if (!recTimerList) return false;
135 // FIXME all drawing stuff in this class and sl.clear somewhere?!
143 for (UINT i = 0; i < recTimerList->size(); i++)
145 recTimer = (*recTimerList)[i];
147 btime = localtime((time_t*)&recTimer->startTime);
148 strftime(strA, 299, "%d/%m %H:%M ", btime);
149 SNPRINTF(strB, 299, "%s\t%s", strA, recTimer->getName());
150 sl.addOption(strB, (ULONG)recTimer, first);
157 void VTimerList::drawClock()
159 // Blank the area first
160 rectangle(area.w - 150, 0, 150, 30, titleBarColour);
165 struct tm* tms = localtime(&t);
166 strftime(timeString, 19, "%d/%m %H:%M:%S", tms);
167 drawTextRJ(timeString, 560, 5, Colour::LIGHTTEXT);
169 Timers::getInstance()->setTimerT(this, 1, t + 1);
172 void VTimerList::drawShowing()
174 int topOption = sl.getTopOption() + 1;
175 if (sl.getNumOptions() == 0) topOption = 0;
177 rectangle(220, 385, 180, 25, Colour::VIEWBACKGROUND);
179 sprintf(showing, tr("%i to %i of %i"), topOption, sl.getBottomOption(), sl.getNumOptions());
180 drawText(showing, 220, 385, Colour::LIGHTTEXT);
183 void VTimerList::drawIndicators()
185 int top = sl.getTopOption();
186 int bottom = sl.getBottomOption();
187 int yinc = surface->getFontHeight() + 1;
190 rectangle(6, 44, 18, 15*yinc, Colour::VIEWBACKGROUND);
192 // The indexes recorded from the wselectlist into the index member of the RecTimer
193 // Is the same as the position in the vector of RecTimers
194 // Because they are in order, they don't change order and wselectlist starts from 0 up consecutively
197 for (int current = top; current < bottom; current++)
199 recTimer = (*recTimerList)[current];
201 if (recTimer->recording) // Flashing red square
205 rectangle(6, ypos, 18, 16, Colour::RED);
206 drawText("R", 8, ypos-3, Colour::LIGHTTEXT);
209 else if (recTimer->pending)
211 rectangle(6, ypos, 18, 16, Colour::RED);
212 drawText("X", 8, ypos-3, Colour::BLACK);
214 else if (recTimer->active == 0)
216 rectangle(6, ypos, 18, 16, Colour::SELECTHIGHLIGHT);
217 drawText("X", 8, ypos-3, Colour::BLACK);
221 // if (flipflop) rectangle(6, ypos, 18, 16, Colour::GREEN);
228 void VTimerList::timercall(int clientReference)
231 BoxStack::getInstance()->update(this, &clockRegion);
233 flipflop = !flipflop;
235 BoxStack::getInstance()->update(this, &indicatorsRegion);
238 int VTimerList::handleCommand(int command)
249 BoxStack::getInstance()->update(this);
252 case Remote::DF_DOWN:
259 BoxStack::getInstance()->update(this);
262 case Remote::SKIPBACK:
268 BoxStack::getInstance()->update(this);
271 case Remote::SKIPFORWARD:
277 BoxStack::getInstance()->update(this);
282 RecTimer* recTimer = NULL;
283 if (recTimerList) recTimer = (RecTimer*)sl.getCurrentOptionData();
284 if (recTimer == NULL) return 2;
286 VTimerEdit* v = new VTimerEdit(recTimer);
289 BoxStack::getInstance()->add(v);
290 BoxStack::getInstance()->update(v);
299 // stop command getting to any more views
303 void VTimerList::processMessage(Message* m)
305 if (m->message == Message::MOUSE_MOVE)
307 if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
310 BoxStack::getInstance()->update(this);
313 else if (m->message == Message::MOUSE_LBDOWN)
315 if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
317 BoxStack::getInstance()->handleCommand(Remote::OK); //simulate OK press
321 //check if press is outside this view! then simulate cancel
322 int x=(m->parameter>>16)-getScreenX();
323 int y=(m->parameter&0xFFFF)-getScreenY();
324 if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
326 BoxStack::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
330 else if (m->message == Message::DELETE_SELECTED_TIMER)
332 RecTimer* recTimer = (RecTimer*)sl.getCurrentOptionData();
333 if (recTimer == NULL) return;
334 Log::getInstance()->log("VTimerList", Log::DEBUG, "Got timer to delete");
337 ULONG retval = VDR::getInstance()->deleteTimer(recTimer);
338 if (!VDR::getInstance()->isConnected()) { Command::getInstance()->connectionLost(); return; }
339 Log::getInstance()->log("VTimerList", Log::DEBUG, "Got return fron delete timer: %lu", retval);
343 VInfo* errorBox = new VInfo();
344 errorBox->setSize(360, 200);
345 errorBox->createBuffer();
346 if (Video::getInstance()->getFormat() == Video::PAL)
347 errorBox->setPosition(190, 170);
349 errorBox->setPosition(180, 120);
352 if (retval == 1) errorBox->setOneLiner(tr("Timers being edited at VDR, please try later"));
353 else if (retval == 3) errorBox->setOneLiner(tr("Unable to delete timer - timer is running"));
354 else if (retval == 4) errorBox->setOneLiner(tr("Error - timer not found at VDR"));
355 else errorBox->setOneLiner(tr("Unknown error"));
357 errorBox->setExitable();
358 errorBox->setBorderOn(1);
359 errorBox->setTitleBarColour(Colour::DANGER);
360 errorBox->okButton();
362 BoxStack::getInstance()->add(errorBox);
363 BoxStack::getInstance()->update(errorBox);
366 int saveIndex = sl.getCurrentOption();
367 int saveTop = sl.getTopOption();
371 for (UINT i = 0; i < recTimerList->size(); i++)
373 delete (*recTimerList)[i];
376 recTimerList->clear();
383 sl.hintSetCurrent(saveIndex);
384 sl.hintSetTop(saveTop);
386 BoxStack::getInstance()->update(this);