]> git.vomp.tv Git - vompclient.git/blob - vchannellist.cc
Changes for demuxer. New mutex code
[vompclient.git] / vchannellist.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 "vchannellist.h"
22
23 VChannelList::VChannelList(ULONG type)
24 {
25   create(570, 420);
26   if (Video::getInstance()->getFormat() == Video::PAL)
27   {
28     setScreenPos(80, 70);
29   }
30   else
31   {
32     setScreenPos(70, 35);
33   }
34
35
36   setBackgroundColour(Colour::VIEWBACKGROUND);
37   setTitleBarOn(1);
38
39   if (type == VDR::VIDEO)
40   {
41     setTitleText(tr("Channels"));
42   }
43   else if (type == VDR::RADIO)
44   {
45     setTitleText(tr("Radio Stations"));
46   }
47   setTitleBarColour(Colour::TITLEBARBACKGROUND);
48
49   sl.setSurface(surface);
50   sl.setSurfaceOffset(10, 30 + 5);
51   sl.setDimensions(area.w - 20, area.h - 30 - 15 - 30);
52 }
53
54 VChannelList::~VChannelList()
55 {
56   if (chanList)
57   {
58     for (UINT i = 0; i < chanList->size(); i++)
59     {
60       delete (*chanList)[i];
61     }
62
63     chanList->clear();
64     delete chanList;
65   }
66 }
67
68 void VChannelList::setList(ChannelList* tlist)
69 {
70   char str[500];
71
72   sl.addColumn(0);
73   sl.addColumn(60);
74
75   chanList = tlist;
76
77   Channel* chan;
78   int first = 1;
79   if (chanList)
80   {
81     for (UINT i = 0; i < chanList->size(); i++)
82     {
83       chan = (*chanList)[i];
84       sprintf(str, "%lu\t%s", chan->number, chan->name);
85       chan->index = sl.addOption(str, first);
86       first = 0;
87     }
88   }
89 }
90
91 void VChannelList::highlightChannel(Channel* chan)
92 {
93   sl.hintSetCurrent(chan->index);
94   sl.draw();
95   doShowingBar();
96   ViewMan::getInstance()->updateView(this);
97 }
98
99 void VChannelList::draw()
100 {
101   View::draw();
102   sl.draw();
103
104   // Put the status stuff at the bottom
105
106   WSymbol w;
107   w.setSurface(surface);
108
109   w.nextSymbol = WSymbol::UP;
110   w.setSurfaceOffset(20, 385);
111   w.draw();
112
113   w.nextSymbol = WSymbol::DOWN;
114   w.setSurfaceOffset(50, 385);
115   w.draw();
116
117   w.nextSymbol = WSymbol::SKIPBACK;
118   w.setSurfaceOffset(85, 385);
119   w.draw();
120
121   w.nextSymbol = WSymbol::SKIPFORWARD;
122   w.setSurfaceOffset(115, 385);
123   w.draw();
124
125   w.nextSymbol = WSymbol::PLAY;
126   w.setSurfaceOffset(150, 385);
127   w.draw();
128
129   doShowingBar();
130 }
131
132 void VChannelList::doShowingBar()
133 {
134   int topOption = sl.getTopOption() + 1;
135   if (sl.getNumOptions() == 0) topOption = 0;
136
137   char showing[200];
138   sprintf(showing, tr("%i to %i of %i"), topOption, sl.getBottomOption(), sl.getNumOptions());
139
140 //  Box b;
141 //  b.setSurfaceOffset(220, 385);
142 //  b.setDimensions(160, 25);
143 //  b.fillColour(Colour::VIEWBACKGROUND);
144 //  b.drawText(showing, 0, 0, Colour::LIGHTTEXT);
145
146   rectangle(220, 385, 220+160, 385+25, Colour::VIEWBACKGROUND);
147   drawText(showing, 220, 385, Colour::LIGHTTEXT);
148 }
149
150 int VChannelList::handleCommand(int command)
151 {
152   switch(command)
153   {
154     case Remote::DF_UP:
155     case Remote::UP:
156     {
157       sl.up();
158       sl.draw();
159
160       doShowingBar();
161       ViewMan::getInstance()->updateView(this);
162       return 2;
163     }
164     case Remote::DF_DOWN:
165     case Remote::DOWN:
166     {
167       sl.down();
168       sl.draw();
169
170       doShowingBar();
171       ViewMan::getInstance()->updateView(this);
172       return 2;
173     }
174     case Remote::SKIPBACK:
175     {
176       sl.pageUp();
177       sl.draw();
178
179       doShowingBar();
180       ViewMan::getInstance()->updateView(this);
181       return 2;
182     }
183     case Remote::SKIPFORWARD:
184     {
185       sl.pageDown();
186       sl.draw();
187
188       doShowingBar();
189       ViewMan::getInstance()->updateView(this);
190       return 2;
191     }
192     case Remote::OK:
193     case Remote::PLAY:
194     {
195       Channel* chan = NULL;
196       if (chanList)
197       {
198         int currentOption = sl.getCurrentOption();
199
200         for (UINT i = 0; i < chanList->size(); i++)
201         {
202           chan = (*chanList)[i];
203           if (currentOption == chan->index) break;
204         }
205       }
206
207       if (chan == NULL) return 2;
208
209       VVideoLive* v = new VVideoLive(chanList, chan->type, this);
210
211       v->draw();
212       ViewMan::getInstance()->add(v);
213       ViewMan::getInstance()->updateView(v);
214
215       v->channelChange(VVideoLive::NUMBER, chan->number);
216
217       return 2;
218     }
219     case Remote::BACK:
220     {
221       return 4;
222     }
223   }
224   // stop command getting to any more views
225   return 1;
226 }