2 Copyright 2004-2020 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, see <https://www.gnu.org/licenses/>.
32 #include "vtimeredit.h"
37 #include "staticartwork.h"
39 #include "vtimerlist.h"
41 VTimerList::VTimerList()
51 indicatorsRegion.x = 6;
52 indicatorsRegion.y = 44;
53 indicatorsRegion.w = 18;
54 indicatorsRegion.h = 15 * (getFontHeight() + 1);
56 if (Video::getInstance()->getFormat() == Video::PAL)
66 setTitleText(tr("Timers"));
67 setTitleBarColour(DrawStyle::TITLEBARBACKGROUND);
68 TVMediaInfo *info= new TVMediaInfo();
69 info->setStaticArtwork(sa_timers);
70 setTitleBarIcon(info);
72 sl.setPosition(30, 30 + 5);
73 sl.setSize(area.w - 40, area.h - 30 - 15 - 30);
77 void VTimerList::preDelete()
79 Timers::getInstance()->cancelTimer(this, 1);
82 VTimerList::~VTimerList()
86 for (UINT i = 0; i < recTimerList->size(); i++)
88 delete (*recTimerList)[i];
91 recTimerList->clear();
96 void VTimerList::draw()
105 w.nextSymbol = WSymbol::UP;
106 w.setPosition(20, 385);
109 w.nextSymbol = WSymbol::DOWN;
110 w.setPosition(50, 385);
113 w.nextSymbol = WSymbol::SKIPBACK;
114 w.setPosition(85, 385);
117 w.nextSymbol = WSymbol::SKIPFORWARD;
118 w.setPosition(115, 385);
121 drawTextRJ("[ok] = edit", 560, 385, DrawStyle::LIGHTTEXT);
128 bool VTimerList::load()
130 recTimerList = VDR::getInstance()->getRecTimersList();
132 if (!recTimerList) return false;
139 // FIXME all drawing stuff in this class and sl.clear somewhere?!
147 for (UINT i = 0; i < recTimerList->size(); i++)
149 recTimer = (*recTimerList)[i];
150 time_t rectime = recTimer->startTime;
151 LOCALTIME_R(&rectime, &btime);
152 strftime(strA, 299, "%d/%m %H:%M ", &btime);
153 int check = SNPRINTF(strB, 300, "%s\t%s", strA, recTimer->getName());
154 if ((check < 0) || (check > 299)) Log::getInstance()->log("VTimerList", Log::ERR, "String too big");
155 sl.addOption(strB, recTimer, first);
162 void VTimerList::drawClock()
164 // Blank the area first
165 #ifndef GRADIENT_DRAWING
166 rectangle(area.w - 150, 0, 150, 30, titleBarColour);
173 LOCALTIME_R(&t, &tms);
174 strftime(timeString, 19, "%d/%m %H:%M:%S", &tms);
175 drawTextRJ(timeString, 560, 5, DrawStyle::LIGHTTEXT);
177 Timers::getInstance()->setTimerT(this, 1, t + 1);
180 void VTimerList::drawShowing()
182 int topOption = sl.getTopOption() + 1;
183 if (sl.getNumOptions() == 0) topOption = 0;
184 #ifndef GRADIENT_DRAWING
185 rectangle(220, 385, 180, 25, DrawStyle::VIEWBACKGROUND);
188 sprintf(showing, tr("%i to %i of %i"), topOption, sl.getBottomOption(), sl.getNumOptions());
189 drawText(showing, 220, 385, DrawStyle::LIGHTTEXT);
192 void VTimerList::quickUpdate() { //only quick for plattform that need it!
193 #ifdef GRADIENT_DRAWING
202 void VTimerList::drawIndicators()
204 int top = sl.getTopOption();
205 int bottom = sl.getBottomOption();
206 int yinc = getFontHeight() + 1;
208 #ifndef GRADIENT_DRAWING
209 rectangle(6, 44, 18, 15*yinc, DrawStyle::VIEWBACKGROUND);
211 // The indexes recorded from the wselectlist into the index member of the RecTimer
212 // Is the same as the position in the vector of RecTimers
213 // Because they are in order, they don't change order and wselectlist starts from 0 up consecutively
216 for (int current = top; current < bottom; current++)
218 recTimer = (*recTimerList)[current];
220 if (recTimer->recording) // Flashing red square
224 rectangle(6, ypos, 18, 16, DrawStyle::RED);
225 drawText("R", 8, ypos-3, DrawStyle::LIGHTTEXT);
228 else if (recTimer->pending)
230 rectangle(6, ypos, 18, 16, DrawStyle::RED);
231 drawText("X", 8, ypos-3, DrawStyle::BLACK);
233 else if (recTimer->active == 0)
235 rectangle(6, ypos, 18, 16, DrawStyle::SELECTHIGHLIGHT);
236 drawText("X", 8, ypos-3, DrawStyle::BLACK);
240 // if (flipflop) rectangle(6, ypos, 18, 16, DrawStyle::GREEN);
247 void VTimerList::timercall(int /* clientReference */)
249 flipflop = !flipflop;
250 #ifndef GRADIENT_DRAWING
252 BoxStack::getInstance()->update(this, &clockRegion);
255 BoxStack::getInstance()->update(this, &indicatorsRegion);
258 BoxStack::getInstance()->update(this);
262 int VTimerList::handleCommand(int command)
270 BoxStack::getInstance()->update(this);
277 BoxStack::getInstance()->update(this);
280 case Input::SKIPBACK:
284 BoxStack::getInstance()->update(this);
287 case Input::SKIPFORWARD:
291 BoxStack::getInstance()->update(this);
296 RecTimer* recTimer = NULL;
297 if (recTimerList) recTimer = reinterpret_cast<RecTimer*>(sl.getCurrentOptionData());
298 if (recTimer == NULL) return 2;
300 VTimerEdit* v = new VTimerEdit(recTimer);
303 BoxStack::getInstance()->add(v);
304 BoxStack::getInstance()->update(v);
313 // stop command getting to any more views
317 void VTimerList::processMessage(Message* m)
319 if (m->message == Message::MOUSE_MOVE)
321 if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
324 BoxStack::getInstance()->update(this);
327 else if (m->message == Message::MOUSE_LBDOWN)
329 if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
331 BoxStack::getInstance()->handleCommand(Input::OK); //simulate OK press
333 else if (coordsOutsideBox(m))
335 BoxStack::getInstance()->handleCommand(Input::BACK); //simulate cancel press
338 else if (m->message == Message::DELETE_SELECTED_TIMER)
340 RecTimer* recTimer = reinterpret_cast<RecTimer*>(sl.getCurrentOptionData());
341 if (recTimer == NULL) return;
342 Log::getInstance()->log("VTimerList", Log::DEBUG, "Got timer to delete");
345 ULONG retval = VDR::getInstance()->deleteTimer(recTimer);
346 if (!VDR::getInstance()->isConnected()) { Command::getInstance()->connectionLost(); return; }
347 Log::getInstance()->log("VTimerList", Log::DEBUG, "Got return fron delete timer: %lu", retval);
351 VInfo* errorBox = new VInfo();
352 errorBox->setSize(360, 200);
353 errorBox->createBuffer();
354 if (Video::getInstance()->getFormat() == Video::PAL)
355 errorBox->setPosition(190, 170);
357 errorBox->setPosition(180, 120);
360 if (retval == 1) errorBox->setOneLiner(tr("Timers being edited at VDR, please try later"));
361 else if (retval == 3) errorBox->setOneLiner(tr("Unable to delete timer - timer is running"));
362 else if (retval == 4) errorBox->setOneLiner(tr("Error - timer not found at VDR"));
363 else errorBox->setOneLiner(tr("Unknown error"));
365 errorBox->setExitable();
366 errorBox->setBorderOn(1);
367 errorBox->setTitleBarColour(DrawStyle::DANGER);
368 errorBox->okButton();
370 BoxStack::getInstance()->add(errorBox);
371 BoxStack::getInstance()->update(errorBox);
374 int saveIndex = sl.getCurrentOption();
375 int saveTop = sl.getTopOption();
379 for (UINT i = 0; i < recTimerList->size(); i++)
381 delete (*recTimerList)[i];
384 recTimerList->clear();
391 sl.hintSetCurrent(saveIndex);
392 sl.hintSetTop(saveTop);
394 BoxStack::getInstance()->update(this);