]> git.vomp.tv Git - vompclient.git/blob - vchannellist.cc
Variable width channel numbers
[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   viewman = ViewMan::getInstance();
26   create(570, 420);
27   if (Video::getInstance()->getFormat() == Video::PAL)
28   {
29     setScreenPos(80, 70);
30   }
31   else
32   {
33     setScreenPos(70, 35);
34   }
35
36
37   setBackgroundColour(Colour::VIEWBACKGROUND);
38   setTitleBarOn(1);
39
40   if (type == VDR::VIDEO)
41   {
42     setTitleText(tr("Channels"));
43   }
44   else if (type == VDR::RADIO)
45   {
46     setTitleText(tr("Radio Stations"));
47   }
48   setTitleBarColour(Colour::TITLEBARBACKGROUND);
49
50   sl.setSurface(surface);
51   sl.setSurfaceOffset(10, 30 + 5);
52   sl.setDimensions(area.w - 20, area.h - 30 - 15 - 30);
53 }
54
55 VChannelList::~VChannelList()
56 {
57   if (chanList)
58   {
59     for (UINT i = 0; i < chanList->size(); i++)
60     {
61       delete (*chanList)[i];
62     }
63
64     chanList->clear();
65     delete chanList;
66   }
67 }
68
69 void VChannelList::setList(ChannelList* tlist)
70 {
71   char str[500];
72
73   sl.addColumn(0);
74   sl.addColumn(60);
75
76   chanList = tlist;
77
78   Channel* chan;
79   int first = 1;
80   if (chanList)
81   {
82     for (UINT i = 0; i < chanList->size(); i++)
83     {
84       chan = (*chanList)[i];
85       sprintf(str, "%lu\t%s", chan->number, chan->name);
86       chan->index = sl.addOption(str, (ULONG)chan, first);
87       first = 0;
88     }
89   }
90 }
91
92 void VChannelList::highlightChannel(Channel* chan)
93 {
94   sl.hintSetCurrent(chan->index);
95   sl.draw();
96   doShowingBar();
97   viewman->updateView(this);
98 }
99
100 void VChannelList::draw()
101 {
102   View::draw();
103   sl.draw();
104
105   // Put the status stuff at the bottom
106
107   WSymbol w;
108   w.setSurface(surface);
109
110   w.nextSymbol = WSymbol::UP;
111   w.setSurfaceOffset(20, 385);
112   w.draw();
113
114   w.nextSymbol = WSymbol::DOWN;
115   w.setSurfaceOffset(50, 385);
116   w.draw();
117
118   w.nextSymbol = WSymbol::SKIPBACK;
119   w.setSurfaceOffset(85, 385);
120   w.draw();
121
122   w.nextSymbol = WSymbol::SKIPFORWARD;
123   w.setSurfaceOffset(115, 385);
124   w.draw();
125
126   w.nextSymbol = WSymbol::PLAY;
127   w.setSurfaceOffset(150, 385);
128   w.draw();
129
130   doShowingBar();
131 }
132
133 void VChannelList::doShowingBar()
134 {
135   int topOption = sl.getTopOption() + 1;
136   if (sl.getNumOptions() == 0) topOption = 0;
137
138   char showing[200];
139   sprintf(showing, tr("%i to %i of %i"), topOption, sl.getBottomOption(), sl.getNumOptions());
140
141 //  Box b;
142 //  b.setSurfaceOffset(220, 385);
143 //  b.setDimensions(160, 25);
144 //  b.fillColour(Colour::VIEWBACKGROUND);
145 //  b.drawText(showing, 0, 0, Colour::LIGHTTEXT);
146
147   rectangle(220, 385, 220+160, 385+25, Colour::VIEWBACKGROUND);
148   drawText(showing, 220, 385, Colour::LIGHTTEXT);
149 }
150
151 int VChannelList::handleCommand(int command)
152 {
153   switch(command)
154   {
155     case Remote::DF_UP:
156     case Remote::UP:
157     {
158       sl.up();
159       sl.draw();
160
161       doShowingBar();
162       viewman->updateView(this);
163       return 2;
164     }
165     case Remote::DF_DOWN:
166     case Remote::DOWN:
167     {
168       sl.down();
169       sl.draw();
170
171       doShowingBar();
172       viewman->updateView(this);
173       return 2;
174     }
175     case Remote::SKIPBACK:
176     {
177       sl.pageUp();
178       sl.draw();
179
180       doShowingBar();
181       viewman->updateView(this);
182       return 2;
183     }
184     case Remote::SKIPFORWARD:
185     {
186       sl.pageDown();
187       sl.draw();
188
189       doShowingBar();
190       viewman->updateView(this);
191       return 2;
192     }
193     case Remote::ZERO:
194     case Remote::ONE:
195     case Remote::TWO:
196     case Remote::THREE:
197     case Remote::FOUR:
198     case Remote::FIVE:
199     case Remote::SIX:
200     case Remote::SEVEN:
201     case Remote::EIGHT:
202     case Remote::NINE:
203     {
204       VChannelSelect* v = new VChannelSelect(this);
205       v->draw();
206       viewman->add(v);
207       viewman->updateView(v);
208       v->handleCommand(command);
209       return 2;
210     }
211     case Remote::OK:
212     case Remote::PLAY:
213     {
214       Channel* chan = NULL;
215       if (chanList) chan = (Channel*)sl.getCurrentOptionData();
216       if (chan == NULL) return 2;
217
218       VVideoLive* v = new VVideoLive(chanList, chan->type, this);
219
220       v->draw();
221       viewman->add(v);
222       viewman->updateView(v);
223
224       v->channelChange(VVideoLive::NUMBER, chan->number);
225
226       return 2;
227     }
228     case Remote::BACK:
229     {
230       return 4;
231     }
232   }
233   // stop command getting to any more views
234   return 1;
235 }
236
237 void VChannelList::processMessage(Message* m)
238 {
239   if (m->message == Message::MOUSE_MOVE)
240   {
241     if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
242     {
243       sl.draw();
244       doShowingBar();
245       viewman->updateView(this);
246     }
247   }
248   else if (m->message == Message::MOUSE_LBDOWN)
249   {
250     if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
251     {
252       viewman->handleCommand(Remote::OK); //simulate OK press
253     }
254     else
255     { //check if press is outside this view! then simulate cancel
256       int x=(m->parameter>>16)-getScreenX();
257       int y=(m->parameter&0xFFFF)-getScreenY();
258       if (x<0 || y <0 || x>getWidth() || y>getHeight())
259       {
260         viewman->handleCommand(Remote::BACK); //simulate cancel press
261       }
262     }
263   }
264   else if (m->message == Message::CHANNEL_CHANGE)
265   {
266     bool isinlist = false;
267
268     for (UINT i = 0; i < chanList->size(); i++)
269     {
270       if ((*chanList)[i]->number == m->parameter)
271       {
272         isinlist = true;
273         break;
274       }
275     }
276     if (!isinlist) return;
277
278     VVideoLive* v = new VVideoLive(chanList, VDR::VIDEO, this); // FIXME - what's wrong with it?
279
280     v->draw();
281     viewman->add(v);
282     viewman->updateView(v);
283     v->channelChange(VVideoLive::NUMBER, m->parameter);
284   }
285 }