]> git.vomp.tv Git - vompclient.git/blob - vchannellist.cc
Implement startup-to-live-TV
[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
82 void VChannelList::setList(std::shared_ptr<ChannelList> tlist)
83 {
84   char str[500];
85   OsdVector *osdv=dynamic_cast<OsdVector*>(Osd::getInstance());
86
87   sl.addColumn(0);
88   if (osdv) sl.addColumn(20);
89   sl.addColumn(60);
90
91   chanList = tlist;
92
93   Channel* chan;
94   int first = 1;
95   if (chanList)
96   {
97
98     for (UINT i = 0; i < chanList->size(); i++)
99     {
100       chan = (*chanList)[i];
101       sprintf(str, "%lu\t%s", chan->number, chan->name);
102       TVMediaInfo *info=NULL;
103       if (osdv) {
104           info= new TVMediaInfo();
105           info->setChannelLogo((*chanList)[i]->number);
106           if (type == VDR::VIDEO) info->setStaticFallback(sa_tv);
107           else info->setStaticFallback(sa_radio);
108       }
109       chan->index = sl.addOption(str, chan, first, info);
110       first = 0;
111     }
112   }
113 }
114
115 void VChannelList::highlightChannel(Channel* chan)
116 {
117   sl.hintSetCurrent(chan->index);
118   sl.draw();
119   doShowingBar();
120   boxstack->update(this);
121 }
122
123 void VChannelList::draw()
124 {
125   TBBoxx::draw();
126
127   // Put the status stuff at the bottom
128
129   WSymbol w;
130   TEMPADD(&w);
131
132   w.nextSymbol = WSymbol::UP;
133   w.setPosition(20, 385);
134   w.draw();
135
136   w.nextSymbol = WSymbol::DOWN;
137   w.setPosition(50, 385);
138   w.draw();
139
140   w.nextSymbol = WSymbol::SKIPBACK;
141   w.setPosition(85, 385);
142   w.draw();
143
144   w.nextSymbol = WSymbol::SKIPFORWARD;
145   w.setPosition(115, 385);
146   w.draw();
147
148   w.nextSymbol = WSymbol::PLAY;
149   w.setPosition(150, 385);
150   w.draw();
151
152   doShowingBar();
153 }
154
155 void VChannelList::doShowingBar()
156 {
157   int topOption = sl.getTopOption() + 1;
158   if (sl.getNumOptions() == 0) topOption = 0;
159
160   rectangle(220, 385, 160, 25, DrawStyle::VIEWBACKGROUND);
161
162   char showing[200];
163   sprintf(showing, tr("%i to %i of %i"), topOption, sl.getBottomOption(), sl.getNumOptions());
164   drawText(showing, 220, 385, DrawStyle::LIGHTTEXT);
165
166   /*
167    * The following would work but the translation files need changing to {} instead of %i
168    * This is server side and so requires a server version bump breaking compatibility with older clients
169    * Maybe this will happen for v0.6 ?
170    *
171    * drawText(
172    * fmt::format(tr("%i to %i of %i"), topOption, sl.getBottomOption(), sl.getNumOptions()).c_str(),
173    * 220, 385, DrawStyle::LIGHTTEXT);
174    *
175    */
176 }
177
178 void VChannelList::quickUpdate() { //only quick for plattform that need it!
179 #ifdef GRADIENT_DRAWING
180       draw();
181 #else
182       sl.draw();
183       doShowingBar();
184 #endif
185 }
186
187 int VChannelList::handleCommand(int command)
188 {
189   switch(command)
190   {
191     case Input::UP:
192     {
193       sl.up();
194       quickUpdate();
195
196       boxstack->update(this);
197       return BoxStack::COMMAND_HANDLED;
198     }
199     case Input::DOWN:
200     {
201       sl.down();
202       quickUpdate();
203
204       boxstack->update(this);
205       return BoxStack::COMMAND_HANDLED;
206     }
207     case Input::SKIPBACK:
208     {
209       sl.pageUp();
210       quickUpdate();
211
212       boxstack->update(this);
213       return BoxStack::COMMAND_HANDLED;
214     }
215     case Input::SKIPFORWARD:
216     {
217       sl.pageDown();
218       quickUpdate();
219
220       boxstack->update(this);
221       return BoxStack::COMMAND_HANDLED;
222     }
223     case Input::ZERO:
224     case Input::ONE:
225     case Input::TWO:
226     case Input::THREE:
227     case Input::FOUR:
228     case Input::FIVE:
229     case Input::SIX:
230     case Input::SEVEN:
231     case Input::EIGHT:
232     case Input::NINE:
233     {
234       VChannelSelect* v = new VChannelSelect(this);
235       v->draw();
236       boxstack->add(v);
237       boxstack->update(v);
238       v->handleCommand(command);
239       return BoxStack::COMMAND_HANDLED;
240     }
241     case Input::OK:
242     case Input::PLAY:
243     {
244       Channel* chan = NULL;
245       if (chanList) chan = reinterpret_cast<Channel*>(sl.getCurrentOptionData());
246       if (chan == NULL) return 2;
247  
248       VVideoLiveTV* v = new VVideoLiveTV(chanList, chan->number, this);
249       boxstack->add(v);
250       v->go();
251
252       return BoxStack::COMMAND_HANDLED;
253     }
254     case Input::BACK:
255     {
256       return BoxStack::DELETE_ME;
257     }
258   }
259   // stop command getting to any more views
260   return BoxStack::ABANDON_COMMAND;
261 }
262
263 void VChannelList::processMessage(Message* m)
264 {
265  /* if (m->message == Message::MOUSE_MOVE) {
266         if (sl.mouseAndroidScroll((m->tag >> 16),(m->tag & 0xFFFF),
267                         (m->parameter >> 16),(m->parameter & 0xFFFF))) {
268                 sl.draw();
269                 doShowingBar();
270                 boxstack->update(this);
271         }
272   }
273   else */if (m->message == Message::MOUSE_MOVE)
274   {
275     if (sl.mouseMove(m->parameter - getScreenX(), m->tag - getScreenY()))
276     {
277       quickUpdate();
278       boxstack->update(this);
279     }
280   }
281   else if (m->message == Message::MOUSE_LBDOWN)
282   {
283     if (sl.mouseLBDOWN(m->parameter - getScreenX(), m->tag - getScreenY()))
284     {
285       Input::sendInputKey(Input::OK);
286     }
287     else if (coordsOutsideBox(m))
288     {
289       Input::sendInputKey(Input::BACK);
290     }
291   }
292   else if (m->message == Message::CHANNEL_CHANGE)
293   {
294     LogNT::getInstance()->debug(TAG, "Channel change {}", m->parameter);
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 }