]> git.vomp.tv Git - vompclient.git/blob - voptions.cc
I18n
[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, 75+(NUM_OPTIONS*30));
26   if (Video::getInstance()->getFormat() == Video::PAL)
27   {
28     setScreenPos(120, 140);
29   }
30   else
31   {
32     setScreenPos(110, 80);
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(330, 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");
51       Log::getInstance()->log("Options", Log::DEBUG, "Add option: %s", optionData[i].options[j]);
52       optionBox[i].addOption(tr(optionData[i].options[j]));
53       Log::getInstance()->log("Options", Log::DEBUG, "Done add option");
54     }
55   }
56
57   char* config;
58   vdr = VDR::getInstance();
59
60   for (i = 0; i < numOptions; i++)
61   {
62     optionBox[i].setSelected(tr(optionData[i].options[optionData[i].defaultOption]));
63     config = vdr->configLoad(optionData[i].configSection, optionData[i].configParam);
64     if (config)
65     {
66       for (UINT j = 0; j < optionData[i].optionCount; j++)
67       {
68         if (!strcasecmp(config, optionData[i].options[j]))
69         {
70           optionBox[i].setSelected(tr(optionData[i].options[j]));
71         }
72       }
73       delete[] config;
74     }
75   }
76
77   selectedOption = 0;
78   optionBox[0].setActive(1);
79 }
80
81 VOptions::~VOptions()
82 {
83 }
84
85 void VOptions::draw()
86 {
87   View::draw();
88
89   WSymbol wsy;
90   Colour cl;
91
92   drawText(tr("Press back to exit, <, > or [ok] to change"), 10, 45+numOptions*30, Colour::LIGHTTEXT);
93
94   wsy.setSurface(surface);
95
96   for (UINT i = 0; i < numOptions; i++)
97   {
98     drawText(tr(optionData[i].title), 10, 45+i*30, Colour::LIGHTTEXT);
99
100     if (i == selectedOption) cl = Colour::SELECTHIGHLIGHT;
101     else cl = Colour::BUTTONBACKGROUND;
102
103     wsy.nextSymbol = WSymbol::LEFTARROW;
104     wsy.nextColour = cl;
105
106     wsy.setSurfaceOffset(312, 47 + (i * 30));
107     wsy.draw();
108     wsy.nextSymbol = WSymbol::RIGHTARROW;
109     wsy.setSurfaceOffset(482, 47 + (i * 30));
110     wsy.draw();
111     optionBox[i].draw();
112     optionBox[i].show();
113   }
114 }
115
116 int VOptions::handleCommand(int command)
117 {
118   switch(command)
119   {
120     case Remote::DF_UP:
121     case Remote::UP:
122     {
123       if (selectedOption > 0)
124       {
125         optionBox[selectedOption].setActive(0);
126         --selectedOption;
127         optionBox[selectedOption].setActive(1);
128         draw();
129         show();
130       }
131       return 2;
132     }
133     case Remote::DF_DOWN:
134     case Remote::DOWN:
135     {
136       if (selectedOption < (numOptions - 1))
137       {
138         optionBox[selectedOption].setActive(0);
139         ++selectedOption;
140         optionBox[selectedOption].setActive(1);
141         draw();
142         show();
143       }
144       return 2;
145     }
146     case Remote::DF_LEFT:
147     case Remote::LEFT:
148     {
149       optionBox[selectedOption].left();
150       draw();
151       show();
152       return 2;
153     }
154     case Remote::DF_RIGHT:
155     case Remote::RIGHT:
156     {
157       optionBox[selectedOption].right();
158       draw();
159       show();
160       return 2;
161     }
162     case Remote::BACK:
163     {
164       doSave();
165       return 4;
166     }
167     case Remote::OK:
168     {
169       optionBox[selectedOption].cycle();
170       draw();
171       show();
172     }
173   }
174
175   return 1;
176 }
177
178 void VOptions::doSave()
179 {
180   int result[numOptions];
181
182   for (UINT i = 0; i < numOptions; i++)
183   {
184     result[i] = optionBox[i].getSelectedIndex();
185     vdr->configSave(optionData[i].configSection, optionData[i].configParam,
186   optionData[i].options[result[i]]);
187   }
188
189   // Apply changes
190   Video* video = Video::getInstance();
191
192   if (result[0] == 1)
193   {
194     Log::getInstance()->log("Options", Log::DEBUG, "Setting New Remote");
195     Remote::getInstance()->setRemoteType(Remote::NEWREMOTE);
196   }
197   else
198   {
199     Log::getInstance()->log("Options", Log::DEBUG, "Setting Old Remote");
200     Remote::getInstance()->setRemoteType(Remote::OLDREMOTE);
201   }
202
203   if (result[2] == 1)
204   {
205     Log::getInstance()->log("Options", Log::DEBUG, "Setting S-Video");
206     video->setConnection(Video::SVIDEO);
207   }
208   else
209   {
210     Log::getInstance()->log("Options", Log::DEBUG, "Setting RGB/Composite");
211     video->setConnection(Video::COMPOSITERGB);
212   }
213
214   if (result[3] == 1)
215   {
216     Log::getInstance()->log("Options", Log::DEBUG, "Setting 16:9 TV");
217     video->setTVsize(Video::ASPECT16X9);
218   }
219   else
220   {
221     Log::getInstance()->log("Options", Log::DEBUG, "Setting 4:3 TV");
222     video->setTVsize(Video::ASPECT4X3);
223   }
224
225   if (result[4] == 1)
226   {
227     Log::getInstance()->log("Options", Log::DEBUG, "Setting letterbox");
228     video->setMode(Video::LETTERBOX);
229   }
230   else
231   {
232     Log::getInstance()->log("Options", Log::DEBUG, "Setting chop-sides");
233     video->setMode(Video::NORMAL);
234   }
235   I18n::Initialize();
236 }
237