]> git.vomp.tv Git - vompclient.git/blob - vwelcome.cc
Rewritten vomp discovery protocol
[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 "vrecordinglist.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 "timers.h"
34 #include "vscreensaver.h"
35 #include "vmedialist.h"
36 #include "boxstack.h"
37 #include "vopts.h"
38
39 VWelcome::VWelcome()
40 {
41   boxstack = BoxStack::getInstance();
42
43   clockRegion.x = 400;
44   clockRegion.y = 0;
45   clockRegion.w = 60;
46   clockRegion.h = 30;
47
48   setSize(460, 220);
49   createBuffer();
50   if (Video::getInstance()->getFormat() == Video::PAL)
51   {
52     setPosition(140, 170);
53   }
54   else
55   {
56     setPosition(130, 140);
57   }
58
59   setTitleBarOn(1);
60   setTitleBarColour(Colour::TITLEBARBACKGROUND);
61
62   sl.setPosition(20, 40);
63   sl.setSize(200, 160);
64   add(&sl);
65
66   setTitleText(tr("Welcome"));
67   sl.addOption(tr("1. Live TV"), 1, 1);
68   sl.addOption(tr("2. Radio"), 2, 0);
69   sl.addOption(tr("3. Recordings"), 3, 0);
70   sl.addOption(tr("4. Timers"), 4, 0);
71 #ifndef _MIPS_ARCH 
72 #ifndef WIN32 
73   sl.addOption(tr("5. MediaPlayer"), 5, 0);
74 #endif
75 #endif
76   sl.addOption(tr("6. Options"), 6, 0);
77 #ifndef _MIPS_ARCH
78   sl.addOption(tr("7. Reboot"), 7, 0);
79 #else
80     sl.addOption(tr("7. Exit to Gaya"), 7, 0);
81 #endif
82
83   jpeg.setPosition(240, 60);
84 #ifndef _MIPS_ARCH  
85   jpeg.init("/vdr.jpg");
86 #else
87   jpeg.init("vdr.jpg");
88 #endif
89   add(&jpeg);
90 }
91
92 void VWelcome::preDelete()
93 {
94   Timers::getInstance()->cancelTimer(this, 1);
95 }
96
97 VWelcome::~VWelcome()
98 {
99 }
100
101 void VWelcome::draw()
102 {
103   TBBoxx::draw();
104   drawClock();
105 }
106
107 void VWelcome::drawClock()
108 {
109   // Blank the area first
110   rectangle(area.w - 60, 0, 60, 30, titleBarColour);
111
112   char timeString[20];
113   time_t t;
114   time(&t);
115   struct tm* tms = localtime(&t);
116   strftime(timeString, 19, "%H:%M", tms);
117   drawTextRJ(timeString, 450, 5, Colour::LIGHTTEXT);
118
119   time_t dt = 60 - (t % 60);  // seconds to the next minute
120   if (dt == 0) dt = 60; // advance a whole minute if necessary
121   dt += t;  // get a time_t value for it rather than using duration
122   // (so it will occur at the actual second and not second and a half)
123
124   Timers::getInstance()->setTimerT(this, 1, dt);
125 }
126
127 void VWelcome::timercall(int clientReference)
128 {
129   drawClock();
130   boxstack->update(this, &clockRegion);
131 }
132
133 int VWelcome::handleCommand(int command)
134 {
135   switch(command)
136   {
137     case Remote::DF_UP:
138     case Remote::UP:
139     {
140       sl.up();
141       sl.draw();
142       boxstack->update(this);
143       return 2;
144     }
145     case Remote::DF_DOWN:
146     case Remote::DOWN:
147     {
148       sl.down();
149       sl.draw();
150       boxstack->update(this);
151       return 2;
152     }
153     case Remote::ONE:
154     {
155       doChannelsList();
156       return 2;
157     }
158     case Remote::TWO:
159     {
160       doRadioList();
161       return 2;
162     }
163     case Remote::THREE:
164     {
165       doRecordingsList();
166       return 2;
167     }
168     case Remote::FOUR:
169     {
170       doTimersList();
171       return 2;
172     }
173     case Remote::FIVE:
174     {
175       doMediaList();
176       return 2;
177     }
178     case Remote::SIX:
179     {
180       doOptions();
181       return 2;
182     }
183     case Remote::SEVEN:
184     {
185       Command::getInstance()->doReboot();
186     }
187     case Remote::OK:
188     {
189       ULONG option = sl.getCurrentOptionData();
190       if (option == 1)
191       {
192         doChannelsList();
193         return 2;
194       }
195       else if (option == 2)
196       {
197         doRadioList();
198         return 2;
199       }
200       else if (option == 3)
201       {
202         doRecordingsList();
203         return 2;
204       }
205       else if (option == 4)
206       {
207         doTimersList();
208         return 2;
209       }
210       else if (option == 5)
211       {
212         doMediaList();
213         return 2;
214       }
215       else if (option == 6)
216       {
217         doOptions();
218         return 2;
219       }
220       else if (option == 7)
221       {
222         Command::getInstance()->doReboot();
223         return 2;
224       }
225       return 2; // never gets here
226     }
227 //#ifdef DEV
228     case Remote::NINE:
229     {
230       VScreensaver* vscreensaver = new VScreensaver();
231       boxstack->add(vscreensaver);
232       vscreensaver->draw();
233 //      boxstack->update(vscreensaver);
234
235       return 2;
236     }
237 //#endif
238
239     // Test
240 //    case Remote::BACK:
241 //    {
242 //      return 4;
243 //    }
244
245   }
246   return 1;
247 }
248
249 void VWelcome::doChannelsList()
250 {
251   ChannelList* chanList = VDR::getInstance()->getChannelsList(VDR::VIDEO);
252
253   if (chanList)
254   {
255     VChannelList* vchan = new VChannelList(VDR::VIDEO);
256     vchan->setList(chanList);
257
258     vchan->draw();
259     boxstack->add(vchan);
260     boxstack->update(vchan);
261   }
262   else
263   {
264     Command::getInstance()->connectionLost();
265   }
266 }
267
268 void VWelcome::doRadioList()
269 {
270   ChannelList* chanList = VDR::getInstance()->getChannelsList(VDR::RADIO);
271
272   if (chanList)
273   {
274     VChannelList* vchan = new VChannelList(VDR::RADIO);
275     vchan->setList(chanList);
276
277     vchan->draw();
278     boxstack->add(vchan);
279     boxstack->update(vchan);
280   }
281   else
282   {
283     Command::getInstance()->connectionLost();
284   }
285 }
286
287 void VWelcome::doRecordingsList()
288 {
289   VRecordingList* vrec = new VRecordingList();
290   vrec->draw();
291   boxstack->add(vrec);
292   boxstack->update(vrec);
293
294   if (!vrec->load())
295   {
296     Command::getInstance()->connectionLost();
297   }
298 }
299
300 void VWelcome::doMediaList()
301 {
302   VMediaList::createList();
303 }
304
305 void VWelcome::doTimersList()
306 {
307   VTimerList* vtl = new VTimerList();
308   if (!vtl->load())
309   {
310     delete vtl;
311     Command::getInstance()->connectionLost();
312     return;
313   }
314   
315   vtl->draw();
316   boxstack->add(vtl);
317   boxstack->update(vtl);
318 }
319
320 void VWelcome::doOptions()
321 {
322 //  VOptionsMenu* voptionsmenu = new VOptionsMenu();
323 //  voptionsmenu->draw();
324 //  boxstack->add(voptionsmenu);
325 //  boxstack->updateView(voptionsmenu);
326
327   VOpts* vopts = new VOpts();
328   vopts->draw();
329   boxstack->add(vopts);
330   boxstack->update(vopts);
331 }
332
333 void VWelcome::processMessage(Message* m)
334 {
335   if (m->message == Message::MOUSE_MOVE)
336   {
337     if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
338     {
339       sl.draw();
340       boxstack->update(this);
341     }
342   }
343   else if (m->message == Message::MOUSE_LBDOWN)
344   {
345     if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
346     {
347       boxstack->handleCommand(Remote::OK); //simulate OK press
348     }
349   }
350 }