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