2 Copyright 2004-2005 Chris Tallon
\r
4 This file is part of VOMP.
\r
6 VOMP is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 VOMP is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with VOMP; if not, write to the Free Software
\r
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
\r
21 #include "vtimerlist.h"
\r
23 #include "message.h"
\r
25 #include "wsymbol.h"
\r
30 #include "vtimeredit.h"
\r
31 #include "command.h"
\r
32 #include "boxstack.h"
\r
37 VTimerList::VTimerList()
\r
39 recTimerList = NULL;
\r
41 clockRegion.x = 420;
\r
43 clockRegion.w = 150;
\r
53 indicatorsRegion.x = 6;
\r
54 indicatorsRegion.y = 44;
\r
55 indicatorsRegion.w = 18;
\r
56 indicatorsRegion.h = 15 * (getFontHeight() + 1);
\r
58 if (Video::getInstance()->getFormat() == Video::PAL)
\r
60 setPosition(80, 70);
\r
64 setPosition(70, 35);
\r
68 setTitleText(tr("Timers"));
\r
69 setTitleBarColour(DrawStyle::TITLEBARBACKGROUND);
\r
71 sl.setPosition(30, 30 + 5);
\r
72 sl.setSize(area.w - 40, area.h - 30 - 15 - 30);
\r
76 void VTimerList::preDelete()
\r
78 Timers::getInstance()->cancelTimer(this, 1);
\r
81 VTimerList::~VTimerList()
\r
85 for (UINT i = 0; i < recTimerList->size(); i++)
\r
87 delete (*recTimerList)[i];
\r
90 recTimerList->clear();
\r
91 delete recTimerList;
\r
95 void VTimerList::draw()
\r
104 w.nextSymbol = WSymbol::UP;
\r
105 w.setPosition(20, 385);
\r
108 w.nextSymbol = WSymbol::DOWN;
\r
109 w.setPosition(50, 385);
\r
112 w.nextSymbol = WSymbol::SKIPBACK;
\r
113 w.setPosition(85, 385);
\r
116 w.nextSymbol = WSymbol::SKIPFORWARD;
\r
117 w.setPosition(115, 385);
\r
120 drawTextRJ("[ok] = edit", 560, 385, DrawStyle::LIGHTTEXT);
\r
127 bool VTimerList::load()
\r
129 recTimerList = VDR::getInstance()->getRecTimersList();
\r
131 if (!recTimerList) return false;
\r
138 // FIXME all drawing stuff in this class and sl.clear somewhere?!
\r
143 RecTimer* recTimer;
\r
146 for (UINT i = 0; i < recTimerList->size(); i++)
\r
148 recTimer = (*recTimerList)[i];
\r
150 btime = localtime((time_t*)&recTimer->startTime);
\r
151 strftime(strA, 299, "%d/%m %H:%M ", btime);
\r
152 SNPRINTF(strB, 299, "%s\t%s", strA, recTimer->getName());
\r
153 sl.addOption(strB, (ULONG)recTimer, first);
\r
160 void VTimerList::drawClock()
\r
162 // Blank the area first
\r
163 rectangle(area.w - 150, 0, 150, 30, titleBarColour);
\r
165 char timeString[20];
\r
168 struct tm* tms = localtime(&t);
\r
169 strftime(timeString, 19, "%d/%m %H:%M:%S", tms);
\r
170 drawTextRJ(timeString, 560, 5, DrawStyle::LIGHTTEXT);
\r
172 Timers::getInstance()->setTimerT(this, 1, t + 1);
\r
175 void VTimerList::drawShowing()
\r
177 int topOption = sl.getTopOption() + 1;
\r
178 if (sl.getNumOptions() == 0) topOption = 0;
\r
180 rectangle(220, 385, 180, 25, DrawStyle::VIEWBACKGROUND);
\r
182 sprintf(showing, tr("%i to %i of %i"), topOption, sl.getBottomOption(), sl.getNumOptions());
\r
183 drawText(showing, 220, 385, DrawStyle::LIGHTTEXT);
\r
186 void VTimerList::drawIndicators()
\r
188 int top = sl.getTopOption();
\r
189 int bottom = sl.getBottomOption();
\r
190 int yinc = getFontHeight() + 1;
\r
191 RecTimer* recTimer;
\r
193 rectangle(6, 44, 18, 15*yinc, DrawStyle::VIEWBACKGROUND);
\r
195 // The indexes recorded from the wselectlist into the index member of the RecTimer
\r
196 // Is the same as the position in the vector of RecTimers
\r
197 // Because they are in order, they don't change order and wselectlist starts from 0 up consecutively
\r
200 for (int current = top; current < bottom; current++)
\r
202 recTimer = (*recTimerList)[current];
\r
204 if (recTimer->recording) // Flashing red square
\r
208 rectangle(6, ypos, 18, 16, DrawStyle::RED);
\r
209 drawText("R", 8, ypos-3, DrawStyle::LIGHTTEXT);
\r
212 else if (recTimer->pending)
\r
214 rectangle(6, ypos, 18, 16, DrawStyle::RED);
\r
215 drawText("X", 8, ypos-3, DrawStyle::BLACK);
\r
217 else if (recTimer->active == 0)
\r
219 rectangle(6, ypos, 18, 16, DrawStyle::SELECTHIGHLIGHT);
\r
220 drawText("X", 8, ypos-3, DrawStyle::BLACK);
\r
224 // if (flipflop) rectangle(6, ypos, 18, 16, DrawStyle::GREEN);
\r
231 void VTimerList::timercall(int clientReference)
\r
234 BoxStack::getInstance()->update(this, &clockRegion);
\r
236 flipflop = !flipflop;
\r
238 BoxStack::getInstance()->update(this, &indicatorsRegion);
\r
241 int VTimerList::handleCommand(int command)
\r
245 case Remote::DF_UP:
\r
252 BoxStack::getInstance()->update(this);
\r
255 case Remote::DF_DOWN:
\r
262 BoxStack::getInstance()->update(this);
\r
265 case Remote::SKIPBACK:
\r
271 BoxStack::getInstance()->update(this);
\r
274 case Remote::SKIPFORWARD:
\r
280 BoxStack::getInstance()->update(this);
\r
285 RecTimer* recTimer = NULL;
\r
286 if (recTimerList) recTimer = (RecTimer*)sl.getCurrentOptionData();
\r
287 if (recTimer == NULL) return 2;
\r
289 VTimerEdit* v = new VTimerEdit(recTimer);
\r
290 v->setParent(this);
\r
292 BoxStack::getInstance()->add(v);
\r
293 BoxStack::getInstance()->update(v);
\r
302 // stop command getting to any more views
\r
306 void VTimerList::processMessage(Message* m)
\r
308 if (m->message == Message::MOUSE_MOVE)
\r
310 if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
\r
313 BoxStack::getInstance()->update(this);
\r
316 else if (m->message == Message::MOUSE_LBDOWN)
\r
318 if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
\r
320 BoxStack::getInstance()->handleCommand(Remote::OK); //simulate OK press
\r
324 //check if press is outside this view! then simulate cancel
\r
325 int x=(m->parameter>>16)-getScreenX();
\r
326 int y=(m->parameter&0xFFFF)-getScreenY();
\r
327 if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
\r
329 BoxStack::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
\r
333 else if (m->message == Message::DELETE_SELECTED_TIMER)
\r
335 RecTimer* recTimer = (RecTimer*)sl.getCurrentOptionData();
\r
336 if (recTimer == NULL) return;
\r
337 Log::getInstance()->log("VTimerList", Log::DEBUG, "Got timer to delete");
\r
340 ULONG retval = VDR::getInstance()->deleteTimer(recTimer);
\r
341 if (!VDR::getInstance()->isConnected()) { Command::getInstance()->connectionLost(); return; }
\r
342 Log::getInstance()->log("VTimerList", Log::DEBUG, "Got return fron delete timer: %lu", retval);
\r
346 VInfo* errorBox = new VInfo();
\r
347 errorBox->setSize(360, 200);
\r
348 errorBox->createBuffer();
\r
349 if (Video::getInstance()->getFormat() == Video::PAL)
\r
350 errorBox->setPosition(190, 170);
\r
352 errorBox->setPosition(180, 120);
\r
355 if (retval == 1) errorBox->setOneLiner(tr("Timers being edited at VDR, please try later"));
\r
356 else if (retval == 3) errorBox->setOneLiner(tr("Unable to delete timer - timer is running"));
\r
357 else if (retval == 4) errorBox->setOneLiner(tr("Error - timer not found at VDR"));
\r
358 else errorBox->setOneLiner(tr("Unknown error"));
\r
360 errorBox->setExitable();
\r
361 errorBox->setBorderOn(1);
\r
362 errorBox->setTitleBarColour(DrawStyle::DANGER);
\r
363 errorBox->okButton();
\r
365 BoxStack::getInstance()->add(errorBox);
\r
366 BoxStack::getInstance()->update(errorBox);
\r
369 int saveIndex = sl.getCurrentOption();
\r
370 int saveTop = sl.getTopOption();
\r
374 for (UINT i = 0; i < recTimerList->size(); i++)
\r
376 delete (*recTimerList)[i];
\r
379 recTimerList->clear();
\r
380 delete recTimerList;
\r
386 sl.hintSetCurrent(saveIndex);
\r
387 sl.hintSetTop(saveTop);
\r
389 BoxStack::getInstance()->update(this);
\r