]> git.vomp.tv Git - vompclient.git/blob - vchannellist.cc
clean up
[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   chanList = tlist;
72
73   Channel* chan;
74   int first = 1;
75   if (chanList)
76   {
77     chanList->reset();
78
79     while((chan = (Channel*)chanList->getCurrent()))
80     {
81       sprintf(str, "%lu. %s", chan->number, chan->name);
82       chan->index = sl.addOption(str, first);
83       first = 0;
84       chanList->next();
85     }
86   }
87 }
88
89 void VChannelList::draw()
90 {
91   View::draw();
92   sl.draw();
93
94   // Put the status stuff at the bottom
95
96   WSymbol w;
97
98   w.nextSymbol = WSymbol::UP;
99   w.setScreenPos(screenX + 20, screenY + 385);
100   w.draw();
101
102   w.nextSymbol = WSymbol::DOWN;
103   w.setScreenPos(screenX + 50, screenY + 385);
104   w.draw();
105
106   w.nextSymbol = WSymbol::SKIPBACK;
107   w.setScreenPos(screenX + 85, screenY + 385);
108   w.draw();
109
110   w.nextSymbol = WSymbol::SKIPFORWARD;
111   w.setScreenPos(screenX + 115, screenY + 385);
112   w.draw();
113
114   w.nextSymbol = WSymbol::PLAY;
115   w.setScreenPos(screenX + 150, screenY + 385);
116   w.draw();
117
118   doShowingBar();
119 }
120
121 void VChannelList::doShowingBar()
122 {
123   int topOption = sl.getTopOption() + 1;
124   if (sl.getNumOptions() == 0) topOption = 0;
125
126   char showing[200];
127   sprintf(showing, "%i to %i of %i", topOption, sl.getBottomOption(), sl.getNumOptions());
128   Box b;
129   b.setScreenPos(screenX + 220, screenY + 385);
130   b.setDimensions(25, 160);
131   b.fillColour(Colour::VIEWBACKGROUND);
132   b.drawText(showing, 0, 0, Colour::LIGHTTEXT);
133 }
134
135 int VChannelList::handleCommand(int command)
136 {
137   switch(command)
138   {
139     case Remote::DF_UP:
140     case Remote::UP:
141     {
142       sl.up();
143       sl.draw();
144
145       doShowingBar();
146       show();
147       return 2;
148     }
149     case Remote::DF_DOWN:
150     case Remote::DOWN:
151     {
152       sl.down();
153       sl.draw();
154
155       doShowingBar();
156       show();
157       return 2;
158     }
159     case Remote::SKIPBACK:
160     {
161       sl.pageUp();
162       sl.draw();
163
164       doShowingBar();
165       show();
166       return 2;
167     }
168     case Remote::SKIPFORWARD:
169     {
170       sl.pageDown();
171       sl.draw();
172
173       doShowingBar();
174       show();
175       return 2;
176     }
177     case Remote::OK:
178     case Remote::PLAY:
179     {
180       Channel* chan = NULL;
181       if (chanList)
182       {
183         int currentOption = sl.getCurrentOption();
184         chanList->reset();
185
186         while((chan = (Channel*)chanList->getCurrent()))
187         {
188           if (currentOption == chan->index) break;
189           chanList->next();
190         }
191       }
192
193       if (chan == NULL) return 2;
194
195       if (chan->type == VDR::RADIO) return 2;
196
197       VVideoLive* v = new VVideoLive(chanList, chan->type);
198       v->setChannel(chan->number);
199
200       ViewMan::getInstance()->addNoLock(v);
201       v->draw();
202       v->show();
203
204       return 2;
205     }
206     case Remote::BACK:
207     {
208       return 4;
209     }
210   }
211   // stop command getting to any more views
212   return 1;
213 }