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