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