]> git.vomp.tv Git - vompclient.git/blob - voptions.cc
Options view files added, new remote type supported
[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(190, 460);
26
27   if (Video::getInstance()->getFormat() == Video::PAL)
28   {
29     setScreenPos(140, 170);
30   }
31   else
32   {
33     setScreenPos(130, 140);
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 + 290, screenY + 45);
44   optionBox[0].setDimensions(fontHeight, 150);
45   optionBox[0].addOption("Old");
46   optionBox[0].addOption("New");
47
48   optionBox[1].setScreenPos(screenX + 290, screenY + 75);
49   optionBox[1].setDimensions(fontHeight, 150);
50   optionBox[1].addOption("RGB+composite");
51   optionBox[1].addOption("S-Video");
52
53   optionBox[2].setScreenPos(screenX + 290, screenY + 105);
54   optionBox[2].setDimensions(fontHeight, 150);
55   optionBox[2].addOption("On");
56   optionBox[2].addOption("Off");
57   optionBox[2].addOption("Last state");
58
59
60   char* config;
61   vdr = VDR::getInstance();
62
63
64   config = vdr->configLoad("General", "Remote type");
65   if (!config)
66   {
67     optionBox[0].setSelected("Old");
68   }
69   else if (!strcasecmp(config, "New"))
70   {
71     optionBox[0].setSelected("New");
72   }
73   else
74   {
75     optionBox[0].setSelected("Old");
76   }
77
78
79   config = vdr->configLoad("TV", "S-Video");
80   if (!config)
81   {
82     optionBox[1].setSelected("RGB+composite");
83   }
84   else if (!strcasecmp(config, "Yes"))
85   {
86     optionBox[1].setSelected("S-Video");
87   }
88   else
89   {
90     optionBox[1].setSelected("RGB+composite");
91   }
92
93
94   config = vdr->configLoad("General", "Power After Boot");
95   if (!config)
96   {
97     optionBox[2].setSelected("On");
98   }
99   else if (!strcasecmp(config, "On")) // just for completeness
100   {
101     optionBox[2].setSelected("On");
102   }
103   else if (!strcasecmp(config, "Off"))
104   {
105     optionBox[2].setSelected("Off");
106   }
107   else if (!strcasecmp(config, "Last state"))
108   {
109     optionBox[2].setSelected("Last state");
110   }
111   else
112   {
113     optionBox[2].setSelected("On");
114   }
115
116
117   selectedOption = 0;
118   optionBox[0].setActive(1);
119 }
120
121 VOptions::~VOptions()
122 {
123 }
124
125 void VOptions::draw()
126 {
127   View::draw();
128
129   WSymbol ws;
130   Colour cl;
131
132   drawText("Remote control type", 10, 45, Colour::LIGHTTEXT);
133   drawText("TV connection type", 10, 75, Colour::LIGHTTEXT);
134   drawText("Power state after bootup", 10, 105, Colour::LIGHTTEXT);
135
136   drawText("Press back to exit, <, > or [ok] to change", 10, 160, Colour::LIGHTTEXT);
137
138   for (UINT i = 0; i < numOptions; i++)
139   {
140     if (i == selectedOption) cl = Colour::SELECTHIGHLIGHT;
141     else cl = Colour::BUTTONBACKGROUND;
142
143     ws.nextSymbol = WSymbol::LEFTARROW;
144     ws.setScreenPos(screenX + 272, screenY + 47 + (i * 30));
145     ws.draw(cl);
146     ws.nextSymbol = WSymbol::RIGHTARROW;
147     ws.setScreenPos(screenX + 442, screenY + 47 + (i * 30));
148     ws.draw(cl);
149     optionBox[i].draw();
150     optionBox[i].show();
151   }
152
153 }
154
155 int VOptions::handleCommand(int command)
156 {
157   switch(command)
158   {
159     case Remote::DF_UP:
160     case Remote::UP:
161     {
162       if (selectedOption > 0)
163       {
164         optionBox[selectedOption].setActive(0);
165         --selectedOption;
166         optionBox[selectedOption].setActive(1);
167         draw();
168         show();
169       }
170       return 2;
171     }
172     case Remote::DF_DOWN:
173     case Remote::DOWN:
174     {
175       if (selectedOption < (numOptions - 1))
176       {
177         optionBox[selectedOption].setActive(0);
178         ++selectedOption;
179         optionBox[selectedOption].setActive(1);
180         draw();
181         show();
182       }
183       return 2;
184     }
185     case Remote::DF_LEFT:
186     case Remote::LEFT:
187     {
188       optionBox[selectedOption].left();
189       draw();
190       show();
191       return 2;
192     }
193     case Remote::DF_RIGHT:
194     case Remote::RIGHT:
195     {
196       optionBox[selectedOption].right();
197       draw();
198       show();
199       return 2;
200     }
201     case Remote::BACK:
202     {
203       doSave();
204       return 4;
205     }
206     case Remote::OK:
207     {
208       optionBox[selectedOption].cycle();
209       draw();
210       show();
211     }
212   }
213
214   return 1;
215 }
216
217 void VOptions::doSave()
218 {
219   char* remoteType = optionBox[0].getSelected();
220   vdr->configSave("General", "Remote type", remoteType);
221   if (!strcmp(remoteType, "New"))
222   {
223     Remote::getInstance()->setRemoteType(Remote::NEWREMOTE);
224   }
225   else
226   {
227     Remote::getInstance()->setRemoteType(Remote::OLDREMOTE);
228   }
229
230   char* tvconnection = optionBox[1].getSelected();
231   if (!strcmp(tvconnection, "S-Video"))
232   {
233     vdr->configSave("TV", "S-Video", "Yes");
234     Video::getInstance()->setConnection(Video::SVIDEO);
235   }
236   else
237   {
238     vdr->configSave("TV", "S-Video", "No");
239     Video::getInstance()->setConnection(Video::COMPOSITERGB);
240   }
241
242   char* powerState = optionBox[2].getSelected();
243   vdr->configSave("General", "Power After Boot", powerState);
244 }