]> git.vomp.tv Git - vompclient.git/blob - vwelcome.cc
New timers 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::instance = NULL;
24
25 VWelcome::VWelcome()
26 {
27   instance = this;
28
29   create(460, 200);
30   if (Video::getInstance()->getFormat() == Video::PAL)
31   {
32     setScreenPos(140, 170);
33   }
34   else
35   {
36     setScreenPos(130, 140);
37   }
38
39   setBackgroundColour(Colour::VIEWBACKGROUND);
40   setTitleBarOn(1);
41   setTitleBarColour(Colour::TITLEBARBACKGROUND);
42
43   sl.setSurface(surface);
44   sl.setSurfaceOffset(20, 40);
45   sl.setDimensions(170, 140);
46
47   jpeg.setSurface(surface);
48   jpeg.setSurfaceOffset(240, 60);
49
50   setup();
51 }
52
53 VWelcome::~VWelcome()
54 {
55   instance = NULL;
56 }
57
58 VWelcome* VWelcome::getInstance()
59 {
60   return instance;
61 }
62
63 void VWelcome::setup()
64 {
65   sl.clear();
66   setTitleText(tr("Welcome"));
67   sl.addOption(tr("1. Live TV"), 1);
68   sl.addOption(tr("2. Radio"), 0);
69   sl.addOption(tr("3. Recordings"), 0);
70   sl.addOption(tr("4. Options"), 0);
71   sl.addOption(tr("5. Stand by"), 0);
72   sl.addOption(tr("6. Reboot"), 0);
73 }
74
75 void VWelcome::draw()
76 {
77   View::draw();
78   sl.draw();
79
80   char timeString[20];
81   time_t t;
82   time(&t);
83   struct tm* tms = localtime(&t);
84   strftime(timeString, 19, "%H:%M", tms);
85
86   drawTextRJ(timeString, 450, 5, Colour::LIGHTTEXT);
87
88   jpeg.init("/vdr.jpg");
89   jpeg.draw();
90 }
91
92 int VWelcome::handleCommand(int command)
93 {
94   switch(command)
95   {
96     case Remote::DF_UP:
97     case Remote::UP:
98     {
99       sl.up();
100       sl.draw();
101       show();
102       return 2;
103     }
104     case Remote::DF_DOWN:
105     case Remote::DOWN:
106     {
107       sl.down();
108       sl.draw();
109       show();
110       return 2;
111     }
112     case Remote::ONE:
113     {
114       doChannelsList();
115       return 2;
116     }
117     case Remote::TWO:
118     {
119       doRadioList();
120       return 2;
121     }
122     case Remote::THREE:
123     {
124       doRecordingsList();
125       return 2;
126     }
127     case Remote::FOUR:
128     {
129       doOptions();
130       return 2;
131     }
132     case Remote::FIVE:
133     {
134       Message* m = new Message();
135       m->message = Message::STANDBY;
136       Command::getInstance()->postMessage(m);
137       return 4;
138     }
139     case Remote::SIX:
140     {
141       Command::getInstance()->doReboot();
142     }
143     case Remote::OK:
144     {
145       int option = sl.getCurrentOption();
146       if (option == 0)
147       {
148         doChannelsList();
149         return 2;
150       }
151       else if (option == 1)
152       {
153         doRadioList();
154         return 2;
155       }
156       else if (option == 2)
157       {
158         doRecordingsList();
159         return 2;
160       }
161       else if (option == 3)
162       {
163         doOptions();
164         return 2;
165       }
166       else if (option == 4)
167       {
168         Message* m = new Message();
169         m->message = Message::STANDBY;
170         Command::getInstance()->postMessage(m);
171         return 4;
172       }
173       else if (option == 5)
174       {
175         Command::getInstance()->doReboot();
176         return 2;
177       }
178       return 2; // never gets here
179     }
180   }
181
182   return 1;
183 }
184
185
186 void VWelcome::doChannelsList()
187 {
188   ChannelList* chanList = VDR::getInstance()->getChannelsList(VDR::VIDEO);
189
190   if (chanList)
191   {
192     VChannelList* vchan = new VChannelList(VDR::VIDEO);
193     vchan->setList(chanList);
194
195     ViewMan::getInstance()->add(vchan);
196     vchan->draw();
197     vchan->show();
198
199
200 //        Message* m = new Message();
201 //        m->from = this;
202 //        m->to = ViewMan::getInstance();
203 //        m->message = Message::SWAP_ME_FOR;
204 //        m->parameter = (ULONG)vchan;
205 //        ViewMan::getInstance()->postMessage(m);
206   }
207 }
208
209 void VWelcome::doRadioList()
210 {
211   ChannelList* chanList = VDR::getInstance()->getChannelsList(VDR::RADIO);
212
213   if (chanList)
214   {
215     VChannelList* vchan = new VChannelList(VDR::RADIO);
216     vchan->setList(chanList);
217
218     ViewMan::getInstance()->add(vchan);
219     vchan->draw();
220     vchan->show();
221   }
222 }
223
224 void VWelcome::doRecordingsList()
225 {
226   ViewMan* viewman = ViewMan::getInstance();
227
228   VInfo* viewWait = new VInfo();
229   viewWait->create(460, 190);
230   if (Video::getInstance()->getFormat() == Video::PAL)
231   {
232     viewWait->setScreenPos(140, 170);
233   }
234   else
235   {
236     viewWait->setScreenPos(130, 140);
237   }
238   viewWait->setOneLiner(tr("Downloading recordings list"));
239   viewWait->draw();
240   viewWait->show();
241   viewman->add(viewWait);
242
243
244   VDR* vdr = VDR::getInstance();
245   Directory* recDir = vdr->getRecordingsList();
246
247   if (recDir)
248   {
249     VRecordingList* vrec = new VRecordingList(NULL);
250     vrec->setDir(recDir);
251
252     ViewMan::getInstance()->add(vrec);
253
254     vrec->draw();
255     vrec->show();
256   }
257
258   Log::getInstance()->log("VWelcome", Log::DEBUG, "possible delay start");
259   viewman->removeView(viewWait);
260   Log::getInstance()->log("VWelcome", Log::DEBUG, "possible delay end");
261 }
262
263 void VWelcome::doOptions()
264 {
265   VOptions* voptions = new VOptions();
266   ViewMan::getInstance()->add(voptions);
267   voptions->draw();
268   voptions->show();
269 }
270
271 void VWelcome::processMessage(Message* m)
272 {
273   if (m->message == Message::REDRAW_LANG)
274   {
275     Log::getInstance()->log("VWelcome", Log::DEBUG, "Got redraw lang message");
276     setup();
277     draw();
278     show(); // careful, this only works properly because the only place
279             // this is called from is voptions and that disappears before
280             // this message is delivered
281   }
282 }