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