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