]> git.vomp.tv Git - vompclient.git/blob - vtimerlist.cc
German updates
[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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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
227   Message* m = new Message();
228   m->message = Message::REDRAW;
229   m->to = BoxStack::getInstance();
230   m->from = this;
231   m->parameter = (ULONG)&clockRegion;
232   Command::getInstance()->postMessageFromOuterSpace(m);
233
234   flipflop = !flipflop;
235   drawIndicators();
236
237   m = new Message();
238   m->message = Message::REDRAW;
239   m->to = BoxStack::getInstance();
240   m->from = this;
241   m->parameter = (ULONG)&indicatorsRegion;
242   Command::getInstance()->postMessageFromOuterSpace(m);
243 }
244
245 int VTimerList::handleCommand(int command)
246 {
247   switch(command)
248   {
249     case Remote::DF_UP:
250     case Remote::UP:
251     {
252       sl.up();
253       sl.draw();
254       drawShowing();
255       drawIndicators();
256       BoxStack::getInstance()->update(this);
257       return 2;
258     }
259     case Remote::DF_DOWN:
260     case Remote::DOWN:
261     {
262       sl.down();
263       sl.draw();
264       drawShowing();
265       drawIndicators();
266       BoxStack::getInstance()->update(this);
267       return 2;
268     }
269     case Remote::SKIPBACK:
270     {
271       sl.pageUp();
272       sl.draw();
273       drawShowing();
274       drawIndicators();
275       BoxStack::getInstance()->update(this);
276       return 2;
277     }
278     case Remote::SKIPFORWARD:
279     {
280       sl.pageDown();
281       sl.draw();
282       drawShowing();
283       drawIndicators();
284       BoxStack::getInstance()->update(this);
285       return 2;
286     }
287     case Remote::OK:
288     {
289       RecTimer* recTimer = NULL;
290       if (recTimerList) recTimer = (RecTimer*)sl.getCurrentOptionData();
291       if (recTimer == NULL) return 2;
292
293       VTimerEdit* v = new VTimerEdit(recTimer);
294       v->setParent(this);
295       v->draw();
296       BoxStack::getInstance()->add(v);
297       BoxStack::getInstance()->update(v);
298
299       return 2;
300     }
301     case Remote::BACK:
302     {
303       return 4;
304     }
305   }
306   // stop command getting to any more views
307   return 1;
308 }
309
310 void VTimerList::processMessage(Message* m)
311 {
312   if (m->message == Message::MOUSE_MOVE)
313   {
314     if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
315     {
316       sl.draw();
317       BoxStack::getInstance()->update(this);
318     }
319   }
320   else if (m->message == Message::MOUSE_LBDOWN)
321   {
322     if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
323     {
324       BoxStack::getInstance()->handleCommand(Remote::OK); //simulate OK press
325     }
326     else
327     {
328       //check if press is outside this view! then simulate cancel
329       int x=(m->parameter>>16)-getScreenX();
330       int y=(m->parameter&0xFFFF)-getScreenY();
331       if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
332       {
333         BoxStack::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
334       }
335     }
336   }
337   else if (m->message == Message::DELETE_SELECTED_TIMER)
338   {
339     RecTimer* recTimer = (RecTimer*)sl.getCurrentOptionData();
340     if (recTimer == NULL) return;
341     Log::getInstance()->log("VTimerList", Log::DEBUG, "Got timer to delete");
342
343   
344     ULONG retval = VDR::getInstance()->deleteTimer(recTimer);
345     Log::getInstance()->log("VTimerList", Log::DEBUG, "Got return fron delete timer: %lu", retval);
346     
347     if (retval != 10)
348     {
349       VInfo* errorBox = new VInfo();
350       errorBox->setSize(360, 200);
351       errorBox->createBuffer();
352       if (Video::getInstance()->getFormat() == Video::PAL)
353         errorBox->setPosition(190, 170);
354       else
355         errorBox->setPosition(180, 120);
356
357     
358       if (retval == 1) errorBox->setOneLiner(tr("Timers being edited at VDR, please try later"));
359       else if (retval == 3)  errorBox->setOneLiner(tr("Unable to delete timer - timer is running"));
360       else if (retval == 4)  errorBox->setOneLiner(tr("Error - timer not found at VDR"));
361       else                   errorBox->setOneLiner(tr("Unknown error"));
362
363       errorBox->setExitable();
364       errorBox->setBorderOn(1);
365       errorBox->setTitleBarColour(Colour::DANGER);
366       errorBox->okButton();
367       errorBox->draw();
368       BoxStack::getInstance()->add(errorBox);
369       BoxStack::getInstance()->update(errorBox);
370     }
371     
372     int saveIndex = sl.getCurrentOption();
373     int saveTop = sl.getTopOption();
374      
375     if (recTimerList)
376     {
377       for (UINT i = 0; i < recTimerList->size(); i++)
378       {
379         delete (*recTimerList)[i];
380       }
381
382       recTimerList->clear();
383       delete recTimerList;
384     }
385
386     sl.clear();
387     load();
388
389     sl.hintSetCurrent(saveIndex);
390     sl.hintSetTop(saveTop);
391     draw();
392     BoxStack::getInstance()->update(this);
393   }
394 }
395