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