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