]> git.vomp.tv Git - vompclient.git/blob - vchannellist.cc
Message tweaks
[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::draw()
92 {
93   View::draw();
94   sl.draw();
95
96   // Put the status stuff at the bottom
97
98   WSymbol w;
99   w.setSurface(surface);
100
101   w.nextSymbol = WSymbol::UP;
102   w.setSurfaceOffset(20, 385);
103   w.draw();
104
105   w.nextSymbol = WSymbol::DOWN;
106   w.setSurfaceOffset(50, 385);
107   w.draw();
108
109   w.nextSymbol = WSymbol::SKIPBACK;
110   w.setSurfaceOffset(85, 385);
111   w.draw();
112
113   w.nextSymbol = WSymbol::SKIPFORWARD;
114   w.setSurfaceOffset(115, 385);
115   w.draw();
116
117   w.nextSymbol = WSymbol::PLAY;
118   w.setSurfaceOffset(150, 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, tr("%i to %i of %i"), topOption, sl.getBottomOption(), sl.getNumOptions());
131
132 //  Box b;
133 //  b.setSurfaceOffset(220, 385);
134 //  b.setDimensions(160, 25);
135 //  b.fillColour(Colour::VIEWBACKGROUND);
136 //  b.drawText(showing, 0, 0, Colour::LIGHTTEXT);
137
138   rectangle(220, 385, 220+160, 385+25, Colour::VIEWBACKGROUND);
139   drawText(showing, 220, 385, Colour::LIGHTTEXT);
140 }
141
142 int VChannelList::handleCommand(int command)
143 {
144   switch(command)
145   {
146     case Remote::DF_UP:
147     case Remote::UP:
148     {
149       sl.up();
150       sl.draw();
151
152       doShowingBar();
153       ViewMan::getInstance()->updateView(this);
154       return 2;
155     }
156     case Remote::DF_DOWN:
157     case Remote::DOWN:
158     {
159       sl.down();
160       sl.draw();
161
162       doShowingBar();
163       ViewMan::getInstance()->updateView(this);
164       return 2;
165     }
166     case Remote::SKIPBACK:
167     {
168       sl.pageUp();
169       sl.draw();
170
171       doShowingBar();
172       ViewMan::getInstance()->updateView(this);
173       return 2;
174     }
175     case Remote::SKIPFORWARD:
176     {
177       sl.pageDown();
178       sl.draw();
179
180       doShowingBar();
181       ViewMan::getInstance()->updateView(this);
182       return 2;
183     }
184     case Remote::OK:
185     case Remote::PLAY:
186     {
187       Channel* chan = NULL;
188       if (chanList)
189       {
190         int currentOption = sl.getCurrentOption();
191
192         for (UINT i = 0; i < chanList->size(); i++)
193         {
194           chan = (*chanList)[i];
195           if (currentOption == chan->index) break;
196         }
197       }
198
199       if (chan == NULL) return 2;
200
201    //   if (chan->type == VDR::RADIO) return 2;
202
203       VVideoLive* v = new VVideoLive(chanList, chan->type);
204
205       v->draw();
206       ViewMan::getInstance()->add(v);
207       ViewMan::getInstance()->updateView(v);
208
209       v->channelChange(VVideoLive::NUMBER, chan->number);
210
211       return 2;
212     }
213     case Remote::BACK:
214     {
215       return 4;
216     }
217   }
218   // stop command getting to any more views
219   return 1;
220 }