]> git.vomp.tv Git - vompclient.git/blob - voptionsmenu.cc
Options menu rearrangement, set timer from EPG
[vompclient.git] / voptionsmenu.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 "voptionsmenu.h"
22
23 VOptionsMenu::VOptionsMenu()
24 {
25   viewman = ViewMan::getInstance();
26
27   create(460, 190);
28   if (Video::getInstance()->getFormat() == Video::PAL)
29   {
30     setScreenPos(140, 170);
31   }
32   else
33   {
34     setScreenPos(130, 140);
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   // Build gui
45   WButton* wb;
46
47   wb = new WButton();
48   wb->setText("General");
49   wb->setSurface(surface);
50   wb->setSurfaceOffset(160, 70);
51   wb->setDimensions(140, fontHeight);
52   wb->setTag(1);
53   buttons.push_back(wb);
54
55   wb = new WButton();
56   wb->setText("Timers");
57   wb->setSurface(surface);
58   wb->setSurfaceOffset(160, 110);
59   wb->setDimensions(140, fontHeight);
60   wb->setTag(2);
61   buttons.push_back(wb);
62
63   selectedButton = buttons.begin();
64   (*selectedButton)->setActive(1);
65 }
66
67 VOptionsMenu::~VOptionsMenu()
68 {
69   while (!buttons.empty())
70   {
71     delete buttons.back();
72     buttons.pop_back();
73   }
74 }
75
76 void VOptionsMenu::draw()
77 {
78   View::draw();
79
80   vector<WButton*>::iterator i;
81   for(i = buttons.begin(); i != buttons.end(); i++)
82   {
83     (*i)->draw();
84   }
85 }
86
87 int VOptionsMenu::handleCommand(int command)
88 {
89   switch(command)
90   {
91     case Remote::DF_UP:
92     case Remote::UP:
93     {
94       if (selectedButton == buttons.begin()) return 2;
95       (*selectedButton)->setActive(0);
96       selectedButton--;
97       (*selectedButton)->setActive(1);
98       draw(); // fixme - just draw buttons
99       viewman->updateView(this);
100       return 2;
101     }
102     case Remote::DF_DOWN:
103     case Remote::DOWN:
104     {
105       if (selectedButton == (buttons.end() - 1)) return 2;
106       (*selectedButton)->setActive(0);
107       selectedButton++;
108       (*selectedButton)->setActive(1);
109       draw(); // fixme - just draw buttons
110       viewman->updateView(this);
111       return 2;
112     }
113     case Remote::BACK:
114     {
115       return 4;
116     }
117     case Remote::OK:
118     {
119       switch((*selectedButton)->getTag())
120       {
121         case 1: doGeneral();   break;
122         case 2: doTimers();    break;
123       }
124       return 2;
125     }
126   }
127
128   return 1;
129 }
130
131 void VOptionsMenu::processMessage(Message* m)
132 {
133   if (m->message == Message::CHANGED_OPTIONS)
134   {
135     doApplyChanges((map<int,int>*)m->parameter);
136     viewman->removeView(this);
137   }
138 }
139
140 void VOptionsMenu::doApplyChanges(map<int,int>* changedOptions)
141 {
142   Video* video = Video::getInstance();
143   map<int,int>::iterator i;
144
145   for(i = changedOptions->begin(); i != changedOptions->end(); i++)
146   {
147     printf("I FIRST = %i SECOND = %i\n", i->first, i->second);
148
149     switch(i->first)
150     {
151       case 1:
152       {
153         if (i->second == 1)
154         {
155           Log::getInstance()->log("Options", Log::DEBUG, "Setting New Remote");
156           Remote::getInstance()->setRemoteType(Remote::NEWREMOTE);
157         }
158         else
159         {
160           Log::getInstance()->log("Options", Log::DEBUG, "Setting Old Remote");
161           Remote::getInstance()->setRemoteType(Remote::OLDREMOTE);
162         }
163         break;
164       }
165       case 2:
166       {
167         I18n::initialize();
168         VWelcome::getInstance()->redrawLang();
169         break;
170       }
171       case 3:
172       {
173         if (i->second == 1)
174         {
175           Log::getInstance()->log("Options", Log::DEBUG, "Setting S-Video");
176           video->setConnection(Video::SVIDEO);
177         }
178         else
179         {
180           Log::getInstance()->log("Options", Log::DEBUG, "Setting RGB/Composite");
181           video->setConnection(Video::COMPOSITERGB);
182         }
183         break;
184       }
185       case 4:
186       {
187         if (i->second == 1)
188         {
189           Log::getInstance()->log("Options", Log::DEBUG, "Setting 16:9 TV");
190           video->setTVsize(Video::ASPECT16X9);
191         }
192         else
193         {
194           Log::getInstance()->log("Options", Log::DEBUG, "Setting 4:3 TV");
195           video->setTVsize(Video::ASPECT4X3);
196         }
197         break;
198       }
199       case 5:
200       {
201         if (i->second == 1)
202         {
203           Log::getInstance()->log("Options", Log::DEBUG, "Setting letterbox");
204           video->setMode(Video::LETTERBOX);
205         }
206         else
207         {
208           Log::getInstance()->log("Options", Log::DEBUG, "Setting chop-sides");
209           video->setMode(Video::NORMAL);
210         }
211         break;
212       }
213     }
214   }
215
216   delete changedOptions;
217
218 }
219
220 void VOptionsMenu::doGeneral()
221 {
222   static const int numOptions = 8;
223
224   static const char* options1[] = {"Old", "New"};
225   static const char* options3[] = {"RGB+composite", "S-Video"};
226   static const char* options4[] = {"4:3", "16:9"};
227   static const char* options5[] = {"Chop sides", "Letterbox"};
228   static const char* options6[] = {"On", "Off", "Last state"};
229   static const char* options7[] = {"All", "FTA only"};
230
231   const static OPTIONDATA optionData[numOptions] =
232   {
233     {1, "Remote control type",      "General", "Remote type",      OPTIONTYPE_TEXT, 2, 0, 0, options1 },
234     {2, "Language",                 "General", "Language",         OPTIONTYPE_TEXT, I18n::NumLanguages, 0, 0, I18n::Languages },
235     {3, "TV connection type",       "TV",      "Connection",       OPTIONTYPE_TEXT, 2, 0, 0, options3 },
236     {4, "TV aspect ratio",          "TV",      "Aspect",           OPTIONTYPE_TEXT, 2, 0, 0, options4 },
237     {5, "16:9 on 4:3 display mode", "TV",      "Widemode",         OPTIONTYPE_TEXT, 2, 0, 0, options5 },
238     {6, "Power state after bootup", "General", "Power After Boot", OPTIONTYPE_TEXT, 3, 0, 0, options6 },
239     {7, "Display channels",         "General", "Channels",         OPTIONTYPE_TEXT, 2, 0, 0, options7 },
240     {8, "VDR-Pri 0=OK !See forums!","General", "Live priority",    OPTIONTYPE_INT,  100, 0, 0, NULL }
241   };
242
243   // As all the above data is const static, it can be sent to the new View, this stack frame can
244   // quit and the pointers will all still be valid. I think. (Hope).
245
246   VOptions* v = new VOptions(this, "General Options", optionData, numOptions);
247   v->draw();
248   viewman->add(v);
249   viewman->updateView(v);
250 }
251
252
253 void VOptionsMenu::doTimers()
254 {
255   static const int numOptions = 4;
256
257   const static OPTIONDATA optionData[numOptions] =
258   {
259     {9, "Default start margin (minutes)", "Timers", "Start margin",  OPTIONTYPE_INT, 20, 5, 0, NULL },
260     {10, "Default end margin (minutes)",   "Timers", "End margin",    OPTIONTYPE_INT, 20, 5, 0, NULL },
261     {11, "Default priority",               "Timers", "Priority",      OPTIONTYPE_INT, 100, 99, 0, NULL },
262     {12, "Default lifetime",               "Timers", "Lifetime",      OPTIONTYPE_INT, 100, 99, 0, NULL }
263   };
264
265   // As all the above data is const static, it can be sent to the new View, this stack frame can
266   // quit and the pointers will all still be valid. I think. (Hope).
267
268   VOptions* v = new VOptions(this, "Timer Options", optionData, numOptions);
269   v->draw();
270   viewman->add(v);
271   viewman->updateView(v);
272 }