]> git.vomp.tv Git - vompclient.git/blob - vwelcome.cc
New timers method
[vompclient.git] / vwelcome.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 "vwelcome.h"
22
23 VWelcome::VWelcome()
24 {
25   viewman = ViewMan::getInstance();
26
27   clockRegion.x = 400;
28   clockRegion.y = 0;
29   clockRegion.w = 60;
30   clockRegion.h = 30;
31
32   create(460, 200);
33   if (Video::getInstance()->getFormat() == Video::PAL)
34   {
35     setScreenPos(140, 170);
36   }
37   else
38   {
39     setScreenPos(130, 140);
40   }
41
42   setBackgroundColour(Colour::VIEWBACKGROUND);
43   setTitleBarOn(1);
44   setTitleBarColour(Colour::TITLEBARBACKGROUND);
45
46   sl.setSurface(surface);
47   sl.setSurfaceOffset(20, 40);
48   sl.setDimensions(170, 140);
49
50   setTitleText(tr("Welcome"));
51   sl.addOption(tr("1. Live TV"), 1, 1);
52   sl.addOption(tr("2. Radio"), 2, 0);
53   sl.addOption(tr("3. Recordings"), 3, 0);
54   sl.addOption(tr("4. Timers"), 4, 0);
55   sl.addOption(tr("5. Options"), 5, 0);
56   sl.addOption(tr("6. Reboot"), 6, 0);
57
58   jpeg.setSurface(surface);
59   jpeg.setSurfaceOffset(240, 60);
60 }
61
62 VWelcome::~VWelcome()
63 {
64   Timers::getInstance()->cancelTimer(this, 1);
65 }
66
67 void VWelcome::draw()
68 {
69   View::draw();
70   sl.draw();
71   jpeg.init("/vdr.jpg");
72   jpeg.draw();
73   drawClock();
74 }
75
76 void VWelcome::drawClock()
77 {
78   // Blank the area first
79   rectangle(area.w - 60, 0, 60, 30, titleBarColour);
80
81   char timeString[20];
82   time_t t;
83   time(&t);
84   struct tm* tms = localtime(&t);
85   strftime(timeString, 19, "%H:%M", tms);
86   drawTextRJ(timeString, 450, 5, Colour::LIGHTTEXT);
87
88   time_t dt = 60 - (t % 60);  // seconds to the next minute
89   if (dt == 0) dt = 60; // advance a whole minute if necessary
90   dt += t;  // get a time_t value for it rather than using duration
91   // (so it will occur at the actual second and not second and a half)
92
93   Timers::getInstance()->setTimerT(this, 1, dt);
94 }
95
96 void VWelcome::timercall(int clientReference)
97 {
98   drawClock();
99   // Put updateView through master mutex since viewman is not mutex protected
100   Message* m = new Message();
101   m->message = Message::REDRAW;
102   m->to = ViewMan::getInstance();
103   m->from = this;
104   m->parameter = (ULONG)&clockRegion;
105   Command::getInstance()->postMessageFromOuterSpace(m);
106 }
107
108 int VWelcome::handleCommand(int command)
109 {
110   switch(command)
111   {
112     case Remote::DF_UP:
113     case Remote::UP:
114     {
115       sl.up();
116       sl.draw();
117       viewman->updateView(this);
118       return 2;
119     }
120     case Remote::DF_DOWN:
121     case Remote::DOWN:
122     {
123       sl.down();
124       sl.draw();
125       viewman->updateView(this);
126       return 2;
127     }
128     case Remote::ONE:
129     {
130       doChannelsList();
131       return 2;
132     }
133     case Remote::TWO:
134     {
135       doRadioList();
136       return 2;
137     }
138     case Remote::THREE:
139     {
140       doRecordingsList();
141       return 2;
142     }
143     case Remote::FOUR:
144     {
145       doTimersList();
146       return 2;
147     }
148     case Remote::FIVE:
149     {
150       doOptions();
151       return 2;
152     }
153     case Remote::SIX:
154     {
155       Command::getInstance()->doReboot();
156     }
157     case Remote::OK:
158     {
159       ULONG option = sl.getCurrentOptionData();
160       if (option == 1)
161       {
162         doChannelsList();
163         return 2;
164       }
165       else if (option == 2)
166       {
167         doRadioList();
168         return 2;
169       }
170       else if (option == 3)
171       {
172         doRecordingsList();
173         return 2;
174       }
175       else if (option == 4)
176       {
177         doTimersList();
178         return 2;
179       }
180       else if (option == 5)
181       {
182         doOptions();
183         return 2;
184       }
185       else if (option == 6)
186       {
187         Command::getInstance()->doReboot();
188         return 2;
189       }
190       return 2; // never gets here
191     }
192 #ifdef DEV
193     case Remote::NINE:
194     {
195       return 2;
196     }
197 #endif
198
199     // Test
200 //    case Remote::BACK:
201 //    {
202 //      return 4;
203 //    }
204
205   }
206   return 1;
207 }
208
209 void VWelcome::doChannelsList()
210 {
211   ChannelList* chanList = VDR::getInstance()->getChannelsList(VDR::VIDEO);
212
213   if (chanList)
214   {
215     VChannelList* vchan = new VChannelList(VDR::VIDEO);
216     vchan->setList(chanList);
217
218     vchan->draw();
219     viewman->add(vchan);
220     viewman->updateView(vchan);
221   }
222   else
223   {
224     Command::getInstance()->connectionLost();
225   }
226 }
227
228 void VWelcome::doRadioList()
229 {
230   ChannelList* chanList = VDR::getInstance()->getChannelsList(VDR::RADIO);
231
232   if (chanList)
233   {
234     VChannelList* vchan = new VChannelList(VDR::RADIO);
235     vchan->setList(chanList);
236
237     vchan->draw();
238     viewman->add(vchan);
239     viewman->updateView(vchan);
240   }
241   else
242   {
243     Command::getInstance()->connectionLost();
244   }
245 }
246
247 void VWelcome::doRecordingsList()
248 {
249   VRecordingList* vrec = new VRecordingList();
250   vrec->draw();
251   viewman->add(vrec);
252   viewman->updateView(vrec);
253
254   if (!vrec->load())
255   {
256     Command::getInstance()->connectionLost();
257   }
258 }
259
260 void VWelcome::doTimersList()
261 {
262   VTimerList* vtl = new VTimerList();
263   viewman->add(vtl);
264   viewman->updateView(vtl);
265
266   if (!vtl->load())
267   {
268     Command::getInstance()->connectionLost();
269   }
270 }
271
272 void VWelcome::doOptions()
273 {
274   VOptionsMenu* voptionsmenu = new VOptionsMenu();
275   voptionsmenu->draw();
276   viewman->add(voptionsmenu);
277   viewman->updateView(voptionsmenu);
278 }
279
280 void VWelcome::processMessage(Message* m)
281 {
282   if (m->message == Message::MOUSE_MOVE)
283   {
284     if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
285     {
286       sl.draw();
287       viewman->updateView(this);
288     }
289   }
290   else if (m->message == Message::MOUSE_LBDOWN)
291   {
292     if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
293     {
294       ViewMan::getInstance()->handleCommand(Remote::OK); //simulate OK press
295     }
296   }
297 }