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()
53 indicatorsRegion.x = 6;
54 indicatorsRegion.y = 44;
55 indicatorsRegion.w = 18;
56 indicatorsRegion.h = 15 * (getFontHeight() + 1);
58 if (Video::getInstance()->getFormat() == Video::PAL)
68 setTitleText(tr("Timers"));
69 setTitleBarColour(DrawStyle::TITLEBARBACKGROUND);
71 sl.setPosition(30, 30 + 5);
72 sl.setSize(area.w - 40, area.h - 30 - 15 - 30);
76 void VTimerList::preDelete()
78 Timers::getInstance()->cancelTimer(this, 1);
81 VTimerList::~VTimerList()
85 for (UINT i = 0; i < recTimerList->size(); i++)
87 delete (*recTimerList)[i];
90 recTimerList->clear();
95 void VTimerList::draw()
104 w.nextSymbol = WSymbol::UP;
105 w.setPosition(20, 385);
108 w.nextSymbol = WSymbol::DOWN;
109 w.setPosition(50, 385);
112 w.nextSymbol = WSymbol::SKIPBACK;
113 w.setPosition(85, 385);
116 w.nextSymbol = WSymbol::SKIPFORWARD;
117 w.setPosition(115, 385);
120 drawTextRJ("[ok] = edit", 560, 385, DrawStyle::LIGHTTEXT);
127 bool VTimerList::load()
129 recTimerList = VDR::getInstance()->getRecTimersList();
131 if (!recTimerList) return false;
138 // FIXME all drawing stuff in this class and sl.clear somewhere?!
146 for (UINT i = 0; i < recTimerList->size(); i++)
148 recTimer = (*recTimerList)[i];
150 btime = localtime((time_t*)&recTimer->startTime);
151 strftime(strA, 299, "%d/%m %H:%M ", btime);
152 SNPRINTF(strB, 299, "%s\t%s", strA, recTimer->getName());
153 sl.addOption(strB, (ULONG)recTimer, first);
160 void VTimerList::drawClock()
162 // Blank the area first
163 rectangle(area.w - 150, 0, 150, 30, titleBarColour);
168 struct tm* tms = localtime(&t);
169 strftime(timeString, 19, "%d/%m %H:%M:%S", tms);
170 drawTextRJ(timeString, 560, 5, DrawStyle::LIGHTTEXT);
172 Timers::getInstance()->setTimerT(this, 1, t + 1);
175 void VTimerList::drawShowing()
177 int topOption = sl.getTopOption() + 1;
178 if (sl.getNumOptions() == 0) topOption = 0;
179 #ifndef GRADIENT_DRAWING
180 rectangle(220, 385, 180, 25, DrawStyle::VIEWBACKGROUND);
183 sprintf(showing, tr("%i to %i of %i"), topOption, sl.getBottomOption(), sl.getNumOptions());
184 drawText(showing, 220, 385, DrawStyle::LIGHTTEXT);
187 void VTimerList::quickUpdate() { //only quick for plattform that need it!
188 #ifdef GRADIENT_DRAWING
197 void VTimerList::drawIndicators()
199 int top = sl.getTopOption();
200 int bottom = sl.getBottomOption();
201 int yinc = getFontHeight() + 1;
203 #ifndef GRADIENT_DRAWING
204 rectangle(6, 44, 18, 15*yinc, DrawStyle::VIEWBACKGROUND);
206 // The indexes recorded from the wselectlist into the index member of the RecTimer
207 // Is the same as the position in the vector of RecTimers
208 // Because they are in order, they don't change order and wselectlist starts from 0 up consecutively
211 for (int current = top; current < bottom; current++)
213 recTimer = (*recTimerList)[current];
215 if (recTimer->recording) // Flashing red square
219 rectangle(6, ypos, 18, 16, DrawStyle::RED);
220 drawText("R", 8, ypos-3, DrawStyle::LIGHTTEXT);
223 else if (recTimer->pending)
225 rectangle(6, ypos, 18, 16, DrawStyle::RED);
226 drawText("X", 8, ypos-3, DrawStyle::BLACK);
228 else if (recTimer->active == 0)
230 rectangle(6, ypos, 18, 16, DrawStyle::SELECTHIGHLIGHT);
231 drawText("X", 8, ypos-3, DrawStyle::BLACK);
235 // if (flipflop) rectangle(6, ypos, 18, 16, DrawStyle::GREEN);
242 void VTimerList::timercall(int clientReference)
245 BoxStack::getInstance()->update(this, &clockRegion);
247 flipflop = !flipflop;
249 BoxStack::getInstance()->update(this, &indicatorsRegion);
252 int VTimerList::handleCommand(int command)
261 BoxStack::getInstance()->update(this);
264 case Remote::DF_DOWN:
269 BoxStack::getInstance()->update(this);
272 case Remote::SKIPBACK:
276 BoxStack::getInstance()->update(this);
279 case Remote::SKIPFORWARD:
283 BoxStack::getInstance()->update(this);
288 RecTimer* recTimer = NULL;
289 if (recTimerList) recTimer = (RecTimer*)sl.getCurrentOptionData();
290 if (recTimer == NULL) return 2;
292 VTimerEdit* v = new VTimerEdit(recTimer);
295 BoxStack::getInstance()->add(v);
296 BoxStack::getInstance()->update(v);
305 // stop command getting to any more views
309 void VTimerList::processMessage(Message* m)
311 if (m->message == Message::MOUSE_MOVE)
313 if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
316 BoxStack::getInstance()->update(this);
319 else if (m->message == Message::MOUSE_LBDOWN)
321 if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
323 BoxStack::getInstance()->handleCommand(Remote::OK); //simulate OK press
327 //check if press is outside this view! then simulate cancel
328 int x=(m->parameter>>16)-getScreenX();
329 int y=(m->parameter&0xFFFF)-getScreenY();
330 if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
332 BoxStack::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
336 else if (m->message == Message::DELETE_SELECTED_TIMER)
338 RecTimer* recTimer = (RecTimer*)sl.getCurrentOptionData();
339 if (recTimer == NULL) return;
340 Log::getInstance()->log("VTimerList", Log::DEBUG, "Got timer to delete");
343 ULONG retval = VDR::getInstance()->deleteTimer(recTimer);
344 if (!VDR::getInstance()->isConnected()) { Command::getInstance()->connectionLost(); return; }
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(DrawStyle::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);