]> git.vomp.tv Git - vompclient.git/blob - vwelcome.cc
Finnish and French added, Timers screen code
[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. Timers"), 0);
69   sl.addOption(tr("5. Options"), 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       doTimersList();
146       return 2;
147     }
148     case Remote::FIVE:
149     {
150       doOptions();
151       return 2;
152     }
153     case Remote::SIX:
154     {
155       Command::getInstance()->doReboot();
156     }
157     case Remote::OK:
158     {
159       int option = sl.getCurrentOption();
160       if (option == 0)
161       {
162         doChannelsList();
163         return 2;
164       }
165       else if (option == 1)
166       {
167         doRadioList();
168         return 2;
169       }
170       else if (option == 2)
171       {
172         doRecordingsList();
173         return 2;
174       }
175       else if (option == 3)
176       {
177         doTimersList();
178         return 2;
179       }
180       else if (option == 4)
181       {
182         doOptions();
183         return 2;
184       }
185       else if (option == 5)
186       {
187         Command::getInstance()->doReboot();
188         return 2;
189       }
190       return 2; // never gets here
191     }
192 #ifdef DEV
193     case Remote::NINE:
194     {
195       return 2;
196     }
197 #endif
198   }
199
200   return 1;
201 }
202
203 void VWelcome::doChannelsList()
204 {
205   ChannelList* chanList = VDR::getInstance()->getChannelsList(VDR::VIDEO);
206
207   if (chanList)
208   {
209     VChannelList* vchan = new VChannelList(VDR::VIDEO);
210     vchan->setList(chanList);
211
212     vchan->draw();
213     viewman->add(vchan);
214     viewman->updateView(vchan);
215   }
216 }
217
218 void VWelcome::doRadioList()
219 {
220   ChannelList* chanList = VDR::getInstance()->getChannelsList(VDR::RADIO);
221
222   if (chanList)
223   {
224     VChannelList* vchan = new VChannelList(VDR::RADIO);
225     vchan->setList(chanList);
226
227     vchan->draw();
228     viewman->add(vchan);
229     viewman->updateView(vchan);
230   }
231 }
232
233 void VWelcome::doRecordingsList()
234 {
235   VInfo* viewWait = new VInfo();
236   viewWait->create(460, 190);
237   if (Video::getInstance()->getFormat() == Video::PAL)
238   {
239     viewWait->setScreenPos(140, 170);
240   }
241   else
242   {
243     viewWait->setScreenPos(130, 140);
244   }
245   viewWait->setOneLiner(tr("Downloading recordings list"));
246   viewWait->draw();
247   viewman->add(viewWait);
248   viewman->updateView(viewWait);
249
250   VDR* vdr = VDR::getInstance();
251   Directory* recDir = vdr->getRecordingsList();
252
253   if (recDir)
254   {
255     VRecordingList* vrec = new VRecordingList(NULL, recDir);
256     vrec->draw();
257
258     viewman->add(vrec);
259     viewman->updateView(vrec);
260   }
261
262   Log::getInstance()->log("VWelcome", Log::DEBUG, "possible delay start");
263   viewman->removeView(viewWait);
264   Log::getInstance()->log("VWelcome", Log::DEBUG, "possible delay end");
265 }
266
267 void VWelcome::doTimersList()
268 {
269   RecTimerList* recTimerList = VDR::getInstance()->getRecTimersList();
270
271   if (recTimerList)
272   {
273     VTimerList* vtl = new VTimerList(recTimerList);
274
275     vtl->draw();
276     viewman->add(vtl);
277     viewman->updateView(vtl);
278   }
279 }
280
281 void VWelcome::doOptions()
282 {
283   VOptions* voptions = new VOptions(this);
284   voptions->draw();
285   viewman->add(voptions);
286   viewman->updateView(voptions);
287 }
288
289 void VWelcome::redrawLang()
290 {
291   Log::getInstance()->log("VWelcome", Log::DEBUG, "Got redraw lang message");
292   setup();
293   draw();
294 }