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