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