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