]> git.vomp.tv Git - vompclient.git/blob - vwelcome.cc
Extended recordings menu, including artwork from tvscraper
[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   rectangle(area.w - 60, 0, 60, 30, titleBarColour);
113
114   char timeString[20];
115   time_t t;
116   time(&t);
117   struct tm* tms = localtime(&t);
118   strftime(timeString, 19, "%H:%M", tms);
119   drawTextRJ(timeString, 450, 5, DrawStyle::LIGHTTEXT);
120
121   time_t dt = 60 - (t % 60);  // seconds to the next minute
122   if (dt == 0) dt = 60; // advance a whole minute if necessary
123   dt += t;  // get a time_t value for it rather than using duration
124   // (so it will occur at the actual second and not second and a half)
125
126   Timers::getInstance()->setTimerT(this, 1, dt);
127 }
128
129 void VWelcome::timercall(int clientReference)
130 {
131   drawClock();
132   boxstack->update(this, &clockRegion);
133 }
134
135 int VWelcome::handleCommand(int command)
136 {
137   switch(command)
138   {
139     case Remote::DF_UP:
140     case Remote::UP:
141     {
142       sl.up();
143       sl.draw();
144       boxstack->update(this);
145       return 2;
146     }
147     case Remote::DF_DOWN:
148     case Remote::DOWN:
149     {
150       sl.down();
151       sl.draw();
152       boxstack->update(this);
153       return 2;
154     }
155     case Remote::ONE:
156     {
157       doChannelsList();
158       return 2;
159     }
160     case Remote::TWO:
161     {
162       doRadioList();
163       return 2;
164     }
165     case Remote::THREE:
166     {
167       doRecordingsList();
168       return 2;
169     }
170     case Remote::FOUR:
171     {
172       doTimersList();
173       return 2;
174     }
175     case Remote::FIVE:
176     {
177 #ifdef VOMP_PLATTFORM_MVP
178       doMediaList();
179 #endif
180       return 2;
181     }
182     case Remote::SIX:
183     {
184       doOptions();
185       return 2;
186     }
187     case Remote::SEVEN:
188     {
189       Command::getInstance()->doReboot();
190       return 2;
191     }
192     case Remote::OK:
193     {
194       ULONG option = sl.getCurrentOptionData();
195       if (option == 1)
196       {
197         doChannelsList();
198         return 2;
199       }
200       else if (option == 2)
201       {
202         doRadioList();
203         return 2;
204       }
205       else if (option == 3)
206       {
207         doRecordingsList();
208         return 2;
209       }
210       else if (option == 4)
211       {
212         doTimersList();
213         return 2;
214       }
215       else if (option == 5)
216       {
217         doMediaList();
218         return 2;
219       }
220       else if (option == 6)
221       {
222         doOptions();
223         return 2;
224       }
225       else if (option == 7)
226       {
227         Command::getInstance()->doReboot();
228         return 2;
229       }
230       return 2; // never gets here
231     }
232 //#ifdef DEV
233     case Remote::NINE:
234     {
235       VScreensaver* vscreensaver = new VScreensaver();
236       boxstack->add(vscreensaver);
237       vscreensaver->draw();
238 //      boxstack->update(vscreensaver);
239
240       return 2;
241     }
242 //#endif
243
244     // Test
245 //    case Remote::BACK:
246 //    {
247 //      return 4;
248 //    }
249
250   }
251   return 1;
252 }
253
254 void VWelcome::doChannelsList()
255 {
256   ChannelList* chanList = VDR::getInstance()->getChannelsList(VDR::VIDEO);
257
258   if (chanList)
259   {
260     VChannelList* vchan = new VChannelList(VDR::VIDEO);
261     vchan->setList(chanList);
262
263     vchan->draw();
264     boxstack->add(vchan);
265     boxstack->update(vchan);
266   }
267   else
268   {
269     Command::getInstance()->connectionLost();
270   }
271 }
272
273 void VWelcome::doRadioList()
274 {
275   ChannelList* chanList = VDR::getInstance()->getChannelsList(VDR::RADIO);
276
277   if (chanList)
278   {
279     VChannelList* vchan = new VChannelList(VDR::RADIO);
280     vchan->setList(chanList);
281
282     vchan->draw();
283     boxstack->add(vchan);
284     boxstack->update(vchan);
285   }
286   else
287   {
288     Command::getInstance()->connectionLost();
289   }
290 }
291
292 void VWelcome::doRecordingsList()
293 {
294         VRecordingList* vrec;
295         if (Command::getInstance()->advMenues()) {
296            vrec =  new VRecordingListAdvanced();
297         } else {
298            vrec = new VRecordingListClassic();
299         }
300         vrec->draw();
301         boxstack->add(vrec);
302         boxstack->update(vrec);
303
304         if (!vrec->load())
305         {
306                 Command::getInstance()->connectionLost();
307         }
308 }
309
310 void VWelcome::doMediaList()
311 {
312 #ifdef VOMP_MEDIAPLAYER
313   VMediaList::createList();
314 #endif
315 }
316
317 void VWelcome::doTimersList()
318 {
319   VTimerList* vtl = new VTimerList();
320   if (!vtl->load())
321   {
322     delete vtl;
323     Command::getInstance()->connectionLost();
324     return;
325   }
326   
327   vtl->draw();
328   boxstack->add(vtl);
329   boxstack->update(vtl);
330 }
331
332 void VWelcome::doOptions()
333 {
334 //  VOptionsMenu* voptionsmenu = new VOptionsMenu();
335 //  voptionsmenu->draw();
336 //  boxstack->add(voptionsmenu);
337 //  boxstack->updateView(voptionsmenu);
338
339   VOpts* vopts = new VOpts();
340   vopts->draw();
341   boxstack->add(vopts);
342   boxstack->update(vopts);
343 }
344
345 void VWelcome::processMessage(Message* m)
346 {
347   if (m->message == Message::MOUSE_MOVE)
348   {
349     if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
350     {
351       sl.draw();
352       boxstack->update(this);
353     }
354   }
355   else if (m->message == Message::MOUSE_LBDOWN)
356   {
357     if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
358     {
359       boxstack->handleCommand(Remote::OK); //simulate OK press
360     }
361   }
362 }