]> git.vomp.tv Git - vompclient.git/blob - voptions.cc
I18n improvements. German translation added. Centre text justify.
[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     optionBox[i].show();
120   }
121 }
122
123 int VOptions::handleCommand(int command)
124 {
125   switch(command)
126   {
127     case Remote::DF_UP:
128     case Remote::UP:
129     {
130       if (selectedOption > 0)
131       {
132         optionBox[selectedOption].setActive(0);
133         --selectedOption;
134         optionBox[selectedOption].setActive(1);
135         draw();
136         show();
137       }
138       return 2;
139     }
140     case Remote::DF_DOWN:
141     case Remote::DOWN:
142     {
143       if (selectedOption < (numOptions - 1))
144       {
145         optionBox[selectedOption].setActive(0);
146         ++selectedOption;
147         optionBox[selectedOption].setActive(1);
148         draw();
149         show();
150       }
151       return 2;
152     }
153     case Remote::DF_LEFT:
154     case Remote::LEFT:
155     {
156       optionBox[selectedOption].left();
157       draw();
158       show();
159       return 2;
160     }
161     case Remote::DF_RIGHT:
162     case Remote::RIGHT:
163     {
164       optionBox[selectedOption].right();
165       draw();
166       show();
167       return 2;
168     }
169     case Remote::BACK:
170     {
171       doSave();
172       return 4;
173     }
174     case Remote::OK:
175     {
176       optionBox[selectedOption].cycle();
177       draw();
178       show();
179     }
180   }
181
182   return 1;
183 }
184
185 void VOptions::doSave()
186 {
187   int result[numOptions];
188
189   for (UINT i = 0; i < numOptions; i++)
190   {
191     result[i] = optionBox[i].getSelectedIndex();
192
193     if (result[i] != optionsAtStart[i])
194     {
195       Log::getInstance()->log("Options", Log::DEBUG, "Option %i has changed", i);
196
197       vdr->configSave(optionData[i].configSection, optionData[i].configParam,
198         optionData[i].options[result[i]]);
199     }
200   }
201
202   // Apply changes
203   Video* video = Video::getInstance();
204
205   if (result[0] != optionsAtStart[0])
206   {
207     if (result[0] == 1)
208     {
209       Log::getInstance()->log("Options", Log::DEBUG, "Setting New Remote");
210       Remote::getInstance()->setRemoteType(Remote::NEWREMOTE);
211     }
212     else
213     {
214       Log::getInstance()->log("Options", Log::DEBUG, "Setting Old Remote");
215       Remote::getInstance()->setRemoteType(Remote::OLDREMOTE);
216     }
217   }
218
219   if (result[1] != optionsAtStart[1])
220   {
221     I18n::initialize();
222     Message *m = new Message();
223     m->to = VWelcome::getInstance();
224     m->message = Message::REDRAW_LANG;
225     ViewMan::getInstance()->postMessage(m);
226   }
227
228   if (result[2] != optionsAtStart[2])
229   {
230     if (result[2] == 1)
231     {
232       Log::getInstance()->log("Options", Log::DEBUG, "Setting S-Video");
233       video->setConnection(Video::SVIDEO);
234     }
235     else
236     {
237       Log::getInstance()->log("Options", Log::DEBUG, "Setting RGB/Composite");
238       video->setConnection(Video::COMPOSITERGB);
239     }
240   }
241
242   if (result[3] != optionsAtStart[3])
243   {
244     if (result[3] == 1)
245     {
246       Log::getInstance()->log("Options", Log::DEBUG, "Setting 16:9 TV");
247       video->setTVsize(Video::ASPECT16X9);
248     }
249     else
250     {
251       Log::getInstance()->log("Options", Log::DEBUG, "Setting 4:3 TV");
252       video->setTVsize(Video::ASPECT4X3);
253     }
254   }
255
256   if (result[4] != optionsAtStart[4])
257   {
258     if (result[4] == 1)
259     {
260       Log::getInstance()->log("Options", Log::DEBUG, "Setting letterbox");
261       video->setMode(Video::LETTERBOX);
262     }
263     else
264     {
265       Log::getInstance()->log("Options", Log::DEBUG, "Setting chop-sides");
266       video->setMode(Video::NORMAL);
267     }
268   }
269 }
270