]> 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 #ifndef GRADIENT_DRAWING
171   rectangle(220, 385,160, 25, DrawStyle::VIEWBACKGROUND);
172 #endif
173   drawText(showing, 220, 385, DrawStyle::LIGHTTEXT);
174 }
175
176 void VChannelList::quickUpdate() { //only quick for plattform that need it!
177 #ifdef GRADIENT_DRAWING
178       draw();
179 #else
180       sl.draw();
181       doShowingBar();
182 #endif
183 }
184
185 int VChannelList::handleCommand(int command)
186 {
187   switch(command)
188   {
189     case Remote::DF_UP:
190     case Remote::UP:
191     {
192       sl.up();
193       quickUpdate();
194
195       boxstack->update(this);
196       return 2;
197     }
198     case Remote::DF_DOWN:
199     case Remote::DOWN:
200     {
201       sl.down();
202       quickUpdate();
203
204       boxstack->update(this);
205       return 2;
206     }
207     case Remote::SKIPBACK:
208     {
209       sl.pageUp();
210       quickUpdate();
211
212       boxstack->update(this);
213       return 2;
214     }
215     case Remote::SKIPFORWARD:
216     {
217       sl.pageDown();
218       quickUpdate();
219
220       boxstack->update(this);
221       return 2;
222     }
223     case Remote::ZERO:
224     case Remote::ONE:
225     case Remote::TWO:
226     case Remote::THREE:
227     case Remote::FOUR:
228     case Remote::FIVE:
229     case Remote::SIX:
230     case Remote::SEVEN:
231     case Remote::EIGHT:
232     case Remote::NINE:
233     {
234       VChannelSelect* v = new VChannelSelect(this);
235       v->draw();
236       boxstack->add(v);
237       boxstack->update(v);
238       v->handleCommand(command);
239       return 2;
240     }
241     case Remote::OK:
242     case Remote::PLAY:
243     {
244       Channel* chan = NULL;
245       if (chanList) chan = (Channel*)sl.getCurrentOptionData();
246       if (chan == NULL) return 2;
247  
248       VVideoLiveTV* v = new VVideoLiveTV(chanList, chan->number, this);
249       boxstack->add(v);
250       v->go();
251
252       return 2;
253     }
254     case Remote::BACK:
255     {
256       return 4;
257     }
258   }
259   // stop command getting to any more views
260   return 1;
261 }
262
263 void VChannelList::processMessage(Message* m)
264 {
265  /* if (m->message == Message::MOUSE_MOVE) {
266         if (sl.mouseAndroidScroll((m->tag >> 16),(m->tag & 0xFFFF),
267                         (m->parameter.num >> 16),(m->parameter.num & 0xFFFF))) {
268                 sl.draw();
269                 doShowingBar();
270                 boxstack->update(this);
271         }
272   }
273   else */if (m->message == Message::MOUSE_MOVE)
274   {
275     if (sl.mouseMove((m->parameter.num>>16)-getScreenX(),(m->parameter.num&0xFFFF)-getScreenY()))
276     {
277       quickUpdate();
278       boxstack->update(this);
279     }
280   }
281   else if (m->message == Message::MOUSE_LBDOWN)
282   {
283     if (sl.mouseLBDOWN((m->parameter.num>>16)-getScreenX(),(m->parameter.num&0xFFFF)-getScreenY()))
284     {
285       boxstack->handleCommand(Remote::OK); //simulate OK press
286     }
287     else
288     { //check if press is outside this view! then simulate cancel
289       int x=(m->parameter.num>>16)-getScreenX();
290       int y=(m->parameter.num&0xFFFF)-getScreenY();
291       if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
292       {
293         boxstack->handleCommand(Remote::BACK); //simulate cancel press
294       }
295     }
296   }
297   else if (m->message == Message::CHANNEL_CHANGE)
298   {
299     Channel* chan = NULL;
300     for (UINT i = 0; i < chanList->size(); i++)
301     {
302       if ((*chanList)[i]->number == m->parameter.num)
303       {
304         chan = (*chanList)[i];
305         break;
306       }
307     }
308     if (!chan) return;
309
310 /*    if (chan->type == VDR::VIDEO)
311     {*/
312       VVideoLiveTV* v = new VVideoLiveTV(chanList, chan->number, this);
313       boxstack->add(v);
314       v->go();    
315 /*    }
316     else
317     {
318     
319       VVideoLive* v = new VVideoLive(chanList, chan->type, this);
320       v->draw();
321       boxstack->add(v);
322       boxstack->update(v);
323       v->channelChange(VVideoLive::NUMBER, chan->number);
324     
325     }*/
326   }
327 }