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