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/>.
31 #include "vtimeredit.h"
36 #include "staticartwork.h"
38 #include "vtimerlist.h"
40 VTimerList::VTimerList()
50 indicatorsRegion.x = 6;
51 indicatorsRegion.y = 44;
52 indicatorsRegion.w = 18;
53 indicatorsRegion.h = 15 * (getFontHeight() + 1);
55 if (Video::getInstance()->getFormat() == Video::PAL)
65 setTitleText(tr("Timers"));
66 setTitleBarColour(DrawStyle::TITLEBARBACKGROUND);
67 TVMediaInfo *info= new TVMediaInfo();
68 info->setStaticArtwork(sa_timers);
69 setTitleBarIcon(info);
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];
149 time_t rectime = recTimer->startTime;
150 LOCALTIME_R(&rectime, &btime);
151 strftime(strA, 299, "%d/%m %H:%M ", &btime);
152 int check = SNPRINTF(strB, 300, "%s\t%s", strA, recTimer->getName());
153 if ((check < 0) || (check > 299)) Log::getInstance()->log("VTimerList", Log::ERR, "String too big");
154 sl.addOption(strB, recTimer, first);
161 void VTimerList::drawClock()
163 // Blank the area first
164 #ifndef GRADIENT_DRAWING
165 rectangle(area.w - 150, 0, 150, 30, titleBarColour);
172 LOCALTIME_R(&t, &tms);
173 strftime(timeString, 19, "%d/%m %H:%M:%S", &tms);
174 drawTextRJ(timeString, 560, 5, DrawStyle::LIGHTTEXT);
176 Timers::getInstance()->setTimerT(this, 1, t + 1);
179 void VTimerList::drawShowing()
181 int topOption = sl.getTopOption() + 1;
182 if (sl.getNumOptions() == 0) topOption = 0;
183 #ifndef GRADIENT_DRAWING
184 rectangle(220, 385, 180, 25, DrawStyle::VIEWBACKGROUND);
187 sprintf(showing, tr("%i to %i of %i"), topOption, sl.getBottomOption(), sl.getNumOptions());
188 drawText(showing, 220, 385, DrawStyle::LIGHTTEXT);
191 void VTimerList::quickUpdate() { //only quick for plattform that need it!
192 #ifdef GRADIENT_DRAWING
201 void VTimerList::drawIndicators()
203 int top = sl.getTopOption();
204 int bottom = sl.getBottomOption();
205 int yinc = getFontHeight() + 1;
207 #ifndef GRADIENT_DRAWING
208 rectangle(6, 44, 18, 15*yinc, DrawStyle::VIEWBACKGROUND);
210 // The indexes recorded from the wselectlist into the index member of the RecTimer
211 // Is the same as the position in the vector of RecTimers
212 // Because they are in order, they don't change order and wselectlist starts from 0 up consecutively
215 for (int current = top; current < bottom; current++)
217 recTimer = (*recTimerList)[current];
219 if (recTimer->recording) // Flashing red square
223 rectangle(6, ypos, 18, 16, DrawStyle::RED);
224 drawText("R", 8, ypos-3, DrawStyle::LIGHTTEXT);
227 else if (recTimer->pending)
229 rectangle(6, ypos, 18, 16, DrawStyle::RED);
230 drawText("X", 8, ypos-3, DrawStyle::BLACK);
232 else if (recTimer->active == 0)
234 rectangle(6, ypos, 18, 16, DrawStyle::SELECTHIGHLIGHT);
235 drawText("X", 8, ypos-3, DrawStyle::BLACK);
239 // if (flipflop) rectangle(6, ypos, 18, 16, DrawStyle::GREEN);
246 void VTimerList::timercall(int /* clientReference */)
248 flipflop = !flipflop;
249 #ifndef GRADIENT_DRAWING
251 BoxStack::getInstance()->update(this, &clockRegion);
254 BoxStack::getInstance()->update(this, &indicatorsRegion);
257 BoxStack::getInstance()->update(this);
261 int VTimerList::handleCommand(int command)
269 BoxStack::getInstance()->update(this);
276 BoxStack::getInstance()->update(this);
279 case Input::SKIPBACK:
283 BoxStack::getInstance()->update(this);
286 case Input::SKIPFORWARD:
290 BoxStack::getInstance()->update(this);
295 RecTimer* recTimer = NULL;
296 if (recTimerList) recTimer = reinterpret_cast<RecTimer*>(sl.getCurrentOptionData());
297 if (recTimer == NULL) return 2;
299 VTimerEdit* v = new VTimerEdit(recTimer);
302 BoxStack::getInstance()->add(v);
303 BoxStack::getInstance()->update(v);
312 // stop command getting to any more views
316 void VTimerList::processMessage(Message* m)
318 if (m->message == Message::MOUSE_MOVE)
320 if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
323 BoxStack::getInstance()->update(this);
326 else if (m->message == Message::MOUSE_LBDOWN)
328 if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
330 BoxStack::getInstance()->handleCommand(Input::OK); //simulate OK press
332 else if (coordsOutsideBox(m))
334 BoxStack::getInstance()->handleCommand(Input::BACK); //simulate cancel press
337 else if (m->message == Message::DELETE_SELECTED_TIMER)
339 RecTimer* recTimer = reinterpret_cast<RecTimer*>(sl.getCurrentOptionData());
340 if (recTimer == NULL) return;
341 Log::getInstance()->log("VTimerList", Log::DEBUG, "Got timer to delete");
344 ULONG retval = VDR::getInstance()->deleteTimer(recTimer);
345 if (!VDR::getInstance()->isConnected()) { Control::getInstance()->connectionLost(); return; }
346 Log::getInstance()->log("VTimerList", Log::DEBUG, "Got return fron delete timer: %lu", retval);
350 VInfo* errorBox = new VInfo();
351 errorBox->setSize(360, 200);
352 errorBox->createBuffer();
353 if (Video::getInstance()->getFormat() == Video::PAL)
354 errorBox->setPosition(190, 170);
356 errorBox->setPosition(180, 120);
359 if (retval == 1) errorBox->setOneLiner(tr("Timers being edited at VDR, please try later"));
360 else if (retval == 3) errorBox->setOneLiner(tr("Unable to delete timer - timer is running"));
361 else if (retval == 4) errorBox->setOneLiner(tr("Error - timer not found at VDR"));
362 else errorBox->setOneLiner(tr("Unknown error"));
364 errorBox->setExitable();
365 errorBox->setBorderOn(1);
366 errorBox->setTitleBarColour(DrawStyle::DANGER);
367 errorBox->okButton();
369 BoxStack::getInstance()->add(errorBox);
370 BoxStack::getInstance()->update(errorBox);
373 int saveIndex = sl.getCurrentOption();
374 int saveTop = sl.getTopOption();
378 for (UINT i = 0; i < recTimerList->size(); i++)
380 delete (*recTimerList)[i];
383 recTimerList->clear();
390 sl.hintSetCurrent(saveIndex);
391 sl.hintSetTop(saveTop);
393 BoxStack::getInstance()->update(this);