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