]> git.vomp.tv Git - vompclient.git/blob - voptions.cc
GUI bug fix
[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(530, 85+(NUM_OPTIONS*30));
26   if (Video::getInstance()->getFormat() == Video::PAL)
27   {
28     setScreenPos(104, 130);
29   }
30   else
31   {
32     setScreenPos(94, 70);
33   }
34
35   setBackgroundColour(Colour::VIEWBACKGROUND);
36   setTitleBarOn(1);
37   setTitleBarColour(Colour::TITLEBARBACKGROUND);
38   setTitleText(tr("Options"));
39
40   int fontHeight = surface->getFontHeight();
41
42   UINT i;
43   for (i = 0; i < numOptions; i++)
44   {
45     optionBox[i].setSurface(surface);
46     optionBox[i].setSurfaceOffset(346, 45 + (i * 30));
47     optionBox[i].setDimensions(150, fontHeight);
48     for (UINT j = 0; j < optionData[i].optionCount; j++)
49     {
50       Log::getInstance()->log("Options", Log::DEBUG, "Add option: %s", optionData[i].options[j]);
51       optionBox[i].addOption(tr((char*)optionData[i].options[j]));
52     }
53   }
54
55   char* config;
56   vdr = VDR::getInstance();
57
58   for (i = 0; i < numOptions; i++)
59   {
60     optionBox[i].setSelected(tr((char*)optionData[i].options[optionData[i].defaultOption]));
61     config = vdr->configLoad(optionData[i].configSection, optionData[i].configParam);
62     if (config)
63     {
64       for (UINT j = 0; j < optionData[i].optionCount; j++)
65       {
66         if (!strcasecmp(config, optionData[i].options[j]))
67         {
68           optionBox[i].setSelected(tr((char*)optionData[i].options[j]));
69         }
70       }
71       delete[] config;
72     }
73   }
74
75   // After setup, save all current indexes
76   optionsAtStart = new int[numOptions];
77
78   for (i = 0; i < numOptions; i++)
79   {
80     optionsAtStart[i] = optionBox[i].getSelectedIndex();
81   }
82
83   selectedOption = 0;
84   optionBox[0].setActive(1);
85 }
86
87 VOptions::~VOptions()
88 {
89   delete[] optionsAtStart;
90 }
91
92 void VOptions::draw()
93 {
94   View::draw();
95
96   WSymbol wsy;
97   Colour cl;
98
99   drawText(tr("Press back to exit, <, > or [ok] to change"), 10, 55+numOptions*30, Colour::LIGHTTEXT);
100
101   wsy.setSurface(surface);
102
103   for (UINT i = 0; i < numOptions; i++)
104   {
105     drawText(tr(optionData[i].title), 10, 45+i*30, Colour::LIGHTTEXT);
106
107     if (i == selectedOption) cl = Colour::SELECTHIGHLIGHT;
108     else cl = Colour::BUTTONBACKGROUND;
109
110     wsy.nextSymbol = WSymbol::LEFTARROW;
111     wsy.nextColour = cl;
112
113     wsy.setSurfaceOffset(328, 47 + (i * 30));
114     wsy.draw();
115     wsy.nextSymbol = WSymbol::RIGHTARROW;
116     wsy.setSurfaceOffset(498, 47 + (i * 30));
117     wsy.draw();
118     optionBox[i].draw();
119   }
120 }
121
122 int VOptions::handleCommand(int command)
123 {
124   switch(command)
125   {
126     case Remote::DF_UP:
127     case Remote::UP:
128     {
129       if (selectedOption > 0)
130       {
131         optionBox[selectedOption].setActive(0);
132         --selectedOption;
133         optionBox[selectedOption].setActive(1);
134         draw();
135         show();
136       }
137       return 2;
138     }
139     case Remote::DF_DOWN:
140     case Remote::DOWN:
141     {
142       if (selectedOption < (numOptions - 1))
143       {
144         optionBox[selectedOption].setActive(0);
145         ++selectedOption;
146         optionBox[selectedOption].setActive(1);
147         draw();
148         show();
149       }
150       return 2;
151     }
152     case Remote::DF_LEFT:
153     case Remote::LEFT:
154     {
155       optionBox[selectedOption].left();
156       draw();
157       show();
158       return 2;
159     }
160     case Remote::DF_RIGHT:
161     case Remote::RIGHT:
162     {
163       optionBox[selectedOption].right();
164       draw();
165       show();
166       return 2;
167     }
168     case Remote::BACK:
169     {
170       doSave();
171       return 4;
172     }
173     case Remote::OK:
174     {
175       optionBox[selectedOption].cycle();
176       draw();
177       show();
178     }
179   }
180
181   return 1;
182 }
183
184 void VOptions::doSave()
185 {
186   int result[numOptions];
187
188   for (UINT i = 0; i < numOptions; i++)
189   {
190     result[i] = optionBox[i].getSelectedIndex();
191
192     if (result[i] != optionsAtStart[i])
193     {
194       Log::getInstance()->log("Options", Log::DEBUG, "Option %i has changed", i);
195
196       vdr->configSave(optionData[i].configSection, optionData[i].configParam,
197         optionData[i].options[result[i]]);
198     }
199   }
200
201   // Apply changes
202   Video* video = Video::getInstance();
203
204   if (result[0] != optionsAtStart[0])
205   {
206     if (result[0] == 1)
207     {
208       Log::getInstance()->log("Options", Log::DEBUG, "Setting New Remote");
209       Remote::getInstance()->setRemoteType(Remote::NEWREMOTE);
210     }
211     else
212     {
213       Log::getInstance()->log("Options", Log::DEBUG, "Setting Old Remote");
214       Remote::getInstance()->setRemoteType(Remote::OLDREMOTE);
215     }
216   }
217
218   if (result[1] != optionsAtStart[1])
219   {
220     I18n::initialize();
221     Message *m = new Message();
222     m->to = VWelcome::getInstance();
223     m->message = Message::REDRAW_LANG;
224     ViewMan::getInstance()->postMessage(m);
225   }
226
227   if (result[2] != optionsAtStart[2])
228   {
229     if (result[2] == 1)
230     {
231       Log::getInstance()->log("Options", Log::DEBUG, "Setting S-Video");
232       video->setConnection(Video::SVIDEO);
233     }
234     else
235     {
236       Log::getInstance()->log("Options", Log::DEBUG, "Setting RGB/Composite");
237       video->setConnection(Video::COMPOSITERGB);
238     }
239   }
240
241   if (result[3] != optionsAtStart[3])
242   {
243     if (result[3] == 1)
244     {
245       Log::getInstance()->log("Options", Log::DEBUG, "Setting 16:9 TV");
246       video->setTVsize(Video::ASPECT16X9);
247     }
248     else
249     {
250       Log::getInstance()->log("Options", Log::DEBUG, "Setting 4:3 TV");
251       video->setTVsize(Video::ASPECT4X3);
252     }
253   }
254
255   if (result[4] != optionsAtStart[4])
256   {
257     if (result[4] == 1)
258     {
259       Log::getInstance()->log("Options", Log::DEBUG, "Setting letterbox");
260       video->setMode(Video::LETTERBOX);
261     }
262     else
263     {
264       Log::getInstance()->log("Options", Log::DEBUG, "Setting chop-sides");
265       video->setMode(Video::NORMAL);
266     }
267   }
268 }
269