]> git.vomp.tv Git - vompclient.git/blob - vtimerlist.cc
Compile fix for MVP re: location change of hmsf
[vompclient.git] / vtimerlist.cc
1 /*
2     Copyright 2004-2005 Chris Tallon
3
4     This file is part of VOMP.
5
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.
10
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.
15
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.
19 */
20
21 #include "vtimerlist.h"
22
23 #include "message.h"
24 #include "remote.h"
25 #include "wsymbol.h"
26 #include "colour.h"
27 #include "video.h"
28 #include "i18n.h"
29 #include "timers.h"
30 #include "vtimeredit.h"
31 #include "command.h"
32 #include "boxstack.h"
33 #include "vdr.h"
34 #include "vinfo.h"
35 #include "log.h"
36 #include "staticartwork.h"
37
38 VTimerList::VTimerList()
39 {
40   recTimerList = NULL;
41
42   clockRegion.x = 420;
43   clockRegion.y = 0;
44   clockRegion.w = 150;
45   clockRegion.h = 30;
46
47
48
49   flipflop = true;
50
51   setSize(570, 420);
52   createBuffer();
53
54   indicatorsRegion.x = 6;
55   indicatorsRegion.y = 44;
56   indicatorsRegion.w = 18;
57   indicatorsRegion.h = 15 * (getFontHeight() + 1);
58
59   if (Video::getInstance()->getFormat() == Video::PAL)
60   {
61     setPosition(80, 70);
62   }
63   else
64   {
65     setPosition(70, 35);
66   }
67
68   setTitleBarOn(1);
69   setTitleText(tr("Timers"));
70   setTitleBarColour(DrawStyle::TITLEBARBACKGROUND);
71   TVMediaInfo *info= new TVMediaInfo();
72   info->setStaticArtwork(sa_timers);
73   setTitleBarIcon(info);
74
75   sl.setPosition(30, 30 + 5);
76   sl.setSize(area.w - 40, area.h - 30 - 15 - 30);
77   add(&sl);
78 }
79
80 void VTimerList::preDelete()
81 {
82   Timers::getInstance()->cancelTimer(this, 1);
83 }
84
85 VTimerList::~VTimerList()
86 {
87   if (recTimerList)
88   {
89     for (UINT i = 0; i < recTimerList->size(); i++)
90     {
91       delete (*recTimerList)[i];
92     }
93
94     recTimerList->clear();
95     delete recTimerList;
96   }
97 }
98
99 void VTimerList::draw()
100 {
101   // Draw statics
102
103   TBBoxx::draw();
104
105   WSymbol w;
106   TEMPADD(&w);
107
108   w.nextSymbol = WSymbol::UP;
109   w.setPosition(20, 385);
110   w.draw();
111
112   w.nextSymbol = WSymbol::DOWN;
113   w.setPosition(50, 385);
114   w.draw();
115
116   w.nextSymbol = WSymbol::SKIPBACK;
117   w.setPosition(85, 385);
118   w.draw();
119
120   w.nextSymbol = WSymbol::SKIPFORWARD;
121   w.setPosition(115, 385);
122   w.draw();
123
124   drawTextRJ("[ok] = edit", 560, 385, DrawStyle::LIGHTTEXT);
125
126   drawClock();
127   drawShowing();
128   drawIndicators();
129 }
130
131 bool VTimerList::load()
132 {
133   recTimerList = VDR::getInstance()->getRecTimersList();
134
135   if (!recTimerList) return false;
136
137   char strA[300];
138   char strB[300];
139
140   struct tm btime;
141
142   // FIXME all drawing stuff in this class and sl.clear somewhere?!
143
144   sl.addColumn(0);
145   sl.addColumn(110);
146
147   RecTimer* recTimer;
148   int first = 1;
149
150   for (UINT i = 0; i < recTimerList->size(); i++)
151   {
152     recTimer = (*recTimerList)[i];
153     time_t rectime = recTimer->startTime;
154     LOCALTIME_R((time_t*)&rectime, &btime);
155     strftime(strA, 299, "%d/%m %H:%M ", &btime);
156     SNPRINTF(strB, 299, "%s\t%s", strA, recTimer->getName());
157     sl.addOption(strB, (ULONG)recTimer, first);
158     first = 0;
159   }
160
161   return true;
162 }
163
164 void VTimerList::drawClock()
165 {
166   // Blank the area first
167 #ifndef GRADIENT_DRAWING
168   rectangle(area.w - 150, 0, 150, 30, titleBarColour);
169 #endif
170
171   char timeString[20];
172   time_t t;
173   time(&t);
174   struct tm tms;
175   LOCALTIME_R(&t, &tms);
176   strftime(timeString, 19, "%d/%m %H:%M:%S", &tms);
177   drawTextRJ(timeString, 560, 5, DrawStyle::LIGHTTEXT);
178
179   Timers::getInstance()->setTimerT(this, 1, t + 1);
180 }
181
182 void VTimerList::drawShowing()
183 {
184   int topOption = sl.getTopOption() + 1;
185   if (sl.getNumOptions() == 0) topOption = 0;
186 #ifndef GRADIENT_DRAWING
187   rectangle(220, 385, 180, 25, DrawStyle::VIEWBACKGROUND);
188 #endif
189   char showing[200];
190   sprintf(showing, tr("%i to %i of %i"), topOption, sl.getBottomOption(), sl.getNumOptions());
191   drawText(showing, 220, 385, DrawStyle::LIGHTTEXT);
192 }
193
194 void VTimerList::quickUpdate() { //only quick for plattform that need it!
195 #ifdef GRADIENT_DRAWING
196       draw();
197 #else
198       sl.draw();
199       drawShowing();
200       drawIndicators();
201 #endif
202 }
203
204 void VTimerList::drawIndicators()
205 {
206   int top = sl.getTopOption();
207   int bottom = sl.getBottomOption();
208   int yinc = getFontHeight() + 1;
209   RecTimer* recTimer;
210 #ifndef GRADIENT_DRAWING
211   rectangle(6, 44, 18, 15*yinc, DrawStyle::VIEWBACKGROUND);
212 #endif
213   // The indexes recorded from the wselectlist into the index member of the RecTimer
214   // Is the same as the position in the vector of RecTimers
215   // Because they are in order, they don't change order and wselectlist starts from 0 up consecutively
216
217   int ypos = 44;
218   for (int current = top; current < bottom; current++)
219   {
220     recTimer = (*recTimerList)[current];
221
222     if (recTimer->recording) // Flashing red square
223     {
224       if (flipflop)
225       {
226         rectangle(6, ypos, 18, 16, DrawStyle::RED);
227         drawText("R", 8, ypos-3, DrawStyle::LIGHTTEXT);
228       }
229     }
230     else if (recTimer->pending)
231     {
232       rectangle(6, ypos, 18, 16, DrawStyle::RED);
233       drawText("X", 8, ypos-3, DrawStyle::BLACK);
234     }
235     else if (recTimer->active == 0)
236     {
237       rectangle(6, ypos, 18, 16, DrawStyle::SELECTHIGHLIGHT);
238       drawText("X", 8, ypos-3, DrawStyle::BLACK);
239     }
240     else
241     {
242 //      if (flipflop) rectangle(6, ypos, 18, 16, DrawStyle::GREEN);
243     }
244
245     ypos += yinc;
246   }
247 }
248
249 void VTimerList::timercall(int clientReference)
250 {
251         flipflop = !flipflop;
252 #ifndef GRADIENT_DRAWING
253   drawClock();
254   BoxStack::getInstance()->update(this, &clockRegion);
255
256   drawIndicators();
257   BoxStack::getInstance()->update(this, &indicatorsRegion);
258 #else
259   draw();
260   BoxStack::getInstance()->update(this);
261 #endif
262 }
263
264 int VTimerList::handleCommand(int command)
265 {
266   switch(command)
267   {
268     case Remote::DF_UP:
269     case Remote::UP:
270     {
271       sl.up();
272       quickUpdate();
273       BoxStack::getInstance()->update(this);
274       return 2;
275     }
276     case Remote::DF_DOWN:
277     case Remote::DOWN:
278     {
279       sl.down();
280       quickUpdate();
281       BoxStack::getInstance()->update(this);
282       return 2;
283     }
284     case Remote::SKIPBACK:
285     {
286       sl.pageUp();
287       quickUpdate();
288       BoxStack::getInstance()->update(this);
289       return 2;
290     }
291     case Remote::SKIPFORWARD:
292     {
293       sl.pageDown();
294       quickUpdate();
295       BoxStack::getInstance()->update(this);
296       return 2;
297     }
298     case Remote::OK:
299     {
300       RecTimer* recTimer = NULL;
301       if (recTimerList) recTimer = (RecTimer*)sl.getCurrentOptionData();
302       if (recTimer == NULL) return 2;
303
304       VTimerEdit* v = new VTimerEdit(recTimer);
305       v->setParent(this);
306       v->draw();
307       BoxStack::getInstance()->add(v);
308       BoxStack::getInstance()->update(v);
309
310       return 2;
311     }
312     case Remote::BACK:
313     {
314       return 4;
315     }
316   }
317   // stop command getting to any more views
318   return 1;
319 }
320
321 void VTimerList::processMessage(Message* m)
322 {
323   if (m->message == Message::MOUSE_MOVE)
324   {
325     if (sl.mouseMove((m->parameter.num>>16)-getScreenX(),(m->parameter.num&0xFFFF)-getScreenY()))
326     {
327         quickUpdate();
328       BoxStack::getInstance()->update(this);
329     }
330   }
331   else if (m->message == Message::MOUSE_LBDOWN)
332   {
333     if (sl.mouseLBDOWN((m->parameter.num>>16)-getScreenX(),(m->parameter.num&0xFFFF)-getScreenY()))
334     {
335       BoxStack::getInstance()->handleCommand(Remote::OK); //simulate OK press
336     }
337     else
338     {
339       //check if press is outside this view! then simulate cancel
340       int x=(m->parameter.num>>16)-getScreenX();
341       int y=(m->parameter.num&0xFFFF)-getScreenY();
342       if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
343       {
344         BoxStack::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
345       }
346     }
347   }
348   else if (m->message == Message::DELETE_SELECTED_TIMER)
349   {
350     RecTimer* recTimer = (RecTimer*)sl.getCurrentOptionData();
351     if (recTimer == NULL) return;
352     Log::getInstance()->log("VTimerList", Log::DEBUG, "Got timer to delete");
353
354   
355     ULONG retval = VDR::getInstance()->deleteTimer(recTimer);
356     if (!VDR::getInstance()->isConnected()) { Command::getInstance()->connectionLost(); return; }
357     Log::getInstance()->log("VTimerList", Log::DEBUG, "Got return fron delete timer: %lu", retval);
358     
359     if (retval != 10)
360     {
361       VInfo* errorBox = new VInfo();
362       errorBox->setSize(360, 200);
363       errorBox->createBuffer();
364       if (Video::getInstance()->getFormat() == Video::PAL)
365         errorBox->setPosition(190, 170);
366       else
367         errorBox->setPosition(180, 120);
368
369     
370       if (retval == 1) errorBox->setOneLiner(tr("Timers being edited at VDR, please try later"));
371       else if (retval == 3)  errorBox->setOneLiner(tr("Unable to delete timer - timer is running"));
372       else if (retval == 4)  errorBox->setOneLiner(tr("Error - timer not found at VDR"));
373       else                   errorBox->setOneLiner(tr("Unknown error"));
374
375       errorBox->setExitable();
376       errorBox->setBorderOn(1);
377       errorBox->setTitleBarColour(DrawStyle::DANGER);
378       errorBox->okButton();
379       errorBox->draw();
380       BoxStack::getInstance()->add(errorBox);
381       BoxStack::getInstance()->update(errorBox);
382     }
383     
384     int saveIndex = sl.getCurrentOption();
385     int saveTop = sl.getTopOption();
386      
387     if (recTimerList)
388     {
389       for (UINT i = 0; i < recTimerList->size(); i++)
390       {
391         delete (*recTimerList)[i];
392       }
393
394       recTimerList->clear();
395       delete recTimerList;
396     }
397
398     sl.clear();
399     load();
400
401     sl.hintSetCurrent(saveIndex);
402     sl.hintSetTop(saveTop);
403     draw();
404     BoxStack::getInstance()->update(this);
405   }
406 }
407