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