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