2 Copyright 2004-2005 Chris Tallon
4 This file is part of VOMP.
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.
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.
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
23 VOptions::VOptions(View* tparent, const char* title, const OPTIONDATA* toptionData, const int tnumOptions)
25 viewman = ViewMan::getInstance();
28 optionData = toptionData;
29 numOptions = tnumOptions;
32 if (numOptions < 4) newHeight += (4 * 30);
33 else newHeight += (numOptions * 30);
35 create(530, newHeight);
37 setBackgroundColour(Colour::VIEWBACKGROUND);
39 setTitleBarColour(Colour::TITLEBARBACKGROUND);
42 int fontHeight = surface->getFontHeight();
44 optionBoxes = new WOptionBox[numOptions];
48 vdr = VDR::getInstance();
49 // After setup, save all current indexes
50 optionsAtStart = new int[numOptions];
52 for (i = 0; i < numOptions; i++)
54 optionBoxes[i].setSurface(surface);
55 optionBoxes[i].setSurfaceOffset(346, 45 + (i * 30));
56 optionBoxes[i].setDimensions(150, fontHeight);
58 if (optionData[i].optionType == OPTIONTYPE_TEXT)
60 for (j = 0; j < optionData[i].optionCount; j++)
62 Log::getInstance()->log("Options", Log::DEBUG, "Add option: %s", optionData[i].options[j]);
63 optionBoxes[i].addOption(tr((char*)optionData[i].options[j]));
66 // Set the built in default
67 optionBoxes[i].setSelected(tr((char*)optionData[i].options[optionData[i].defaultOption]));
72 optionBoxes[i].setIntMode(optionData[i].startInt, optionData[i].optionCount);
73 optionBoxes[i].setSelected(optionData[i].defaultOption);
76 // Now see if there is a config option for it
77 config = vdr->configLoad(optionData[i].configSection, optionData[i].configParam);
80 if (optionData[i].optionType == OPTIONTYPE_TEXT)
82 for (j = 0; j < optionData[i].optionCount; j++)
84 if (!STRCASECMP(config, optionData[i].options[j]))
86 optionBoxes[i].setSelected(tr((char*)optionData[i].options[j]));
92 optionBoxes[i].setSelected(atoi(config));
97 // After setup, save initial option
98 optionsAtStart[i] = optionBoxes[i].getSelectedIndex();
102 optionBoxes[0].setActive(1);
105 if ((numOptions < 8) && (numOptions >= 4))
107 voff = (8 - numOptions) * 10;
109 else if (numOptions < 4)
111 voff = 40; //(4 * 10)
114 if (Video::getInstance()->getFormat() == Video::PAL)
116 setScreenPos(104, 130 + voff);
120 setScreenPos(94, 70 + voff);
123 if (!vdr->isConnected()) Command::getInstance()->connectionLost();
126 VOptions::~VOptions()
128 delete[] optionsAtStart;
129 delete[] optionBoxes;
132 void VOptions::draw()
139 drawText(tr("Press back to exit, <, > or [ok] to change"), 10, area.h - 30, Colour::LIGHTTEXT);
141 wsy.setSurface(surface);
143 for (UINT i = 0; i < numOptions; i++)
145 drawText(tr(optionData[i].title), 10, 45+i*30, Colour::LIGHTTEXT);
147 if (i == selectedOption) cl = Colour::SELECTHIGHLIGHT;
148 else cl = Colour::BUTTONBACKGROUND;
150 wsy.nextSymbol = WSymbol::LEFTARROW;
153 wsy.setSurfaceOffset(328, 47 + (i * 30));
155 wsy.nextSymbol = WSymbol::RIGHTARROW;
156 wsy.setSurfaceOffset(498, 47 + (i * 30));
158 optionBoxes[i].draw();
162 int VOptions::handleCommand(int command)
169 if (selectedOption > 0)
171 optionBoxes[selectedOption].setActive(0);
173 optionBoxes[selectedOption].setActive(1);
175 viewman->updateView(this);
179 case Remote::DF_DOWN:
182 if (selectedOption < (numOptions - 1))
184 optionBoxes[selectedOption].setActive(0);
186 optionBoxes[selectedOption].setActive(1);
188 viewman->updateView(this);
192 case Remote::DF_LEFT:
195 optionBoxes[selectedOption].left();
197 viewman->updateView(this);
200 case Remote::DF_RIGHT:
203 optionBoxes[selectedOption].right();
205 viewman->updateView(this);
212 // Instead of returning 4 here which would delete this view
213 // before the doSave message is processed, let the message queue
214 // do the doSave then this close message. That will make the options menu
215 // disappear before this view
217 Message* m = new Message();
218 m->message = Message::CLOSE_ME;
221 Command::getInstance()->postMessageNoLock(m);
227 optionBoxes[selectedOption].cycle();
229 viewman->updateView(this);
236 void VOptions::doSave()
239 int* result = new int[numOptions];
241 for (i = 0; i < numOptions; i++)
243 result[i] = optionBoxes[i].getSelectedIndex();
245 if (result[i] != optionsAtStart[i])
247 Log::getInstance()->log("Options", Log::DEBUG, "Option %i has changed", i);
249 if (optionData[i].optionType == OPTIONTYPE_TEXT)
251 vdr->configSave(optionData[i].configSection, optionData[i].configParam,
252 optionData[i].options[result[i]]);
257 sprintf(buffer, "%i", result[i]);
258 vdr->configSave(optionData[i].configSection, optionData[i].configParam,
264 // Save a vector of option IDs that have changed
266 map<int, int>* optionChanges = new map<int, int>;
268 for (i = 0; i < numOptions; i++)
270 if (result[i] != optionsAtStart[i])
272 (*optionChanges)[optionData[i].id] = result[i];
278 // Send it to parent for changes to be applied
279 Message* m = new Message();
280 m->message = Message::CHANGED_OPTIONS;
282 m->parameter = (ULONG)optionChanges;
283 Command::getInstance()->postMessageNoLock(m);