]> git.vomp.tv Git - vompclient.git/blob - vwelcome.cc
Big code cleanup
[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()->postMessage(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()->postMessage(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   }
197
198   return 1;
199 }
200
201 void VWelcome::doChannelsList()
202 {
203   ChannelList* chanList = VDR::getInstance()->getChannelsList(VDR::VIDEO);
204
205   if (chanList)
206   {
207     VChannelList* vchan = new VChannelList(VDR::VIDEO);
208     vchan->setList(chanList);
209
210     vchan->draw();
211     viewman->add(vchan);
212     viewman->updateView(vchan);
213   }
214 }
215
216 void VWelcome::doRadioList()
217 {
218   ChannelList* chanList = VDR::getInstance()->getChannelsList(VDR::RADIO);
219
220   if (chanList)
221   {
222     VChannelList* vchan = new VChannelList(VDR::RADIO);
223     vchan->setList(chanList);
224
225     vchan->draw();
226     viewman->add(vchan);
227     viewman->updateView(vchan);
228   }
229 }
230
231 void VWelcome::doRecordingsList()
232 {
233   VInfo* viewWait = new VInfo();
234   viewWait->create(460, 190);
235   if (Video::getInstance()->getFormat() == Video::PAL)
236   {
237     viewWait->setScreenPos(140, 170);
238   }
239   else
240   {
241     viewWait->setScreenPos(130, 140);
242   }
243   viewWait->setOneLiner(tr("Downloading recordings list"));
244   viewWait->draw();
245   viewman->add(viewWait);
246   viewman->updateView(viewWait);
247
248   VDR* vdr = VDR::getInstance();
249   Directory* recDir = vdr->getRecordingsList();
250
251   if (recDir)
252   {
253     VRecordingList* vrec = new VRecordingList(NULL, recDir);
254     vrec->draw();
255
256     viewman->add(vrec);
257     viewman->updateView(vrec);
258   }
259
260   Log::getInstance()->log("VWelcome", Log::DEBUG, "possible delay start");
261   viewman->removeView(viewWait);
262   Log::getInstance()->log("VWelcome", Log::DEBUG, "possible delay end");
263 }
264
265 void VWelcome::doOptions()
266 {
267   VOptions* voptions = new VOptions(this);
268   voptions->draw();
269   viewman->add(voptions);
270   viewman->updateView(voptions);
271 }
272
273 void VWelcome::redrawLang()
274 {
275   Log::getInstance()->log("VWelcome", Log::DEBUG, "Got redraw lang message");
276   setup();
277   draw();
278 }