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