]> git.vomp.tv Git - vompclient.git/blob - voptions.cc
New gui code
[vompclient.git] / voptions.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 "voptions.h"
22
23 VOptions::VOptions()
24 {
25   create(500, 250);
26   if (Video::getInstance()->getFormat() == Video::PAL)
27   {
28     setScreenPos(120, 140);
29   }
30   else
31   {
32     setScreenPos(110, 110);
33   }
34
35   setBackgroundColour(Colour::VIEWBACKGROUND);
36   setTitleBarOn(1);
37   setTitleBarColour(Colour::TITLEBARBACKGROUND);
38   setTitleText("Options");
39
40   int fontHeight = surface->getFontHeight();
41
42   optionBox[0].setSurface(surface);
43   optionBox[0].setSurfaceOffset(330, 45);
44   optionBox[0].setDimensions(150, fontHeight);
45   optionBox[0].addOption("Old");
46   optionBox[0].addOption("New");
47
48   optionBox[1].setSurface(surface);
49   optionBox[1].setSurfaceOffset(330, 75);
50   optionBox[1].setDimensions(150, fontHeight);
51   optionBox[1].addOption("RGB+composite");
52   optionBox[1].addOption("S-Video");
53
54   optionBox[2].setSurface(surface);
55   optionBox[2].setSurfaceOffset(330, 105);
56   optionBox[2].setDimensions(150, fontHeight);
57   optionBox[2].addOption("4:3");
58   optionBox[2].addOption("16:9");
59
60   optionBox[3].setSurface(surface);
61   optionBox[3].setSurfaceOffset(330, 135);
62   optionBox[3].setDimensions(150, fontHeight);
63   optionBox[3].addOption("On");
64   optionBox[3].addOption("Off");
65   optionBox[3].addOption("Last state");
66
67   optionBox[4].setSurface(surface);
68   optionBox[4].setSurfaceOffset(330, 165);
69   optionBox[4].setDimensions(150, fontHeight);
70   optionBox[4].addOption("All");
71   optionBox[4].addOption("FTA only");
72
73   char* config;
74   vdr = VDR::getInstance();
75
76
77   config = vdr->configLoad("General", "Remote type");
78   if (!config)
79   {
80     optionBox[0].setSelected("Old");
81   }
82   else if (!strcasecmp(config, "New"))
83   {
84     optionBox[0].setSelected("New");
85   }
86   else
87   {
88     optionBox[0].setSelected("Old");
89   }
90
91
92   config = vdr->configLoad("TV", "S-Video");
93   if (!config)
94   {
95     optionBox[1].setSelected("RGB+composite");
96   }
97   else if (!strcasecmp(config, "Yes"))
98   {
99     optionBox[1].setSelected("S-Video");
100   }
101   else
102   {
103     optionBox[1].setSelected("RGB+composite");
104   }
105
106   config = vdr->configLoad("TV", "Aspect");
107   if (!config)
108   {
109     optionBox[2].setSelected("4:3");
110   }
111   else if (!strcasecmp(config, "16:9"))
112   {
113     optionBox[2].setSelected("16:9");
114   }
115   else
116   {
117     optionBox[2].setSelected("4:3");
118   }
119
120   config = vdr->configLoad("General", "Power After Boot");
121   if (!config)
122   {
123     optionBox[3].setSelected("On");
124   }
125   else if (!strcasecmp(config, "On")) // just for completeness
126   {
127     optionBox[3].setSelected("On");
128   }
129   else if (!strcasecmp(config, "Off"))
130   {
131     optionBox[3].setSelected("Off");
132   }
133   else if (!strcasecmp(config, "Last state"))
134   {
135     optionBox[3].setSelected("Last state");
136   }
137   else
138   {
139     optionBox[3].setSelected("On");
140   }
141
142   config = vdr->configLoad("General", "Channels");
143   if (!config)
144   {
145     optionBox[4].setSelected("All");
146   }
147   else if (!strcasecmp(config, "FTA only"))
148   {
149     optionBox[4].setSelected("FTA only");
150   }
151   else
152   {
153     optionBox[4].setSelected("All");
154   }
155
156   selectedOption = 0;
157   optionBox[0].setActive(1);
158 }
159
160 VOptions::~VOptions()
161 {
162 }
163
164 void VOptions::draw()
165 {
166   View::draw();
167
168   WSymbol wsy;
169   Colour cl;
170
171   drawText("Remote control type", 10, 45, Colour::LIGHTTEXT);
172   drawText("TV connection type", 10, 75, Colour::LIGHTTEXT);
173   drawText("TV aspect ratio", 10, 105, Colour::LIGHTTEXT);
174   drawText("Power state after bootup", 10, 135, Colour::LIGHTTEXT);
175   drawText("Display channels", 10, 165, Colour::LIGHTTEXT);
176
177   drawText("Press back to exit, <, > or [ok] to change", 10, 220, Colour::LIGHTTEXT);
178
179   wsy.setSurface(surface);
180
181   for (UINT i = 0; i < numOptions; i++)
182   {
183     if (i == selectedOption) cl = Colour::SELECTHIGHLIGHT;
184     else cl = Colour::BUTTONBACKGROUND;
185
186     wsy.nextSymbol = WSymbol::LEFTARROW;
187     wsy.nextColour = cl;
188
189     wsy.setSurfaceOffset(312, 47 + (i * 30));
190     wsy.draw();
191     wsy.nextSymbol = WSymbol::RIGHTARROW;
192     wsy.setSurfaceOffset(482, 47 + (i * 30));
193     wsy.draw();
194     optionBox[i].draw();
195     optionBox[i].show();
196   }
197
198 }
199
200 int VOptions::handleCommand(int command)
201 {
202   switch(command)
203   {
204     case Remote::DF_UP:
205     case Remote::UP:
206     {
207       if (selectedOption > 0)
208       {
209         optionBox[selectedOption].setActive(0);
210         --selectedOption;
211         optionBox[selectedOption].setActive(1);
212         draw();
213         show();
214       }
215       return 2;
216     }
217     case Remote::DF_DOWN:
218     case Remote::DOWN:
219     {
220       if (selectedOption < (numOptions - 1))
221       {
222         optionBox[selectedOption].setActive(0);
223         ++selectedOption;
224         optionBox[selectedOption].setActive(1);
225         draw();
226         show();
227       }
228       return 2;
229     }
230     case Remote::DF_LEFT:
231     case Remote::LEFT:
232     {
233       optionBox[selectedOption].left();
234       draw();
235       show();
236       return 2;
237     }
238     case Remote::DF_RIGHT:
239     case Remote::RIGHT:
240     {
241       optionBox[selectedOption].right();
242       draw();
243       show();
244       return 2;
245     }
246     case Remote::BACK:
247     {
248       doSave();
249       return 4;
250     }
251     case Remote::OK:
252     {
253       optionBox[selectedOption].cycle();
254       draw();
255       show();
256     }
257   }
258
259   return 1;
260 }
261
262 void VOptions::doSave()
263 {
264   char* remoteType = optionBox[0].getSelected();
265   vdr->configSave("General", "Remote type", remoteType);
266
267   char* tvconnection = optionBox[1].getSelected();
268   if (!strcmp(tvconnection, "S-Video"))
269     vdr->configSave("TV", "S-Video", "Yes");
270   else
271     vdr->configSave("TV", "S-Video", "No");
272
273   char* aspect = optionBox[2].getSelected();
274   vdr->configSave("TV", "Aspect", aspect);
275
276   char* powerState = optionBox[3].getSelected();
277   vdr->configSave("General", "Power After Boot", powerState);
278
279   char* channels = optionBox[4].getSelected();
280   vdr->configSave("General", "Channels", channels);
281
282   // Apply changes
283
284   if (!strcmp(remoteType, "New"))
285     Remote::getInstance()->setRemoteType(Remote::NEWREMOTE);
286   else
287     Remote::getInstance()->setRemoteType(Remote::OLDREMOTE);
288
289   Video* video = Video::getInstance();
290
291   if (!strcmp(tvconnection, "S-Video"))
292     video->setConnection(Video::SVIDEO);
293   else
294     video->setConnection(Video::COMPOSITERGB);
295
296   if (!strcmp(aspect, "16:9"))
297   {
298     Log::getInstance()->log("Options", Log::DEBUG, "Setting letterbox");
299     video->setTVsize(Video::ASPECT16X9);
300   }
301   else
302   {
303     Log::getInstance()->log("Options", Log::DEBUG, "Setting normal");
304     video->setTVsize(Video::ASPECT4X3);
305   }
306 }