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 LOCALTIME_R((time_t*)&rectime, &btime);
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);
175 LOCALTIME_R(&t, &tms);
176 strftime(timeString, 19, "%d/%m %H:%M:%S", &tms);
177 drawTextRJ(timeString, 560, 5, DrawStyle::LIGHTTEXT);
179 Timers::getInstance()->setTimerT(this, 1, t + 1);
182 void VTimerList::drawShowing()
184 int topOption = sl.getTopOption() + 1;
185 if (sl.getNumOptions() == 0) topOption = 0;
186 #ifndef GRADIENT_DRAWING
187 rectangle(220, 385, 180, 25, DrawStyle::VIEWBACKGROUND);
190 sprintf(showing, tr("%i to %i of %i"), topOption, sl.getBottomOption(), sl.getNumOptions());
191 drawText(showing, 220, 385, DrawStyle::LIGHTTEXT);
194 void VTimerList::quickUpdate() { //only quick for plattform that need it!
195 #ifdef GRADIENT_DRAWING
204 void VTimerList::drawIndicators()
206 int top = sl.getTopOption();
207 int bottom = sl.getBottomOption();
208 int yinc = getFontHeight() + 1;
210 #ifndef GRADIENT_DRAWING
211 rectangle(6, 44, 18, 15*yinc, DrawStyle::VIEWBACKGROUND);
213 // The indexes recorded from the wselectlist into the index member of the RecTimer
214 // Is the same as the position in the vector of RecTimers
215 // Because they are in order, they don't change order and wselectlist starts from 0 up consecutively
218 for (int current = top; current < bottom; current++)
220 recTimer = (*recTimerList)[current];
222 if (recTimer->recording) // Flashing red square
226 rectangle(6, ypos, 18, 16, DrawStyle::RED);
227 drawText("R", 8, ypos-3, DrawStyle::LIGHTTEXT);
230 else if (recTimer->pending)
232 rectangle(6, ypos, 18, 16, DrawStyle::RED);
233 drawText("X", 8, ypos-3, DrawStyle::BLACK);
235 else if (recTimer->active == 0)
237 rectangle(6, ypos, 18, 16, DrawStyle::SELECTHIGHLIGHT);
238 drawText("X", 8, ypos-3, DrawStyle::BLACK);
242 // if (flipflop) rectangle(6, ypos, 18, 16, DrawStyle::GREEN);
249 void VTimerList::timercall(int clientReference)
251 flipflop = !flipflop;
252 #ifndef GRADIENT_DRAWING
254 BoxStack::getInstance()->update(this, &clockRegion);
257 BoxStack::getInstance()->update(this, &indicatorsRegion);
260 BoxStack::getInstance()->update(this);
264 int VTimerList::handleCommand(int command)
273 BoxStack::getInstance()->update(this);
276 case Remote::DF_DOWN:
281 BoxStack::getInstance()->update(this);
284 case Remote::SKIPBACK:
288 BoxStack::getInstance()->update(this);
291 case Remote::SKIPFORWARD:
295 BoxStack::getInstance()->update(this);
300 RecTimer* recTimer = NULL;
301 if (recTimerList) recTimer = (RecTimer*)sl.getCurrentOptionData();
302 if (recTimer == NULL) return 2;
304 VTimerEdit* v = new VTimerEdit(recTimer);
307 BoxStack::getInstance()->add(v);
308 BoxStack::getInstance()->update(v);
317 // stop command getting to any more views
321 void VTimerList::processMessage(Message* m)
323 if (m->message == Message::MOUSE_MOVE)
325 if (sl.mouseMove((m->parameter.num>>16)-getScreenX(),(m->parameter.num&0xFFFF)-getScreenY()))
328 BoxStack::getInstance()->update(this);
331 else if (m->message == Message::MOUSE_LBDOWN)
333 if (sl.mouseLBDOWN((m->parameter.num>>16)-getScreenX(),(m->parameter.num&0xFFFF)-getScreenY()))
335 BoxStack::getInstance()->handleCommand(Remote::OK); //simulate OK press
339 //check if press is outside this view! then simulate cancel
340 int x=(m->parameter.num>>16)-getScreenX();
341 int y=(m->parameter.num&0xFFFF)-getScreenY();
342 if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
344 BoxStack::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
348 else if (m->message == Message::DELETE_SELECTED_TIMER)
350 RecTimer* recTimer = (RecTimer*)sl.getCurrentOptionData();
351 if (recTimer == NULL) return;
352 Log::getInstance()->log("VTimerList", Log::DEBUG, "Got timer to delete");
355 ULONG retval = VDR::getInstance()->deleteTimer(recTimer);
356 if (!VDR::getInstance()->isConnected()) { Command::getInstance()->connectionLost(); return; }
357 Log::getInstance()->log("VTimerList", Log::DEBUG, "Got return fron delete timer: %lu", retval);
361 VInfo* errorBox = new VInfo();
362 errorBox->setSize(360, 200);
363 errorBox->createBuffer();
364 if (Video::getInstance()->getFormat() == Video::PAL)
365 errorBox->setPosition(190, 170);
367 errorBox->setPosition(180, 120);
370 if (retval == 1) errorBox->setOneLiner(tr("Timers being edited at VDR, please try later"));
371 else if (retval == 3) errorBox->setOneLiner(tr("Unable to delete timer - timer is running"));
372 else if (retval == 4) errorBox->setOneLiner(tr("Error - timer not found at VDR"));
373 else errorBox->setOneLiner(tr("Unknown error"));
375 errorBox->setExitable();
376 errorBox->setBorderOn(1);
377 errorBox->setTitleBarColour(DrawStyle::DANGER);
378 errorBox->okButton();
380 BoxStack::getInstance()->add(errorBox);
381 BoxStack::getInstance()->update(errorBox);
384 int saveIndex = sl.getCurrentOption();
385 int saveTop = sl.getTopOption();
389 for (UINT i = 0; i < recTimerList->size(); i++)
391 delete (*recTimerList)[i];
394 recTimerList->clear();
401 sl.hintSetCurrent(saveIndex);
402 sl.hintSetTop(saveTop);
404 BoxStack::getInstance()->update(this);