]> git.vomp.tv Git - vompclient.git/blob - vwelcome.cc
Connection failed detection
[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);
76   sl.addOption(tr("2. Radio"), 0);
77   sl.addOption(tr("3. Recordings"), 0);
78   sl.addOption(tr("4. Timers"), 0);
79   sl.addOption(tr("5. Options"), 0);
80   sl.addOption(tr("6. Reboot"), 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()->setTimer(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       int option = sl.getCurrentOption();
170       if (option == 0)
171       {
172         doChannelsList();
173         return 2;
174       }
175       else if (option == 1)
176       {
177         doRadioList();
178         return 2;
179       }
180       else if (option == 2)
181       {
182         doRecordingsList();
183         return 2;
184       }
185       else if (option == 3)
186       {
187         doTimersList();
188         return 2;
189       }
190       else if (option == 4)
191       {
192         doOptions();
193         return 2;
194       }
195       else if (option == 5)
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 }
227
228 void VWelcome::doRadioList()
229 {
230   ChannelList* chanList = VDR::getInstance()->getChannelsList(VDR::RADIO);
231
232   if (chanList)
233   {
234     VChannelList* vchan = new VChannelList(VDR::RADIO);
235     vchan->setList(chanList);
236
237     vchan->draw();
238     viewman->add(vchan);
239     viewman->updateView(vchan);
240   }
241 }
242
243 void VWelcome::doRecordingsList()
244 {
245   VInfo* viewWait = new VInfo();
246   viewWait->create(460, 190);
247   if (Video::getInstance()->getFormat() == Video::PAL)
248   {
249     viewWait->setScreenPos(140, 170);
250   }
251   else
252   {
253     viewWait->setScreenPos(130, 140);
254   }
255   viewWait->setOneLiner(tr("Downloading recordings list"));
256   viewWait->draw();
257   viewman->add(viewWait);
258   viewman->updateView(viewWait);
259
260   VDR* vdr = VDR::getInstance();
261   Directory* recDir = vdr->getRecordingsList();
262
263   if (recDir)
264   {
265     VRecordingList* vrec = new VRecordingList(NULL, recDir);
266     vrec->draw();
267
268     viewman->add(vrec);
269     viewman->updateView(vrec);
270   }
271   else
272   {
273     Command::getInstance()->connectionLost();
274   }
275
276   viewman->removeView(viewWait);
277 }
278
279 void VWelcome::doTimersList()
280 {
281   RecTimerList* recTimerList = VDR::getInstance()->getRecTimersList();
282
283   if (recTimerList)
284   {
285     VTimerList* vtl = new VTimerList(recTimerList);
286
287     viewman->add(vtl);
288     viewman->updateView(vtl);
289   }
290 }
291
292 void VWelcome::doOptions()
293 {
294   VOptionsMenu* voptionsmenu = new VOptionsMenu();
295   voptionsmenu->draw();
296   viewman->add(voptionsmenu);
297   viewman->updateView(voptionsmenu);
298 }
299
300 void VWelcome::redrawLang()
301 {
302   Log::getInstance()->log("VWelcome", Log::DEBUG, "Got redraw lang message");
303   setup();
304   draw();
305 }