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