]> git.vomp.tv Git - vompclient.git/blob - vwelcome.cc
43 CWFs
[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, see <https://www.gnu.org/licenses/>.
18 */
19
20
21 #include "log.h"
22 #include "input.h"
23 #include "vdr.h"
24 #include "vchannellist.h"
25 #include "vrecordinglistclassic.h"
26 #include "vrecordinglistadvanced.h"
27 #include "vtimerlist.h"
28 #include "control.h"
29 #include "message.h"
30 #include "colour.h"
31 #include "video.h"
32 #include "i18n.h"
33 #include "vscreensaver.h"
34 #include "vmedialist.h"
35 #include "boxstack.h"
36 #include "vopts.h"
37 #include "staticartwork.h"
38
39 #include "vwelcome.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 #ifndef GRADIENT_DRAWING
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 #else
62   setSize(460, 280);
63   createBuffer();
64   setPosition(140, 150);
65 #endif
66
67   setTitleBarOn(1);
68   setTitleBarColour(DrawStyle::TITLEBARBACKGROUND);
69
70
71 #ifndef GRADIENT_DRAWING
72   jpeg.setPosition(240, 60);
73 #ifndef _MIPS_ARCH
74   jpeg.init("/vdr.jpg");
75 #else
76   jpeg.init("vdr.jpg");
77 #endif
78   add(&jpeg);
79 #else
80   vdr.setPosition(250, 65);
81   vdr.setSize(180, 160);
82   TVMediaInfo sinfo;
83   sinfo.setStaticArtwork(sa_vdrlogo);
84   vdr.setTVMedia(sinfo, WTVMedia::ZoomHorizontal);
85   add(&vdr);
86
87 #endif
88
89   sl.setPosition(20, 40);
90 #ifdef GRADIENT_DRAWING
91   sl.addColumn(0);
92   sl.addColumn(25);
93   sl.setLinesPerOption(1.5f);
94   sl.setSize(200, 230);
95 #else
96   sl.setSize(200, 160);
97 #endif
98   add(&sl);
99
100   setTitleText(tr("Welcome"));
101
102
103   TVMediaInfo *info= new TVMediaInfo();
104   info->setStaticArtwork(sa_tv);
105   sl.addOption(tr("1. Live TV"), reinterpret_cast<void*>(1), 1, info);
106
107   info= new TVMediaInfo();
108   info->setStaticArtwork(sa_radio);
109   sl.addOption(tr("2. Radio"), reinterpret_cast<void*>(2), 0, info);
110
111   info= new TVMediaInfo();
112   info->setStaticArtwork(sa_recordings);
113   sl.addOption(tr("3. Recordings"), reinterpret_cast<void*>(3), 0, info);
114
115   info= new TVMediaInfo();
116   info->setStaticArtwork(sa_timers);
117   sl.addOption(tr("4. Timers"), reinterpret_cast<void*>(4), 0, info);
118 #ifdef VOMP_PLATTFORM_MVP
119   sl.addOption(tr("5. MediaPlayer"), reinterpret_cast<void*>(5), 0);
120 #endif
121
122   info= new TVMediaInfo();
123   info->setStaticArtwork(sa_properties);
124   sl.addOption(tr("6. Options"), reinterpret_cast<void*>(6), 0,info);
125
126   info= new TVMediaInfo();
127   info->setStaticArtwork(sa_restart);
128   // NCONFIG
129 #ifndef VOMP_HAS_EXIT
130   sl.addOption(tr("7. Reboot"), reinterpret_cast<void*>(7), 0,info);
131 #else
132   sl.addOption(tr("7. Exit"), reinterpret_cast<void*>(7), 0,info);
133 #endif
134
135   MessageQueue::getInstance()->addReceiver(this);
136 }
137
138 void VWelcome::preDelete()
139 {
140   Timers::getInstance()->cancelTimer(this, 1);
141 }
142
143 VWelcome::~VWelcome()
144 {
145   MessageQueue::getInstance()->removeReceiver(this);
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
166   strftime(timeString, 19, "%H:%M", &tms);
167   drawTextRJ(timeString, 450, 5, DrawStyle::LIGHTTEXT);
168
169   time_t dt = 60 - (t % 60);  // seconds to the next minute
170   if (dt == 0) dt = 60; // advance a whole minute if necessary
171   dt += t;  // get a time_t value for it rather than using duration
172   // (so it will occur at the actual second and not second and a half)
173
174   Timers::getInstance()->setTimerT(this, 1, dt);
175 }
176
177 void VWelcome::timercall(int /* clientReference */)
178 {
179 #ifndef GRADIENT_DRAWING
180   drawClock();
181 #else
182   draw();
183 #endif
184   boxstack->update(this, &clockRegion);
185 }
186
187 int VWelcome::handleCommand(int command)
188 {
189   switch(command)
190   {
191     case Input::UP:
192     {
193       sl.up();
194       sl.draw();
195       boxstack->update(this);
196       return BoxStack::COMMAND_HANDLED;
197     }
198     case Input::DOWN:
199     {
200       sl.down();
201       sl.draw();
202       boxstack->update(this);
203       return BoxStack::COMMAND_HANDLED;
204     }
205     case Input::ONE:
206     {
207       doChannelsList();
208       return BoxStack::COMMAND_HANDLED;
209     }
210     case Input::TWO:
211     {
212       doRadioList();
213       return BoxStack::COMMAND_HANDLED;
214     }
215     case Input::THREE:
216     {
217       doRecordingsList();
218       return BoxStack::COMMAND_HANDLED;
219     }
220     case Input::FOUR:
221     {
222       doTimersList();
223       return BoxStack::COMMAND_HANDLED;
224     }
225     case Input::FIVE:
226     {
227 #ifdef VOMP_PLATTFORM_MVP
228       doMediaList();
229 #endif
230       return BoxStack::COMMAND_HANDLED;
231     }
232     case Input::SIX:
233     {
234       doOptions();
235       return BoxStack::COMMAND_HANDLED;
236     }
237     case Input::SEVEN:
238     {
239       Control::getInstance()->doReboot();
240       return BoxStack::COMMAND_HANDLED;
241     }
242     case Input::OK:
243     {
244       ULONG option = reinterpret_cast<ULONG>(sl.getCurrentOptionData());
245       if (option == 1)
246       {
247         doChannelsList();
248         return BoxStack::COMMAND_HANDLED;
249       }
250       else if (option == 2)
251       {
252         doRadioList();
253         return BoxStack::COMMAND_HANDLED;
254       }
255       else if (option == 3)
256       {
257         doRecordingsList();
258         return BoxStack::COMMAND_HANDLED;
259       }
260       else if (option == 4)
261       {
262         doTimersList();
263         return BoxStack::COMMAND_HANDLED;
264       }
265       else if (option == 5)
266       {
267         doMediaList();
268         return BoxStack::COMMAND_HANDLED;
269       }
270       else if (option == 6)
271       {
272         doOptions();
273         return BoxStack::COMMAND_HANDLED;
274       }
275       else if (option == 7)
276       {
277         Control::getInstance()->doReboot();
278         return BoxStack::COMMAND_HANDLED;
279       }
280       return BoxStack::COMMAND_HANDLED; // never gets here
281     }
282 //#ifdef DEV
283     case Input::NINE:
284     {
285       VScreensaver* vscreensaver = new VScreensaver();
286       boxstack->add(vscreensaver);
287       vscreensaver->draw();
288 //      boxstack->update(vscreensaver);
289
290       return BoxStack::COMMAND_HANDLED;
291     }
292 //#endif
293
294     // Test
295 //    case Input::BACK:
296 //    {
297 //      return BoxStack::DELETE_ME;
298 //    }
299
300   }
301   return BoxStack::ABANDON_COMMAND;
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     Control::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     Control::getInstance()->connectionLost();
339   }
340 }
341
342 void VWelcome::doRecordingsList()
343 {
344         VRecordingList* vrec;
345         if (Control::getInstance()->isAdvMenus())
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                 Control::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     Control::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 - getScreenX(), m->tag - 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 - getScreenX(), m->tag - getScreenY()))
408     {
409       Input::sendInputKey(Input::OK);
410     }
411   }
412 }