]> git.vomp.tv Git - vompclient.git/blob - vwelcome.cc
Fix subs running during pause - after a jump then quick pause
[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 #include "image.h"
39 #include "imageloader.h"
40
41 #include "vwelcome.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
85   ImageLoader* loader = ImageLoader::getInstance();
86
87   Image vdrImage = loader->createStatic(sa_vdrlogo);
88   vdr.setImage(vdrImage, WTVMedia::ZoomHorizontal);
89   add(&vdr);
90
91 #endif
92
93   sl.setPosition(20, 40);
94 #ifdef GRADIENT_DRAWING
95   sl.addColumn(0);
96   sl.addColumn(25);
97   sl.setLinesPerOption(1.5f);
98   sl.setSize(200, 230);
99 #else
100   sl.setSize(200, 160);
101 #endif
102   add(&sl);
103
104   setTitleText(tr("Welcome"));
105
106   Image icon;
107
108   icon = loader->createStatic(sa_tv);
109   sl.addOption(tr("1. Live TV"), reinterpret_cast<void*>(1), 1, icon);
110
111   icon = loader->createStatic(sa_radio);
112   sl.addOption(tr("2. Radio"), reinterpret_cast<void*>(2), 0, icon);
113
114   icon = loader->createStatic(sa_recordings);
115   sl.addOption(tr("3. Recordings"), reinterpret_cast<void*>(3), 0, icon);
116
117   icon = loader->createStatic(sa_timers);
118   sl.addOption(tr("4. Timers"), reinterpret_cast<void*>(4), 0, icon);
119 #ifdef VOMP_PLATTFORM_MVP
120   sl.addOption(tr("5. MediaPlayer"), reinterpret_cast<void*>(5), 0);
121 #endif
122
123   icon = loader->createStatic(sa_properties);
124   sl.addOption(tr("6. Options"), reinterpret_cast<void*>(6), 0, icon);
125
126   icon = loader->createStatic(sa_restart);
127   // NCONFIG
128 #ifndef VOMP_HAS_EXIT
129   sl.addOption(tr("7. Reboot"), reinterpret_cast<void*>(7), 0, icon);
130 #else
131   sl.addOption(tr("7. Exit"), reinterpret_cast<void*>(7), 0, icon);
132 #endif
133
134   MessageQueue::getInstance()->addReceiver(this);
135 }
136
137 void VWelcome::preDelete()
138 {
139   Timers::getInstance()->cancelTimer(this, 1);
140 }
141
142 VWelcome::~VWelcome()
143 {
144   MessageQueue::getInstance()->removeReceiver(this);
145 }
146
147 void VWelcome::draw()
148 {
149   TBBoxx::draw();
150   drawClock();
151 }
152
153 void VWelcome::drawClock()
154 {
155   // Blank the area first
156 #ifndef GRADIENT_DRAWING
157   rectangle(area.w - 60, 0, 60, 30, titleBarColour);
158 #endif
159   char timeString[20];
160   time_t t;
161   time(&t);
162   struct tm tms;
163   LOCALTIME_R(&t, &tms);
164
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 Input::UP:
191     {
192       sl.up();
193       sl.draw();
194       boxstack->update(this);
195       return BoxStack::COMMAND_HANDLED;
196     }
197     case Input::DOWN:
198     {
199       sl.down();
200       sl.draw();
201       boxstack->update(this);
202       return BoxStack::COMMAND_HANDLED;
203     }
204     case Input::ONE:
205     {
206       doChannelsList();
207       return BoxStack::COMMAND_HANDLED;
208     }
209     case Input::TWO:
210     {
211       doRadioList();
212       return BoxStack::COMMAND_HANDLED;
213     }
214     case Input::THREE:
215     {
216       doRecordingsList();
217       return BoxStack::COMMAND_HANDLED;
218     }
219     case Input::FOUR:
220     {
221       doTimersList();
222       return BoxStack::COMMAND_HANDLED;
223     }
224     case Input::FIVE:
225     {
226 #ifdef VOMP_PLATTFORM_MVP
227       doMediaList();
228 #endif
229       return BoxStack::COMMAND_HANDLED;
230     }
231     case Input::SIX:
232     {
233       doOptions();
234       return BoxStack::COMMAND_HANDLED;
235     }
236     case Input::SEVEN:
237     {
238       Control::getInstance()->doReboot();
239       return BoxStack::COMMAND_HANDLED;
240     }
241     case Input::OK:
242     {
243       ULONG option = reinterpret_cast<ULONG>(sl.getCurrentOptionData());
244       if (option == 1)
245       {
246         doChannelsList();
247         return BoxStack::COMMAND_HANDLED;
248       }
249       else if (option == 2)
250       {
251         doRadioList();
252         return BoxStack::COMMAND_HANDLED;
253       }
254       else if (option == 3)
255       {
256         doRecordingsList();
257         return BoxStack::COMMAND_HANDLED;
258       }
259       else if (option == 4)
260       {
261         doTimersList();
262         return BoxStack::COMMAND_HANDLED;
263       }
264       else if (option == 5)
265       {
266         doMediaList();
267         return BoxStack::COMMAND_HANDLED;
268       }
269       else if (option == 6)
270       {
271         doOptions();
272         return BoxStack::COMMAND_HANDLED;
273       }
274       else if (option == 7)
275       {
276         Control::getInstance()->doReboot();
277         return BoxStack::COMMAND_HANDLED;
278       }
279       return BoxStack::COMMAND_HANDLED; // never gets here
280     }
281 //#ifdef DEV
282     case Input::NINE:
283     {
284       VScreensaver* vscreensaver = new VScreensaver();
285       boxstack->add(vscreensaver);
286       vscreensaver->draw();
287 //      boxstack->update(vscreensaver);
288
289       return BoxStack::COMMAND_HANDLED;
290     }
291 //#endif
292
293     // Test
294 //    case Input::BACK:
295 //    {
296 //      return BoxStack::DELETE_ME;
297 //    }
298
299   }
300   return BoxStack::ABANDON_COMMAND;
301 }
302
303 void VWelcome::doChannelsList()
304 {
305   std::shared_ptr<ChannelList> chanList = VDR::getInstance()->getChannelsList(VDR::VIDEO);
306
307   if (chanList)
308   {
309     VChannelList* vchan = new VChannelList(VDR::VIDEO);
310     vchan->setList(chanList);
311
312     vchan->draw();
313     boxstack->add(vchan);
314     boxstack->update(vchan);
315   }
316   else
317   {
318     Control::getInstance()->connectionLost();
319   }
320 }
321
322 void VWelcome::doRadioList()
323 {
324   std::shared_ptr<ChannelList> chanList = VDR::getInstance()->getChannelsList(VDR::RADIO);
325
326   if (chanList)
327   {
328     VChannelList* vchan = new VChannelList(VDR::RADIO);
329     vchan->setList(chanList);
330
331     vchan->draw();
332     boxstack->add(vchan);
333     boxstack->update(vchan);
334   }
335   else
336   {
337     Control::getInstance()->connectionLost();
338   }
339 }
340
341 void VWelcome::doRecordingsList()
342 {
343         VRecordingList* vrec;
344         if (Control::getInstance()->isAdvMenus())
345            vrec = new VRecordingListAdvanced();
346         else
347            vrec = new VRecordingListClassic();
348
349         vrec->draw();
350         boxstack->add(vrec);
351         boxstack->update(vrec);
352
353         if (!vrec->load())
354         {
355                 Control::getInstance()->connectionLost();
356         }
357 }
358
359 void VWelcome::doMediaList()
360 {
361 #ifdef VOMP_MEDIAPLAYER
362   VMediaList::createList();
363 #endif
364 }
365
366 void VWelcome::doTimersList()
367 {
368   VTimerList* vtl = new VTimerList();
369   if (!vtl->load())
370   {
371     delete vtl;
372     Control::getInstance()->connectionLost();
373     return;
374   }
375   
376   vtl->draw();
377   boxstack->add(vtl);
378   boxstack->update(vtl);
379 }
380
381 void VWelcome::doOptions()
382 {
383 //  VOptionsMenu* voptionsmenu = new VOptionsMenu();
384 //  voptionsmenu->draw();
385 //  boxstack->add(voptionsmenu);
386 //  boxstack->updateView(voptionsmenu);
387
388   VOpts* vopts = new VOpts();
389   vopts->draw();
390   boxstack->add(vopts);
391   boxstack->update(vopts);
392 }
393
394 void VWelcome::processMessage(Message* m)
395 {
396   if (m->message == Message::MOUSE_MOVE)
397   {
398     if (sl.mouseMove(m->parameter - getScreenX(), m->tag - getScreenY()))
399     {
400       sl.draw();
401       boxstack->update(this);
402     }
403   }
404   else if (m->message == Message::MOUSE_LBDOWN)
405   {
406     if (sl.mouseLBDOWN(m->parameter - getScreenX(), m->tag - getScreenY()))
407     {
408       Input::sendInputKey(Input::OK);
409     }
410   }
411 }