]> git.vomp.tv Git - vompclient.git/blob - vvideolive.cc
Channel schedules in live banner
[vompclient.git] / vvideolive.cc
1 /*
2     Copyright 2004-2005 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20
21 #include "vvideolive.h"
22
23 VVideoLive::VVideoLive(ChannelList* tchanList, ULONG tstreamType)
24 {
25   vdr = VDR::getInstance();
26   viewman = ViewMan::getInstance();
27   chanList = tchanList;
28   currentChannel = 0;
29   unavailable = 0;
30   unavailableView = NULL;
31   streamType = tstreamType;
32   if (streamType == VDR::VIDEO)
33   {
34     player = new PlayerVideo(NULL, 0);
35   }
36   else
37   {
38     player = new PlayerRadio();
39   }
40   player->init();
41
42   Video* video = Video::getInstance();
43   setDimensions(video->getScreenWidth(), video->getScreenHeight());
44   Colour transparent(0, 0, 0, 0);
45   setBackgroundColour(transparent);
46 }
47
48 VVideoLive::~VVideoLive()
49 {
50   delete player;
51 }
52
53 void VVideoLive::draw()
54 {
55   View::draw();
56 }
57
58 int VVideoLive::handleCommand(int command)
59 {
60   switch(command)
61   {
62     case Remote::PLAY:
63     {
64       if (!unavailable) player->play(); // do resync
65       return 2;
66     }
67
68     case Remote::STOP:
69     case Remote::BACK:
70     case Remote::MENU:
71     {
72       if (unavailable) showUnavailable(0);
73       else stop();
74       return 4;
75     }
76     case Remote::DF_UP:
77     case Remote::CHANNELUP:
78     {
79       if (unavailable) showUnavailable(0);
80       else stop();
81       upChannel();
82       play();
83       return 2;
84     }
85     case Remote::DF_DOWN:
86     case Remote::CHANNELDOWN:
87     {
88       if (unavailable) showUnavailable(0);
89       else stop();
90       downChannel();
91       play();
92       return 2;
93     }
94     case Remote::OK:
95     {
96       doBanner();
97       return 2;
98     }
99
100     case Remote::ZERO ... Remote::NINE:
101     {
102       VChannelSelect* v = new VChannelSelect(this, command);
103       viewman->addNoLock(v);
104 //      ViewMan::getInstance()->timedDelete(v, 4, 0);
105       v->draw();
106       v->show();
107     }
108   }
109
110   return 1;
111 }
112
113 void VVideoLive::processMessage(Message* m)
114 {
115   if (m->message == Message::CHANNEL_CHANGE)
116   {
117     // check channel number is valid
118     currentChannel = channelIndexFromNumber(m->parameter);
119     if (unavailable) showUnavailable(0);
120     else stop();
121     play();
122   }
123   else if (m->message == Message::CHANNEL_UP)
124   {
125     // from vlivebanner
126     if (unavailable) showUnavailable(0);
127     else stop(1);
128     upChannel();
129     play(1);
130     vlb->setChannel((*chanList)[currentChannel]);
131     vlb->draw();
132     vlb->show();
133   }
134   else if (m->message == Message::CHANNEL_DOWN)
135   {
136     // from vlivebanner
137     if (unavailable) showUnavailable(0);
138     else stop(1);
139     downChannel();
140     play(1);
141     vlb->setChannel((*chanList)[currentChannel]);
142     vlb->draw();
143     vlb->show();
144   }
145
146 }
147
148 void VVideoLive::doBanner()
149 {
150   vlb = new VLiveBanner(this, (*chanList)[currentChannel]);
151   viewman->timedDelete(vlb, 4, 0);
152
153   Message* m = new Message();
154   m->from = this;
155   m->to = viewman;
156   m->message = Message::ADD_VIEW;
157   m->parameter = (ULONG)vlb;
158
159   viewman->postMessage(m);
160 }
161
162 void VVideoLive::showUnavailable(int active)
163 {
164   if (active == unavailable) return;
165
166   if (active)
167   {
168     unavailable = 1;
169
170     unavailableView = new VInfo();
171     unavailableView->setDimensions(400, 200);
172     if (Video::getInstance()->getFormat() == Video::PAL)
173     {
174       unavailableView->setScreenPos(170, 200);
175     }
176     else
177     {
178       unavailableView->setScreenPos(160, 150);
179     }
180     unavailableView->setTitleText((*chanList)[currentChannel]->name);
181     unavailableView->setMainText("\n                    Channel unavailable");
182     unavailableView->setDropThrough();
183
184     Message* m = new Message();
185     m->from = this;
186     m->to = viewman;
187     m->message = Message::ADD_VIEW;
188     m->parameter = (ULONG)unavailableView;
189
190     viewman->postMessage(m);
191   }
192   else
193   {
194     unavailable = 0;
195     ViewMan::getInstance()->removeView(unavailableView, 1);
196     unavailableView = NULL;
197   }
198 }
199
200 void VVideoLive::setChannel(int number)
201 {
202   currentChannel = channelIndexFromNumber(number);
203   play();
204 }
205
206 void VVideoLive::play(int noShowVLB)
207 {
208   showUnavailable(0);
209
210   int available = vdr->streamChannel((*chanList)[currentChannel]->number);
211
212   if (!available)
213   {
214     showUnavailable(1);
215     if (!noShowVLB) doBanner();
216   }
217   else
218   {
219     if (!noShowVLB) doBanner();
220     player->play();
221   }
222 }
223
224 void VVideoLive::stop(int noRemoveVLB)
225 {
226   if (unavailable) return;
227   if (!noRemoveVLB) viewman->removeView(vlb, 1, 1); // if live banner is present, remove it. won't cause damage if its not present
228
229   player->stop();
230   vdr->stopStreaming();
231 }
232
233 int VVideoLive::upChannel()
234 {
235   if (currentChannel == (chanList->size() - 1)) return 0; // at the end
236
237   ++currentChannel;
238   return 1;
239 }
240
241 int VVideoLive::downChannel()
242 {
243   if (currentChannel == 0) return 0; // at the start
244
245   --currentChannel;
246   return 1;
247 }
248
249 UINT VVideoLive::channelIndexFromNumber(int number)
250 {
251   for(UINT i = 0; i < chanList->size(); i++)
252   {
253     if ((*chanList)[i]->number == (UINT)number) return i;
254   }
255   return 0;
256 }
257