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