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