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