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