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