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