]> git.vomp.tv Git - vompclient.git/blob - vwelcome.cc
Fix timercall/boxstack->update thread clash with boxstack->remove
[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 void VWelcome::preDelete()
81 {
82   Timers::getInstance()->cancelTimer(this, 1);
83 }
84
85 VWelcome::~VWelcome()
86 {
87 }
88
89 void VWelcome::draw()
90 {
91   TBBoxx::draw();
92   drawClock();
93 }
94
95 void VWelcome::drawClock()
96 {
97   // Blank the area first
98   rectangle(area.w - 60, 0, 60, 30, titleBarColour);
99
100   char timeString[20];
101   time_t t;
102   time(&t);
103   struct tm* tms = localtime(&t);
104   strftime(timeString, 19, "%H:%M", tms);
105   drawTextRJ(timeString, 450, 5, Colour::LIGHTTEXT);
106
107   time_t dt = 60 - (t % 60);  // seconds to the next minute
108   if (dt == 0) dt = 60; // advance a whole minute if necessary
109   dt += t;  // get a time_t value for it rather than using duration
110   // (so it will occur at the actual second and not second and a half)
111
112   Timers::getInstance()->setTimerT(this, 1, dt);
113 }
114
115 void VWelcome::timercall(int clientReference)
116 {
117   drawClock();
118   boxstack->update(this, &clockRegion);
119 }
120
121 int VWelcome::handleCommand(int command)
122 {
123   switch(command)
124   {
125     case Remote::DF_UP:
126     case Remote::UP:
127     {
128       sl.up();
129       sl.draw();
130       boxstack->update(this);
131       return 2;
132     }
133     case Remote::DF_DOWN:
134     case Remote::DOWN:
135     {
136       sl.down();
137       sl.draw();
138       boxstack->update(this);
139       return 2;
140     }
141     case Remote::ONE:
142     {
143       doChannelsList();
144       return 2;
145     }
146     case Remote::TWO:
147     {
148       doRadioList();
149       return 2;
150     }
151     case Remote::THREE:
152     {
153       doRecordingsList();
154       return 2;
155     }
156     case Remote::FOUR:
157     {
158       doTimersList();
159       return 2;
160     }
161     case Remote::FIVE:
162     {
163       doMediaList();
164       return 2;
165     }
166     case Remote::SIX:
167     {
168       doOptions();
169       return 2;
170     }
171     case Remote::SEVEN:
172     {
173       Command::getInstance()->doReboot();
174     }
175     case Remote::OK:
176     {
177       ULONG option = sl.getCurrentOptionData();
178       if (option == 1)
179       {
180         doChannelsList();
181         return 2;
182       }
183       else if (option == 2)
184       {
185         doRadioList();
186         return 2;
187       }
188       else if (option == 3)
189       {
190         doRecordingsList();
191         return 2;
192       }
193       else if (option == 4)
194       {
195         doTimersList();
196         return 2;
197       }
198       else if (option == 5)
199       {
200         doMediaList();
201         return 2;
202       }
203       else if (option == 6)
204       {
205         doOptions();
206         return 2;
207       }
208       else if (option == 7)
209       {
210         Command::getInstance()->doReboot();
211         return 2;
212       }
213       return 2; // never gets here
214     }
215 //#ifdef DEV
216     case Remote::NINE:
217     {
218       VScreensaver* vscreensaver = new VScreensaver();
219       boxstack->add(vscreensaver);
220       vscreensaver->draw();
221 //      boxstack->update(vscreensaver);
222
223       return 2;
224     }
225 //#endif
226
227     // Test
228 //    case Remote::BACK:
229 //    {
230 //      return 4;
231 //    }
232
233   }
234   return 1;
235 }
236
237 void VWelcome::doChannelsList()
238 {
239   ChannelList* chanList = VDR::getInstance()->getChannelsList(VDR::VIDEO);
240
241   if (chanList)
242   {
243     VChannelList* vchan = new VChannelList(VDR::VIDEO);
244     vchan->setList(chanList);
245
246     vchan->draw();
247     boxstack->add(vchan);
248     boxstack->update(vchan);
249   }
250   else
251   {
252     Command::getInstance()->connectionLost();
253   }
254 }
255
256 void VWelcome::doRadioList()
257 {
258   ChannelList* chanList = VDR::getInstance()->getChannelsList(VDR::RADIO);
259
260   if (chanList)
261   {
262     VChannelList* vchan = new VChannelList(VDR::RADIO);
263     vchan->setList(chanList);
264
265     vchan->draw();
266     boxstack->add(vchan);
267     boxstack->update(vchan);
268   }
269   else
270   {
271     Command::getInstance()->connectionLost();
272   }
273 }
274
275 void VWelcome::doRecordingsList()
276 {
277   VRecordingList* vrec = new VRecordingList();
278   vrec->draw();
279   boxstack->add(vrec);
280   boxstack->update(vrec);
281
282   if (!vrec->load())
283   {
284     Command::getInstance()->connectionLost();
285   }
286 }
287
288 void VWelcome::doMediaList()
289 {
290   VMediaList::createList();
291 }
292
293 void VWelcome::doTimersList()
294 {
295   VTimerList* vtl = new VTimerList();
296   if (!vtl->load())
297   {
298     delete vtl;
299     Command::getInstance()->connectionLost();
300     return;
301   }
302   
303   vtl->draw();
304   boxstack->add(vtl);
305   boxstack->update(vtl);
306 }
307
308 void VWelcome::doOptions()
309 {
310 //  VOptionsMenu* voptionsmenu = new VOptionsMenu();
311 //  voptionsmenu->draw();
312 //  boxstack->add(voptionsmenu);
313 //  boxstack->updateView(voptionsmenu);
314
315   VOpts* vopts = new VOpts();
316   vopts->draw();
317   boxstack->add(vopts);
318   boxstack->update(vopts);
319 }
320
321 void VWelcome::processMessage(Message* m)
322 {
323   if (m->message == Message::MOUSE_MOVE)
324   {
325     if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
326     {
327       sl.draw();
328       boxstack->update(this);
329     }
330   }
331   else if (m->message == Message::MOUSE_LBDOWN)
332   {
333     if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
334     {
335       boxstack->handleCommand(Remote::OK); //simulate OK press
336     }
337   }
338 }