]> git.vomp.tv Git - vompclient.git/blob - vchannellist.cc
Convert PlayerRadioRec to std::thread
[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 "input.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, 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 Input::UP:
190     {
191       sl.up();
192       quickUpdate();
193
194       boxstack->update(this);
195       return 2;
196     }
197     case Input::DOWN:
198     {
199       sl.down();
200       quickUpdate();
201
202       boxstack->update(this);
203       return 2;
204     }
205     case Input::SKIPBACK:
206     {
207       sl.pageUp();
208       quickUpdate();
209
210       boxstack->update(this);
211       return 2;
212     }
213     case Input::SKIPFORWARD:
214     {
215       sl.pageDown();
216       quickUpdate();
217
218       boxstack->update(this);
219       return 2;
220     }
221     case Input::ZERO:
222     case Input::ONE:
223     case Input::TWO:
224     case Input::THREE:
225     case Input::FOUR:
226     case Input::FIVE:
227     case Input::SIX:
228     case Input::SEVEN:
229     case Input::EIGHT:
230     case Input::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 Input::OK:
240     case Input::PLAY:
241     {
242       Channel* chan = NULL;
243       if (chanList) chan = reinterpret_cast<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 Input::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 >> 16),(m->parameter & 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>>16)-getScreenX(),(m->parameter&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>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
282     {
283       boxstack->handleCommand(Input::OK); //simulate OK press
284     }
285     else if (coordsOutsideBox(m))
286     {
287       boxstack->handleCommand(Input::BACK); //simulate cancel press
288     }
289   }
290   else if (m->message == Message::CHANNEL_CHANGE)
291   {
292     Channel* chan = NULL;
293     for (UINT i = 0; i < chanList->size(); i++)
294     {
295       if ((*chanList)[i]->number == m->parameter)
296       {
297         chan = (*chanList)[i];
298         break;
299       }
300     }
301     if (!chan) return;
302
303 /*    if (chan->type == VDR::VIDEO)
304     {*/
305       VVideoLiveTV* v = new VVideoLiveTV(chanList, chan->number, this);
306       boxstack->add(v);
307       v->go();    
308 /*    }
309     else
310     {
311     
312       VVideoLive* v = new VVideoLive(chanList, chan->type, this);
313       v->draw();
314       boxstack->add(v);
315       boxstack->update(v);
316       v->channelChange(VVideoLive::NUMBER, chan->number);
317     
318     }*/
319   }
320 }