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 #include "staticartwork.h"
38 VTimerList::VTimerList()
54 indicatorsRegion.x = 6;
55 indicatorsRegion.y = 44;
56 indicatorsRegion.w = 18;
57 indicatorsRegion.h = 15 * (getFontHeight() + 1);
59 if (Video::getInstance()->getFormat() == Video::PAL)
69 setTitleText(tr("Timers"));
70 setTitleBarColour(DrawStyle::TITLEBARBACKGROUND);
71 TVMediaInfo *info= new TVMediaInfo();
72 info->setStaticArtwork(sa_timers);
73 setTitleBarIcon(info);
75 sl.setPosition(30, 30 + 5);
76 sl.setSize(area.w - 40, area.h - 30 - 15 - 30);
80 void VTimerList::preDelete()
82 Timers::getInstance()->cancelTimer(this, 1);
85 VTimerList::~VTimerList()
89 for (UINT i = 0; i < recTimerList->size(); i++)
91 delete (*recTimerList)[i];
94 recTimerList->clear();
99 void VTimerList::draw()
108 w.nextSymbol = WSymbol::UP;
109 w.setPosition(20, 385);
112 w.nextSymbol = WSymbol::DOWN;
113 w.setPosition(50, 385);
116 w.nextSymbol = WSymbol::SKIPBACK;
117 w.setPosition(85, 385);
120 w.nextSymbol = WSymbol::SKIPFORWARD;
121 w.setPosition(115, 385);
124 drawTextRJ("[ok] = edit", 560, 385, DrawStyle::LIGHTTEXT);
131 bool VTimerList::load()
133 recTimerList = VDR::getInstance()->getRecTimersList();
135 if (!recTimerList) return false;
142 // FIXME all drawing stuff in this class and sl.clear somewhere?!
150 for (UINT i = 0; i < recTimerList->size(); i++)
152 recTimer = (*recTimerList)[i];
153 time_t rectime = recTimer->startTime;
154 btime = localtime((time_t*)&rectime);
155 strftime(strA, 299, "%d/%m %H:%M ", btime);
156 SNPRINTF(strB, 299, "%s\t%s", strA, recTimer->getName());
157 sl.addOption(strB, (ULONG)recTimer, first);
164 void VTimerList::drawClock()
166 // Blank the area first
167 #ifndef GRADIENT_DRAWING
168 rectangle(area.w - 150, 0, 150, 30, titleBarColour);
174 struct tm* tms = localtime(&t);
175 strftime(timeString, 19, "%d/%m %H:%M:%S", tms);
176 drawTextRJ(timeString, 560, 5, DrawStyle::LIGHTTEXT);
178 Timers::getInstance()->setTimerT(this, 1, t + 1);
181 void VTimerList::drawShowing()
183 int topOption = sl.getTopOption() + 1;
184 if (sl.getNumOptions() == 0) topOption = 0;
185 #ifndef GRADIENT_DRAWING
186 rectangle(220, 385, 180, 25, DrawStyle::VIEWBACKGROUND);
189 sprintf(showing, tr("%i to %i of %i"), topOption, sl.getBottomOption(), sl.getNumOptions());
190 drawText(showing, 220, 385, DrawStyle::LIGHTTEXT);
193 void VTimerList::quickUpdate() { //only quick for plattform that need it!
194 #ifdef GRADIENT_DRAWING
203 void VTimerList::drawIndicators()
205 int top = sl.getTopOption();
206 int bottom = sl.getBottomOption();
207 int yinc = getFontHeight() + 1;
209 #ifndef GRADIENT_DRAWING
210 rectangle(6, 44, 18, 15*yinc, DrawStyle::VIEWBACKGROUND);
212 // The indexes recorded from the wselectlist into the index member of the RecTimer
213 // Is the same as the position in the vector of RecTimers
214 // Because they are in order, they don't change order and wselectlist starts from 0 up consecutively
217 for (int current = top; current < bottom; current++)
219 recTimer = (*recTimerList)[current];
221 if (recTimer->recording) // Flashing red square
225 rectangle(6, ypos, 18, 16, DrawStyle::RED);
226 drawText("R", 8, ypos-3, DrawStyle::LIGHTTEXT);
229 else if (recTimer->pending)
231 rectangle(6, ypos, 18, 16, DrawStyle::RED);
232 drawText("X", 8, ypos-3, DrawStyle::BLACK);
234 else if (recTimer->active == 0)
236 rectangle(6, ypos, 18, 16, DrawStyle::SELECTHIGHLIGHT);
237 drawText("X", 8, ypos-3, DrawStyle::BLACK);
241 // if (flipflop) rectangle(6, ypos, 18, 16, DrawStyle::GREEN);
248 void VTimerList::timercall(int clientReference)
250 flipflop = !flipflop;
251 #ifndef GRADIENT_DRAWING
253 BoxStack::getInstance()->update(this, &clockRegion);
256 BoxStack::getInstance()->update(this, &indicatorsRegion);
259 BoxStack::getInstance()->update(this);
263 int VTimerList::handleCommand(int command)
272 BoxStack::getInstance()->update(this);
275 case Remote::DF_DOWN:
280 BoxStack::getInstance()->update(this);
283 case Remote::SKIPBACK:
287 BoxStack::getInstance()->update(this);
290 case Remote::SKIPFORWARD:
294 BoxStack::getInstance()->update(this);
299 RecTimer* recTimer = NULL;
300 if (recTimerList) recTimer = (RecTimer*)sl.getCurrentOptionData();
301 if (recTimer == NULL) return 2;
303 VTimerEdit* v = new VTimerEdit(recTimer);
306 BoxStack::getInstance()->add(v);
307 BoxStack::getInstance()->update(v);
316 // stop command getting to any more views
320 void VTimerList::processMessage(Message* m)
322 if (m->message == Message::MOUSE_MOVE)
324 if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
327 BoxStack::getInstance()->update(this);
330 else if (m->message == Message::MOUSE_LBDOWN)
332 if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
334 BoxStack::getInstance()->handleCommand(Remote::OK); //simulate OK press
338 //check if press is outside this view! then simulate cancel
339 int x=(m->parameter>>16)-getScreenX();
340 int y=(m->parameter&0xFFFF)-getScreenY();
341 if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
343 BoxStack::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
347 else if (m->message == Message::DELETE_SELECTED_TIMER)
349 RecTimer* recTimer = (RecTimer*)sl.getCurrentOptionData();
350 if (recTimer == NULL) return;
351 Log::getInstance()->log("VTimerList", Log::DEBUG, "Got timer to delete");
354 ULONG retval = VDR::getInstance()->deleteTimer(recTimer);
355 if (!VDR::getInstance()->isConnected()) { Command::getInstance()->connectionLost(); return; }
356 Log::getInstance()->log("VTimerList", Log::DEBUG, "Got return fron delete timer: %lu", retval);
360 VInfo* errorBox = new VInfo();
361 errorBox->setSize(360, 200);
362 errorBox->createBuffer();
363 if (Video::getInstance()->getFormat() == Video::PAL)
364 errorBox->setPosition(190, 170);
366 errorBox->setPosition(180, 120);
369 if (retval == 1) errorBox->setOneLiner(tr("Timers being edited at VDR, please try later"));
370 else if (retval == 3) errorBox->setOneLiner(tr("Unable to delete timer - timer is running"));
371 else if (retval == 4) errorBox->setOneLiner(tr("Error - timer not found at VDR"));
372 else errorBox->setOneLiner(tr("Unknown error"));
374 errorBox->setExitable();
375 errorBox->setBorderOn(1);
376 errorBox->setTitleBarColour(DrawStyle::DANGER);
377 errorBox->okButton();
379 BoxStack::getInstance()->add(errorBox);
380 BoxStack::getInstance()->update(errorBox);
383 int saveIndex = sl.getCurrentOption();
384 int saveTop = sl.getTopOption();
388 for (UINT i = 0; i < recTimerList->size(); i++)
390 delete (*recTimerList)[i];
393 recTimerList->clear();
400 sl.hintSetCurrent(saveIndex);
401 sl.hintSetTop(saveTop);
403 BoxStack::getInstance()->update(this);