]> git.vomp.tv Git - vompclient.git/blob - vsleeptimer.cc
Compile fix for MVP re: location change of hmsf
[vompclient.git] / vsleeptimer.cc
1 /*
2     Copyright 2008 Thomas Steger
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 "vsleeptimer.h"
22
23 #include "remote.h"
24 #include "wsymbol.h"
25 #include "colour.h"
26 #include "video.h"
27 #include "timers.h"
28 #include "boxstack.h"
29 #include "command.h"
30
31 Sleeptimer* Sleeptimer::instance = NULL;
32
33 Sleeptimer::Sleeptimer()
34 {
35    if (instance) return;
36    sec = -1;
37    active = false;
38    instance = this;
39    
40 }
41
42 Sleeptimer::~Sleeptimer()
43 {
44    instance = NULL;
45 }
46
47
48 const char* Sleeptimer::SetTime()
49 {
50    if (sec <890)
51      {
52         sec=900;
53         if (active==false)
54         {
55            active = true;
56            threadStart();
57         }
58         
59         return "0:15";
60      }
61    else if (sec <1790)
62      {
63         sec = 1800;
64         if (active==false)
65         {
66            active = true;
67            threadStart();
68         }
69         
70         return "0:30";
71      }
72    else if (sec < 2690)
73      {
74         sec = 2700;
75         if (active==false)
76         {
77            active = true;  
78            threadStart();
79         }
80         
81         return "0:45";
82      }
83    else if (sec < 3590)
84      {
85         sec = 3600;
86         if (active==false)
87         {
88            active = true;
89            threadStart();
90         }
91         
92         return "1:00";
93      }
94    else if (sec < 4490)
95      {
96         sec = 4500;
97         if (active==false)
98         {
99            active = true;
100            threadStart();
101         }
102         
103         return "1:15";
104      }
105    else if (sec < 5390)
106      {
107         sec = 5400;
108         if (active==false)
109         {
110            active = true;
111            threadStart();
112         }
113         
114         return "1:30";
115      }
116    else if (sec < 6290)
117      {
118         sec = 6300;
119         if (active==false)
120         {
121            active = true;
122            threadStart();
123         }
124         
125         return "1:45";
126      }
127    else if (sec < 7190)
128      {
129         sec = 7200;
130         if (active==false)
131         {
132            active = true;
133            threadStart();
134         }
135         
136         return "2:00";
137         
138      }
139    else
140      {
141         sec = -1;
142         if (active==true)
143         shutdown();
144         return "AUS";
145      }
146    
147 }
148
149 Sleeptimer* Sleeptimer::getInstance()
150 {
151      return instance;
152 }
153
154 void Sleeptimer::threadMethod()
155 {
156    
157    while (sec>-1 && active==true)
158      {
159         sec--;
160         if (sec<31 && sec>-1)
161           {
162              VCountdown* count = new VCountdown();
163              char* temp = (char*)malloc(20);
164              sprintf(temp, "0:%02d", sec);
165              count->draw(temp);
166              free(temp);
167              Message* m1 = new Message();
168              m1->message = Message::ADD_VIEW;
169          m1->to = BoxStack::getInstance();
170              m1->parameter.num = (ULONG)count;
171              Command::getInstance()->postMessageNoLock(m1);
172           }
173          MILLISLEEP(1000);
174         
175         
176         if (sec==-1)
177           {
178              Message* m2 = new Message(); // Delete self
179              m2->message = Message::UDP_BUTTON;
180              m2->to = Command::getInstance();
181              m2->from = this;
182                  m2->parameter.num = 61;
183              Command::getInstance()->postMessageFromOuterSpace(m2);
184              shutdown();
185           }
186         
187      }
188    
189      
190 }
191
192 void Sleeptimer::shutdown()
193 {
194    if (active==true)
195      {
196         sec=-1; 
197         threadCancel();
198         active = false;
199      }
200    
201 }
202
203
204 VSleeptimer::VSleeptimer()
205 {
206   setSize(100, 28);
207   createBuffer();
208   if (Video::getInstance()->getFormat() == Video::PAL)
209   {
210     setPosition(100, 499);
211   }
212   else
213   {
214     setPosition(90, 400);
215   }
216 }
217
218 VSleeptimer::~VSleeptimer()
219 {
220   // Make sure the timer is deleted
221   Timers::getInstance()->cancelTimer(this, 1);
222 }
223
224 void VSleeptimer::draw()
225 {
226    fillColour(DrawStyle::VIEWBACKGROUND);
227    WSymbol w;
228    TEMPADD(&w);
229    w.nextSymbol = WSymbol::CLOCK;
230    w.setPosition(3, 0);
231    w.draw();
232  
233    Boxx::draw();
234    drawText(displaySleeptimer,50,2,DrawStyle::LIGHTTEXT);
235    Timers::getInstance()->setTimerD(this, 1, 2);
236 }
237
238 void VSleeptimer::timercall(int clientReference)
239 {
240   // delete me!
241   Message* m = new Message(); // Delete self
242   m->message = Message::CLOSE_ME;
243   m->to = BoxStack::getInstance();
244   m->from = this;
245   Command::getInstance()->postMessageFromOuterSpace(m);
246 }
247
248 int VSleeptimer::handleCommand(int command)
249 {
250   switch(command)
251   {
252     case Remote::GO:
253     {
254       displaySleeptimer = Sleeptimer::getInstance()->SetTime();
255       draw();
256       BoxStack::getInstance()->update(this);
257       // handled
258       return 2;
259     }
260   }
261
262   // allow command to drop through to other views
263   return 0;
264 }
265
266
267
268
269 VCountdown::VCountdown()
270 {
271
272   setSize(100, 28);
273   createBuffer();
274   if (Video::getInstance()->getFormat() == Video::PAL)
275   {
276     setPosition(100, 499);
277   }
278   else
279   {
280     setPosition(90, 400);
281   }
282 }
283
284 VCountdown::~VCountdown()
285 {
286   // Make sure the timer is deleted
287   Timers::getInstance()->cancelTimer(this, 1);
288 }
289
290 void VCountdown::draw(const char* sec)
291 {
292    
293    fillColour(DrawStyle::VIEWBACKGROUND);
294    WSymbol w;
295    TEMPADD(&w);
296    w.nextSymbol = WSymbol::CLOCK;
297    w.nextColour = DrawStyle::RED;
298    w.setPosition(3, 0);
299    w.draw();
300  
301    Boxx::draw();
302    drawText(sec,50,2,DrawStyle::RED);
303    Timers::getInstance()->setTimerD(this, 1, 1);
304 }
305
306 void VCountdown::timercall(int clientReference)
307 {
308   // delete me!
309   Message* m = new Message(); // Delete self
310   m->message = Message::CLOSE_ME;
311   m->to = BoxStack::getInstance();
312   m->from = this;
313   Command::getInstance()->postMessageFromOuterSpace(m);
314 }