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