]> git.vomp.tv Git - vompclient.git/blob - vtimerlist.cc
Update for windows
[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(RecTimerList* trtl)
24 {
25   recTimerList = trtl;
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
85   insertData();
86   sl.draw();
87   drawShowing();
88   drawIndicators();
89   drawClock();
90 }
91
92 VTimerList::~VTimerList()
93 {
94   Timers::getInstance()->cancelTimer(this, 1);
95   if (recTimerList)
96   {
97     for (UINT i = 0; i < recTimerList->size(); i++)
98     {
99       delete (*recTimerList)[i];
100     }
101
102     recTimerList->clear();
103     delete recTimerList;
104   }
105 }
106
107 void VTimerList::insertData()
108 {
109   char strA[300];
110   char strB[300];
111
112   struct tm* btime;
113
114   // FIXME all drawing stuff in this class and sl.clear somewhere?!
115
116   sl.addColumn(0);
117   sl.addColumn(110);
118
119   RecTimer* recTimer;
120   int first = 1;
121
122   for (UINT i = 0; i < recTimerList->size(); i++)
123   {
124     recTimer = (*recTimerList)[i];
125
126     btime = localtime((time_t*)&recTimer->startTime);
127     strftime(strA, 299, "%d/%m %H:%M ", btime);
128     SNPRINTF(strB, 299, "%s\t%s", strA, recTimer->getName());
129     sl.addOption(strB, (ULONG)recTimer, first);
130     first = 0;
131   }
132 }
133
134 void VTimerList::drawClock()
135 {
136   // Blank the area first
137   rectangle(area.w - 150, 0, 150, 30, titleBarColour);
138
139   char timeString[20];
140   time_t t;
141   time(&t);
142   struct tm* tms = localtime(&t);
143   strftime(timeString, 19, "%d/%m %H:%M:%S", tms);
144   drawTextRJ(timeString, 560, 5, Colour::LIGHTTEXT);
145
146   Timers::getInstance()->setTimerT(this, 1, t + 1);
147 }
148
149 void VTimerList::drawShowing()
150 {
151   int topOption = sl.getTopOption() + 1;
152   if (sl.getNumOptions() == 0) topOption = 0;
153
154   rectangle(220, 385, 180, 25, Colour::VIEWBACKGROUND);
155   char showing[200];
156   sprintf(showing, tr("%i to %i of %i"), topOption, sl.getBottomOption(), sl.getNumOptions());
157   drawText(showing, 220, 385, Colour::LIGHTTEXT);
158 }
159
160 void VTimerList::drawIndicators()
161 {
162   int top = sl.getTopOption();
163   int bottom = sl.getBottomOption();
164   int yinc = surface->getFontHeight() + 1;
165   RecTimer* recTimer;
166
167   rectangle(6, 44, 18, 15*yinc, Colour::VIEWBACKGROUND);
168
169   // The indexes recorded from the wselectlist into the index member of the RecTimer
170   // Is the same as the position in the vector of RecTimers
171   // Because they are in order, they don't change order and wselectlist starts from 0 up consecutively
172
173   int ypos = 44;
174   for (int current = top; current < bottom; current++)
175   {
176     recTimer = (*recTimerList)[current];
177
178     if (recTimer->recording) // Flashing red square
179     {
180       if (flipflop)
181       {
182         //rectangle(6, ypos, 18, 16, Colour::RED);
183         rectangle(6, ypos, 18, 16, Colour::RED);
184         drawText("R", 8, ypos-3, Colour::LIGHTTEXT);
185       }
186     }
187     else if (recTimer->pending)
188     {
189       rectangle(6, ypos, 18, 16, Colour::RED);
190       drawText("X", 8, ypos-3, Colour::BLACK);
191     }
192     else if (recTimer->active == 0)
193     {
194       rectangle(6, ypos, 18, 16, Colour::SELECTHIGHLIGHT);
195       drawText("X", 8, ypos-3, Colour::BLACK);
196     }
197     else
198     {
199 //      if (flipflop) rectangle(6, ypos, 18, 16, Colour::GREEN);
200     }
201
202     ypos += yinc;
203   }
204 }
205
206 void VTimerList::timercall(int clientReference)
207 {
208   drawClock();
209   ViewMan::getInstance()->updateView(this, &clockRegion);
210
211   flipflop = !flipflop;
212   drawIndicators();
213   ViewMan::getInstance()->updateView(this, &indicatorsRegion);
214 }
215
216 int VTimerList::handleCommand(int command)
217 {
218   switch(command)
219   {
220     case Remote::DF_UP:
221     case Remote::UP:
222     {
223       sl.up();
224       sl.draw();
225       drawShowing();
226       drawIndicators();
227       ViewMan::getInstance()->updateView(this);
228       return 2;
229     }
230     case Remote::DF_DOWN:
231     case Remote::DOWN:
232     {
233       sl.down();
234       sl.draw();
235       drawShowing();
236       drawIndicators();
237       ViewMan::getInstance()->updateView(this);
238       return 2;
239     }
240     case Remote::SKIPBACK:
241     {
242       sl.pageUp();
243       sl.draw();
244       drawShowing();
245       drawIndicators();
246       ViewMan::getInstance()->updateView(this);
247       return 2;
248     }
249     case Remote::SKIPFORWARD:
250     {
251       sl.pageDown();
252       sl.draw();
253       drawShowing();
254       drawIndicators();
255       ViewMan::getInstance()->updateView(this);
256       return 2;
257     }
258     case Remote::OK:
259     {
260       RecTimer* recTimer = NULL;
261       if (recTimerList) recTimer = (RecTimer*)sl.getCurrentOptionData();
262 //      {
263 //        int currentOption = sl.getCurrentOption();
264 //
265 //        for (UINT i = 0; i < recTimerList->size(); i++)
266 //        {
267 //          recTimer = (*recTimerList)[i];
268 //          if (currentOption == recTimer->index) break;
269 //        }
270 //      }
271
272       if (recTimer == NULL) return 2;
273
274       VTimerEdit* v = new VTimerEdit(recTimer);
275       ViewMan::getInstance()->add(v);
276       ViewMan::getInstance()->updateView(v);
277
278       return 2;
279     }
280     case Remote::BACK:
281     {
282       return 4;
283     }
284   }
285   // stop command getting to any more views
286   return 1;
287 }