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"
37 VTimerList::VTimerList()
53 indicatorsRegion.x = 6;
54 indicatorsRegion.y = 44;
55 indicatorsRegion.w = 18;
56 indicatorsRegion.h = 15 * (getFontHeight() + 1);
58 if (Video::getInstance()->getFormat() == Video::PAL)
68 setTitleText(tr("Timers"));
69 setTitleBarColour(DrawStyle::TITLEBARBACKGROUND);
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];
150 btime = localtime((time_t*)&recTimer->startTime);
151 strftime(strA, 299, "%d/%m %H:%M ", btime);
152 SNPRINTF(strB, 299, "%s\t%s", strA, recTimer->getName());
153 sl.addOption(strB, (ULONG)recTimer, first);
160 void VTimerList::drawClock()
162 // Blank the area first
163 rectangle(area.w - 150, 0, 150, 30, titleBarColour);
168 struct tm* tms = localtime(&t);
169 strftime(timeString, 19, "%d/%m %H:%M:%S", tms);
170 drawTextRJ(timeString, 560, 5, DrawStyle::LIGHTTEXT);
172 Timers::getInstance()->setTimerT(this, 1, t + 1);
175 void VTimerList::drawShowing()
177 int topOption = sl.getTopOption() + 1;
178 if (sl.getNumOptions() == 0) topOption = 0;
180 rectangle(220, 385, 180, 25, DrawStyle::VIEWBACKGROUND);
182 sprintf(showing, tr("%i to %i of %i"), topOption, sl.getBottomOption(), sl.getNumOptions());
183 drawText(showing, 220, 385, DrawStyle::LIGHTTEXT);
186 void VTimerList::drawIndicators()
188 int top = sl.getTopOption();
189 int bottom = sl.getBottomOption();
190 int yinc = getFontHeight() + 1;
193 rectangle(6, 44, 18, 15*yinc, DrawStyle::VIEWBACKGROUND);
195 // The indexes recorded from the wselectlist into the index member of the RecTimer
196 // Is the same as the position in the vector of RecTimers
197 // Because they are in order, they don't change order and wselectlist starts from 0 up consecutively
200 for (int current = top; current < bottom; current++)
202 recTimer = (*recTimerList)[current];
204 if (recTimer->recording) // Flashing red square
208 rectangle(6, ypos, 18, 16, DrawStyle::RED);
209 drawText("R", 8, ypos-3, DrawStyle::LIGHTTEXT);
212 else if (recTimer->pending)
214 rectangle(6, ypos, 18, 16, DrawStyle::RED);
215 drawText("X", 8, ypos-3, DrawStyle::BLACK);
217 else if (recTimer->active == 0)
219 rectangle(6, ypos, 18, 16, DrawStyle::SELECTHIGHLIGHT);
220 drawText("X", 8, ypos-3, DrawStyle::BLACK);
224 // if (flipflop) rectangle(6, ypos, 18, 16, DrawStyle::GREEN);
231 void VTimerList::timercall(int clientReference)
234 BoxStack::getInstance()->update(this, &clockRegion);
236 flipflop = !flipflop;
238 BoxStack::getInstance()->update(this, &indicatorsRegion);
241 int VTimerList::handleCommand(int command)
252 BoxStack::getInstance()->update(this);
255 case Remote::DF_DOWN:
262 BoxStack::getInstance()->update(this);
265 case Remote::SKIPBACK:
271 BoxStack::getInstance()->update(this);
274 case Remote::SKIPFORWARD:
280 BoxStack::getInstance()->update(this);
285 RecTimer* recTimer = NULL;
286 if (recTimerList) recTimer = (RecTimer*)sl.getCurrentOptionData();
287 if (recTimer == NULL) return 2;
289 VTimerEdit* v = new VTimerEdit(recTimer);
292 BoxStack::getInstance()->add(v);
293 BoxStack::getInstance()->update(v);
302 // stop command getting to any more views
306 void VTimerList::processMessage(Message* m)
308 if (m->message == Message::MOUSE_MOVE)
310 if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
313 BoxStack::getInstance()->update(this);
316 else if (m->message == Message::MOUSE_LBDOWN)
318 if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
320 BoxStack::getInstance()->handleCommand(Remote::OK); //simulate OK press
324 //check if press is outside this view! then simulate cancel
325 int x=(m->parameter>>16)-getScreenX();
326 int y=(m->parameter&0xFFFF)-getScreenY();
327 if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
329 BoxStack::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
333 else if (m->message == Message::DELETE_SELECTED_TIMER)
335 RecTimer* recTimer = (RecTimer*)sl.getCurrentOptionData();
336 if (recTimer == NULL) return;
337 Log::getInstance()->log("VTimerList", Log::DEBUG, "Got timer to delete");
340 ULONG retval = VDR::getInstance()->deleteTimer(recTimer);
341 if (!VDR::getInstance()->isConnected()) { Command::getInstance()->connectionLost(); return; }
342 Log::getInstance()->log("VTimerList", Log::DEBUG, "Got return fron delete timer: %lu", retval);
346 VInfo* errorBox = new VInfo();
347 errorBox->setSize(360, 200);
348 errorBox->createBuffer();
349 if (Video::getInstance()->getFormat() == Video::PAL)
350 errorBox->setPosition(190, 170);
352 errorBox->setPosition(180, 120);
355 if (retval == 1) errorBox->setOneLiner(tr("Timers being edited at VDR, please try later"));
356 else if (retval == 3) errorBox->setOneLiner(tr("Unable to delete timer - timer is running"));
357 else if (retval == 4) errorBox->setOneLiner(tr("Error - timer not found at VDR"));
358 else errorBox->setOneLiner(tr("Unknown error"));
360 errorBox->setExitable();
361 errorBox->setBorderOn(1);
362 errorBox->setTitleBarColour(DrawStyle::DANGER);
363 errorBox->okButton();
365 BoxStack::getInstance()->add(errorBox);
366 BoxStack::getInstance()->update(errorBox);
369 int saveIndex = sl.getCurrentOption();
370 int saveTop = sl.getTopOption();
374 for (UINT i = 0; i < recTimerList->size(); i++)
376 delete (*recTimerList)[i];
379 recTimerList->clear();
386 sl.hintSetCurrent(saveIndex);
387 sl.hintSetTop(saveTop);
389 BoxStack::getInstance()->update(this);