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