]> git.vomp.tv Git - vompclient.git/blob - vwelcome.cc
Add static icons in menu
[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, 240);
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, 200);
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 = localtime(&t);
164   strftime(timeString, 19, "%H:%M", tms);
165   drawTextRJ(timeString, 450, 5, DrawStyle::LIGHTTEXT);
166
167   time_t dt = 60 - (t % 60);  // seconds to the next minute
168   if (dt == 0) dt = 60; // advance a whole minute if necessary
169   dt += t;  // get a time_t value for it rather than using duration
170   // (so it will occur at the actual second and not second and a half)
171
172   Timers::getInstance()->setTimerT(this, 1, dt);
173 }
174
175 void VWelcome::timercall(int clientReference)
176 {
177 #ifndef GRADIENT_DRAWING
178   drawClock();
179 #else
180   draw();
181 #endif
182   boxstack->update(this, &clockRegion);
183 }
184
185 int VWelcome::handleCommand(int command)
186 {
187   switch(command)
188   {
189     case Remote::DF_UP:
190     case Remote::UP:
191     {
192       sl.up();
193       sl.draw();
194       boxstack->update(this);
195       return 2;
196     }
197     case Remote::DF_DOWN:
198     case Remote::DOWN:
199     {
200       sl.down();
201       sl.draw();
202       boxstack->update(this);
203       return 2;
204     }
205     case Remote::ONE:
206     {
207       doChannelsList();
208       return 2;
209     }
210     case Remote::TWO:
211     {
212       doRadioList();
213       return 2;
214     }
215     case Remote::THREE:
216     {
217       doRecordingsList();
218       return 2;
219     }
220     case Remote::FOUR:
221     {
222       doTimersList();
223       return 2;
224     }
225     case Remote::FIVE:
226     {
227 #ifdef VOMP_PLATTFORM_MVP
228       doMediaList();
229 #endif
230       return 2;
231     }
232     case Remote::SIX:
233     {
234       doOptions();
235       return 2;
236     }
237     case Remote::SEVEN:
238     {
239       Command::getInstance()->doReboot();
240       return 2;
241     }
242     case Remote::OK:
243     {
244       ULONG option = sl.getCurrentOptionData();
245       if (option == 1)
246       {
247         doChannelsList();
248         return 2;
249       }
250       else if (option == 2)
251       {
252         doRadioList();
253         return 2;
254       }
255       else if (option == 3)
256       {
257         doRecordingsList();
258         return 2;
259       }
260       else if (option == 4)
261       {
262         doTimersList();
263         return 2;
264       }
265       else if (option == 5)
266       {
267         doMediaList();
268         return 2;
269       }
270       else if (option == 6)
271       {
272         doOptions();
273         return 2;
274       }
275       else if (option == 7)
276       {
277         Command::getInstance()->doReboot();
278         return 2;
279       }
280       return 2; // never gets here
281     }
282 //#ifdef DEV
283     case Remote::NINE:
284     {
285       VScreensaver* vscreensaver = new VScreensaver();
286       boxstack->add(vscreensaver);
287       vscreensaver->draw();
288 //      boxstack->update(vscreensaver);
289
290       return 2;
291     }
292 //#endif
293
294     // Test
295 //    case Remote::BACK:
296 //    {
297 //      return 4;
298 //    }
299
300   }
301   return 1;
302 }
303
304 void VWelcome::doChannelsList()
305 {
306   ChannelList* chanList = VDR::getInstance()->getChannelsList(VDR::VIDEO);
307
308   if (chanList)
309   {
310     VChannelList* vchan = new VChannelList(VDR::VIDEO);
311     vchan->setList(chanList);
312
313     vchan->draw();
314     boxstack->add(vchan);
315     boxstack->update(vchan);
316   }
317   else
318   {
319     Command::getInstance()->connectionLost();
320   }
321 }
322
323 void VWelcome::doRadioList()
324 {
325   ChannelList* chanList = VDR::getInstance()->getChannelsList(VDR::RADIO);
326
327   if (chanList)
328   {
329     VChannelList* vchan = new VChannelList(VDR::RADIO);
330     vchan->setList(chanList);
331
332     vchan->draw();
333     boxstack->add(vchan);
334     boxstack->update(vchan);
335   }
336   else
337   {
338     Command::getInstance()->connectionLost();
339   }
340 }
341
342 void VWelcome::doRecordingsList()
343 {
344         VRecordingList* vrec;
345         if (Command::getInstance()->advMenues()) {
346            vrec =  new VRecordingListAdvanced();
347         } else {
348            vrec = new VRecordingListClassic();
349         }
350         vrec->draw();
351         boxstack->add(vrec);
352         boxstack->update(vrec);
353
354         if (!vrec->load())
355         {
356                 Command::getInstance()->connectionLost();
357         }
358 }
359
360 void VWelcome::doMediaList()
361 {
362 #ifdef VOMP_MEDIAPLAYER
363   VMediaList::createList();
364 #endif
365 }
366
367 void VWelcome::doTimersList()
368 {
369   VTimerList* vtl = new VTimerList();
370   if (!vtl->load())
371   {
372     delete vtl;
373     Command::getInstance()->connectionLost();
374     return;
375   }
376   
377   vtl->draw();
378   boxstack->add(vtl);
379   boxstack->update(vtl);
380 }
381
382 void VWelcome::doOptions()
383 {
384 //  VOptionsMenu* voptionsmenu = new VOptionsMenu();
385 //  voptionsmenu->draw();
386 //  boxstack->add(voptionsmenu);
387 //  boxstack->updateView(voptionsmenu);
388
389   VOpts* vopts = new VOpts();
390   vopts->draw();
391   boxstack->add(vopts);
392   boxstack->update(vopts);
393 }
394
395 void VWelcome::processMessage(Message* m)
396 {
397   if (m->message == Message::MOUSE_MOVE)
398   {
399     if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
400     {
401       sl.draw();
402       boxstack->update(this);
403     }
404   }
405   else if (m->message == Message::MOUSE_LBDOWN)
406   {
407     if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
408     {
409       boxstack->handleCommand(Remote::OK); //simulate OK press
410     }
411   }
412 }