]> git.vomp.tv Git - vompclient.git/blob - vchannellist.cc
69d5fb0d579bfa7801379f4f125ab90e255c9815
[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(DrawStyle::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
68   if (chanList)
69   {
70     for (UINT i = 0; i < chanList->size(); i++)
71     {
72       delete (*chanList)[i];
73     }
74
75     chanList->clear();
76     delete chanList;
77   }
78 }
79
80 void VChannelList::setList(ChannelList* tlist)
81 {
82   char str[500];
83
84   sl.addColumn(0);
85   sl.addColumn(60);
86
87   chanList = tlist;
88
89   Channel* chan;
90   int first = 1;
91   if (chanList)
92   {
93     for (UINT i = 0; i < chanList->size(); i++)
94     {
95       chan = (*chanList)[i];
96       sprintf(str, "%lu\t%s", chan->number, chan->name);
97       chan->index = sl.addOption(str, (ULONG)chan, first);
98       first = 0;
99     }
100   }
101 }
102
103 void VChannelList::highlightChannel(Channel* chan)
104 {
105   sl.hintSetCurrent(chan->index);
106   sl.draw();
107   doShowingBar();
108   boxstack->update(this);
109 }
110
111 void VChannelList::draw()
112 {
113   TBBoxx::draw();
114   sl.draw();
115
116   // Put the status stuff at the bottom
117
118   WSymbol w;
119   TEMPADD(&w);
120
121   w.nextSymbol = WSymbol::UP;
122   w.setPosition(20, 385);
123   w.draw();
124
125   w.nextSymbol = WSymbol::DOWN;
126   w.setPosition(50, 385);
127   w.draw();
128
129   w.nextSymbol = WSymbol::SKIPBACK;
130   w.setPosition(85, 385);
131   w.draw();
132
133   w.nextSymbol = WSymbol::SKIPFORWARD;
134   w.setPosition(115, 385);
135   w.draw();
136
137   w.nextSymbol = WSymbol::PLAY;
138   w.setPosition(150, 385);
139   w.draw();
140
141   doShowingBar();
142 }
143
144 void VChannelList::doShowingBar()
145 {
146   int topOption = sl.getTopOption() + 1;
147   if (sl.getNumOptions() == 0) topOption = 0;
148
149   char showing[200];
150   sprintf(showing, tr("%i to %i of %i"), topOption, sl.getBottomOption(), sl.getNumOptions());
151 #ifndef GRADIENT_DRAWING
152   rectangle(220, 385,160, 25, DrawStyle::VIEWBACKGROUND);
153 #endif
154   drawText(showing, 220, 385, DrawStyle::LIGHTTEXT);
155 }
156
157 void VChannelList::quickUpdate() { //only quick for plattform that need it!
158 #ifdef GRADIENT_DRAWING
159       draw();
160 #else
161       sl.draw();
162       doShowingBar();
163 #endif
164 }
165
166 int VChannelList::handleCommand(int command)
167 {
168   switch(command)
169   {
170     case Remote::DF_UP:
171     case Remote::UP:
172     {
173       sl.up();
174       quickUpdate();
175
176       boxstack->update(this);
177       return 2;
178     }
179     case Remote::DF_DOWN:
180     case Remote::DOWN:
181     {
182       sl.down();
183       quickUpdate();
184
185       boxstack->update(this);
186       return 2;
187     }
188     case Remote::SKIPBACK:
189     {
190       sl.pageUp();
191       quickUpdate();
192
193       boxstack->update(this);
194       return 2;
195     }
196     case Remote::SKIPFORWARD:
197     {
198       sl.pageDown();
199       quickUpdate();
200
201       boxstack->update(this);
202       return 2;
203     }
204     case Remote::ZERO:
205     case Remote::ONE:
206     case Remote::TWO:
207     case Remote::THREE:
208     case Remote::FOUR:
209     case Remote::FIVE:
210     case Remote::SIX:
211     case Remote::SEVEN:
212     case Remote::EIGHT:
213     case Remote::NINE:
214     {
215       VChannelSelect* v = new VChannelSelect(this);
216       v->draw();
217       boxstack->add(v);
218       boxstack->update(v);
219       v->handleCommand(command);
220       return 2;
221     }
222     case Remote::OK:
223     case Remote::PLAY:
224     {
225       Channel* chan = NULL;
226       if (chanList) chan = (Channel*)sl.getCurrentOptionData();
227       if (chan == NULL) return 2;
228  
229       VVideoLiveTV* v = new VVideoLiveTV(chanList, chan->number, this);
230       boxstack->add(v);
231       v->go();
232
233       return 2;
234     }
235     case Remote::BACK:
236     {
237       return 4;
238     }
239   }
240   // stop command getting to any more views
241   return 1;
242 }
243
244 void VChannelList::processMessage(Message* m)
245 {
246  /* if (m->message == Message::MOUSE_MOVE) {
247         if (sl.mouseAndroidScroll((m->tag >> 16),(m->tag & 0xFFFF),
248                         (m->parameter >> 16),(m->parameter & 0xFFFF))) {
249                 sl.draw();
250                 doShowingBar();
251                 boxstack->update(this);
252         }
253   }
254   else */if (m->message == Message::MOUSE_MOVE)
255   {
256     if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
257     {
258       quickUpdate();
259       boxstack->update(this);
260     }
261   }
262   else if (m->message == Message::MOUSE_LBDOWN)
263   {
264     if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
265     {
266       boxstack->handleCommand(Remote::OK); //simulate OK press
267     }
268     else
269     { //check if press is outside this view! then simulate cancel
270       int x=(m->parameter>>16)-getScreenX();
271       int y=(m->parameter&0xFFFF)-getScreenY();
272       if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
273       {
274         boxstack->handleCommand(Remote::BACK); //simulate cancel press
275       }
276     }
277   }
278   else if (m->message == Message::CHANNEL_CHANGE)
279   {
280     Channel* chan = NULL;
281     for (UINT i = 0; i < chanList->size(); i++)
282     {
283       if ((*chanList)[i]->number == m->parameter)
284       {
285         chan = (*chanList)[i];
286         break;
287       }
288     }
289     if (!chan) return;
290
291 /*    if (chan->type == VDR::VIDEO)
292     {*/
293       VVideoLiveTV* v = new VVideoLiveTV(chanList, chan->number, this);
294       boxstack->add(v);
295       v->go();    
296 /*    }
297     else
298     {
299     
300       VVideoLive* v = new VVideoLive(chanList, chan->type, this);
301       v->draw();
302       boxstack->add(v);
303       boxstack->update(v);
304       v->channelChange(VVideoLive::NUMBER, chan->number);
305     
306     }*/
307   }
308 }