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