]> git.vomp.tv Git - vompclient.git/blob - vchannellist.cc
Sleep timer
[vompclient.git] / vchannellist.cc
1 /*
2     Copyright 2004-2007 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 */
20
21 #include "vchannellist.h"
22
23 #include "remote.h"
24 #include "wsymbol.h"
25 #include "vvideolivetv.h"
26 #include "colour.h"
27 #include "video.h"
28 #include "i18n.h"
29 #include "channel.h"
30 #include "message.h"
31 #include "boxstack.h"
32 #include "vchannelselect.h"
33
34 VChannelList::VChannelList(ULONG type)
35 {
36   boxstack = BoxStack::getInstance();
37   setSize(570, 420);
38   createBuffer();
39   if (Video::getInstance()->getFormat() == Video::PAL)
40   {
41     setPosition(80, 70);
42   }
43   else
44   {
45     setPosition(70, 35);
46   }
47
48   setTitleBarOn(1);
49
50   if (type == VDR::VIDEO)
51   {
52     setTitleText(tr("Channels"));
53   }
54   else if (type == VDR::RADIO)
55   {
56     setTitleText(tr("Radio Stations"));
57   }
58   setTitleBarColour(Colour::TITLEBARBACKGROUND);
59
60   sl.setPosition(10, 30 + 5);
61   sl.setSize(area.w - 20, area.h - 30 - 15 - 30);
62   add(&sl);
63 }
64
65 VChannelList::~VChannelList()
66 {
67   if (chanList)
68   {
69     for (UINT i = 0; i < chanList->size(); i++)
70     {
71       delete (*chanList)[i];
72     }
73
74     chanList->clear();
75     delete chanList;
76   }
77 }
78
79 void VChannelList::setList(ChannelList* tlist)
80 {
81   char str[500];
82
83   sl.addColumn(0);
84   sl.addColumn(60);
85
86   chanList = tlist;
87
88   Channel* chan;
89   int first = 1;
90   if (chanList)
91   {
92     for (UINT i = 0; i < chanList->size(); i++)
93     {
94       chan = (*chanList)[i];
95       sprintf(str, "%lu\t%s", chan->number, chan->name);
96       chan->index = sl.addOption(str, (ULONG)chan, first);
97       first = 0;
98     }
99   }
100 }
101
102 void VChannelList::highlightChannel(Channel* chan)
103 {
104   sl.hintSetCurrent(chan->index);
105   sl.draw();
106   doShowingBar();
107   boxstack->update(this);
108 }
109
110 void VChannelList::draw()
111 {
112   TBBoxx::draw();
113   sl.draw();
114
115   // Put the status stuff at the bottom
116
117   WSymbol w;
118   TEMPADD(&w);
119
120   w.nextSymbol = WSymbol::UP;
121   w.setPosition(20, 385);
122   w.draw();
123
124   w.nextSymbol = WSymbol::DOWN;
125   w.setPosition(50, 385);
126   w.draw();
127
128   w.nextSymbol = WSymbol::SKIPBACK;
129   w.setPosition(85, 385);
130   w.draw();
131
132   w.nextSymbol = WSymbol::SKIPFORWARD;
133   w.setPosition(115, 385);
134   w.draw();
135
136   w.nextSymbol = WSymbol::PLAY;
137   w.setPosition(150, 385);
138   w.draw();
139
140   doShowingBar();
141 }
142
143 void VChannelList::doShowingBar()
144 {
145   int topOption = sl.getTopOption() + 1;
146   if (sl.getNumOptions() == 0) topOption = 0;
147
148   char showing[200];
149   sprintf(showing, tr("%i to %i of %i"), topOption, sl.getBottomOption(), sl.getNumOptions());
150
151   rectangle(220, 385, 220+160, 385+25, Colour::VIEWBACKGROUND);
152   drawText(showing, 220, 385, Colour::LIGHTTEXT);
153 }
154
155 int VChannelList::handleCommand(int command)
156 {
157   switch(command)
158   {
159     case Remote::DF_UP:
160     case Remote::UP:
161     {
162       sl.up();
163       sl.draw();
164
165       doShowingBar();
166       boxstack->update(this);
167       return 2;
168     }
169     case Remote::DF_DOWN:
170     case Remote::DOWN:
171     {
172       sl.down();
173       sl.draw();
174
175       doShowingBar();
176       boxstack->update(this);
177       return 2;
178     }
179     case Remote::SKIPBACK:
180     {
181       sl.pageUp();
182       sl.draw();
183
184       doShowingBar();
185       boxstack->update(this);
186       return 2;
187     }
188     case Remote::SKIPFORWARD:
189     {
190       sl.pageDown();
191       sl.draw();
192
193       doShowingBar();
194       boxstack->update(this);
195       return 2;
196     }
197     case Remote::ZERO:
198     case Remote::ONE:
199     case Remote::TWO:
200     case Remote::THREE:
201     case Remote::FOUR:
202     case Remote::FIVE:
203     case Remote::SIX:
204     case Remote::SEVEN:
205     case Remote::EIGHT:
206     case Remote::NINE:
207     {
208       VChannelSelect* v = new VChannelSelect(this);
209       v->draw();
210       boxstack->add(v);
211       boxstack->update(v);
212       v->handleCommand(command);
213       return 2;
214     }
215     case Remote::OK:
216     case Remote::PLAY:
217     {
218       Channel* chan = NULL;
219       if (chanList) chan = (Channel*)sl.getCurrentOptionData();
220       if (chan == NULL) return 2;
221  
222       VVideoLiveTV* v = new VVideoLiveTV(chanList, chan->number, this);
223       boxstack->add(v);
224       v->go();
225
226       return 2;
227     }
228     case Remote::BACK:
229     {
230       return 4;
231     }
232   }
233   // stop command getting to any more views
234   return 1;
235 }
236
237 void VChannelList::processMessage(Message* m)
238 {
239   if (m->message == Message::MOUSE_MOVE)
240   {
241     if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
242     {
243       sl.draw();
244       doShowingBar();
245       boxstack->update(this);
246     }
247   }
248   else if (m->message == Message::MOUSE_LBDOWN)
249   {
250     if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
251     {
252       boxstack->handleCommand(Remote::OK); //simulate OK press
253     }
254     else
255     { //check if press is outside this view! then simulate cancel
256       int x=(m->parameter>>16)-getScreenX();
257       int y=(m->parameter&0xFFFF)-getScreenY();
258       if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
259       {
260         boxstack->handleCommand(Remote::BACK); //simulate cancel press
261       }
262     }
263   }
264   else if (m->message == Message::CHANNEL_CHANGE)
265   {
266     Channel* chan = NULL;
267     for (UINT i = 0; i < chanList->size(); i++)
268     {
269       if ((*chanList)[i]->number == m->parameter)
270       {
271         chan = (*chanList)[i];
272         break;
273       }
274     }
275     if (!chan) return;
276
277     if (chan->type == VDR::VIDEO)
278     {
279       VVideoLiveTV* v = new VVideoLiveTV(chanList, chan->number, this);
280       boxstack->add(v);
281       v->go();    
282     }
283     else
284     {
285     /*
286       VVideoLive* v = new VVideoLive(chanList, chan->type, this);
287       v->draw();
288       boxstack->add(v);
289       boxstack->update(v);
290       v->channelChange(VVideoLive::NUMBER, chan->number);
291     */
292     }
293   }
294 }