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