]> git.vomp.tv Git - vompclient.git/blob - vwelcome.cc
*** empty log message ***
[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 #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   // Put updateView through master mutex since boxstack is not mutex protected
115   Message* m = new Message();
116   m->message = Message::REDRAW;
117   m->to = boxstack;
118   m->from = this;
119   m->parameter = (ULONG)&clockRegion;
120   Command::getInstance()->postMessageFromOuterSpace(m);
121 }
122
123 int VWelcome::handleCommand(int command)
124 {
125   switch(command)
126   {
127     case Remote::DF_UP:
128     case Remote::UP:
129     {
130       sl.up();
131       sl.draw();
132       boxstack->update(this);
133       return 2;
134     }
135     case Remote::DF_DOWN:
136     case Remote::DOWN:
137     {
138       sl.down();
139       sl.draw();
140       boxstack->update(this);
141       return 2;
142     }
143     case Remote::ONE:
144     {
145       doChannelsList();
146       return 2;
147     }
148     case Remote::TWO:
149     {
150       doRadioList();
151       return 2;
152     }
153     case Remote::THREE:
154     {
155       doRecordingsList();
156       return 2;
157     }
158     case Remote::FOUR:
159     {
160       doTimersList();
161       return 2;
162     }
163     case Remote::FIVE:
164     {
165       doMediaList();
166       return 2;
167     }
168     case Remote::SIX:
169     {
170       doOptions();
171       return 2;
172     }
173     case Remote::SEVEN:
174     {
175       Command::getInstance()->doReboot();
176     }
177     case Remote::OK:
178     {
179       ULONG option = sl.getCurrentOptionData();
180       if (option == 1)
181       {
182         doChannelsList();
183         return 2;
184       }
185       else if (option == 2)
186       {
187         doRadioList();
188         return 2;
189       }
190       else if (option == 3)
191       {
192         doRecordingsList();
193         return 2;
194       }
195       else if (option == 4)
196       {
197         doTimersList();
198         return 2;
199       }
200       else if (option == 5)
201       {
202         doMediaList();
203         return 2;
204       }
205       else if (option == 6)
206       {
207         doOptions();
208         return 2;
209       }
210       else if (option == 7)
211       {
212         Command::getInstance()->doReboot();
213         return 2;
214       }
215       return 2; // never gets here
216     }
217 //#ifdef DEV
218     case Remote::NINE:
219     {
220       VScreensaver* vscreensaver = new VScreensaver();
221       boxstack->add(vscreensaver);
222       vscreensaver->draw();
223 //      boxstack->update(vscreensaver);
224
225       return 2;
226     }
227 //#endif
228
229     // Test
230 //    case Remote::BACK:
231 //    {
232 //      return 4;
233 //    }
234
235   }
236   return 1;
237 }
238
239 void VWelcome::doChannelsList()
240 {
241   ChannelList* chanList = VDR::getInstance()->getChannelsList(VDR::VIDEO);
242
243   if (chanList)
244   {
245     VChannelList* vchan = new VChannelList(VDR::VIDEO);
246     vchan->setList(chanList);
247
248     vchan->draw();
249     boxstack->add(vchan);
250     boxstack->update(vchan);
251   }
252   else
253   {
254     Command::getInstance()->connectionLost();
255   }
256 }
257
258 void VWelcome::doRadioList()
259 {
260   ChannelList* chanList = VDR::getInstance()->getChannelsList(VDR::RADIO);
261
262   if (chanList)
263   {
264     VChannelList* vchan = new VChannelList(VDR::RADIO);
265     vchan->setList(chanList);
266
267     vchan->draw();
268     boxstack->add(vchan);
269     boxstack->update(vchan);
270   }
271   else
272   {
273     Command::getInstance()->connectionLost();
274   }
275 }
276
277 void VWelcome::doRecordingsList()
278 {
279   VRecordingList* vrec = new VRecordingList();
280   vrec->draw();
281   boxstack->add(vrec);
282   boxstack->update(vrec);
283
284   if (!vrec->load())
285   {
286     Command::getInstance()->connectionLost();
287   }
288 }
289
290 void VWelcome::doMediaList()
291 {
292   VMediaList::createList();
293 }
294
295 void VWelcome::doTimersList()
296 {
297   VTimerList* vtl = new VTimerList();
298   if (!vtl->load())
299   {
300     delete vtl;
301     Command::getInstance()->connectionLost();
302     return;
303   }
304   
305   vtl->draw();
306   boxstack->add(vtl);
307   boxstack->update(vtl);
308 }
309
310 void VWelcome::doOptions()
311 {
312 //  VOptionsMenu* voptionsmenu = new VOptionsMenu();
313 //  voptionsmenu->draw();
314 //  boxstack->add(voptionsmenu);
315 //  boxstack->updateView(voptionsmenu);
316
317   VOpts* vopts = new VOpts();
318   vopts->draw();
319   boxstack->add(vopts);
320   boxstack->update(vopts);
321 }
322
323 void VWelcome::processMessage(Message* m)
324 {
325   if (m->message == Message::MOUSE_MOVE)
326   {
327     if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
328     {
329       sl.draw();
330       boxstack->update(this);
331     }
332   }
333   else if (m->message == Message::MOUSE_LBDOWN)
334   {
335     if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
336     {
337       boxstack->handleCommand(Remote::OK); //simulate OK press
338     }
339   }
340 }