]> git.vomp.tv Git - vompclient.git/blob - vwelcome.cc
Moving clock
[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   time_t dt = 60 - (t % 60);
102   if (dt == 0) dt = 60;
103   Timers::getInstance()->setTimer(this, 1, (struct timespec){dt, 0});
104 }
105
106 void VWelcome::timercall(int clientReference)
107 {
108   drawClock();
109   ViewMan::getInstance()->updateView(this, &clockRegion);
110 }
111
112 int VWelcome::handleCommand(int command)
113 {
114   switch(command)
115   {
116     case Remote::NINE:
117     {
118       VInfo* viewWait = new VInfo();
119       viewWait->create(100, 100);
120       viewWait->setScreenPos(485, 185);
121       viewWait->setTitleBarOn(0);
122       viewWait->setBackgroundColour(Colour::DANGER);
123       viewWait->draw();
124       viewWait->show();
125       ViewMan::getInstance()->add(viewWait);
126
127       return 2;
128     }
129
130     case Remote::DF_UP:
131     case Remote::UP:
132     {
133       sl.up();
134       sl.draw();
135       show();
136       return 2;
137     }
138     case Remote::DF_DOWN:
139     case Remote::DOWN:
140     {
141       sl.down();
142       sl.draw();
143       show();
144       return 2;
145     }
146     case Remote::ONE:
147     {
148       doChannelsList();
149       return 2;
150     }
151     case Remote::TWO:
152     {
153       doRadioList();
154       return 2;
155     }
156     case Remote::THREE:
157     {
158       doRecordingsList();
159       return 2;
160     }
161     case Remote::FOUR:
162     {
163       doOptions();
164       return 2;
165     }
166     case Remote::FIVE:
167     {
168       Message* m = new Message();
169       m->message = Message::STANDBY;
170       Command::getInstance()->postMessage(m);
171       return 4;
172     }
173     case Remote::SIX:
174     {
175       Command::getInstance()->doReboot();
176     }
177     case Remote::OK:
178     {
179       int option = sl.getCurrentOption();
180       if (option == 0)
181       {
182         doChannelsList();
183         return 2;
184       }
185       else if (option == 1)
186       {
187         doRadioList();
188         return 2;
189       }
190       else if (option == 2)
191       {
192         doRecordingsList();
193         return 2;
194       }
195       else if (option == 3)
196       {
197         doOptions();
198         return 2;
199       }
200       else if (option == 4)
201       {
202         Message* m = new Message();
203         m->message = Message::STANDBY;
204         Command::getInstance()->postMessage(m);
205         return 4;
206       }
207       else if (option == 5)
208       {
209         Command::getInstance()->doReboot();
210         return 2;
211       }
212       return 2; // never gets here
213     }
214   }
215
216   return 1;
217 }
218
219
220 void VWelcome::doChannelsList()
221 {
222   ChannelList* chanList = VDR::getInstance()->getChannelsList(VDR::VIDEO);
223
224   if (chanList)
225   {
226     VChannelList* vchan = new VChannelList(VDR::VIDEO);
227     vchan->setList(chanList);
228
229     ViewMan::getInstance()->add(vchan);
230     vchan->draw();
231     vchan->show();
232
233
234 //        Message* m = new Message();
235 //        m->from = this;
236 //        m->to = ViewMan::getInstance();
237 //        m->message = Message::SWAP_ME_FOR;
238 //        m->parameter = (ULONG)vchan;
239 //        ViewMan::getInstance()->postMessage(m);
240   }
241 }
242
243 void VWelcome::doRadioList()
244 {
245   ChannelList* chanList = VDR::getInstance()->getChannelsList(VDR::RADIO);
246
247   if (chanList)
248   {
249     VChannelList* vchan = new VChannelList(VDR::RADIO);
250     vchan->setList(chanList);
251
252     ViewMan::getInstance()->add(vchan);
253     vchan->draw();
254     vchan->show();
255   }
256 }
257
258 void VWelcome::doRecordingsList()
259 {
260   ViewMan* viewman = ViewMan::getInstance();
261
262   VInfo* viewWait = new VInfo();
263   viewWait->create(460, 190);
264   if (Video::getInstance()->getFormat() == Video::PAL)
265   {
266     viewWait->setScreenPos(140, 170);
267   }
268   else
269   {
270     viewWait->setScreenPos(130, 140);
271   }
272   viewWait->setOneLiner(tr("Downloading recordings list"));
273   viewWait->draw();
274   viewWait->show();
275   viewman->add(viewWait);
276
277
278   VDR* vdr = VDR::getInstance();
279   Directory* recDir = vdr->getRecordingsList();
280
281   if (recDir)
282   {
283     VRecordingList* vrec = new VRecordingList(NULL);
284     vrec->setDir(recDir);
285
286     ViewMan::getInstance()->add(vrec);
287
288     vrec->draw();
289     vrec->show();
290   }
291
292   Log::getInstance()->log("VWelcome", Log::DEBUG, "possible delay start");
293   viewman->removeView(viewWait);
294   Log::getInstance()->log("VWelcome", Log::DEBUG, "possible delay end");
295 }
296
297 void VWelcome::doOptions()
298 {
299   VOptions* voptions = new VOptions();
300   ViewMan::getInstance()->add(voptions);
301   voptions->draw();
302   voptions->show();
303 }
304
305 void VWelcome::processMessage(Message* m)
306 {
307   if (m->message == Message::REDRAW_LANG)
308   {
309     Log::getInstance()->log("VWelcome", Log::DEBUG, "Got redraw lang message");
310     setup();
311     draw();
312     show(); // careful, this only works properly because the only place
313             // this is called from is voptions and that disappears before
314             // this message is delivered
315   }
316 }