]> git.vomp.tv Git - vompclient.git/blob - vwelcome.cc
Fix resuming recording directly after stopping it
[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
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 Remote::DF_UP:
192     case Remote::UP:
193     {
194       sl.up();
195       sl.draw();
196       boxstack->update(this);
197       return 2;
198     }
199     case Remote::DF_DOWN:
200     case Remote::DOWN:
201     {
202       sl.down();
203       sl.draw();
204       boxstack->update(this);
205       return 2;
206     }
207     case Remote::ONE:
208     {
209       doChannelsList();
210       return 2;
211     }
212     case Remote::TWO:
213     {
214       doRadioList();
215       return 2;
216     }
217     case Remote::THREE:
218     {
219       doRecordingsList();
220       return 2;
221     }
222     case Remote::FOUR:
223     {
224       doTimersList();
225       return 2;
226     }
227     case Remote::FIVE:
228     {
229 #ifdef VOMP_PLATTFORM_MVP
230       doMediaList();
231 #endif
232       return 2;
233     }
234     case Remote::SIX:
235     {
236       doOptions();
237       return 2;
238     }
239     case Remote::SEVEN:
240     {
241       Command::getInstance()->doReboot();
242       return 2;
243     }
244     case Remote::OK:
245     {
246       ULONG option = sl.getCurrentOptionData();
247       if (option == 1)
248       {
249         doChannelsList();
250         return 2;
251       }
252       else if (option == 2)
253       {
254         doRadioList();
255         return 2;
256       }
257       else if (option == 3)
258       {
259         doRecordingsList();
260         return 2;
261       }
262       else if (option == 4)
263       {
264         doTimersList();
265         return 2;
266       }
267       else if (option == 5)
268       {
269         doMediaList();
270         return 2;
271       }
272       else if (option == 6)
273       {
274         doOptions();
275         return 2;
276       }
277       else if (option == 7)
278       {
279         Command::getInstance()->doReboot();
280         return 2;
281       }
282       return 2; // never gets here
283     }
284 //#ifdef DEV
285     case Remote::NINE:
286     {
287       VScreensaver* vscreensaver = new VScreensaver();
288       boxstack->add(vscreensaver);
289       vscreensaver->draw();
290 //      boxstack->update(vscreensaver);
291
292       return 2;
293     }
294 //#endif
295
296     // Test
297 //    case Remote::BACK:
298 //    {
299 //      return 4;
300 //    }
301
302   }
303   return 1;
304 }
305
306 void VWelcome::doChannelsList()
307 {
308   ChannelList* chanList = VDR::getInstance()->getChannelsList(VDR::VIDEO);
309
310   if (chanList)
311   {
312     VChannelList* vchan = new VChannelList(VDR::VIDEO);
313     vchan->setList(chanList);
314
315     vchan->draw();
316     boxstack->add(vchan);
317     boxstack->update(vchan);
318   }
319   else
320   {
321     Command::getInstance()->connectionLost();
322   }
323 }
324
325 void VWelcome::doRadioList()
326 {
327   ChannelList* chanList = VDR::getInstance()->getChannelsList(VDR::RADIO);
328
329   if (chanList)
330   {
331     VChannelList* vchan = new VChannelList(VDR::RADIO);
332     vchan->setList(chanList);
333
334     vchan->draw();
335     boxstack->add(vchan);
336     boxstack->update(vchan);
337   }
338   else
339   {
340     Command::getInstance()->connectionLost();
341   }
342 }
343
344 void VWelcome::doRecordingsList()
345 {
346         VRecordingList* vrec;
347         if (Command::getInstance()->advMenues()) {
348            vrec =  new VRecordingListAdvanced();
349         } else {
350            vrec = new VRecordingListClassic();
351         }
352         vrec->draw();
353         boxstack->add(vrec);
354         boxstack->update(vrec);
355
356         if (!vrec->load())
357         {
358                 Command::getInstance()->connectionLost();
359         }
360 }
361
362 void VWelcome::doMediaList()
363 {
364 #ifdef VOMP_MEDIAPLAYER
365   VMediaList::createList();
366 #endif
367 }
368
369 void VWelcome::doTimersList()
370 {
371   VTimerList* vtl = new VTimerList();
372   if (!vtl->load())
373   {
374     delete vtl;
375     Command::getInstance()->connectionLost();
376     return;
377   }
378   
379   vtl->draw();
380   boxstack->add(vtl);
381   boxstack->update(vtl);
382 }
383
384 void VWelcome::doOptions()
385 {
386 //  VOptionsMenu* voptionsmenu = new VOptionsMenu();
387 //  voptionsmenu->draw();
388 //  boxstack->add(voptionsmenu);
389 //  boxstack->updateView(voptionsmenu);
390
391   VOpts* vopts = new VOpts();
392   vopts->draw();
393   boxstack->add(vopts);
394   boxstack->update(vopts);
395 }
396
397 void VWelcome::processMessage(Message* m)
398 {
399   if (m->message == Message::MOUSE_MOVE)
400   {
401     if (sl.mouseMove((m->parameter.num>>16)-getScreenX(),(m->parameter.num&0xFFFF)-getScreenY()))
402     {
403       sl.draw();
404       boxstack->update(this);
405     }
406   }
407   else if (m->message == Message::MOUSE_LBDOWN)
408   {
409     if (sl.mouseLBDOWN((m->parameter.num>>16)-getScreenX(),(m->parameter.num&0xFFFF)-getScreenY()))
410     {
411       boxstack->handleCommand(Remote::OK); //simulate OK press
412     }
413   }
414 }