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 static const char* TAG = "VTimerList";
42 VTimerList::VTimerList()
52 indicatorsRegion.x = 6;
53 indicatorsRegion.y = 44;
54 indicatorsRegion.w = 18;
55 indicatorsRegion.h = 15 * (getFontHeight() + 1);
57 if (Video::getInstance()->getFormat() == Video::PAL)
67 setTitleText(tr("Timers"));
68 setTitleBarColour(DrawStyle::TITLEBARBACKGROUND);
69 TVMediaInfo *info= new TVMediaInfo();
70 info->setStaticArtwork(sa_timers);
71 setTitleBarIcon(info);
73 sl.setPosition(30, 30 + 5);
74 sl.setSize(area.w - 40, area.h - 30 - 15 - 30);
78 void VTimerList::preDelete()
80 Timers::getInstance()->cancelTimer(this, 1);
83 VTimerList::~VTimerList()
87 for (UINT i = 0; i < recTimerList->size(); i++)
89 delete (*recTimerList)[i];
92 recTimerList->clear();
97 void VTimerList::draw()
106 w.nextSymbol = WSymbol::UP;
107 w.setPosition(20, 385);
110 w.nextSymbol = WSymbol::DOWN;
111 w.setPosition(50, 385);
114 w.nextSymbol = WSymbol::SKIPBACK;
115 w.setPosition(85, 385);
118 w.nextSymbol = WSymbol::SKIPFORWARD;
119 w.setPosition(115, 385);
122 drawTextRJ("[ok] = edit", 560, 385, DrawStyle::LIGHTTEXT);
129 bool VTimerList::load()
131 recTimerList = VDR::getInstance()->getRecTimersList();
133 if (!recTimerList) return false;
140 // FIXME all drawing stuff in this class and sl.clear somewhere?!
148 for (UINT i = 0; i < recTimerList->size(); i++)
150 recTimer = (*recTimerList)[i];
151 time_t rectime = recTimer->startTime;
152 LOCALTIME_R(&rectime, &btime);
153 strftime(strA, 299, "%d/%m %H:%M ", &btime);
154 int check = SNPRINTF(strB, 300, "%s\t%s", strA, recTimer->getName());
155 if ((check < 0) || (check > 299)) LogNT::getInstance()->error(TAG, "String too big");
156 sl.addOption(strB, recTimer, first);
163 void VTimerList::drawClock()
165 // Blank the area first
166 #ifndef GRADIENT_DRAWING
167 rectangle(area.w - 150, 0, 150, 30, titleBarColour);
174 LOCALTIME_R(&t, &tms);
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)
271 BoxStack::getInstance()->update(this);
278 BoxStack::getInstance()->update(this);
281 case Input::SKIPBACK:
285 BoxStack::getInstance()->update(this);
288 case Input::SKIPFORWARD:
292 BoxStack::getInstance()->update(this);
297 RecTimer* recTimer = NULL;
298 if (recTimerList) recTimer = reinterpret_cast<RecTimer*>(sl.getCurrentOptionData());
299 if (recTimer == NULL) return 2;
301 VTimerEdit* v = new VTimerEdit(recTimer);
304 BoxStack::getInstance()->add(v);
305 BoxStack::getInstance()->update(v);
314 // stop command getting to any more views
318 void VTimerList::processMessage(Message* m)
320 if (m->message == Message::MOUSE_MOVE)
322 if (sl.mouseMove(m->parameter - getScreenX(), m->tag - getScreenY()))
325 BoxStack::getInstance()->update(this);
328 else if (m->message == Message::MOUSE_LBDOWN)
330 if (sl.mouseLBDOWN(m->parameter - getScreenX(), m->tag - getScreenY()))
332 BoxStack::getInstance()->handleCommand(Input::OK); //simulate OK press
334 else if (coordsOutsideBox(m))
336 BoxStack::getInstance()->handleCommand(Input::BACK); //simulate cancel press
339 else if (m->message == Message::DELETE_SELECTED_TIMER)
341 RecTimer* recTimer = reinterpret_cast<RecTimer*>(sl.getCurrentOptionData());
342 if (recTimer == NULL) return;
343 LogNT::getInstance()->debug(TAG, "Got timer to delete");
346 ULONG retval = VDR::getInstance()->deleteTimer(recTimer);
347 if (!VDR::getInstance()->isConnected()) { Control::getInstance()->connectionLost(); return; }
348 LogNT::getInstance()->debug(TAG, "Got return fron delete timer: {}", retval);
352 VInfo* errorBox = new VInfo();
353 errorBox->setSize(360, 200);
354 errorBox->createBuffer();
355 if (Video::getInstance()->getFormat() == Video::PAL)
356 errorBox->setPosition(190, 170);
358 errorBox->setPosition(180, 120);
361 if (retval == 1) errorBox->setOneLiner(tr("Timers being edited at VDR, please try later"));
362 else if (retval == 3) errorBox->setOneLiner(tr("Unable to delete timer - timer is running"));
363 else if (retval == 4) errorBox->setOneLiner(tr("Error - timer not found at VDR"));
364 else errorBox->setOneLiner(tr("Unknown error"));
366 errorBox->setExitable();
367 errorBox->setBorderOn(1);
368 errorBox->setTitleBarColour(DrawStyle::DANGER);
369 errorBox->okButton();
371 BoxStack::getInstance()->add(errorBox);
372 BoxStack::getInstance()->update(errorBox);
375 int saveIndex = sl.getCurrentOption();
376 int saveTop = sl.getTopOption();
380 for (UINT i = 0; i < recTimerList->size(); i++)
382 delete (*recTimerList)[i];
385 recTimerList->clear();
392 sl.hintSetCurrent(saveIndex);
393 sl.hintSetTop(saveTop);
395 BoxStack::getInstance()->update(this);